浏览代码

[Bug fix] Hard reset when team changes (#3870)

/develop/dockerfile
GitHub 5 年前
当前提交
4092d937
共有 6 个文件被更改,包括 631 次插入425 次删除
  1. 26
      Project/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab
  2. 1001
      Project/Assets/ML-Agents/Examples/Tennis/TFModels/Tennis.nn
  3. 13
      ml-agents/mlagents/trainers/ghost/controller.py
  4. 3
      ml-agents/mlagents/trainers/tests/simple_test_envs.py
  5. 9
      ml-agents/mlagents/trainers/tests/test_trainer_controller.py
  6. 4
      ml-agents/mlagents/trainers/trainer_controller.py

26
Project/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab


m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 9
numStackedVectorObservations: 3
vectorActionSize: 03000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
VectorObservationSize: 9
NumStackedVectorObservations: 3
VectorActionSize: 03000000
VectorActionDescriptions: []
VectorActionSpaceType: 1
m_Model: {fileID: 11400000, guid: d6c5e749e4ceb4cf79640a5955706d3d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0

agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
maxStep: 0
MaxStep: 0
ball: {fileID: 1273406647218856}
invertX: 0
score: 0

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!114 &6467897465973556822
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 9
numStackedVectorObservations: 3
vectorActionSize: 03000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
VectorObservationSize: 9
NumStackedVectorObservations: 3
VectorActionSize: 03000000
VectorActionDescriptions: []
VectorActionSpaceType: 1
m_Model: {fileID: 11400000, guid: d6c5e749e4ceb4cf79640a5955706d3d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0

agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
maxStep: 0
MaxStep: 0
ball: {fileID: 1273406647218856}
invertX: 1
score: 0

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!114 &1420140102966759323
MonoBehaviour:
m_ObjectHideFlags: 0

1001
Project/Assets/ML-Agents/Examples/Tennis/TFModels/Tennis.nn
文件差异内容过多而无法显示
查看文件

13
ml-agents/mlagents/trainers/ghost/controller.py


self._learning_team: int = -1
# Dict from team id to GhostTrainer for ELO calculation
self._ghost_trainers: Dict[int, GhostTrainer] = {}
# Signals to the trainer control to perform a hard change_training_team
self._changed_training_team = False
@property
def get_learning_team(self) -> int:

"""
return self._learning_team
def should_reset(self) -> bool:
"""
Whether or not team change occurred. Causes full reset in trainer_controller
:return: The truth value of the team changing
"""
changed_team = self._changed_training_team
if self._changed_training_team:
self._changed_training_team = False
return changed_team
def subscribe_team_id(self, team_id: int, trainer: GhostTrainer) -> None:
"""

logger.debug(
"Learning team {} swapped on step {}".format(self._learning_team, step)
)
self._changed_training_team = True
# Adapted from https://github.com/Unity-Technologies/ml-agents/pull/1975 and
# https://metinmediamath.wordpress.com/2013/11/27/how-to-calculate-the-elo-rating-including-example/

3
ml-agents/mlagents/trainers/tests/simple_test_envs.py


self.goal[name] = self.random.choice([-1, 1])
self.positions[name] = [0.0 for _ in range(self.action_size)]
self.step_count[name] = 0
self.final_rewards[name].append(self.rewards[name])
self.rewards[name] = 0
self.agent_id[name] = self.agent_id[name] + 1

decision_step = DecisionSteps(m_vector_obs, m_reward, m_agent_id, action_mask)
terminal_step = TerminalSteps.empty(self.behavior_spec)
if done:
self.final_rewards[name].append(self.rewards[name])
self._reset_agent(name)
new_vector_obs = self._make_obs(self.goal[name])
(

decision_step = DecisionSteps(m_vector_obs, m_reward, m_agent_id, action_mask)
terminal_step = TerminalSteps.empty(self.behavior_spec)
if done:
self.final_rewards[name].append(self.rewards[name])
self._reset_agent(name)
recurrent_obs_val = (
self.goal[name] if self.step_count[name] <= self.num_show_steps else 0

9
ml-agents/mlagents/trainers/tests/test_trainer_controller.py


from mlagents.tf_utils import tf
from mlagents.trainers.trainer_controller import TrainerController
from mlagents.trainers.ghost.controller import GhostController
trainer_factory_mock = MagicMock()
trainer_factory_mock.ghost_controller = GhostController()
trainer_factory=None,
trainer_factory=trainer_factory_mock,
model_path="test_model_path",
summaries_dir="test_summaries_dir",
run_id="test_run_id",

@patch.object(tf, "set_random_seed")
def test_initialization_seed(numpy_random_seed, tensorflow_set_seed):
seed = 27
trainer_factory_mock = MagicMock()
trainer_factory_mock.ghost_controller = GhostController()
trainer_factory=None,
trainer_factory=trainer_factory_mock,
model_path="",
summaries_dir="",
run_id="1",

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


self.meta_curriculum = meta_curriculum
self.sampler_manager = sampler_manager
self.resampling_interval = resampling_interval
self.ghost_controller = self.trainer_factory.ghost_controller
self.trainer_threads: List[threading.Thread] = []
self.kill_trainers = False

and (self.resampling_interval)
and (steps % self.resampling_interval == 0)
)
if meta_curriculum_reset or generalization_reset:
ghost_controller_reset = self.ghost_controller.should_reset()
if meta_curriculum_reset or generalization_reset or ghost_controller_reset:
self.end_trainer_episodes(env, lessons_incremented)
@timed

正在加载...
取消
保存