-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Allow manually writing to return ObjectIDs from tasks/actor methods #3805
Allow manually writing to return ObjectIDs from tasks/actor methods #3805
Conversation
Test PASSed. |
Test PASSed. |
Personally I think adding a test in this case would be helpful. If it's not intended for general purpose usage, how about adding it to |
Adding the API to |
|
@raulchen Adding a Using the decorator |
I agree that we should just make the task object accessible (through implementation details and not an API for the time being) and get rid of @ray.remote
def f():
return_ids = ray.worker.global_worker.task_context.task.returns() Note that this should allow us to remove a bunch of fields like This is not a real API yet, it's just an experimental hack to try things out. @raulchen Note that something like @ray.remote(num_return_vals=3)
def f():
return_ids = ray.worker.global_worker.task_context.task.returns()
ray.worker.global_worker.put_object(return_ids[1], 222)
return 1, ray.worker.RayNoReturn(), 3 @pschafhalter I think Minor comment: |
@pschafhalter could you add some tests including the following cases.
What should the behavior be in the following cases? Please also add tests for these.
|
@robertnishihara I don't think so. Because Regarding |
@raulchen, returning things earlier could be one reason, however, there are some situations where it isn't possible to return the object from the function. For example, suppose that I have an actor method that runs a TensorFlow graph, and the graph takes an object ID as input and actually stores its output directly in the plasma store using the object ID (we do this in the SGD implementation). What you're proposing could certainly work during regular execution, but if we lose the object, and somebody calls |
@robertnishihara thanks, that makes sense. |
Let's do the following
|
Test FAILed. |
40d54da
to
c2f62e5
Compare
Test PASSed. |
Test PASSed. |
Test PASSed. |
Test FAILed. |
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.
@pschafhalter nice work! This looks pretty good :) I left some comments.
Note that I removed the pytest timing stuff because I think it's important to run the tests even if pytest timing is not installed. Also, any test in the codebase could hang if there are bugs, so that isn't unique to these tests.
@@ -790,7 +792,6 @@ def _store_outputs_in_object_store(self, object_ids, outputs): | |||
if isinstance(outputs[i], ray.actor.ActorHandle): | |||
raise Exception("Returning an actor handle from a remote " | |||
"function is not allowed).") | |||
|
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.
What about having an
if outputs[i] is ray.experimental.NoReturn:
if not self.plasma_client.contains(object_ids[i]):
raise Exception("Attempting to return 'ray.experimental.NoReturn' from a remote function, but the corresponding ObjectID does not exist in the local object store.")
not actually Exception
, something more specific should be used.
The only issue I can think of is if the task is a long-running task and the object ends up getting evicted before the task returns..
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.
I ended up using a ValueError
for this. Do you think that's specific enough?
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.
Changed to RuntimeError because ValueError seems to be intended for the case where an argument to a function has the right type but the wrong value.
Test PASSed. |
Test FAILed. |
@robertnishihara thanks for the feedback! It should be addressed in the latest commit. |
Test PASSed. |
Test FAILed. |
Test PASSed. |
Test PASSed. |
Test PASSed. |
Test PASSed. |
What do these changes do?
Allows manually writing to return ObjectIDs from tasks and actor methods.
Implements the
ray.worker.Worker.return_object_ids
property which provides the list of ObjectIDs returned by the current task/actor method.Also adds the
ray.worker.RayNoReturn
class which when returned signals not to store the return value in the object store .This works for tasks:
As well as actors: