From 52804abf58d1b7af181a46f2aa756ddc35d9554b Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 11 Jan 2023 14:48:10 +0100 Subject: [PATCH 1/5] fix --- src/lightning_fabric/connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_fabric/connector.py b/src/lightning_fabric/connector.py index 1b0d960e8413a..9d41722446594 100644 --- a/src/lightning_fabric/connector.py +++ b/src/lightning_fabric/connector.py @@ -541,7 +541,7 @@ def _argument_from_env(name: str, current: Any, default: Any) -> Any: if env_value is not None and env_value != str(current) and str(current) != str(default): raise ValueError( f"Your code has `Fabric({name}={current!r}, ...)` but it conflicts with the value " - f"`--{name}={current}` set through the CLI. " + f"`--{name}={env_value!r}` set through the CLI. " " Remove it either from the CLI or from the Lightning Fabric object." ) if env_value is None: From e0c449c4a372d62dd11d5bdcc805abba246b80ff Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 11 Jan 2023 14:56:16 +0100 Subject: [PATCH 2/5] tests --- src/lightning_fabric/connector.py | 2 +- tests/tests_fabric/test_connector.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/lightning_fabric/connector.py b/src/lightning_fabric/connector.py index 9d41722446594..2b07f1dee77ec 100644 --- a/src/lightning_fabric/connector.py +++ b/src/lightning_fabric/connector.py @@ -541,7 +541,7 @@ def _argument_from_env(name: str, current: Any, default: Any) -> Any: if env_value is not None and env_value != str(current) and str(current) != str(default): raise ValueError( f"Your code has `Fabric({name}={current!r}, ...)` but it conflicts with the value " - f"`--{name}={env_value!r}` set through the CLI. " + f"`--{name}={env_value}` set through the CLI. " " Remove it either from the CLI or from the Lightning Fabric object." ) if env_value is None: diff --git a/tests/tests_fabric/test_connector.py b/tests/tests_fabric/test_connector.py index 94fc2def786f9..008a78018ae50 100644 --- a/tests/tests_fabric/test_connector.py +++ b/tests/tests_fabric/test_connector.py @@ -829,27 +829,23 @@ def test_devices_from_environment(*_): def test_arguments_from_environment_collision(): """Test that the connector raises an error when the CLI settings conflict with settings in the code.""" with mock.patch.dict(os.environ, {"LT_ACCELERATOR": "cpu"}): - with pytest.raises( - ValueError, match=escape("Your code has `Fabric(accelerator='cuda', ...)` but it conflicts") - ): + with pytest.raises(ValueError, match="`Fabric\\(accelerator='cuda', ...\\)` but .* `--accelerator=cpu`"): _Connector(accelerator="cuda") with mock.patch.dict(os.environ, {"LT_STRATEGY": "ddp"}): - with pytest.raises( - ValueError, match=escape("Your code has `Fabric(strategy='ddp_spawn', ...)` but it conflicts") - ): + with pytest.raises(ValueError, match="`Fabric\\(strategy='ddp_spawn', ...\\)` but .* `--strategy=ddp`"): _Connector(strategy="ddp_spawn") with mock.patch.dict(os.environ, {"LT_DEVICES": "2"}): - with pytest.raises(ValueError, match=escape("Your code has `Fabric(devices=3, ...)` but it conflicts")): + with pytest.raises(ValueError, match="`Fabric\\(devices=3, ...\\)` but .* `--devices=2`"): _Connector(devices=3) with mock.patch.dict(os.environ, {"LT_NUM_NODES": "3"}): - with pytest.raises(ValueError, match=escape("Your code has `Fabric(num_nodes=2, ...)` but it conflicts")): + with pytest.raises(ValueError, match="`Fabric\\(num_nodes=2, ...\\)` but .* `--num_nodes=3`"): _Connector(num_nodes=2) with mock.patch.dict(os.environ, {"LT_PRECISION": "16"}): - with pytest.raises(ValueError, match=escape("Your code has `Fabric(precision=64, ...)` but it conflicts")): + with pytest.raises(ValueError, match="`Fabric\\(precision=64, ...\\)` but .* `--precision=16`"): _Connector(precision=64) From 8f87ae0b804db01a5696a28d769b022188b977bf Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 11 Jan 2023 14:59:12 +0100 Subject: [PATCH 3/5] changelog --- src/lightning_fabric/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lightning_fabric/CHANGELOG.md b/src/lightning_fabric/CHANGELOG.md index 271e1bff87304..06fbad215d095 100644 --- a/src/lightning_fabric/CHANGELOG.md +++ b/src/lightning_fabric/CHANGELOG.md @@ -71,6 +71,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Restored sampling parity between PyTorch and Fabric dataloaders when using the `DistributedSampler` ([#16101](https://github.com/Lightning-AI/lightning/issues/16101)) +- Fixes an issue where the error message wouldn't tell the user the real value that was passed through the CLI ([#16334](https://github.com/Lightning-AI/lightning/issues/16334)) + ## [1.8.6] - 2022-12-21 From 256d157a243525a8ac85b2d87307285e4d6ab263 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:00:21 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/lightning_fabric/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning_fabric/CHANGELOG.md b/src/lightning_fabric/CHANGELOG.md index 06fbad215d095..650c26be76093 100644 --- a/src/lightning_fabric/CHANGELOG.md +++ b/src/lightning_fabric/CHANGELOG.md @@ -72,7 +72,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Restored sampling parity between PyTorch and Fabric dataloaders when using the `DistributedSampler` ([#16101](https://github.com/Lightning-AI/lightning/issues/16101)) - Fixes an issue where the error message wouldn't tell the user the real value that was passed through the CLI ([#16334](https://github.com/Lightning-AI/lightning/issues/16334)) - + ## [1.8.6] - 2022-12-21 From 14c51d46fafc7d434445b8b40e0cbac647ff15c3 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 11 Jan 2023 15:52:10 +0100 Subject: [PATCH 5/5] remove unused import --- tests/tests_fabric/test_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests_fabric/test_connector.py b/tests/tests_fabric/test_connector.py index 008a78018ae50..e4cf77272c122 100644 --- a/tests/tests_fabric/test_connector.py +++ b/tests/tests_fabric/test_connector.py @@ -13,7 +13,6 @@ # limitations under the License import os -from re import escape from typing import Any, Dict from unittest import mock