Skip to content

Commit 0782df1

Browse files
Ervin TvincentpierreChris Elion
authored
[refactor] Make PyTorch the default and TensorFlow optional (#4517)
* Torch setup.py * Set torch to default * Make torch default in setup.py * Remove indents * Remove other instances of TF being used * Add tensorboard to setup.py * Adding correst setup commands for verifying torch is installed (#4524) * Adding correst setup commands for verifying torch is installed * Editing the test_requirments to add tf and remove torch * Develop torchdefault raise outside setup (#4530) * Torch not imported error to raise at first usage * Torch not imported error to raise at first usage * [refactor] Use PyTorch TensorBoard utils (#4518) * Convert stats writer to use PyTorch TB support * Use common function to print params * Update test * Bump tensorboard to 1.15 to fix the tests * putting tensorboard 1.15.0 as min version requirement Co-authored-by: vincentpierre <[email protected]> * [Docs] Initial documentation changes for making Torch the default (#4561) * Initial commit * Forgotten doc * Removing the `Installation-Anaconda-Windows.md` as it is deprecated * Readding the depreacted Installation-Anaconda-Windows.md but leaving it unchanged * more references to tensorflow removed * Update README.md Co-authored-by: Ervin T. <[email protected]> * Change references to .nn to .onnx in docs (#4583) Co-authored-by: Ervin T. <[email protected]> * [refactor] Add --tensorflow, enable Torch as default setting (#4582) * Add --tensorflow option * Switch framework to Pytorch default * Update changelog * Re-add --torch * Edit warning * Modify Yamato tests (#4584) * Don't check for PB file in Yamato inference * Only run inference on ONNX * Update docs/Unity-Inference-Engine.md with correct tf2onnx versions Co-authored-by: Chris Elion <[email protected]> * Add reward signal class comments * More descriptive import of is_available * Updated installation instructions for PyTorch * More reward signal comments * More Windows instructions Co-authored-by: Vincent-Pierre BERGES <[email protected]> Co-authored-by: Chris Elion <[email protected]>
1 parent 65644d1 commit 0782df1

32 files changed

+297
-293
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ If applicable, add screenshots to help explain your problem.
2727
- Unity Version: [e.g. Unity 2020.1f1]
2828
- OS + version: [e.g. Windows 10]
2929
- _ML-Agents version_: (e.g. ML-Agents v0.8, or latest `develop` branch from source)
30-
- _TensorFlow version_: (you can run `pip3 show tensorflow` to get this)
30+
- _Torch version_: (you can run `pip3 show torch` to get this)
3131
- _Environment_: (which example environment you used to reproduce the error)
3232

3333
**NOTE:** We are unable to help reproduce bugs with custom environments. Please attempt to reproduce your issue with one of the example environments, or provide a minimal patch to one of the environments needed to reproduce the issue.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
project that enables games and simulations to serve as environments for
1414
training intelligent agents. Agents can be trained using reinforcement learning,
1515
imitation learning, neuroevolution, or other machine learning methods through a
16-
simple-to-use Python API. We also provide implementations (based on TensorFlow)
16+
simple-to-use Python API. We also provide implementations (based on PyTorch)
1717
of state-of-the-art algorithms to enable game developers and hobbyists to easily
1818
train intelligent agents for 2D, 3D and VR/AR games. These trained agents can be
1919
used for multiple purposes, including controlling NPC behavior (in a variety of

com.unity.ml-agents/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ and this project adheres to
1212
### Major Changes
1313
#### com.unity.ml-agents (C#)
1414
#### ml-agents / ml-agents-envs / gym-unity (Python)
15+
- PyTorch trainers are now the default. See the
16+
[installation docs](https://github.com/Unity-Technologies/ml-agents/blob/mastere/docs/Installation.md) for
17+
more information on installing PyTorch. For the time being, TensorFlow is still available;
18+
you can use the TensorFlow backend by adding `--tensorflow` to the CLI, or
19+
adding `framework: tensorflow` in the configuration YAML. (#4517)
1520

1621
### Minor Changes
1722
#### com.unity.ml-agents (C#)

docs/Background-Machine-Learning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ we can learn policies for very complex environments (a complex environment is
194194
one where the number of observations an agent perceives and the number of
195195
actions they can take are large). Many of the algorithms we provide in ML-Agents
196196
use some form of deep learning, built on top of the open-source library,
197-
[TensorFlow](Background-TensorFlow.md).
197+
[PyTorch](Background-PyTorch.md).

docs/Background-TensorFlow.md renamed to docs/Background-PyTorch.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Background: TensorFlow
1+
# Background: PyTorch
22

33
As discussed in our
44
[machine learning background page](Background-Machine-Learning.md), many of the
55
algorithms we provide in the ML-Agents Toolkit leverage some form of deep
66
learning. More specifically, our implementations are built on top of the
7-
open-source library [TensorFlow](https://www.tensorflow.org/). In this page we
8-
provide a brief overview of TensorFlow, in addition to TensorFlow-related tools
7+
open-source library [PyTorch](https://pytorch.org/). In this page we
8+
provide a brief overview of PyTorch and TensorBoard
99
that we leverage within the ML-Agents Toolkit.
1010

11-
## TensorFlow
11+
## PyTorch
1212

13-
[TensorFlow](https://www.tensorflow.org/) is an open source library for
13+
[PyTorch](https://pytorch.org/) is an open source library for
1414
performing computations using data flow graphs, the underlying representation of
1515
deep learning models. It facilitates training and inference on CPUs and GPUs in
1616
a desktop, server, or mobile device. Within the ML-Agents Toolkit, when you
17-
train the behavior of an agent, the output is a model (.nn) file that you can
17+
train the behavior of an agent, the output is a model (.onnx) file that you can
1818
then associate with an Agent. Unless you implement a new algorithm, the use of
19-
TensorFlow is mostly abstracted away and behind the scenes.
19+
PyTorch is mostly abstracted away and behind the scenes.
2020

2121
## TensorBoard
2222

23-
One component of training models with TensorFlow is setting the values of
23+
One component of training models with PyTorch is setting the values of
2424
certain model attributes (called _hyperparameters_). Finding the right values of
2525
these hyperparameters can require a few iterations. Consequently, we leverage a
26-
visualization tool within TensorFlow called
26+
visualization tool called
2727
[TensorBoard](https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard).
2828
It allows the visualization of certain agent attributes (e.g. reward) throughout
2929
training which can be helpful in both building intuitions for the different

docs/Getting-Started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ itself to keep the ball balanced on its head.
9191

9292
## Running a pre-trained model
9393

94-
We include pre-trained models for our agents (`.nn` files) and we use the
94+
We include pre-trained models for our agents (`.onnx` files) and we use the
9595
[Unity Inference Engine](Unity-Inference-Engine.md) to run these models inside
9696
Unity. In this section, we will use the pre-trained model for the 3D Ball
9797
example.
@@ -124,7 +124,7 @@ example.
124124

125125
## Training a new model with Reinforcement Learning
126126

127-
While we provide pre-trained `.nn` files for the agents in this environment, any
127+
While we provide pre-trained models for the agents in this environment, any
128128
environment you make yourself will require training agents from scratch to
129129
generate a new model file. In this section we will demonstrate how to use the
130130
reinforcement learning algorithms that are part of the ML-Agents Python package
@@ -229,7 +229,7 @@ Once the training process completes, and the training process saves the model
229229
use it with compatible Agents (the Agents that generated the model). **Note:**
230230
Do not just close the Unity Window once the `Saved Model` message appears.
231231
Either wait for the training process to close the window or press `Ctrl+C` at
232-
the command-line prompt. If you close the window manually, the `.nn` file
232+
the command-line prompt. If you close the window manually, the `.onnx` file
233233
containing the trained model is not exported into the ml-agents folder.
234234

235235
If you've quit the training early using `Ctrl+C` and want to resume training,
@@ -239,7 +239,7 @@ run the same command again, appending the `--resume` flag:
239239
mlagents-learn config/ppo/3DBall.yaml --run-id=first3DBallRun --resume
240240
```
241241

242-
Your trained model will be at `results/<run-identifier>/<behavior_name>.nn` where
242+
Your trained model will be at `results/<run-identifier>/<behavior_name>.onnx` where
243243
`<behavior_name>` is the name of the `Behavior Name` of the agents corresponding
244244
to the model. This file corresponds to your model's latest checkpoint. You can
245245
now embed this trained model into your Agents by following the steps below,
@@ -249,7 +249,7 @@ which is similar to the steps described [above](#running-a-pre-trained-model).
249249
`Project/Assets/ML-Agents/Examples/3DBall/TFModels/`.
250250
1. Open the Unity Editor, and select the **3DBall** scene as described above.
251251
1. Select the **3DBall** prefab Agent object.
252-
1. Drag the `<behavior_name>.nn` file from the Project window of the Editor to
252+
1. Drag the `<behavior_name>.onnx` file from the Project window of the Editor to
253253
the **Model** placeholder in the **Ball3DAgent** inspector window.
254254
1. Press the **Play** button at the top of the Editor.
255255

docs/Installation.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ If your Python environment doesn't include `pip3`, see these
4444
[instructions](https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers)
4545
on installing it.
4646

47-
Although we do not provide support for Anaconda installation on Windows, the
48-
previous
49-
[Windows Anaconda Installation (Deprecated) guide](Installation-Anaconda-Windows.md)
50-
is still available.
51-
5247
### Clone the ML-Agents Toolkit Repository (Optional)
5348

5449
Now that you have installed Unity and Python, you can now install the Unity and
@@ -124,6 +119,22 @@ Virtual Environments. Virtual Environments provide a mechanism for isolating the
124119
dependencies for each project and are supported on Mac / Windows / Linux. We
125120
offer a dedicated [guide on Virtual Environments](Using-Virtual-Environment.md).
126121

122+
#### (Windows) Installing PyTorch
123+
124+
On Windows, you'll have to install the PyTorch package separately prior to
125+
installing ML-Agents. Activate your virtual environment and run from the command line:
126+
127+
```sh
128+
pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html
129+
```
130+
131+
Note that on Windows, you may also need Microsoft's
132+
[Visual C++ Redistributable](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads)
133+
if you don't have it already. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/)
134+
for more installation options and versions.
135+
136+
#### Installing `mlagents`
137+
127138
To install the `mlagents` Python package, activate your virtual environment and
128139
run from the command line:
129140

@@ -138,7 +149,7 @@ line parameters you can use with `mlagents-learn`.
138149

139150
By installing the `mlagents` package, the dependencies listed in the
140151
[setup.py file](../ml-agents/setup.py) are also installed. These include
141-
[TensorFlow](Background-TensorFlow.md) (Requires a CPU w/ AVX support).
152+
[PyTorch](Background-PyTorch.md) (Requires a CPU w/ AVX support).
142153

143154
#### Advanced: Local Installation for Development
144155

@@ -148,6 +159,7 @@ this, you will need to install `mlagents` and `mlagents_envs` separately. From
148159
the repository's root directory, run:
149160

150161
```sh
162+
pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html
151163
pip3 install -e ./ml-agents-envs
152164
pip3 install -e ./ml-agents
153165
```

docs/Learning-Environment-Executable.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ INFO:mlagents.trainers: first-run-0: Ball3DLearning: Step: 10000. Mean Reward: 2
171171
```
172172

173173
You can press Ctrl+C to stop the training, and your trained model will be at
174-
`results/<run-identifier>/<behavior_name>.nn`, which corresponds to your model's
174+
`results/<run-identifier>/<behavior_name>.onnx`, which corresponds to your model's
175175
latest checkpoint. (**Note:** There is a known bug on Windows that causes the
176176
saving of the model to fail when you early terminate the training, it's
177177
recommended to wait until Step has reached the max_steps parameter you set in
@@ -182,6 +182,6 @@ following the steps below:
182182
`Project/Assets/ML-Agents/Examples/3DBall/TFModels/`.
183183
1. Open the Unity Editor, and select the **3DBall** scene as described above.
184184
1. Select the **3DBall** prefab from the Project window and select **Agent**.
185-
1. Drag the `<behavior_name>.nn` file from the Project window of the Editor to
185+
1. Drag the `<behavior_name>.onnx` file from the Project window of the Editor to
186186
the **Model** placeholder in the **Ball3DAgent** inspector window.
187187
1. Press the **Play** button at the top of the Editor.

docs/ML-Agents-Overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open-source project that enables games and simulations to serve as environments
3535
for training intelligent agents. Agents can be trained using reinforcement
3636
learning, imitation learning, neuroevolution, or other machine learning methods
3737
through a simple-to-use Python API. We also provide implementations (based on
38-
TensorFlow) of state-of-the-art algorithms to enable game developers and
38+
PyTorch) of state-of-the-art algorithms to enable game developers and
3939
hobbyists to easily train intelligent agents for 2D, 3D and VR/AR games. These
4040
trained agents can be used for multiple purposes, including controlling NPC
4141
behavior (in a variety of settings such as multi-agent and adversarial),
@@ -51,9 +51,9 @@ transition to the ML-Agents Toolkit easier, we provide several background pages
5151
that include overviews and helpful resources on the
5252
[Unity Engine](Background-Unity.md),
5353
[machine learning](Background-Machine-Learning.md) and
54-
[TensorFlow](Background-TensorFlow.md). We **strongly** recommend browsing the
54+
[PyTorch](Background-PyTorch.md). We **strongly** recommend browsing the
5555
relevant background pages if you're not familiar with a Unity scene, basic
56-
machine learning concepts or have not previously heard of TensorFlow.
56+
machine learning concepts or have not previously heard of PyTorch.
5757

5858
The remainder of this page contains a deep dive into ML-Agents, its key
5959
components, different training modes and scenarios. By the end of it, you should
@@ -280,7 +280,7 @@ for additional information.
280280

281281
### Custom Training and Inference
282282

283-
In the previous mode, the Agents were used for training to generate a TensorFlow
283+
In the previous mode, the Agents were used for training to generate a PyTorch
284284
model that the Agents can later use. However, any user of the ML-Agents Toolkit
285285
can leverage their own algorithms for training. In this case, the behaviors of
286286
all the Agents in the scene will be controlled within Python. You can even turn

docs/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- [ML-Agents Toolkit Overview](ML-Agents-Overview.md)
1212
- [Background: Unity](Background-Unity.md)
1313
- [Background: Machine Learning](Background-Machine-Learning.md)
14-
- [Background: TensorFlow](Background-TensorFlow.md)
14+
- [Background: PyTorch](Background-PyTorch.md)
1515
- [Example Environments](Learning-Environment-Examples.md)
1616

1717
## Creating Learning Environments

0 commit comments

Comments
 (0)