-
Notifications
You must be signed in to change notification settings - Fork 6k
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] Dynamic generators that error return partial ObjectRefs followed by exception ObjectRef #28864
Conversation
@@ -69,18 +69,28 @@ We can also pass the ``ObjectRef`` returned by a task with ``num_returns="dynami | |||
:start-after: __dynamic_generator_pass_start__ | |||
:end-before: __dynamic_generator_pass_end__ | |||
|
|||
Limitations | |||
----------- | |||
Exception handling and limitations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we separate "Exception handling" and "Limitations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, good point.
|
||
Although a generator function creates ``ObjectRefs`` one at a time, currently Ray will not schedule dependent tasks until the entire task is complete and all values have been created. This is similar to the semantics used by tasks that return multiple values as a list. | ||
|
||
``num_returns="dynamic"`` is not yet supported for actor tasks. | ||
|
||
If a generator function raises an exception before yielding all its values, all values returned by the generator will be replaced by the exception traceback, including values that were already successfully yielded. | ||
If the task was called with ``num_returns="dynamic"``, the exception will be stored in the ``ObjectRef`` returned by the task instead of the usual ``ObjectRefGenerator``. | ||
If a generator function raises an exception before yielding all its values, the values that it already stored will still be accessible through their ``ObjectRefs``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a static generator function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually for both static and dynamic ones. I can make this clearer.
…ed by exception ObjectRef (ray-project#28864) Previously if a dynamic generator task errored, we would store the error as the top-level ObjectRef, which could lead to a leak of any objects already stored, since the ObjectRefs are never returned to Python. This PR improves usability by storing the exception as an additional final ObjectRef returned by the generator (see included examples in docs code). All successfully stored objects will still be returned by the generator as usual. Updated some tests to match this new behavior. Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Why are these changes needed?
Previously if a dynamic generator task errored, we would store the error as the top-level ObjectRef, which could lead to a leak of any objects already stored, since the ObjectRefs are never returned to Python.
This PR improves usability by storing the exception as an additional final ObjectRef returned by the generator (see included examples in docs code). All successfully stored objects will still be returned by the generator as usual. Updated some tests to match this new behavior.
Related issue number
Part 1 of #28686:
Handles application-level errors: we now make the partially stored ObjectRefs visible to the application.
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.