浏览代码

Added option to use environment arguments in learn (#2594)

* Added option to use environment arguments in learn

* hook into argparse

* add example to readme
/develop-gpu-test
GitHub 5 年前
当前提交
d64a01e1
共有 5 个文件被更改,包括 42 次插入4 次删除
  1. 2
      UnitySDK/ProjectSettings/ProjectVersion.txt
  2. 13
      docs/Training-ML-Agents.md
  3. 4
      ml-agents-envs/mlagents/envs/environment.py
  4. 11
      ml-agents/mlagents/trainers/learn.py
  5. 16
      ml-agents/mlagents/trainers/tests/test_learn.py

2
UnitySDK/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.4.10f1
m_EditorVersion: 2017.4.29f1

13
docs/Training-ML-Agents.md


When training, **always** use the `--train` option.
* `--num-envs=<n>`: Specifies the number of concurrent Unity environment instances to collect
experiences from when training. Defaults to 1.
* `--base-port`: Specifies the starting port. Each concurrent Unity environment instance will get assigned a port sequentially, starting from the `base-port`. Each instance will use the port `(base_port + worker_id)`, where the `worker_id` is sequential IDs given to each instance from 0 to `num_envs - 1`. Default is 5005.
* `--base-port`: Specifies the starting port. Each concurrent Unity environment instance will
get assigned a port sequentially, starting from the `base-port`. Each instance will use the
port `(base_port + worker_id)`, where the `worker_id` is sequential IDs given to each instance
from 0 to `num_envs - 1`. Default is 5005.
* `--docker-target-name=<dt>`: The Docker Volume on which to store curriculum,
executable and model files. See [Using Docker](Using-Docker.md).
* `--no-graphics`: Specify this option to run the Unity executable in

details.
* `--debug`: Specify this option to enable debug-level logging for some parts of the code.
* `--multi-gpu`: Setting this flag enables the use of multiple GPU's (if available) during training.
* `--env-args=<string>`: Specify arguments for the executable environment. Be aware that
the standalone build will also process these as
[Unity Command Line Arguments](https://docs.unity3d.com/Manual/CommandLineArguments.html).
You should choose different argument names if you want to create environment-specific arguments.
All arguments after this flag will be passed to the executable. For example, setting
`mlagents-learn config/trainer_config.yaml --env-args --num-orcs 42` would result in
` --num-orcs 42` passed to the executable.
### Training Config File

4
ml-agents-envs/mlagents/envs/environment.py


docker_training: bool = False,
no_graphics: bool = False,
timeout_wait: int = 30,
args: list = [],
args: Optional[List[str]] = None,
):
"""
Starts a new unity environment and establishes a connection with the environment.

:bool train_mode: Whether to run in training mode, speeding up the simulation, by default.
:list args: Addition Unity command line arguments
"""
args = args or []
atexit.register(self._close)
self.port = base_port + worker_id
self._buffer_size = 12000

11
ml-agents/mlagents/trainers/learn.py


trainer_config_path: str
sampler_file_path: Optional[str]
docker_target_name: Optional[str]
env_args: Optional[List[str]]
@property
def fast_simulation(self) -> bool:

action="store_true",
help="Setting this flag enables the use of multiple GPU's (if available) during training",
)
parser.add_argument(
"--env-args",
default=None,
nargs=argparse.REMAINDER,
help="Arguments passed to the Unity executable.",
)
args = parser.parse_args(argv)
return CommandLineOptions.from_argparse(args)

:param run_options: Command line arguments for training.
"""
# Docker Parameters
trainer_config_path = options.trainer_config_path
curriculum_folder = options.curriculum_folder

options.no_graphics,
run_seed,
options.base_port + (sub_id * options.num_envs),
options.env_args,
)
env = SubprocessEnvManager(env_factory, options.num_envs)
maybe_meta_curriculum = try_create_meta_curriculum(

no_graphics: bool,
seed: Optional[int],
start_port: int,
env_args: Optional[List[str]],
) -> Callable[[int], BaseUnityEnvironment]:
if env_path is not None:
# Strip out executable extensions if passed

docker_training=docker_training,
no_graphics=no_graphics,
base_port=start_port,
args=env_args,
)
return create_unity_environment

16
ml-agents/mlagents/trainers/tests/test_learn.py


assert opt.no_graphics is False
assert opt.debug is False
assert opt.multi_gpu is False
assert opt.env_args is None
full_args = [
"mytrainerpath",

assert opt.no_graphics is True
assert opt.debug is True
assert opt.multi_gpu is True
def test_env_args():
full_args = [
"mytrainerpath",
"--env=./myenvfile",
"--env-args", # Everything after here will be grouped in a list
"--foo=bar",
"--blah",
"baz",
"100",
]
opt = parse_command_line(full_args)
assert opt.env_args == ["--foo=bar", "--blah", "baz", "100"]
正在加载...
取消
保存