diff --git a/.github/unittest/linux_examples/scripts/10_nvidia.json b/.github/unittest/linux_sota/scripts/10_nvidia.json similarity index 100% rename from .github/unittest/linux_examples/scripts/10_nvidia.json rename to .github/unittest/linux_sota/scripts/10_nvidia.json diff --git a/.github/unittest/linux_examples/scripts/environment.yml b/.github/unittest/linux_sota/scripts/environment.yml similarity index 100% rename from .github/unittest/linux_examples/scripts/environment.yml rename to .github/unittest/linux_sota/scripts/environment.yml diff --git a/.github/unittest/linux_examples/scripts/post_process.sh b/.github/unittest/linux_sota/scripts/post_process.sh similarity index 100% rename from .github/unittest/linux_examples/scripts/post_process.sh rename to .github/unittest/linux_sota/scripts/post_process.sh diff --git a/.github/unittest/linux_examples/scripts/run-clang-format.py b/.github/unittest/linux_sota/scripts/run-clang-format.py similarity index 100% rename from .github/unittest/linux_examples/scripts/run-clang-format.py rename to .github/unittest/linux_sota/scripts/run-clang-format.py diff --git a/.github/unittest/linux_examples/scripts/run_all.sh b/.github/unittest/linux_sota/scripts/run_all.sh similarity index 71% rename from .github/unittest/linux_examples/scripts/run_all.sh rename to .github/unittest/linux_sota/scripts/run_all.sh index 073ef59ed3f..6b1ba7070eb 100755 --- a/.github/unittest/linux_examples/scripts/run_all.sh +++ b/.github/unittest/linux_sota/scripts/run_all.sh @@ -106,30 +106,6 @@ python -c """import gym;import d4rl""" # install ale-py: manylinux names are broken for CentOS so we need to manually download and # rename them -PY_VERSION=$(python --version) -if [[ $PY_VERSION == *"3.7"* ]]; then - wget https://files.pythonhosted.org/packages/ab/fd/6615982d9460df7f476cad265af1378057eee9daaa8e0026de4cedbaffbd/ale_py-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pip install ale_py-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - rm ale_py-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -elif [[ $PY_VERSION == *"3.8"* ]]; then - wget https://files.pythonhosted.org/packages/0f/8a/feed20571a697588bc4bfef05d6a487429c84f31406a52f8af295a0346a2/ale_py-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pip install ale_py-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - rm ale_py-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -elif [[ $PY_VERSION == *"3.9"* ]]; then - wget https://files.pythonhosted.org/packages/a0/98/4316c1cedd9934f9a91b6e27a9be126043b4445594b40cfa391c8de2e5e8/ale_py-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pip install ale_py-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - rm ale_py-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -elif [[ $PY_VERSION == *"3.10"* ]]; then - wget https://files.pythonhosted.org/packages/60/1b/3adde7f44f79fcc50d0a00a0643255e48024c4c3977359747d149dc43500/ale_py-0.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl - mv ale_py-0.8.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl ale_py-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pip install ale_py-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - rm ale_py-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -elif [[ $PY_VERSION == *"3.11"* ]]; then - wget https://files.pythonhosted.org/packages/60/1b/3adde7f44f79fcc50d0a00a0643255e48024c4c3977359747d149dc43500/ale_py-0.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl - mv ale_py-0.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl ale_py-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pip install ale_py-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - rm ale_py-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -fi pip install "gymnasium[atari,accept-rom-license]<1.0" # ============================================================================================ # diff --git a/.github/unittest/linux_examples/scripts/run_local.sh b/.github/unittest/linux_sota/scripts/run_local.sh similarity index 100% rename from .github/unittest/linux_examples/scripts/run_local.sh rename to .github/unittest/linux_sota/scripts/run_local.sh diff --git a/.github/unittest/linux_sota/scripts/run_test.sh b/.github/unittest/linux_sota/scripts/run_test.sh new file mode 100755 index 00000000000..3ddb92e6cdd --- /dev/null +++ b/.github/unittest/linux_sota/scripts/run_test.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Leave blank as code needs to start on line 29 for run_local.sh +# +# +# +# +# +# +# + +#set -e +set -v + +# Initialize an error flag +error_occurred=0 +# Function to handle errors +error_handler() { + echo "Error on line $1" + error_occurred=1 +} +# Trap ERR to call the error_handler function with the failing line number +trap 'error_handler $LINENO' ERR + +export PYTORCH_TEST_WITH_SLOW='1' +python -m torch.utils.collect_env +# Avoid error: "fatal: unsafe repository" +git config --global --add safe.directory '*' + +root_dir="$(git rev-parse --show-toplevel)" +env_dir="${root_dir}/env" +lib_dir="${env_dir}/lib" + +# solves ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$lib_dir +export MKL_THREADING_LAYER=GNU +export CUDA_LAUNCH_BLOCKING=1 + +python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test.py -v --durations 200 + +coverage run -m pytest .github/unittest/linux_sota/scripts/run_tests.py --instafail --durations 200 -vvv --capture no --timeout=120 + +coverage combine +coverage xml -i + +# Check if any errors occurred during the script execution +if [ "$error_occurred" -ne 0 ]; then + echo "Errors occurred during script execution" + exit 1 +else + echo "Script executed successfully" +fi diff --git a/.github/unittest/linux_examples/scripts/run_test.sh b/.github/unittest/linux_sota/scripts/test_sota.py old mode 100755 new mode 100644 similarity index 52% rename from .github/unittest/linux_examples/scripts/run_test.sh rename to .github/unittest/linux_sota/scripts/test_sota.py index ef0d081f8fd..90c2adbe88c --- a/.github/unittest/linux_examples/scripts/run_test.sh +++ b/.github/unittest/linux_sota/scripts/test_sota.py @@ -1,80 +1,41 @@ -#!/usr/bin/env bash - -# Leave blank as code needs to start on line 29 for run_local.sh -# -# -# +# Copyright (c) Meta Platforms, Inc. and affiliates. # -# -# -# - -#set -e -set -v +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. +import os +import subprocess +from pathlib import Path -# Initialize an error flag -error_occurred=0 -# Function to handle errors -error_handler() { - echo "Error on line $1" - error_occurred=1 -} -# Trap ERR to call the error_handler function with the failing line number -trap 'error_handler $LINENO' ERR - -export PYTORCH_TEST_WITH_SLOW='1' -python -m torch.utils.collect_env -# Avoid error: "fatal: unsafe repository" -git config --global --add safe.directory '*' - -root_dir="$(git rev-parse --show-toplevel)" -env_dir="${root_dir}/env" -lib_dir="${env_dir}/lib" - -# solves ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$lib_dir -export MKL_THREADING_LAYER=GNU -export CUDA_LAUNCH_BLOCKING=1 +import pytest -python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test.py -v --durations 200 -#python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test_deps.py -v --durations 200 - -# ==================================================================================== # -# ================================ gym 0.23 ========================================== # - -# With batched environments -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/decision_transformer/dt.py \ +commands = { + "dt": """python sota-implementations/decision_transformer/dt.py \ optim.pretrain_gradient_steps=55 \ optim.updates_per_episode=3 \ optim.warmup_steps=10 \ logger.backend= \ env.backend=gymnasium \ env.name=HalfCheetah-v4 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/decision_transformer/online_dt.py \ +""", + "online_dt": """python sota-implementations/decision_transformer/online_dt.py \ optim.pretrain_gradient_steps=55 \ optim.updates_per_episode=3 \ optim.warmup_steps=10 \ env.backend=gymnasium \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/iql/iql_offline.py \ - optim.gradient_steps=55 \ - logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/cql/cql_offline.py \ +""", + "td3_bc": """python sota-implementations/td3_bc/td3_bc.py \ optim.gradient_steps=55 \ logger.backend= -# ==================================================================================== # -# ================================ Gymnasium ========================================= # - -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/td3_bc/td3_bc.py \ - optim.gradient_steps=55 \ - logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/impala/impala_single_node.py \ +""", + "impala_single_node": """python sota-implementations/impala/impala_single_node.py \ collector.total_frames=80 \ collector.frames_per_batch=20 \ collector.num_workers=1 \ logger.backend= \ logger.test_interval=10 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/ppo/ppo_mujoco.py \ +""", + "ppo_mujoco": """python sota-implementations/ppo/ppo_mujoco.py \ env.env_name=HalfCheetah-v4 \ collector.total_frames=40 \ collector.frames_per_batch=20 \ @@ -82,14 +43,16 @@ loss.ppo_epochs=2 \ logger.backend= \ logger.test_interval=10 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/ppo/ppo_atari.py \ +""", + "ppo_atari": """python sota-implementations/ppo/ppo_atari.py \ collector.total_frames=80 \ collector.frames_per_batch=20 \ loss.mini_batch_size=20 \ loss.ppo_epochs=2 \ logger.backend= \ logger.test_interval=10 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/ddpg/ddpg.py \ +""", + "ddpg": """python sota-implementations/ddpg/ddpg.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ optim.batch_size=10 \ @@ -99,20 +62,23 @@ replay_buffer.size=120 \ env.name=Pendulum-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/a2c/a2c_mujoco.py \ +""", + "a2c_mujoco": """python sota-implementations/a2c/a2c_mujoco.py \ env.env_name=HalfCheetah-v4 \ collector.total_frames=40 \ collector.frames_per_batch=20 \ loss.mini_batch_size=10 \ logger.backend= \ logger.test_interval=40 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/a2c/a2c_atari.py \ +""", + "a2c_atari": """python sota-implementations/a2c/a2c_atari.py \ collector.total_frames=80 \ collector.frames_per_batch=20 \ loss.mini_batch_size=20 \ logger.backend= \ logger.test_interval=40 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/dqn/dqn_atari.py \ +""", + "dqn_atari": """python sota-implementations/dqn/dqn_atari.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ collector.frames_per_batch=16 \ @@ -120,7 +86,8 @@ loss.num_updates=1 \ logger.backend= \ buffer.buffer_size=120 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/cql/discrete_cql_online.py \ +""", + "discrete_cql_online": """python sota-implementations/cql/discrete_cql_online.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ optim.batch_size=10 \ @@ -128,7 +95,8 @@ collector.env_per_collector=2 \ replay_buffer.size=120 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/redq/redq.py \ +""", + "redq": """python sota-implementations/redq/redq.py \ num_workers=4 \ collector.total_frames=48 \ collector.init_random_frames=10 \ @@ -140,7 +108,8 @@ logger.record_frames=4 \ buffer.size=120 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/sac/sac.py \ +""", + "sac": """python sota-implementations/sac/sac.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ collector.frames_per_batch=16 \ @@ -150,7 +119,8 @@ replay_buffer.size=120 \ env.name=Pendulum-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/discrete_sac/discrete_sac.py \ +""", + "discrete_sac": """python sota-implementations/discrete_sac/discrete_sac.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ collector.frames_per_batch=16 \ @@ -162,7 +132,8 @@ replay_buffer.size=120 \ env.name=CartPole-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/crossq/crossq.py \ +""", + "crossq": """python sota-implementations/crossq/crossq.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ collector.frames_per_batch=16 \ @@ -174,7 +145,8 @@ env.name=Pendulum-v1 \ network.device= \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/td3/td3.py \ +""", + "td3": """python sota-implementations/td3/td3.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ optim.batch_size=10 \ @@ -184,37 +156,40 @@ logger.mode=offline \ env.name=Pendulum-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/iql/iql_online.py \ +""", + "iql_online": """python sota-implementations/iql/iql_online.py \ collector.total_frames=48 \ optim.batch_size=10 \ collector.frames_per_batch=16 \ env.train_num_envs=2 \ logger.mode=offline \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/iql/discrete_iql.py \ +""", + "discrete_iql": """python sota-implementations/iql/discrete_iql.py \ collector.total_frames=48 \ optim.batch_size=10 \ collector.frames_per_batch=16 \ env.train_num_envs=2 \ logger.mode=offline \ logger.backend= - python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/cql/cql_online.py \ +""", + "cql_online": """python sota-implementations/cql/cql_online.py \ collector.total_frames=48 \ optim.batch_size=10 \ collector.frames_per_batch=16 \ env.train_num_envs=2 \ logger.mode=offline \ logger.backend= - python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/gail/gail.py \ +""", + "gail": """python sota-implementations/gail/gail.py \ ppo.collector.total_frames=48 \ replay_buffer.batch_size=16 \ ppo.loss.mini_batch_size=10 \ ppo.collector.frames_per_batch=16 \ logger.mode=offline \ logger.backend= - -# With single envs -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/dreamer/dreamer.py \ +""", + "dreamer": """python sota-implementations/dreamer/dreamer.py \ collector.total_frames=200 \ collector.init_random_frames=10 \ collector.frames_per_batch=200 \ @@ -226,7 +201,8 @@ replay_buffer.batch_size=24 \ replay_buffer.batch_length=12 \ networks.rssm_hidden_dim=17 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/ddpg/ddpg.py \ +""", + "ddpg-single": """python sota-implementations/ddpg/ddpg.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ optim.batch_size=10 \ @@ -236,15 +212,8 @@ replay_buffer.size=120 \ env.name=Pendulum-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/dqn/dqn_atari.py \ - collector.total_frames=48 \ - collector.init_random_frames=10 \ - collector.frames_per_batch=16 \ - buffer.batch_size=10 \ - loss.num_updates=1 \ - logger.backend= \ - buffer.buffer_size=120 -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/redq/redq.py \ +""", + "redq-single": """python sota-implementations/redq/redq.py \ num_workers=2 \ collector.total_frames=48 \ collector.init_random_frames=10 \ @@ -256,21 +225,24 @@ logger.record_frames=4 \ buffer.size=120 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/iql/iql_online.py \ +""", + "iql_online-single": """python sota-implementations/iql/iql_online.py \ collector.total_frames=48 \ optim.batch_size=10 \ collector.frames_per_batch=16 \ env.train_num_envs=1 \ logger.mode=offline \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/cql/cql_online.py \ +""", + "cql_online-single": """python sota-implementations/cql/cql_online.py \ collector.total_frames=48 \ optim.batch_size=10 \ collector.frames_per_batch=16 \ collector.env_per_collector=1 \ logger.mode=offline \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/td3/td3.py \ +""", + "td3-single": """python sota-implementations/td3/td3.py \ collector.total_frames=48 \ collector.init_random_frames=10 \ collector.frames_per_batch=16 \ @@ -280,49 +252,66 @@ optim.batch_size=10 \ env.name=Pendulum-v1 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/multiagent/mappo_ippo.py \ +""", + "mappo_ippo": """python sota-implementations/multiagent/mappo_ippo.py \ collector.n_iters=2 \ collector.frames_per_batch=200 \ train.num_epochs=3 \ train.minibatch_size=100 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/multiagent/maddpg_iddpg.py \ +""", + "maddpg_iddpg": """python sota-implementations/multiagent/maddpg_iddpg.py \ collector.n_iters=2 \ collector.frames_per_batch=200 \ train.num_epochs=3 \ train.minibatch_size=100 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/multiagent/iql.py \ +""", + "iql_marl": """python sota-implementations/multiagent/iql.py \ collector.n_iters=2 \ collector.frames_per_batch=200 \ train.num_epochs=3 \ train.minibatch_size=100 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/multiagent/qmix_vdn.py \ +""", + "qmix_vdn": """python sota-implementations/multiagent/qmix_vdn.py \ collector.n_iters=2 \ collector.frames_per_batch=200 \ train.num_epochs=3 \ train.minibatch_size=100 \ logger.backend= -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/multiagent/sac.py \ +""", + "marl_sac": """python sota-implementations/multiagent/sac.py \ collector.n_iters=2 \ collector.frames_per_batch=200 \ train.num_epochs=3 \ train.minibatch_size=100 \ logger.backend= +""", + "bandits": """python sota-implementations/bandits/dqn.py --n_steps=100 +""", +} + + +def run_command(command): + # Get the current coverage settings + cov_settings = os.environ.get('COVERAGE_PROCESS_START') + + if cov_settings: + # If coverage is enabled, run the command with coverage + command = f"coverage run --parallel-mode {command}" + + subprocess.check_call( + command, shell=True, cwd=Path(__file__).parent.parent.parent.parent.parent + ) -python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/bandits/dqn.py --n_steps=100 -## RLHF -# RLHF tests are executed in the dedicated workflow +@pytest.mark.parametrize("algo", list(commands)) +def test_multiagent_commands(algo): + run_command(commands[algo]) -coverage combine -coverage xml -i -# Check if any errors occurred during the script execution -if [ "$error_occurred" -ne 0 ]; then - echo "Errors occurred during script execution" - exit 1 -else - echo "Script executed successfully" -fi +# Test bandits separately +def test_bandits(): + command = "" + run_command(command) diff --git a/.github/workflows/test-linux-examples.yml b/.github/workflows/test-linux-sota.yml similarity index 94% rename from .github/workflows/test-linux-examples.yml rename to .github/workflows/test-linux-sota.yml index c4fb8ad003b..d1fc38359b9 100644 --- a/.github/workflows/test-linux-examples.yml +++ b/.github/workflows/test-linux-sota.yml @@ -1,4 +1,4 @@ -name: Examples Tests on Linux +name: SOTA Tests on Linux on: pull_request: @@ -52,4 +52,4 @@ jobs: export TD_GET_DEFAULTS_TO_NONE=1 ## setup_env.sh - bash .github/unittest/linux_examples/scripts/run_all.sh + bash .github/unittest/linux_sota/scripts/run_all.sh