浏览代码

Merge branch 'master' into develop-action-buffer

/develop/action-spec-gym
Andrew Cohen 4 年前
当前提交
b5d1c071
共有 11 个文件被更改,包括 41 次插入22 次删除
  1. 4
      .github/workflows/pytest.yml
  2. 22
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  3. 3
      com.unity.ml-agents/CHANGELOG.md
  4. 2
      docs/Installation.md
  5. 2
      ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_gail.py
  6. 6
      ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py
  7. 4
      ml-agents/mlagents/trainers/tests/torch/test_utils.py
  8. 4
      ml-agents/mlagents/trainers/tf/model_serialization.py
  9. 6
      ml-agents/mlagents/trainers/torch/distributions.py
  10. 2
      ml-agents/mlagents/trainers/torch/utils.py
  11. 8
      ml-agents/setup.py

4
.github/workflows/pytest.yml


python -m pip install --progress-bar=off -r test_requirements.txt -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./gym-unity -c ${{ matrix.pip_constraints }}
- name: Save python dependencies
run: pip freeze > pip_versions-${{ matrix.python-version }}.txt
run: |
pip freeze > pip_versions-${{ matrix.python-version }}.txt
cat pip_versions-${{ matrix.python-version }}.txt
- name: Run pytest
run: pytest --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings
- name: Upload pytest test results

22
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


var bp = m_Agent.GetComponent<BehaviorParameters>();
var behaviorName = bp.BehaviorName;
var nnModel = GetModelForBehaviorName(behaviorName);
NNModel nnModel = null;
try
{
nnModel = GetModelForBehaviorName(behaviorName);
}
catch (Exception e)
{
overrideError = $"Exception calling GetModelForBehaviorName: {e}";
}
overrideError =
$"Didn't find a model for behaviorName {behaviorName}. Make " +
$"sure the behaviorName is set correctly in the commandline " +
$"and that the model file exists";
if (string.IsNullOrEmpty(overrideError))
{
overrideError =
$"Didn't find a model for behaviorName {behaviorName}. Make " +
"sure the behaviorName is set correctly in the commandline " +
"and that the model file exists";
}
}
else
{

3
com.unity.ml-agents/CHANGELOG.md


#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- PyTorch trainers are now the default. See the
[installation docs](https://github.com/Unity-Technologies/ml-agents/blob/mastere/docs/Installation.md) for
[installation docs](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md) for
more information on installing PyTorch. For the time being, TensorFlow is still available;
you can use the TensorFlow backend by adding `--tensorflow` to the CLI, or
adding `framework: tensorflow` in the configuration YAML. (#4517)

- The Barracuda dependency was upgraded to 1.1.2 (#4571)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- The `action_probs` node is no longer listed as an output in TensorFlow models (#4613).
### Bug Fixes
#### com.unity.ml-agents (C#)

2
docs/Installation.md


installing ML-Agents. Activate your virtual environment and run from the command line:
```sh
pip3 install torch -f https://download.pytorch.org/whl/torch_stable.html
pip3 install torch==1.7.0 -f https://download.pytorch.org/whl/torch_stable.html
```
Note that on Windows, you may also need Microsoft's

2
ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_gail.py


RewardSignalType.GAIL, behavior_spec, gail_settings
)
for _ in range(200):
for _ in range(300):
gail_rp.update(buffer_policy)
reward_expert = gail_rp.evaluate(buffer_expert)[0]
reward_policy = gail_rp.evaluate(buffer_policy)[0]

6
ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py


) -> AgentBuffer:
buffer = AgentBuffer()
curr_observations = [
np.random.normal(size=shape) for shape in behavior_spec.observation_shapes
np.random.normal(size=shape).astype(np.float32)
for shape in behavior_spec.observation_shapes
np.random.normal(size=shape) for shape in behavior_spec.observation_shapes
np.random.normal(size=shape).astype(np.float32)
for shape in behavior_spec.observation_shapes
]
action_buffer = behavior_spec.action_spec.random_action(1)
action = {}

4
ml-agents/mlagents/trainers/tests/torch/test_utils.py


def test_list_to_tensor():
# Test converting pure list
unconverted_list = [[1, 2], [1, 3], [1, 4]]
unconverted_list = [[1.0, 2], [1, 3], [1, 4]]
tensor = ModelUtils.list_to_tensor(unconverted_list)
# Should be equivalent to torch.tensor conversion
assert torch.equal(tensor, torch.tensor(unconverted_list))

list_of_np = [np.asarray(_el) for _el in unconverted_list]
tensor = ModelUtils.list_to_tensor(list_of_np)
# Should be equivalent to torch.tensor conversion
assert torch.equal(tensor, torch.tensor(unconverted_list))
assert torch.equal(tensor, torch.tensor(unconverted_list, dtype=torch.float32))
def test_break_into_branches():

4
ml-agents/mlagents/trainers/tf/model_serialization.py


]
)
POSSIBLE_OUTPUT_NODES = frozenset(
["action", "action_probs", "recurrent_out", "value_estimate"]
)
POSSIBLE_OUTPUT_NODES = frozenset(["action", "recurrent_out", "value_estimate"])
MODEL_CONSTANTS = frozenset(
[

6
ml-agents/mlagents/trainers/torch/distributions.py


if self.conditional_sigma:
log_sigma = torch.clamp(self.log_sigma(inputs), min=-20, max=2)
else:
# Expand so that entropy matches batch size
log_sigma = self.log_sigma.expand(inputs.shape[0], -1)
# Expand so that entropy matches batch size. Note that we're using
# torch.cat here instead of torch.expand() becuase it is not supported in the
# verified version of Barracuda (1.0.2).
log_sigma = torch.cat([self.log_sigma] * inputs.shape[0], axis=0)
if self.tanh_squash:
return [TanhGaussianDistInstance(mu, torch.exp(log_sigma))]
else:

2
ml-agents/mlagents/trainers/torch/utils.py


@staticmethod
def list_to_tensor(
ndarray_list: List[np.ndarray], dtype: Optional[torch.dtype] = None
ndarray_list: List[np.ndarray], dtype: Optional[torch.dtype] = torch.float32
) -> torch.Tensor:
"""
Converts a list of numpy arrays into a tensor. MUCH faster than

8
ml-agents/setup.py


"Pillow>=4.2.1",
"protobuf>=3.6",
"pyyaml>=3.1.0",
# Windows ver. of PyTorch doesn't work from PyPi
'torch>=1.6.0;platform_system!="Windows"',
# Windows ver. of PyTorch doesn't work from PyPi. Installation:
# https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md#windows-installing-pytorch
'torch>=1.6.0,<1.8.0;platform_system!="Windows"',
"cattrs>=1.0.0",
# cattrs 1.1.0 dropped support for python 3.6.
"cattrs>=1.0.0,<1.1.0",
"attrs>=19.3.0",
'pypiwin32==223;platform_system=="Windows"',
],

正在加载...
取消
保存