You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* update title caps
* Rename Custom-Protos.md to Creating-Custom-Protobuf-Messages.md
* Updated with custom protobuf messages
* Cleanup against to our doc guidelines
* Minor text revision
* Create Training-Concurrent-Unity-Instances
* Rename Training-Concurrent-Unity-Instances to Training-Concurrent-Unity-Instances.md
* update to right format for --num-envs
* added link to concurrent unity instances
* Update and rename Training-Concurrent-Unity-Instances.md to Training-Using-Concurrent-Unity-Instances.md
* Added considerations section
* Update Training-Using-Concurrent-Unity-Instances.md
* cleaned up language to match doc
* minor updates
* retroactive migration from 0.6 to 0.7
* Updated from 0.7 to 0.8 migration
* Minor typo
* minor fix
* accidentally duplicated step
* updated with new features list
Copy file name to clipboardExpand all lines: docs/Creating-Custom-Protobuf-Messages.md
+34-33Lines changed: 34 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,30 @@
1
-
# Creating custom protobuf messages
1
+
# Creating Custom Protobuf Messages
2
2
3
3
Unity and Python communicate by sending protobuf messages to and from each other. You can create custom protobuf messages if you want to exchange structured data beyond what is included by default.
4
4
5
-
Assume the ml-agents repository is checked out to a folder named $MLAGENTS_ROOT. Whenever you change the fields of a custom message, you must run `$MLAGENTS_ROOT/protobuf-definitions/make.bat` to create C# and Python files corresponding to the new message. Follow the directions in [this file](../protobuf-definitions/README.md) for guidance. After running it, reinstall the Python package by running `pip install $MLAGENTS_ROOT/ml-agents` and make sure your Unity project is using the newly-generated version of `$MLAGENTS_ROOT/UnitySDK`.
5
+
## Implementing a Custom Message
6
6
7
-
## Custom message types
7
+
Assume the ml-agents repository is checked out to a folder named $MLAGENTS_ROOT. Whenever you change the fields of a custom message, you must run `$MLAGENTS_ROOT/protobuf-definitions/make.bat` to create C# and Python files corresponding to the new message. Follow the directions in [this file](../protobuf-definitions/README.md) for guidance. After running `$MLAGENTS_ROOT/protobuf-definitions/make.bat`, reinstall the Python package by running `pip install $MLAGENTS_ROOT/ml-agents` and make sure your Unity project is using the newly-generated version of `$MLAGENTS_ROOT/UnitySDK`.
8
8
9
-
There are three custom message types currently supported, described below. In each case, `env` is an instance of a `UnityEnvironment` in Python. `CustomAction` is described most thoroughly; usage of the other custom messages follows a similar template.
9
+
## Custom Message Types
10
10
11
-
### Custom actions
11
+
There are three custom message types currently supported - Custom Actions, Custom Reset Parameters, and Custom Observations. In each case, `env` is an instance of a `UnityEnvironment` in Python.
12
12
13
-
By default, the Python API sends actions to Unity in the form of a floating-point list per agent and an optional string-valued text action.
13
+
### Custom Actions
14
14
15
-
You can define a custom action type to replace or augment this by adding fields to the `CustomAction` message, which you can do by editing the file `protobuf-definitions/proto/mlagents/envs/communicator_objects/custom_action.proto`.
15
+
By default, the Python API sends actions to Unity in the form of a floating point list and an optional string-valued text action for each agent.
16
16
17
-
Instances of custom actions are set via the `custom_action` parameter of `env.step`. An agent receives a custom action by defining a method with the signature
17
+
You can define a custom action type, to either replace or augment the default, by adding fields to the `CustomAction` message, which you can do by editing the file `protobuf-definitions/proto/mlagents/envs/communicator_objects/custom_action.proto`.
18
+
19
+
Instances of custom actions are set via the `custom_action` parameter of the `env.step`. An agent receives a custom action by defining a method with the signature:
Note that the protobuffer compiler automatically configures the capitalization scheme of the C# version of the custom field names you defined in the `CustomAction` message to match C# conventions - "NORTH" becomes "North", "walkAmount" becomes "WalkAmount", etc.
77
+
Keep in mind that the protobuffer compiler automatically configures the capitalization scheme of the C# version of the custom field names you defined in the `CustomAction` message to match C# conventions - "NORTH" becomes "North", "walkAmount" becomes "WalkAmount", etc.
76
78
77
-
### Custom reset parameters
79
+
### Custom Reset Parameters
78
80
79
-
By default, you can configure an environment `env` in the Python API by specifying a `config` parameter that is a dictionary mapping strings to floats.
81
+
By default, you can configure an environment `env` in the Python API by specifying a `config` parameter that is a dictionary mapping strings to floats.
80
82
81
-
You can also configure an environment using a custom protobuf message. To do so, add fields to the `CustomResetParameters` protobuf message in `custom_reset_parameters.proto`, analogously to `CustomAction` above. Then pass an instance of the message to `env.reset` via the `custom_reset_parameters` keyword parameter.
83
+
You can also configure the environment reset using a custom protobuf message. To do this, add fields to the `CustomResetParameters` protobuf message in `custom_reset_parameters.proto`, analogously to `CustomAction` above. Then pass an instance of the message to `env.reset` via the `custom_reset_parameters` keyword parameter.
82
84
83
85
In Unity, you can then access the `customResetParameters` field of your academy to accesss the values set in your Python script.
84
86
85
-
In this example, an academy is setting the initial position of a box based on custom reset parameters that looks like
87
+
In this example, the academy is setting the initial position of a box based on custom reset parameters. The `custom_reset_parameters.proto` would look like:
By default, Unity returns observations to Python in the form of a floating-point vector.
139
141
@@ -143,8 +145,7 @@ Then in your agent, create an instance of a custom observation via `new Communic
143
145
144
146
In Python, the custom observation can be accessed by calling `env.step` or `env.reset` and accessing the `custom_observations` property of the return value. It will contain a list with one `CustomObservation` instance per agent.
145
147
146
-
For example, if you have added a field called `customField` to the `CustomObservation` message, you would program your agent like
147
-
148
+
For example, if you have added a field called `customField` to the `CustomObservation` message, the agent code looks like:
148
149
149
150
```csharp
150
151
classMyAgent : Agent {
@@ -156,7 +157,7 @@ class MyAgent : Agent {
156
157
}
157
158
```
158
159
159
-
Then in Python, the custom field would be accessed like
160
+
In Python, the custom field would be accessed like:
Copy file name to clipboardExpand all lines: docs/Migrating.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,22 @@
1
1
# Migrating
2
2
3
+
## Migrating from ML-Agents toolkit v0.7 to v0.8
4
+
5
+
### Important Changes
6
+
* We have split the Python packges into two seperate packages `ml-agents` and `ml-agents-envs`
7
+
8
+
#### Steps to Migrate
9
+
* If you are installing via PyPI, there is no change.
10
+
* If you intend to make modifications to `ml-agents` or `ml-agents-envs` please check the Installing for Development in the [Installation documentation](Installation.md).
11
+
12
+
## Migrating from ML-Agents toolkit v0.6 to v0.7
13
+
14
+
### Important Changes
15
+
* We no longer support TFS and are now using the [Unity Inference Engine](Unity-Inference-Engine.md)
16
+
17
+
#### Steps to Migrate
18
+
* Make sure to remove the `ENABLE_TENSORFLOW` flag in your Unity Project settings
*`--train` – Specifies whether to train model or only run in inference mode.
136
136
When training, **always** use the `--train` option.
137
-
*`--num-envs` - Specifies the number of parallel environments to collect
137
+
*`--num-envs=<n>` - Specifies the number of concurrent Unity environment instances to collect
138
138
experiences from when training. Defaults to 1.
139
-
*`--base-port` - Specifies the starting port for environment workers. Each Unity
140
-
environment will use the port `(base_port + worker_id)`, where the worker ID
141
-
are sequential IDs given to each environment from 0 to `num_envs - 1`.
142
-
Defaults to 5005.
139
+
*`--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.
143
140
*`--docker-target-name=<dt>` – The Docker Volume on which to store curriculum,
144
141
executable and model files. See [Using Docker](Using-Docker.md).
145
142
*`--no-graphics` - Specify this option to run the Unity executable in
As part of release v0.8, we enabled developers to run concurrent, parallel instances of the Unity executable during training. For certain scenarios, this should speed up the training.
4
+
5
+
## How to Run Concurrent Unity Instances During Training
6
+
7
+
Please refer to the general instructions on [Training ML-Agents](Training-ML-Agents.md). In order to run concurrent Unity instances during training, set the number of environment instances using the command line option `--num-envs=<n>` when you invoke `mlagents-learn`. Optionally, you can also set the `--base-port`, which is the starting port used for the concurrent Unity instances.
8
+
9
+
## Considerations
10
+
11
+
### Buffer Size
12
+
13
+
If you are having trouble getting an agent to train, even with multiple concurrent Unity instances, you could increase `buffer_size` in the `config/trainer_config.yaml` file. A common practice is to multiply `buffer_size` by `num-envs`.
14
+
15
+
### Resource Constraints
16
+
17
+
Invoking concurrent Unity instances is constrained by the resources on the machine. Please use discretion when setting `--num-envs=<n>`.
18
+
19
+
### Using num-runs and num-envs
20
+
21
+
If you set `--num-runs=<n>` greater than 1 and are also invoking concurrent Unity instances using `--num-envs=<n>`, then the number of concurrent Unity instances is equal to `num-runs` times `num-envs`.
22
+
23
+
### Result Variation Using Concurrent Unity Instances
24
+
25
+
If you keep all the hyperparameters the same, but change `--num-envs=<n>`, the results and model would likely change.
0 commit comments