vincentpierre
4 年前
当前提交
a3a9a56b
共有 100 个文件被更改,包括 1269 次插入 和 805 次删除
-
2.github/ISSUE_TEMPLATE/bug_report.md
-
11.yamato/test_versions.metafile
-
2.yamato/training-int-tests.yml
-
22Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
-
8README.md
-
10com.unity.ml-agents/CHANGELOG.md
-
27com.unity.ml-agents/Runtime/Academy.cs
-
24com.unity.ml-agents/Runtime/Agent.cs
-
56com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs
-
2com.unity.ml-agents/package.json
-
2docs/Background-Machine-Learning.md
-
10docs/Getting-Started.md
-
24docs/Installation.md
-
4docs/Learning-Environment-Executable.md
-
8docs/ML-Agents-Overview.md
-
2docs/Readme.md
-
2docs/Training-Configuration-File.md
-
35docs/Training-ML-Agents.md
-
2docs/Training-on-Amazon-Web-Service.md
-
5docs/Unity-Inference-Engine.md
-
21gym-unity/gym_unity/envs/__init__.py
-
8gym-unity/gym_unity/tests/test_gym.py
-
154ml-agents-envs/mlagents_envs/base_env.py
-
35ml-agents-envs/mlagents_envs/environment.py
-
27ml-agents-envs/mlagents_envs/rpc_utils.py
-
15ml-agents-envs/mlagents_envs/tests/test_envs.py
-
30ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py
-
60ml-agents-envs/mlagents_envs/tests/test_steps.py
-
1ml-agents/mlagents/tf_utils/__init__.py
-
63ml-agents/mlagents/tf_utils/tf.py
-
1ml-agents/mlagents/torch_utils/__init__.py
-
66ml-agents/mlagents/torch_utils/torch.py
-
11ml-agents/mlagents/trainers/cli_utils.py
-
13ml-agents/mlagents/trainers/demo_loader.py
-
16ml-agents/mlagents/trainers/ghost/trainer.py
-
6ml-agents/mlagents/trainers/learn.py
-
19ml-agents/mlagents/trainers/policy/policy.py
-
6ml-agents/mlagents/trainers/policy/tf_policy.py
-
18ml-agents/mlagents/trainers/policy/torch_policy.py
-
4ml-agents/mlagents/trainers/ppo/optimizer_torch.py
-
41ml-agents/mlagents/trainers/ppo/trainer.py
-
27ml-agents/mlagents/trainers/sac/optimizer_torch.py
-
61ml-agents/mlagents/trainers/sac/trainer.py
-
2ml-agents/mlagents/trainers/settings.py
-
86ml-agents/mlagents/trainers/stats.py
-
60ml-agents/mlagents/trainers/tests/mock_brain.py
-
15ml-agents/mlagents/trainers/tests/simple_test_envs.py
-
46ml-agents/mlagents/trainers/tests/tensorflow/test_ghost.py
-
5ml-agents/mlagents/trainers/tests/tensorflow/test_models.py
-
8ml-agents/mlagents/trainers/tests/tensorflow/test_nn_policy.py
-
12ml-agents/mlagents/trainers/tests/tensorflow/test_ppo.py
-
9ml-agents/mlagents/trainers/tests/tensorflow/test_sac.py
-
4ml-agents/mlagents/trainers/tests/tensorflow/test_saver.py
-
8ml-agents/mlagents/trainers/tests/tensorflow/test_simple_rl.py
-
25ml-agents/mlagents/trainers/tests/tensorflow/test_tf_policy.py
-
19ml-agents/mlagents/trainers/tests/test_agent_processor.py
-
6ml-agents/mlagents/trainers/tests/test_rl_trainer.py
-
20ml-agents/mlagents/trainers/tests/test_stats.py
-
4ml-agents/mlagents/trainers/tests/test_trajectory.py
-
46ml-agents/mlagents/trainers/tests/torch/test_ghost.py
-
79ml-agents/mlagents/trainers/tests/torch/test_layers.py
-
41ml-agents/mlagents/trainers/tests/torch/test_networks.py
-
15ml-agents/mlagents/trainers/tests/torch/test_policy.py
-
8ml-agents/mlagents/trainers/tests/torch/test_ppo.py
-
32ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_curiosity.py
-
18ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_extrinsic.py
-
29ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_gail.py
-
25ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_rnd.py
-
8ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py
-
6ml-agents/mlagents/trainers/tests/torch/test_simple_rl.py
-
4ml-agents/mlagents/trainers/tests/torch/test_utils.py
-
2ml-agents/mlagents/trainers/tf/components/bc/model.py
-
4ml-agents/mlagents/trainers/tf/components/bc/module.py
-
2ml-agents/mlagents/trainers/tf/components/reward_signals/curiosity/model.py
-
2ml-agents/mlagents/trainers/tf/components/reward_signals/gail/model.py
-
2ml-agents/mlagents/trainers/torch/components/bc/module.py
-
16ml-agents/mlagents/trainers/torch/components/reward_providers/curiosity_reward_provider.py
-
3ml-agents/mlagents/trainers/torch/components/reward_providers/gail_reward_provider.py
-
1ml-agents/mlagents/trainers/torch/components/reward_providers/rnd_reward_provider.py
-
5ml-agents/mlagents/trainers/torch/distributions.py
-
66ml-agents/mlagents/trainers/torch/layers.py
-
4ml-agents/mlagents/trainers/torch/model_serialization.py
-
42ml-agents/mlagents/trainers/torch/networks.py
-
18ml-agents/mlagents/trainers/torch/utils.py
-
34ml-agents/mlagents/trainers/trainer/rl_trainer.py
-
18ml-agents/mlagents/trainers/trainer/trainer_factory.py
-
10ml-agents/mlagents/trainers/trainer_controller.py
-
12ml-agents/mlagents/trainers/training_status.py
-
10ml-agents/setup.py
-
8ml-agents/tests/yamato/scripts/run_llapi.py
-
21ml-agents/tests/yamato/training_int_tests.py
-
5ml-agents/tests/yamato/yamato_utils.py
-
1test_constraints_min_version.txt
-
4test_requirements.txt
-
35com.unity.ml-agents/Runtime/RecursionChecker.cs
-
3com.unity.ml-agents/Runtime/RecursionChecker.cs.meta
-
72com.unity.ml-agents/Tests/Editor/RecursionCheckerTests.cs
-
3com.unity.ml-agents/Tests/Editor/RecursionCheckerTests.cs.meta
-
35docs/Background-PyTorch.md
-
35docs/Background-TensorFlow.md
|
|||
# List of editor versions for standalone-build-test and its dependencies. |
|||
# csharp_backcompat_version is used in training-int-tests to determine the |
|||
# older package version to run the backwards compat tests against. |
|||
csharp_backcompat_version: 1.0.0 |
|||
csharp_backcompat_version: 1.0.0 |
|||
# Waiting on a barracuda fix, see https://jira.unity3d.com/browse/MLA-1464 |
|||
# - version: 2020.2 |
|||
csharp_backcompat_version: 1.0.0 |
|||
- version: 2020.2 |
|||
# 2020.2 moved the AssetImporters namespace |
|||
# but we didn't handle this until 1.2.0 |
|||
csharp_backcompat_version: 1.2.0 |
|
|||
from mlagents.tf_utils.tf import tf as tf # noqa |
|||
from mlagents.tf_utils.tf import set_warnings_enabled # noqa |
|||
from mlagents.tf_utils.tf import generate_session_config # noqa |
|||
from mlagents.tf_utils.tf import is_available # noqa |
|
|||
from mlagents.torch_utils.torch import torch as torch # noqa |
|||
from mlagents.torch_utils.torch import nn # noqa |
|||
from mlagents.torch_utils.torch import is_available # noqa |
|||
from mlagents.torch_utils.torch import default_device # noqa |
|
|||
import os |
|||
|
|||
from distutils.version import LooseVersion |
|||
import pkg_resources |
|||
# Detect availability of torch package here. |
|||
# NOTE: this try/except is temporary until torch is required for ML-Agents. |
|||
try: |
|||
# This should be the only place that we import torch directly. |
|||
# Everywhere else is caught by the banned-modules setting for flake8 |
|||
import torch # noqa I201 |
|||
torch.set_num_threads(cpu_utils.get_num_threads_to_use()) |
|||
os.environ["KMP_BLOCKTIME"] = "0" |
|||
def assert_torch_installed(): |
|||
# Check that torch version 1.6.0 or later has been installed. If not, refer |
|||
# user to the PyTorch webpage for install instructions. |
|||
torch_pkg = None |
|||
try: |
|||
torch_pkg = pkg_resources.get_distribution("torch") |
|||
except pkg_resources.DistributionNotFound: |
|||
pass |
|||
assert torch_pkg is not None and LooseVersion(torch_pkg.version) >= LooseVersion( |
|||
"1.6.0" |
|||
), ( |
|||
"A compatible version of PyTorch was not installed. Please visit the PyTorch homepage " |
|||
+ "(https://pytorch.org/get-started/locally/) and follow the instructions to install. " |
|||
+ "Version 1.6.0 and later are supported." |
|||
) |
|||
# Known PyLint compatibility with PyTorch https://github.com/pytorch/pytorch/issues/701 |
|||
# pylint: disable=E1101 |
|||
if torch.cuda.is_available(): |
|||
torch.set_default_tensor_type(torch.cuda.FloatTensor) |
|||
device = torch.device("cuda") |
|||
else: |
|||
torch.set_default_tensor_type(torch.FloatTensor) |
|||
device = torch.device("cpu") |
|||
nn = torch.nn |
|||
# pylint: disable=E1101 |
|||
except ImportError: |
|||
torch = None |
|||
nn = None |
|||
device = None |
|||
|
|||
assert_torch_installed() |
|||
|
|||
# This should be the only place that we import torch directly. |
|||
# Everywhere else is caught by the banned-modules setting for flake8 |
|||
import torch # noqa I201 |
|||
|
|||
|
|||
torch.set_num_threads(cpu_utils.get_num_threads_to_use()) |
|||
os.environ["KMP_BLOCKTIME"] = "0" |
|||
|
|||
# Known PyLint compatibility with PyTorch https://github.com/pytorch/pytorch/issues/701 |
|||
# pylint: disable=E1101 |
|||
if torch.cuda.is_available(): |
|||
torch.set_default_tensor_type(torch.cuda.FloatTensor) |
|||
device = torch.device("cuda") |
|||
else: |
|||
torch.set_default_tensor_type(torch.FloatTensor) |
|||
device = torch.device("cpu") |
|||
nn = torch.nn |
|||
|
|||
|
|||
def is_available(): |
|||
""" |
|||
Returns whether Torch is available in this Python environment |
|||
""" |
|||
return torch is not None |
|
|||
using System; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
internal class RecursionChecker : IDisposable |
|||
{ |
|||
private bool m_IsRunning; |
|||
private string m_MethodName; |
|||
|
|||
public RecursionChecker(string methodName) |
|||
{ |
|||
m_MethodName = methodName; |
|||
} |
|||
|
|||
public IDisposable Start() |
|||
{ |
|||
if (m_IsRunning) |
|||
{ |
|||
throw new UnityAgentsException( |
|||
$"{m_MethodName} called recursively. " + |
|||
"This might happen if you call EnvironmentStep() or EndEpisode() from custom " + |
|||
"code such as CollectObservations() or OnActionReceived()." |
|||
); |
|||
} |
|||
m_IsRunning = true; |
|||
return this; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
// Reset the flag when we're done (or if an exception occurred).
|
|||
m_IsRunning = false; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 49ebd06532b24078a6edda823aeff5d2 |
|||
timeCreated: 1602731302 |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
|
|||
namespace Unity.MLAgents.Tests |
|||
{ |
|||
[TestFixture] |
|||
public class RecursionCheckerTests |
|||
{ |
|||
class InfiniteRecurser |
|||
{ |
|||
RecursionChecker m_checker = new RecursionChecker("InfiniteRecurser"); |
|||
public int NumCalls = 0; |
|||
|
|||
public void Implode() |
|||
{ |
|||
NumCalls++; |
|||
using (m_checker.Start()) |
|||
{ |
|||
Implode(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Test] |
|||
public void TestRecursionCheck() |
|||
{ |
|||
var rc = new InfiniteRecurser(); |
|||
Assert.Throws<UnityAgentsException>(() => |
|||
{ |
|||
rc.Implode(); |
|||
}); |
|||
|
|||
// Should increment twice before bailing out.
|
|||
Assert.AreEqual(2, rc.NumCalls); |
|||
} |
|||
|
|||
class OneTimeThrower |
|||
{ |
|||
RecursionChecker m_checker = new RecursionChecker("OneTimeThrower"); |
|||
public int NumCalls; |
|||
|
|||
public void DoStuff() |
|||
{ |
|||
// This method throws from inside the checker the first time.
|
|||
// Later calls do nothing.
|
|||
NumCalls++; |
|||
using (m_checker.Start()) |
|||
{ |
|||
if (NumCalls == 1) |
|||
{ |
|||
throw new ArgumentException("oops"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Test] |
|||
public void TestThrowResetsFlag() |
|||
{ |
|||
var ott = new OneTimeThrower(); |
|||
Assert.Throws<ArgumentException>(() => |
|||
{ |
|||
ott.DoStuff(); |
|||
}); |
|||
|
|||
// Make sure the flag is cleared if we throw in the "using". Should be able to step subsequently.
|
|||
ott.DoStuff(); |
|||
ott.DoStuff(); |
|||
Assert.AreEqual(3, ott.NumCalls); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5a7183e11dd5434684a4225c80169173 |
|||
timeCreated: 1602781778 |
|
|||
# Background: PyTorch |
|||
|
|||
As discussed in our |
|||
[machine learning background page](Background-Machine-Learning.md), many of the |
|||
algorithms we provide in the ML-Agents Toolkit leverage some form of deep |
|||
learning. More specifically, our implementations are built on top of the |
|||
open-source library [PyTorch](https://pytorch.org/). In this page we |
|||
provide a brief overview of PyTorch and TensorBoard |
|||
that we leverage within the ML-Agents Toolkit. |
|||
|
|||
## PyTorch |
|||
|
|||
[PyTorch](https://pytorch.org/) is an open source library for |
|||
performing computations using data flow graphs, the underlying representation of |
|||
deep learning models. It facilitates training and inference on CPUs and GPUs in |
|||
a desktop, server, or mobile device. Within the ML-Agents Toolkit, when you |
|||
train the behavior of an agent, the output is a model (.onnx) file that you can |
|||
then associate with an Agent. Unless you implement a new algorithm, the use of |
|||
PyTorch is mostly abstracted away and behind the scenes. |
|||
|
|||
## TensorBoard |
|||
|
|||
One component of training models with PyTorch is setting the values of |
|||
certain model attributes (called _hyperparameters_). Finding the right values of |
|||
these hyperparameters can require a few iterations. Consequently, we leverage a |
|||
visualization tool called |
|||
[TensorBoard](https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard). |
|||
It allows the visualization of certain agent attributes (e.g. reward) throughout |
|||
training which can be helpful in both building intuitions for the different |
|||
hyperparameters and setting the optimal values for your Unity environment. We |
|||
provide more details on setting the hyperparameters in the |
|||
[Training ML-Agents](Training-ML-Agents.md) page. If you are unfamiliar with |
|||
TensorBoard we recommend our guide on |
|||
[using TensorBoard with ML-Agents](Using-Tensorboard.md) or this |
|||
[tutorial](https://github.com/dandelionmane/tf-dev-summit-tensorboard-tutorial). |
|
|||
# Background: TensorFlow |
|||
|
|||
As discussed in our |
|||
[machine learning background page](Background-Machine-Learning.md), many of the |
|||
algorithms we provide in the ML-Agents Toolkit leverage some form of deep |
|||
learning. More specifically, our implementations are built on top of the |
|||
open-source library [TensorFlow](https://www.tensorflow.org/). In this page we |
|||
provide a brief overview of TensorFlow, in addition to TensorFlow-related tools |
|||
that we leverage within the ML-Agents Toolkit. |
|||
|
|||
## TensorFlow |
|||
|
|||
[TensorFlow](https://www.tensorflow.org/) is an open source library for |
|||
performing computations using data flow graphs, the underlying representation of |
|||
deep learning models. It facilitates training and inference on CPUs and GPUs in |
|||
a desktop, server, or mobile device. Within the ML-Agents Toolkit, when you |
|||
train the behavior of an agent, the output is a model (.nn) file that you can |
|||
then associate with an Agent. Unless you implement a new algorithm, the use of |
|||
TensorFlow is mostly abstracted away and behind the scenes. |
|||
|
|||
## TensorBoard |
|||
|
|||
One component of training models with TensorFlow is setting the values of |
|||
certain model attributes (called _hyperparameters_). Finding the right values of |
|||
these hyperparameters can require a few iterations. Consequently, we leverage a |
|||
visualization tool within TensorFlow called |
|||
[TensorBoard](https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard). |
|||
It allows the visualization of certain agent attributes (e.g. reward) throughout |
|||
training which can be helpful in both building intuitions for the different |
|||
hyperparameters and setting the optimal values for your Unity environment. We |
|||
provide more details on setting the hyperparameters in the |
|||
[Training ML-Agents](Training-ML-Agents.md) page. If you are unfamiliar with |
|||
TensorBoard we recommend our guide on |
|||
[using TensorBoard with ML-Agents](Using-Tensorboard.md) or this |
|||
[tutorial](https://github.com/dandelionmane/tf-dev-summit-tensorboard-tutorial). |
撰写
预览
正在加载...
取消
保存
Reference in new issue