Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example of how to use BatchSize #980

Merged
merged 6 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cookbook/core/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ docstring-parser==0.15
# via flytekit
executing==1.2.0
# via stack-data
flyteidl==1.3.11
flyteidl==1.3.18
# via flytekit
flytekit==1.4.1
flytekit==1.5.0
# via
# -r ../common/requirements-common.in
# flytekitplugins-deck-standard
Expand Down
28 changes: 28 additions & 0 deletions cookbook/core/type_system/flyte_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ def welcome(name: str) -> People:
the custom object (People) will be marshalled to and from python pickle.
"""
welcome(name="Foo")


# %%
# By default, if the list subtype is unrecognized, a single pickle file is generated.
# To also improve serialization and deserialization performance for cases with millions of items or large list items,
# users can specify a batch size, processing each batch as a separate pickle file.
# Example below shows how users can set batch size.
from flytekit.types.pickle.pickle import BatchSize
from typing import List
from typing_extensions import Annotated

@task
def greet_all(names: List[str]) -> Annotated[List[People],BatchSize(2)]:
return [People(name) for name in names]


@workflow
def welcome_all(names: List[str]) -> Annotated[List[People],BatchSize(2)]:
return greet_all(names=names)


if __name__ == "__main__":
"""
In this example, two pickle files will be generated:
- One containing two People objects
- One containing one People object
"""
welcome_all(names=["f","o","o"])