0

If I understand correctly the following piece of code should run in parallel

@ray.remote
class Worker:
  ...

  def train(self, item, i):
    time.sleep(i)
    logging.info(f'{i} {item}')
...

worker = Worker.remote()
list = ['a', 'b', 'c']
results = ray.get([worker.train.remote(item, len(list) - idx) for idx, item in enumerate(list)])
print(results)
logging.info("successful print")

This should output

1 c
2 b
3 a
[1,2,3]

However, this outputs:

3 a
2 b
[3,2,1]

I am new to using ray and am unable to understand this behaviour. If anyone could point me towards the right direction, that'd be great!

pleasehalp
  • 136
  • 7

1 Answers1

0

Actor is running within a single process. As a result, worker.train.remote() will be synchronous.

Sang
  • 885
  • 5
  • 4
  • I am not sure I understand. I was under the impression that ray.remote decorator created actors and that when invoking func.remote, it would trigger parallel executions of the actors. – pleasehalp Feb 28 '20 at 07:07
  • Check this out. https://ray.readthedocs.io/en/latest/walkthrough.html#remote-classes-actors This mentions `Each actor runs in its own Python process`. – Sang Mar 04 '20 at 17:19