_owner parameter for ray.put

Hi, I don’t quite get the docstring of _owner parameter in ray.put (link). What would a scenario of its usage be? Is there any example on this?

Thanks in advance!

When you call ray.put, the current ray worker will be the owner of the object and when the worker exits, the object will be lost.

Suppose you have a long-running actor and you set the owner of the object to be the actor, then, even the worker exits, the object will still be there.

Suppose the following scenario

...
@ray.remote
class Foo
    ...

owner = Foo.remote()

@ray.remote
def foo():
    o_ref = ray.put(1, _owner=owner)


foo.remote()
...

How can I get the o_ref from the owner?

It’s just about specifying the owner, nothing else. Could you check the ownership model in the white paper?

To answer your question, there is no way for you to get o_ref from the owner. It’s all about lifetime, nothing else. Basically, o_ref will be alive as long as owner is alive.

Thanks for pointing to the docs! I think it would good to make it possible to get the o_ref from the owner with some way. IIRC, something related have been discussed in Creating objref from manually created object-id and [core] Support detached/GCS owned objects · Issue #12635 · ray-project/ray · GitHub. Are there any plans/thoughts to support a feature of getting the o_ref from the owner?

If you like to get it from the owner, you can pass it explicitly to the owner back. For example:

@ray.remote
class Actor:
  def __init__(self):
      self._obj_refs = []
  def save(self, obj)
     self._obj_refs.append(obj[0])


a = Actor.remote()

a.save([ray.put("Hello World", _owner = a)])

I don’t think we’ll support creating objref from manually created object-id. It brings a lot of complexity for safety guarantee.

Btw, the detached/gcs owned objects means assign the owner to gcs. It has nothing to do with getting o_ref from the owner.

I see, thanks a lot!