From 5d422d6f22874ace9ca62291de6e14fb801b7969 Mon Sep 17 00:00:00 2001 From: hiha3456 <744762298@qq.com> Date: Thu, 16 Jun 2022 13:58:00 +0800 Subject: [PATCH] add log --- ding/framework/middleware/league_actor.py | 4 ++-- ding/framework/middleware/league_coordinator.py | 10 +++++----- ding/framework/middleware/league_learner.py | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ding/framework/middleware/league_actor.py b/ding/framework/middleware/league_actor.py index 39228ecc36..66b978f545 100644 --- a/ding/framework/middleware/league_actor.py +++ b/ding/framework/middleware/league_actor.py @@ -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 @@ -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) diff --git a/ding/framework/middleware/league_coordinator.py b/ding/framework/middleware/league_coordinator.py index 43300d8711..ec85766a8d 100644 --- a/ding/framework/middleware/league_coordinator.py +++ b/ding/framework/middleware/league_coordinator.py @@ -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] @@ -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) diff --git a/ding/framework/middleware/league_learner.py b/ding/framework/middleware/league_learner.py index af7ec59039..cb02eb25e6 100644 --- a/ding/framework/middleware/league_learner.py +++ b/ding/framework/middleware/league_learner.py @@ -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): @@ -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) @@ -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: @@ -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)