I would like to let multiple actors work collaboratively on collective operations, such as reductions. A difficult part of this is to get object-references that other actors created (or will create) without extra tasks or alike.
A relatively straight-forward solution would be to allow programmers the creation an objref from a user-provided id. This objref could then be used on any actor without additional tasks/communication. Of course only one actor would be allowed to put the actual object related to the objref.
Here’s a very simple example of what I would like to do:
@ray.remote class reducer: "reduction class, each actor holds one block" def __init__(self, block): self.block = block def reduce(op): "collaboratively reduce blocks on n actors to a single value" # first reduce my block locally l_res = self.block.reduce(op, n) # now form a tree to iteratively reduce all local values n /= 2 while n: if block.id >= n: ray.put(local, block.id) break else: # we know the id of the other value and make a objref from it other = ray.get(ray.make_objref(n*2)) l_res = op(local, other) n /= 2 return l_res if block.id == 0 else None def foo(blocks): "use the reducer" n = len(blocks) acts = [reducer.remote(b) for b in blocks] # trigger reduction and assign obj-ids to results reduced = [a.reduce.options(obj_id=n+i).remote(sum, n) for i,a in enumerate(acts)] x = ray.get(ray.make_objref(n)) # equivalent to x = ray.get(reduced)
I know a reduction can be formulated in ray right now in a different way which some might consider simpler and/or better. The above is just for illustration and a traditional ray-remote formulation will not address the issue. You could view this as a request to mimic SPMD-like or message-passing style programming.