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

Support async predictors (✨ updated ✨) #2010

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

meatballhat
Copy link
Contributor

@meatballhat meatballhat commented Oct 21, 2024

which is #1896 with main merged in with conflicts resolved plus fixes to get tests happy. I don't want to replace #1896 outright since it provides a much more easily digestible group of commits. If this PR is deemed acceptable and merged, then I think we can safely delete #1896.

Connected to PLAT-259

nickstenning and others added 5 commits August 23, 2024 18:48
First steps towards allowing `async def predict` method signatures. This
commit adds support to Worker for starting an `asyncio` event loop if
the `predict` function returns an awaitable or an async generator.

For now, we drop support for output capture as well as cancelation.
In an async context, attempting to intercept stream writes at the file
descriptor layer is futile. We can do it, but we will have no way of
associating a write made from native code with a specific prediction --
and the only reason to intercept/swap out the STDOUT/STDERR file
descriptors is so that we can catch writes from native code.

This commit adds an altogether simpler implementation which can work for
async code with that restriction. All it does is patch `sys.stdout` and
`sys.stderr` with objects that can redirect (or tee) the output to a
callback function.
This implements basic cancelation for async predictors. Whereas regular
predictors implement cancelation using a custom CancelationException,
asyncio already has a concept of task cancelation, so we use that.

When cancelation is requested, we send a `Cancel()` event down the
events pipe to the child. Regular predictors ignore these, but async
predictors cancel the currently-running task when they receive one.

In future, these `Cancel()` events will specify which running prediction
they are intended to cancel.
When a `Shutdown()` event is sent, any running prediction should be
allowed to completed.

For now, we implement this by awaiting any task that is tracked when we
break out of the child worker's event loop.
@meatballhat meatballhat changed the title Support async predictors merged Support async predictors merging main Oct 22, 2024
@meatballhat meatballhat changed the base branch from main to support-async-predictors October 22, 2024 18:43
@meatballhat meatballhat changed the base branch from support-async-predictors to main October 22, 2024 18:43
@meatballhat meatballhat marked this pull request as ready for review October 22, 2024 18:54
@meatballhat meatballhat changed the title Support async predictors merging main Support async predictors (✨ updated ✨) Oct 22, 2024
@evilstreak evilstreak force-pushed the support-async-predictors-merged branch from 88568d9 to eedac64 Compare October 23, 2024 12:26
meatballhat and others added 2 commits October 23, 2024 14:12
- Use renamed _ChildWorker type
- Set initial `__url__` to `None` prior to URL parsing potentially
  throwing `ValueError`
- Declare `pid` field in `FakeChildWorker`
- Do not use nested redirectors
@evilstreak evilstreak force-pushed the support-async-predictors-merged branch from 8c73c7a to 2830d4d Compare October 23, 2024 13:12
@evilstreak evilstreak merged commit a86adcd into main Oct 23, 2024
20 checks passed
@evilstreak evilstreak deleted the support-async-predictors-merged branch October 23, 2024 14:11
meatballhat added a commit that referenced this pull request Oct 24, 2024
meatballhat added a commit that referenced this pull request Oct 25, 2024
meatballhat added a commit that referenced this pull request Oct 25, 2024
meatballhat added a commit that referenced this pull request Oct 28, 2024
meatballhat added a commit that referenced this pull request Oct 28, 2024
meatballhat added a commit that referenced this pull request Oct 29, 2024
* Revert "Revert "Support async predictors (#2010)" (#2022)"

This reverts commit 8333a83.

* Use anync stream redirector in setup

so that the sync stream redirector context is only entered once, as this
is a known source of problems associated with stdout/stderr orphaning.

* Do not assert that writes from C are captured during setup

* Do not wrap empty data in Log events

* Exclude invalid output paths from infrastructure errors (#2030)

* Exclude invalid output paths from infrastructure errors

Closes PLAT-380

* Fix words given pluralization

Co-authored-by: F <f@replicate.com>
Signed-off-by: Dan Buch <dan@meatballhat.com>

---------

Signed-off-by: Dan Buch <dan@meatballhat.com>
Co-authored-by: F <f@replicate.com>

---------

Signed-off-by: Dan Buch <dan@meatballhat.com>
Co-authored-by: F <f@replicate.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants