浏览代码

Remove empty_queue interface

/develop/sac-apex
Ervin Teng 5 年前
当前提交
d1fed8ae
共有 5 个文件被更改,包括 18 次插入21 次删除
  1. 7
      ml-agents/mlagents/trainers/agent_processor.py
  2. 16
      ml-agents/mlagents/trainers/ghost/trainer.py
  3. 10
      ml-agents/mlagents/trainers/trainer/rl_trainer.py
  4. 4
      ml-agents/mlagents/trainers/trainer/trainer.py
  5. 2
      ml-agents/mlagents/trainers/trainer_controller.py

7
ml-agents/mlagents/trainers/agent_processor.py


"""
return self._behavior_id
def qsize(self) -> int:
"""
Returns the approximate size of the queue. Note that values may differ
depending on the underlying queue implementation.
"""
return self._queue.qsize()
def empty(self) -> bool:
return self._queue.empty()

16
ml-agents/mlagents/trainers/ghost/trainer.py


self.change_current_elo(change)
self._stats_reporter.add_stat("Self-play/ELO", self.current_elo)
def advance(self, empty_queue: bool = False) -> None:
def advance(self) -> None:
"""
Steps the trainer, passing trajectories to wrapped trainer and calling trainer advance
"""

# We grab at most the maximum length of the queue.
# This ensures that even if the queue is being filled faster than it is
# being emptied, the trajectories in the queue are on-policy.
for _ in range(trajectory_queue.maxlen):
t = trajectory_queue.get(block=not empty_queue, timeout=0.05)
for _ in range(trajectory_queue.qsize()):
t = trajectory_queue.get(block=False)
if not empty_queue:
break
for _ in range(trajectory_queue.maxlen):
t = trajectory_queue.get(block=not empty_queue, timeout=0.05)
for _ in range(trajectory_queue.qsize()):
t = trajectory_queue.get(block=False)
if not empty_queue:
break
self.trainer.advance(empty_queue=empty_queue)
self.trainer.advance()
if self.get_step - self.last_team_change > self.steps_to_train_team:
self.controller.change_training_team(self.get_step)
self.last_team_change = self.get_step

10
ml-agents/mlagents/trainers/trainer/rl_trainer.py


if step_after_process >= self.next_summary_step and self.get_step != 0:
self._write_summary(self.next_summary_step)
def advance(self, empty_queue: bool = False) -> None:
def advance(self) -> None:
:param empty_queue: Whether or not to empty the queue when called. For synchronous
operation, we need to do so to avoid the queue filling up.
"""
with hierarchical_timer("process_trajectory"):
for traj_queue in self.trajectory_queues:

for _ in range(traj_queue.maxlen):
for _ in range(traj_queue.qsize()):
t = traj_queue.get(block=not empty_queue, timeout=0.05)
t = traj_queue.get(block=False)
if not empty_queue:
break
except AgentManagerQueue.Empty:
break
if self.should_still_train:

4
ml-agents/mlagents/trainers/trainer/trainer.py


pass
@abc.abstractmethod
def advance(self, empty_queue: bool = False) -> None:
def advance(self) -> None:
:param empty_queue: Whether or not to empty the queue when called. For synchronous
operation, we need to do so to avoid the queue filling up.
"""
pass

2
ml-agents/mlagents/trainers/trainer_controller.py


if not self.threaded:
with hierarchical_timer("trainer_advance"):
for trainer in self.trainers.values():
trainer.advance(empty_queue=True)
trainer.advance()
return num_steps

正在加载...
取消
保存