MCPcopy Create free account
hub / github.com/pytorch/examples / run_worker

Function run_worker

distributed/rpc/batch/reinforce.py:220–241  ·  view source on GitHub ↗

r""" This is the entry point for all processes. The rank 0 is the agent. All other ranks are observers.

(rank, world_size, n_episode, batch, print_log=True)

Source from the content-addressed store, hash-verified

218
219
220def run_worker(rank, world_size, n_episode, batch, print_log=True):
221 r"""
222 This is the entry point for all processes. The rank 0 is the agent. All
223 other ranks are observers.
224 """
225 os.environ['MASTER_ADDR'] = 'localhost'
226 os.environ['MASTER_PORT'] = '29500'
227 if rank == 0:
228 # rank0 is the agent
229 rpc.init_rpc(AGENT_NAME, rank=rank, world_size=world_size)
230
231 agent = Agent(world_size, batch)
232 for i_episode in range(n_episode):
233 last_reward, running_reward = agent.run_episode(n_steps=NUM_STEPS)
234
235 if print_log:
236 print(f'Episode {i_episode}\tLast reward: {last_reward:.2f}\tAverage reward: {running_reward:.2f}')
237 else:
238 # other ranks are the observer
239 rpc.init_rpc(OBSERVER_NAME.format(rank), rank=rank, world_size=world_size)
240 # observers passively waiting for instructions from agents
241 rpc.shutdown()
242
243
244def main():

Callers

nothing calls this directly

Calls 2

run_episodeMethod · 0.95
AgentClass · 0.70

Tested by

no test coverage detected