Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polish(zms): add log #377

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ding/framework/middleware/league_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _on_learner_model(self, learner_model: "LearnerModel"):
"""
If get newest learner model, put it inside model_queue.
"""
print('Actor {} recieved model \n'.format(task.router.node_id), flush=True)
print('Actor {} recieved model {} \n'.format(task.router.node_id, learner_model.player_id), flush=True)
with self.model_dict_lock:
self.model_dict[learner_model.player_id] = learner_model

Expand Down Expand Up @@ -252,7 +252,7 @@ def __call__(self, ctx: "BattleContext"):
job = self._get_job()
if job is None:
return
print('For actor {}, a job begin \n'.format(task.router.node_id), flush=True)
print('For actor {}, a job {} begin \n'.format(task.router.node_id, job.launch_player), flush=True)

ctx.player_id_list = [player.player_id for player in job.players]
self.agent_num = len(job.players)
Expand Down
10 changes: 5 additions & 5 deletions ding/framework/middleware/league_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, league: "BaseLeague") -> None:
task.on(EventEnum.ACTOR_FINISH_JOB, self._on_actor_job)

def _on_actor_greeting(self, actor_id):
print('coordinator recieve actor greeting\n', flush=True)
print('coordinator recieve actor {} greeting\n'.format(actor_id), flush=True)
with self._lock:
player_num = len(self.league.active_players_ids)
player_id = self.league.active_players_ids[self._total_send_jobs % player_num]
Expand All @@ -37,22 +37,22 @@ def _on_actor_greeting(self, actor_id):
if job.job_no > 0 and job.job_no % self._eval_frequency == 0:
job.is_eval = True
job.actor_id = actor_id
print('coordinator emit job\n', flush=True)
print('coordinator emit job (main_player: {}) to actor {}\n'.format(job.launch_player, actor_id), flush=True)
task.emit(EventEnum.COORDINATOR_DISPATCH_ACTOR_JOB.format(actor_id=actor_id), job)

def _on_learner_meta(self, player_meta: "PlayerMeta"):
print('coordinator recieve learner meta\n', flush=True)
print('coordinator recieve learner meta for player{}\n'.format(player_meta.player_id), flush=True)
# print("on_learner_meta {}".format(player_meta))
self.league.update_active_player(player_meta)
self.league.create_historical_player(player_meta)

def _on_actor_job(self, job: "Job"):
print('coordinator recieve actor finished job\n', flush=True)
print('coordinator recieve actor finished job, palyer {}\n'.format(job.launch_player), flush=True)
print("on_actor_job {}".format(job.launch_player)) # right
self.league.update_payoff(job)

def __del__(self):
print('task finished, coordinator closed', flush=True)
print('task finished, coordinator {} closed'.format(task.router.node_id), flush=True)

def __call__(self, ctx: "Context") -> None:
sleep(1)
Expand Down
8 changes: 4 additions & 4 deletions ding/framework/middleware/league_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, cfg: dict, policy_fn: Callable, player: "ActivePlayer") -> No
self._step = 0

def _on_actor_send_data(self, actor_data: "ActorData"):
print("learner receive data from actor! \n", flush=True)
print("learner {} receive data from actor! \n".format(task.router.node_id), flush=True)
with self._lock:
cfg = self.cfg
for _ in range(cfg.policy.learn.update_per_collect):
Expand All @@ -50,7 +50,7 @@ def _on_actor_send_data(self, actor_data: "ActorData"):
# print("save checkpoint")
checkpoint = self._save_checkpoint() if self.player.is_trained_enough() else None

print('learner send player meta\n', flush=True)
print('learner {} send player meta {}\n'.format(task.router.node_id, self.player_id), flush=True)
task.emit(
EventEnum.LEARNER_SEND_META,
PlayerMeta(player_id=self.player_id, checkpoint=checkpoint, total_agent_step=self._learner.train_iter)
Expand All @@ -60,7 +60,7 @@ def _on_actor_send_data(self, actor_data: "ActorData"):
learner_model = LearnerModel(
player_id=self.player_id, state_dict=self._learner.policy.state_dict(), train_iter=self._learner.train_iter
)
print('learner send model\n', flush=True)
print('learner {} send model\n'.format(task.router.node_id), flush=True)
task.emit(EventEnum.LEARNER_SEND_MODEL, learner_model)

def _get_learner(self) -> BaseLearner:
Expand All @@ -84,7 +84,7 @@ def _save_checkpoint(self) -> Optional[Storage]:
return storage

def __del__(self):
print('task finished, learner closed', flush=True)
print('task finished, learner {} closed\n'.format(task.router.node_id), flush=True)

def __call__(self, _: "Context") -> None:
sleep(1)
Expand Down