Sending an attribute of an object to a remote function through the object ref

How severe does this issue affect your experience of using Ray?

  • Medium: It contributes to significant difficulty to complete my task, but I can work around it.

Hi everyone,

So I have a remote function (2) that I need to give it an attribute of an object, however, I have the object ref of this object since I get it from another remote function (1). I would like to know how I can somehow reference the attribute of the object and send it to function 2, without having to do ray.get().

Minimal example:

class Dummy:
    def __init__(self):
        self.value = 3
dummy = Dummy()
print(dummy.value)
dummy_ref = ray.put(dummy)

@ray.remote
def get_value(value):
    return value

value_ref = get_value.remote(dummy_ref.value)

I know that I can modify get_value to take the object reference, but I can’t do that in my code.

# As I requirement of my code doing this is not possible, or will break a lot of the abstraction that I have
@ray.remote
def get_value(obj):
    return obj.value

It’s not possible to reference the attribute from the object ref without calling ray.get. Why can’t you use ray.get here? If your object is zero-copyable, the overhead should be small. Otherwise, you can probably make the “value” itself a reference.

class Dummy:
    def __init__(self):
        self.value = ray.put(3)
dummy = Dummy()
print(dummy.value)

@ray.remote
def get_value(value):
    return value

value_ref = get_value.remote(dummy.value)
1 Like