最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Ray ObjectRef automatically collected and deserialised? - Stack Overflow

programmeradmin1浏览0评论

I have Ray actors who interact with each other, one generates a numpy array, When I collect the object reference and send it to another actor, it seems to deserialize automatically.

See the following for context:

sp_refs = [sp.self_play.remote() for _ in range(GAMES_TOTAL)]
buffer_refs = []
start_time = time.time()
# ? Preload the ReplayBuffer

print(f"Number of Jobs Running: {len(sp_refs)=}")
while sp_refs:
     complete, sp_refs = ray.wait(sp_refs)
     print(f"{complete=}")
     buffer.add.remote(complete)
     for r in complete:
         buffer_refs.append(buffer.add.remote(r))

buffers add code is:

    def add(self, experience: ray.ObjectRef):
        print(f"{experience} - add function")
        print(f"{type(experience)=}")
        print(f"{type(experience[0])}")
        data = ray.get(experience)
        print(data)
        print(type(data))
        assert False

which gives the following output:

ValueError: Invalid type of object refs, <class 'numpy.ndarray'>, is given. 'object_refs' must either be an ObjectRef or a list of ObjectRefs.
(ReplayBuffer pid=527599) [ObjectRef(f91b78d7db9a659302e1adadcf69844dfe0a8bc60100000001000000)] - add function
(ReplayBuffer pid=527599) type(experience)=<class 'list'>
(ReplayBuffer pid=527599) <class 'ray._raylet.ObjectRef'>
(ReplayBuffer pid=527599) [array([[1.000e+00, 1.000e+00, 1.000e+00, ..., 0.000e+00, 1.829e+03,
(ReplayBuffer pid=527599)         0.000e+00],
(ReplayBuffer pid=527599)        [1.000e+00, 1.000e+00, 1.000e+00, ..., 0.000e+00, 1.837e+03,
(ReplayBuffer pid=527599)         0.000e+00],
(ReplayBuffer pid=527599)        [1.000e+00, 1.000e+00, 1.000e+00, ..., 0.000e+00, 2.997e+03,
(ReplayBuffer pid=527599)         0.000e+00],
(ReplayBuffer pid=527599)        ...,
(ReplayBuffer pid=527599)        [0.000e+00, 0.000e+00, 0.000e+00, ..., 0.000e+00, 4.105e+03,
(ReplayBuffer pid=527599)         0.000e+00],
(ReplayBuffer pid=527599)        [0.000e+00, 0.000e+00, 0.000e+00, ..., 0.000e+00, 3.510e+03,
(ReplayBuffer pid=527599)         0.000e+00],
(ReplayBuffer pid=527599)        [0.000e+00, 0.000e+00, 0.000e+00, ..., 0.000e+00, 2.358e+03,
(ReplayBuffer pid=527599)         0.000e+00]])]
(ReplayBuffer pid=527599) <class 'list'>
(ReplayBuffer pid=527599) [[1.000e+00 1.000e+00 1.000e+00 ... 0.000e+00 1.829e+03 0.000e+00]
(ReplayBuffer pid=527599)  [1.000e+00 1.000e+00 1.000e+00 ... 0.000e+00 1.837e+03 0.000e+00]
(ReplayBuffer pid=527599)  [1.000e+00 1.000e+00 1.000e+00 ... 0.000e+00 2.997e+03 0.000e+00]
(ReplayBuffer pid=527599)  ...
(ReplayBuffer pid=527599)  [0.000e+00 0.000e+00 0.000e+00 ... 0.000e+00 4.105e+03 0.000e+00]
(ReplayBuffer pid=527599)  [0.000e+00 0.000e+00 0.000e+00 ... 0.000e+00 3.510e+03 0.000e+00]
(ReplayBuffer pid=527599)  [0.000e+00 0.000e+00 0.000e+00 ... 0.000e+00 2.358e+03 0.000e+00]] - add function
(ReplayBuffer pid=527599) type(experience)=<class 'numpy.ndarray'>
(ReplayBuffer pid=527599) <class 'numpy.ndarray'>

Note, this is only one object. We can also see that the function has in essence been called twice, once on the object ref, and then again on the actual list (containing the array) which then fails at.

        data = ray.get(experience)

Anyone know why?

发布评论

评论列表(0)

  1. 暂无评论