Ruo-Ping Dong
4 年前
当前提交
fd1dc3a6
共有 52 个文件被更改,包括 419 次插入 和 423 次删除
-
219.circleci/config.yml
-
1DevProject/.gitignore
-
4com.unity.ml-agents.extensions/.gitignore
-
2com.unity.ml-agents/.gitignore
-
9com.unity.ml-agents/CHANGELOG.md
-
2docs/Background-Machine-Learning.md
-
2ml-agents/mlagents/trainers/ghost/trainer.py
-
4ml-agents/mlagents/trainers/optimizer/torch_optimizer.py
-
16ml-agents/mlagents/trainers/policy/torch_policy.py
-
9ml-agents/mlagents/trainers/ppo/optimizer_torch.py
-
19ml-agents/mlagents/trainers/ppo/trainer.py
-
2ml-agents/mlagents/trainers/ppo/optimizer_tf.py
-
18ml-agents/mlagents/trainers/sac/optimizer_torch.py
-
19ml-agents/mlagents/trainers/sac/trainer.py
-
10ml-agents/mlagents/trainers/tests/test_ppo.py
-
4ml-agents/mlagents/trainers/tests/test_reward_signals.py
-
15ml-agents/mlagents/trainers/tests/test_rl_trainer.py
-
9ml-agents/mlagents/trainers/tests/test_sac.py
-
50ml-agents/mlagents/trainers/tests/test_saver.py
-
21ml-agents/mlagents/trainers/tests/torch/test_bcmodule.py
-
9ml-agents/mlagents/trainers/tests/torch/test_reward_providers/test_curiosity.py
-
2ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py
-
4ml-agents/mlagents/trainers/tf/models.py
-
2ml-agents/mlagents/trainers/torch/components/bc/module.py
-
9ml-agents/mlagents/trainers/torch/components/reward_providers/base_reward_provider.py
-
9ml-agents/mlagents/trainers/torch/components/reward_providers/curiosity_reward_provider.py
-
32ml-agents/mlagents/trainers/torch/components/reward_providers/gail_reward_provider.py
-
1ml-agents/mlagents/trainers/torch/model_serialization.py
-
8ml-agents/mlagents/trainers/torch/utils.py
-
24ml-agents/mlagents/trainers/trainer/rl_trainer.py
-
16ml-agents/mlagents/trainers/trainer_controller.py
-
16ml-agents/mlagents/trainers/model_saver/torch_model_saver.py
-
16ml-agents/mlagents/trainers/model_saver/tf_model_saver.py
-
22ml-agents/mlagents/trainers/model_saver/model_saver.py
-
3ml-agents/setup.py
-
2test_constraints_max_tf2_version.txt
-
2test_constraints_min_version.txt
-
3test_requirements.txt
-
38ml-agents/mlagents/trainers/tests/torch/saver/test_saver.py
-
19.github/workflows/nightly.yml
-
41.github/workflows/pre-commit.yml
-
60.github/workflows/pytest.yml
-
69ml-agents/mlagents/trainers/tests/torch/saver/test_saver_reward_providers.py
-
0/ml-agents/mlagents/trainers/ppo/optimizer_tf.py
-
0/ml-agents/mlagents/trainers/sac/optimizer_tf.py
-
0/ml-agents/mlagents/trainers/model_saver
-
0/ml-agents/mlagents/trainers/model_saver/torch_model_saver.py
-
0/ml-agents/mlagents/trainers/model_saver/tf_model_saver.py
-
0/ml-agents/mlagents/trainers/model_saver/model_saver.py
-
0/ml-agents/mlagents/trainers/tests/torch/saver/test_saver.py
|
|||
name: nightly |
|||
|
|||
on: |
|||
schedule: |
|||
- cron: '0 7 * * *' # run at 7 AM UTC == midnight PST |
|||
|
|||
jobs: |
|||
markdown-link-check-full: |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- uses: actions/setup-python@v1 |
|||
- uses: actions/setup-node@v2-beta |
|||
with: |
|||
node-version: '12' |
|||
- run: sudo npm install -g markdown-link-check |
|||
- uses: pre-commit/action@v2.0.0 |
|||
with: |
|||
extra_args: --hook-stage manual markdown-link-check-full --all-files |
|
|||
name: pre-commit |
|||
|
|||
on: |
|||
pull_request: |
|||
push: |
|||
branches: [master] |
|||
|
|||
jobs: |
|||
pre-commit: |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- uses: actions/setup-python@v1 |
|||
- uses: actions/setup-ruby@v1 |
|||
with: |
|||
ruby-version: '2.6' |
|||
- uses: actions/setup-dotnet@v1 |
|||
with: |
|||
dotnet-version: '3.1.x' |
|||
- run: dotnet tool install -g dotnet-format --version 4.1.131201 |
|||
- uses: pre-commit/action@v2.0.0 |
|||
|
|||
markdown-link-check: |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- uses: actions/setup-python@v1 |
|||
- uses: actions/setup-node@v2-beta |
|||
with: |
|||
node-version: '12' |
|||
- run: sudo npm install -g markdown-link-check |
|||
- uses: pre-commit/action@v2.0.0 |
|||
with: |
|||
extra_args: --hook-stage manual markdown-link-check --all-files |
|||
|
|||
validate-meta-files: |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- uses: actions/setup-python@v1 |
|||
- run: python utils/validate_meta_files.py |
|
|||
name: pytest |
|||
|
|||
on: |
|||
pull_request: |
|||
push: |
|||
branches: [master] |
|||
|
|||
jobs: |
|||
pytest: |
|||
runs-on: ubuntu-latest |
|||
strategy: |
|||
matrix: |
|||
python-version: [3.6.x, 3.7.x, 3.8.x] |
|||
include: |
|||
- python-version: 3.6.x |
|||
pip_constraints: test_constraints_min_version.txt |
|||
- python-version: 3.7.x |
|||
pip_constraints: test_constraints_max_tf1_version.txt |
|||
- python-version: 3.8.x |
|||
pip_constraints: test_constraints_max_tf2_version.txt |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- name: Set up Python |
|||
uses: actions/setup-python@v2 |
|||
with: |
|||
python-version: ${{ matrix.python-version }} |
|||
- name: Cache pip |
|||
uses: actions/cache@v2 |
|||
with: |
|||
# 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', matrix.pip_constraints) }} |
|||
restore-keys: | |
|||
${{ runner.os }}-pip- |
|||
${{ runner.os }}- |
|||
- name: Display Python version |
|||
run: python -c "import sys; print(sys.version)" |
|||
- name: Install dependencies |
|||
run: | |
|||
python -m pip install --upgrade pip |
|||
python -m pip install --upgrade setuptools |
|||
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 }} |
|||
- name: Save python dependencies |
|||
run: pip freeze > 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 |
|||
uses: actions/upload-artifact@v2 |
|||
with: |
|||
name: artifacts-${{ matrix.python-version }} |
|||
path: | |
|||
htmlcov |
|||
pip_versions-${{ matrix.python-version }}.txt |
|||
junit/test-results-${{ matrix.python-version }}.xml |
|||
# Use always() to always run this step to publish test results when there are test failures |
|||
if: ${{ always() }} |
|
|||
import pytest |
|||
import os |
|||
|
|||
from mlagents.trainers.ppo.optimizer_torch import TorchPPOOptimizer |
|||
from mlagents.trainers.sac.optimizer_torch import TorchSACOptimizer |
|||
from mlagents.trainers.model_saver.torch_model_saver import TorchModelSaver |
|||
from mlagents.trainers.settings import ( |
|||
TrainerSettings, |
|||
RewardSignalType, |
|||
CuriositySettings, |
|||
GAILSettings, |
|||
PPOSettings, |
|||
SACSettings, |
|||
) |
|||
from mlagents.trainers.tests.torch.test_policy import create_policy_mock |
|||
|
|||
DEMO_PATH = ( |
|||
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir) |
|||
+ "/test.demo" |
|||
) |
|||
|
|||
|
|||
@pytest.mark.parametrize( |
|||
"optimizer", |
|||
[(TorchPPOOptimizer, PPOSettings), (TorchSACOptimizer, SACSettings)], |
|||
ids=["ppo", "sac"], |
|||
) |
|||
def test_reward_provider_save(tmp_path, optimizer): |
|||
OptimizerClass, HyperparametersClass = optimizer |
|||
|
|||
trainer_settings = TrainerSettings() |
|||
trainer_settings.hyperparameters = HyperparametersClass() |
|||
trainer_settings.reward_signals = { |
|||
RewardSignalType.CURIOSITY: CuriositySettings(), |
|||
RewardSignalType.GAIL: GAILSettings(demo_path=DEMO_PATH), |
|||
} |
|||
policy = create_policy_mock(trainer_settings, use_discrete=False) |
|||
optimizer = OptimizerClass(policy, trainer_settings) |
|||
|
|||
# save at path 1 |
|||
path1 = os.path.join(tmp_path, "runid1") |
|||
model_saver = TorchModelSaver(trainer_settings, path1) |
|||
model_saver.register(policy) |
|||
model_saver.register(optimizer) |
|||
model_saver.initialize_or_load() |
|||
policy.set_step(2000) |
|||
model_saver.save_checkpoint("MockBrain", 2000) |
|||
|
|||
# create a new optimizer and policy |
|||
optimizer2 = OptimizerClass(policy, trainer_settings) |
|||
policy2 = create_policy_mock(trainer_settings, use_discrete=False) |
|||
|
|||
# load weights |
|||
model_saver2 = TorchModelSaver(trainer_settings, path1, load=True) |
|||
model_saver2.register(policy2) |
|||
model_saver2.register(optimizer2) |
|||
model_saver2.initialize_or_load() # This is to load the optimizers |
|||
|
|||
# assert the models have the same weights |
|||
module_dict_1 = optimizer.get_modules() |
|||
module_dict_2 = optimizer2.get_modules() |
|||
assert "Module:GAIL" in module_dict_1 |
|||
assert "Module:GAIL" in module_dict_2 |
|||
for name, module1 in module_dict_1.items(): |
|||
assert name in module_dict_2 |
|||
module2 = module_dict_2[name] |
|||
if hasattr(module1, "parameters"): |
|||
for param1, param2 in zip(module1.parameters(), module2.parameters()): |
|||
assert param1.data.ne(param2.data).sum() == 0 |
撰写
预览
正在加载...
取消
保存
Reference in new issue