-
Notifications
You must be signed in to change notification settings - Fork 671
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
[Core][Flytekit] support async methods in python #1840
Comments
@bethebunny this was the original issue for async support. I added your example to the main description. Also related is this ticket #2483 |
Hello 👋, This issue has been inactive for over 9 months. To help maintain a clean and focused backlog, we'll be marking this issue as stale and will close the issue if we detect no activity in the next 7 days. Thank you for your contribution and understanding! 🙏 |
Hello 👋, This issue has been inactive for over 9 months and hasn't received any updates since it was marked as stale. We'll be closing this issue for now, but if you believe this issue is still relevant, please feel free to reopen it. Thank you for your contribution and understanding! 🙏 |
@kumare3
thanks @task
async def ensemble(trained_models_and_weights: Dict[ModelID, float]) -> ModelID:
...
@task
async def train_ensemble(models_and_weights: Dict[str, Tuple[float, ModelConfig]) -> ModelID:
responses = await gather([train_model(cfg) for _, cfg in models_and_weights.values()])
return await ensemble({response["model_id"]: weight for response, (weight, _) in zip(responses, models_and_weights.values()}) |
I think this example is wrong and should be @eager - but cc @wild-endeavor as he added that section |
@kumare3 Thanks, I ran the following with current flytekit and seems that the eager version works. @task(enable_deck=True)
async def async_add_one(x: int) -> int:
await asyncio.sleep(7.5)
return x + 1
@eager(
remote=FlyteRemote(
config=Config.auto(),
default_project="flytesnacks",
default_domain="development",
)
)
async def simple_async_workflow(models: list[int] = [1,2,3]) -> list[int]:
coros = [async_add_one(x=x) for x in models]
res = await asyncio.gather(*coros)
return res |
What @task can be async? I guess it is running in sync mode |
Sorry, can you elaborate more on "running in sync mode"? Do you mean that coroutines are executed before awaited or the coroutines didn't execute in parallel? |
Motivating Example 1
Motivation: Why do you think this is important?
It is possible that users may define their tasks as async
Since the invocation of this call is hijacked by flytekit (pyflyte), in the default call pattern -
asyncio.run(foo)
is not invoked.Goal: What should the final outcome look like, ideally?
pyflyte execute - eventually the
execute
method should invoke the underlying task function using asyncio.run, if it is declared to beasync
. This can be detected easily usingCare should be taken to allow all task extensions to use this basic construct.
Also, it is possible that users potentially do no wait for their own downstream tasks. This is not really a problem with flytekit, but Flytekit should do its best to help the users identify the problem.
This can be achieved by listing all pending tasks
Describe alternatives you've considered
It is possible for users to invoke their async methods today
But this is less desirable.
Motivating Example 2
I would love an
async/await
API where there's just tasks which areasync
, and they return a special Promise type which can be awaited to get the real value. As an example, I just wanted to write something likebut because of the way promises are resolved I need to do something like
with
async/await
I could instead write something likeMisc
Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: