anyscale / academy

Ray tutorials from Anyscale
https://anyscale.com
Apache License 2.0
567 stars 195 forks source link

May I ask why ray remote can not send dict? #108

Open lucasjinreal opened 1 year ago

lucasjinreal commented 1 year ago

I have a gather Actor which takes all outputs of previous Actor:

@ray.remote
class GatherAll:

    def __init__(self) -> None:
        pass

    # def infer(self, hands, kpts):
    #     if hands.shape[0] > kpts.shape[0]:
    #         out = hands.copy()
    #         out[:kpts.shape[0], :] += kpts[..., :4]
    #         return out
    #     else:
    #         out = kpts.copy()[..., :4]
    #         out[:hands.shape[0], :] += hands
    #         return out

    def infer(self, datas):
        hands = datas['a']
        kpts = datas['b']
        if hands.shape[0] > kpts.shape[0]:
            out = hands.copy()
            out[:kpts.shape[0], :] += kpts[..., :4]
            return out
        else:
            out = kpts.copy()[..., :4]
            out[:hands.shape[0], :] += hands
            return out

the uncommented parts not work, which I call it in dict:

# out = G.infer.remote(hands, kpts)
out = G.infer.remote({'a': hands, 'b': kpts})

Get error:

AttributeError: 'ray._raylet.ObjectRef' object has no attribute 'shape'

Why using separated is OK, but dictionary is not ? Very confused here.

lucasjinreal commented 1 year ago

There are plenty scenarios need sending dict since this is more flexible and can be scaled to any data pack. Otherwise in case I have 1000 outputs, I need send them 1000 function params? That is redicoules.