-
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
Add experimental API for ray.get and ray.wait with additional argument types #2071
Conversation
Test PASSed. |
6b7126d
to
062eb48
Compare
This seems like a good idea, some comments/questions:
|
Test PASSed. |
I will also update other methods to support this once the types are finalized (e.g. Additional question: Does it make sense to handle Iterables passed into |
@kunalgosar some questions. What are the types that you think are important to support? Lists and tuples make a lot of sense. Maybe numpy arrays? Does anything else make sense? I'm still unsure about whether the return container type should match the input container type.. We could make this change for Let's not change |
I agree it makes sense to support lists and tuples. I would also add in numpy arrays and dictionaries. For the return type, I think that all of these could return just lists, except dictionaries, where is might make sense to return a dict back as well. The types for ray.wait should probably follow the same as ray.get. It would definitely be hard to change ray.put, without adding a parameter for num_vals or something similar. I won't change this here. |
062eb48
to
a0332cc
Compare
python/ray/experimental/worker.py
Outdated
.format(threading.current_thread().getName())) | ||
|
||
|
||
def get(object_ids, worker=None): |
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.
@robertnishihara: The function names here can be changed, if needed. I was unsure what to call them so have kept it as get
and wait
for now.
Test PASSed. |
Test PASSed. |
This passes on Private travis. |
@kunalgosar, instead of reimplementing We shouldn't need to duplicate |
92e476f
to
5e0e15e
Compare
Test PASSed. |
Test PASSed. |
@robertnishihara I've addressed the above comment and the test failures are unrelated. |
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.
Thanks! This looks pretty good. Left some comments.
python/ray/experimental/worker.py
Outdated
|
||
def get(object_ids, worker=None): | ||
"""Get a remote object or a collection of remote objects from the object | ||
store. |
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.
the first doc line should fit on a single line
python/ray/experimental/worker.py
Outdated
def get(object_ids, worker=None): | ||
"""Get a remote object or a collection of remote objects from the object | ||
store. | ||
|
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.
Could you add a note explaining how this differs from ray.get
. The block below is probably not necessary, since you can assume people know how ray.get
works.
python/ray/experimental/worker.py
Outdated
if isinstance(object_ids, (list, tuple, np.ndarray)): | ||
# There is a dependency on ray.worker which prevents importing | ||
# global_worker at the top of this file | ||
return ray.get(list(object_ids)) if worker is None else \ |
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.
this worker is None
appears a number of times, can we just do
worker = ray.worker.global_worker if worker is None else worker
once at the beginning of this function?
python/ray/experimental/worker.py
Outdated
return ray.get(list(object_ids)) if worker is None else \ | ||
ray.get(list(object_ids), worker) | ||
elif isinstance(object_ids, dict): | ||
to_get = [ |
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 think this can be simplified, maybe something like
keys_to_get = [k for k, v in object_ids.items() if isinstance(v, ray.ObjectID)]
ids_to_get = [v for k, v in object_ids.items() if isinstance(v, ray.ObjectID)]
values = ray.get(ids_to_get)
result = object_ids.copy()
for key, value in zip(keys_to_get, values):
result[key] = value
python/ray/experimental/worker.py
Outdated
result[key] = val | ||
return result | ||
else: | ||
return ray.get(object_ids) if worker is None else \ |
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.
In this file, let's avoid using \
. If multiline things are necessary, let's do
return (ray.get(object_ids) if worker is None
else ray.get(object_ids, worker))
python/ray/experimental/worker.py
Outdated
def wait(object_ids, num_returns=1, timeout=None, worker=None): | ||
"""Return a list of IDs that are ready and a list of IDs that are not. | ||
|
||
If timeout is set, the function returns either when the requested number of |
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'd suggest explaining documenting this function primarily by explaining the difference from ray.wait
.
python/ray/experimental/worker.py
Outdated
@@ -0,0 +1,78 @@ | |||
from __future__ import absolute_import |
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.
Let's change this filename to be api.py
55036f9
to
b38f8ad
Compare
@robertnishihara thanks for taking a look! I've resolved the above comments. |
Test FAILed. |
Jenkins, retest this please |
Test FAILed. |
Jenkins, retest this please |
Test PASSed. |
Looks good to me, thanks! |
@robertnishihara I think the "right sort of iterable" for this problem is actually pretty hard to express in Python. We want an iterable that contains only concrete types that is not itself a concrete type (which rules out strings). Dicts would require special handling to support, but this covers all the "flat" types like ndarrays, lists, sets (though order would be a sticking point there), and tuples. |
What do these changes do?
This adds in an experimental API to allow
ray.experimental.get
to take in lists, tuples, ndarrays or dicts. It also allowsray.experimental.wait
to take in lists, tuples or ndarrays.