Skip to content

Commit

Permalink
Upgrade PyTorch version for python 3.9 (Unity-Technologies#5028)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruo-Ping Dong authored Mar 11, 2021
1 parent 1158df0 commit 65d1983
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ jobs:
TEST_ENFORCE_BUFFER_KEY_TYPES: 1
strategy:
matrix:
python-version: [3.6.x, 3.7.x, 3.8.x]
python-version: [3.6.x, 3.7.x, 3.8.x, 3.9.x]
include:
- python-version: 3.6.x
pip_constraints: test_constraints_min_version.txt
- python-version: 3.7.x
pip_constraints: test_constraints_mid_version.txt
- python-version: 3.8.x
pip_constraints: test_constraints_mid_version.txt
- python-version: 3.9.x
pip_constraints: test_constraints_max_version.txt
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -32,7 +41,7 @@ jobs:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('ml-agents/setup.py', 'ml-agents-envs/setup.py', 'gym-unity/setup.py', 'test_requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('ml-agents/setup.py', 'ml-agents-envs/setup.py', 'gym-unity/setup.py', 'test_requirements.txt', matrix.pip_constraints) }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
Expand All @@ -42,11 +51,11 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install --progress-bar=off -e ./ml-agents-envs
python -m pip install --progress-bar=off -e ./ml-agents
python -m pip install --progress-bar=off -r test_requirements.txt
python -m pip install --progress-bar=off -e ./gym-unity
python -m pip install --progress-bar=off -e ./ml-agents-plugin-examples
python -m pip install --progress-bar=off -e ./ml-agents-envs -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./ml-agents -c ${{ matrix.pip_constraints }}
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 }}
python -m pip install --progress-bar=off -e ./ml-agents-plugin-examples -c ${{ matrix.pip_constraints }}
- name: Save python dependencies
run: |
pip freeze > pip_versions-${{ matrix.python-version }}.txt
Expand Down
15 changes: 10 additions & 5 deletions ml-agents/mlagents/trainers/tests/torch/test_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ def test_hybrid_visual_ppo(num_visual, training_seed):
[BRAIN_NAME], num_visual=num_visual, num_vector=0, action_sizes=(1, 1)
)
new_hyperparams = attr.evolve(
PPO_TORCH_CONFIG.hyperparameters, learning_rate=3.0e-4
PPO_TORCH_CONFIG.hyperparameters,
batch_size=64,
buffer_size=1024,
learning_rate=1e-4,
)
config = attr.evolve(
PPO_TORCH_CONFIG, hyperparameters=new_hyperparams, max_steps=8000
)
config = attr.evolve(PPO_TORCH_CONFIG, hyperparameters=new_hyperparams)
check_environment_trains(env, {BRAIN_NAME: config}, training_seed=training_seed)


Expand Down Expand Up @@ -85,7 +90,7 @@ def test_hybrid_sac(action_size):
buffer_init_steps=0,
)
config = attr.evolve(
SAC_TORCH_CONFIG, hyperparameters=new_hyperparams, max_steps=2200
SAC_TORCH_CONFIG, hyperparameters=new_hyperparams, max_steps=6000
)
check_environment_trains(env, {BRAIN_NAME: config}, success_threshold=0.9)

Expand Down Expand Up @@ -118,14 +123,14 @@ def test_hybrid_recurrent_sac():
new_hyperparams = attr.evolve(
SAC_TORCH_CONFIG.hyperparameters,
batch_size=256,
learning_rate=1e-3,
learning_rate=3e-4,
buffer_init_steps=1000,
steps_per_update=2,
)
config = attr.evolve(
SAC_TORCH_CONFIG,
hyperparameters=new_hyperparams,
network_settings=new_networksettings,
max_steps=3500,
max_steps=4000,
)
check_environment_trains(env, {BRAIN_NAME: config}, training_seed=1212)
6 changes: 4 additions & 2 deletions ml-agents/mlagents/trainers/tests/torch/test_simple_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,11 @@ def test_gail_visual_ppo(simple_record, action_sizes):
)
bc_settings = BehavioralCloningSettings(demo_path=demo_path, steps=1500)
reward_signals = {
RewardSignalType.GAIL: GAILSettings(encoding_size=32, demo_path=demo_path)
RewardSignalType.GAIL: GAILSettings(
gamma=0.8, encoding_size=32, demo_path=demo_path
)
}
hyperparams = attr.evolve(PPO_TORCH_CONFIG.hyperparameters, learning_rate=5e-3)
hyperparams = attr.evolve(PPO_TORCH_CONFIG.hyperparameters, learning_rate=1e-3)
config = attr.evolve(
PPO_TORCH_CONFIG,
reward_signals=reward_signals,
Expand Down
5 changes: 4 additions & 1 deletion ml-agents/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def run(self):
"pyyaml>=3.1.0",
# Windows ver. of PyTorch doesn't work from PyPi. Installation:
# https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Installation.md#windows-installing-pytorch
'torch>=1.6.0,<1.8.0;platform_system!="Windows"',
# Torch only working on python 3.9 for 1.8.0 and above. Details see:
# https://github.com/pytorch/pytorch/issues/50014
"torch>=1.8.0,<1.9.0;(platform_system!='Windows' and python_version>='3.9')",
"torch>=1.6.0,<1.9.0;(platform_system!='Windows' and python_version<'3.9')",
"tensorboard>=1.15",
# cattrs 1.1.0 dropped support for python 3.6, but 1.0.0 doesn't work for python 3.9
# Since there's no version that supports both, we have to draw the line somwehere.
Expand Down
3 changes: 3 additions & 0 deletions test_constraints_max_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pip constraints to use the *highest* versions allowed in ml-agents/setup.py
# For projects with upper bounds, we should periodically update this list to the latest
torch==1.8.0
2 changes: 2 additions & 0 deletions test_constraints_mid_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pip constraints to use a version in the middle of allowed ranges in ml-agents/setup.py
torch==1.7.0
2 changes: 2 additions & 0 deletions test_constraints_min_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pip constraints to use the *lowest* versions allowed in ml-agents/setup.py
torch==1.6.0

0 comments on commit 65d1983

Please sign in to comment.