From 8958ea47c686d35338dcef0490a24273d249dd43 Mon Sep 17 00:00:00 2001 From: belerico Date: Thu, 27 Jun 2024 13:26:41 +0200 Subject: [PATCH 1/5] Fix numpy version --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2d1c9433..c89f0a50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ dependencies = [ "torchmetrics", "rich==13.5.*", "opencv-python==4.8.0.*", - "torch>=2.0,!=2.2.0" + "torch>=2.0,!=2.2.0", + "numpy<2.0" ] dynamic = ["version"] From aed21f6e0b912905be0aa47de8dbc42ced0c8dde Mon Sep 17 00:00:00 2001 From: belerico Date: Thu, 27 Jun 2024 13:27:58 +0200 Subject: [PATCH 2/5] Extract module from _FabricModule: prevent error with deepcopies with P2E --- sheeprl/utils/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sheeprl/utils/utils.py b/sheeprl/utils/utils.py index 3bdc16e7..74bf8a35 100644 --- a/sheeprl/utils/utils.py +++ b/sheeprl/utils/utils.py @@ -246,9 +246,7 @@ def unwrap_fabric(model: _FabricModule | nn.Module) -> nn.Module: Returns: nn.Module: the unwrapped model. """ - model = copy.deepcopy(model) - if isinstance(model, _FabricModule): - model = model.module + model = copy.deepcopy(getattr(model, "module", model)) for name, child in model.named_children(): setattr(model, name, unwrap_fabric(child)) return model From 3f8a11be3a7943cb9ebfda51744c7a20df2c5024 Mon Sep 17 00:00:00 2001 From: belerico Date: Thu, 27 Jun 2024 13:28:12 +0200 Subject: [PATCH 3/5] Fix tests --- tests/conftest.py | 1 - tests/test_algos/test_algos.py | 2 +- tests/test_algos/test_cli.py | 10 +--------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6bee80da..2e6e24f5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,7 +21,6 @@ def preserve_global_rank_variable(): def restore_env_variables(): """Ensures that environment variables set during the test do not leak out.""" env_backup = os.environ.copy() - os.environ["CUDA_VISIBLE_DEVICES"] = "-1" os.environ["SHEEPRL_SEARCH_PATH"] = "file://tests/configs;pkg://sheeprl.configs" yield leaked_vars = os.environ.keys() - env_backup.keys() diff --git a/tests/test_algos/test_algos.py b/tests/test_algos/test_algos.py index 09e98221..e8528bba 100644 --- a/tests/test_algos/test_algos.py +++ b/tests/test_algos/test_algos.py @@ -27,7 +27,7 @@ def standard_args(): "dry_run=True", "checkpoint.save_last=False", "env.num_envs=2", - f"env.sync_env={_IS_WINDOWS}", + "env.sync_env=True", "env.capture_video=False", "fabric.devices=auto", "fabric.accelerator=cpu", diff --git a/tests/test_algos/test_cli.py b/tests/test_algos/test_cli.py index 275ac9b4..db9140bb 100644 --- a/tests/test_algos/test_cli.py +++ b/tests/test_algos/test_cli.py @@ -51,16 +51,8 @@ def test_dp_strategy_instance_warning(): "metric.log_level=0", ] with mock.patch.object(sys, "argv", args): - with pytest.warns(UserWarning) as record: + with pytest.raises(ValueError, match="Expected a non cpu device, but got"): run() - assert len(record) >= 1 - assert ( - record[0].message.args[0] == "Running an algorithm with a strategy (DataParallelStrategy) " - "different than 'SingleDeviceStrategy' or 'DDPStrategy' can cause unexpected problems. " - "Please launch the script with a 'DDP' strategy with 'python sheeprl.py fabric.strategy=ddp' " - "or with a single device with 'python sheeprl.py fabric.strategy=auto fabric.devices=1' " - "if you run into any problems." - ) def test_decoupled_strategy_instance_fail(): From a2142d58c8357e63c31a15be6f4ca07c9ac93dcc Mon Sep 17 00:00:00 2001 From: belerico Date: Thu, 27 Jun 2024 13:28:22 +0200 Subject: [PATCH 4/5] Update version to dev --- sheeprl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheeprl/__init__.py b/sheeprl/__init__.py index a7a0bff7..3815ffcb 100644 --- a/sheeprl/__init__.py +++ b/sheeprl/__init__.py @@ -52,7 +52,7 @@ np.int = np.int64 np.bool = bool -__version__ = "0.5.7" +__version__ = "0.5.8.dev" # Replace `moviepy.decorators.use_clip_fps_by_default` method to work with python 3.8, 3.9, and 3.10 From 51c0fb981d1fa406ccd3289a48369f0fd208ccdd Mon Sep 17 00:00:00 2001 From: belerico Date: Thu, 27 Jun 2024 14:14:49 +0200 Subject: [PATCH 5/5] Fallback ValueError with DPStrategy --- tests/test_algos/test_cli.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_algos/test_cli.py b/tests/test_algos/test_cli.py index db9140bb..275ac9b4 100644 --- a/tests/test_algos/test_cli.py +++ b/tests/test_algos/test_cli.py @@ -51,8 +51,16 @@ def test_dp_strategy_instance_warning(): "metric.log_level=0", ] with mock.patch.object(sys, "argv", args): - with pytest.raises(ValueError, match="Expected a non cpu device, but got"): + with pytest.warns(UserWarning) as record: run() + assert len(record) >= 1 + assert ( + record[0].message.args[0] == "Running an algorithm with a strategy (DataParallelStrategy) " + "different than 'SingleDeviceStrategy' or 'DDPStrategy' can cause unexpected problems. " + "Please launch the script with a 'DDP' strategy with 'python sheeprl.py fabric.strategy=ddp' " + "or with a single device with 'python sheeprl.py fabric.strategy=auto fabric.devices=1' " + "if you run into any problems." + ) def test_decoupled_strategy_instance_fail():