From e0633998247e4ceb8f81ea41ddd685df6f9b9fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 14:24:08 -0300 Subject: [PATCH 1/8] Using the Lightning CLI interface to run tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- tests/test_finetune.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/test_finetune.py b/tests/test_finetune.py index 4812d5f3..1fc6be7a 100644 --- a/tests/test_finetune.py +++ b/tests/test_finetune.py @@ -6,8 +6,7 @@ import subprocess import os -from terratorch.models.backbones.prithvi_vit import checkpoint_filter_fn as checkpoint_filter_fn_vit -from terratorch.models.backbones.prithvi_swin import checkpoint_filter_fn as checkpoint_filter_fn_swin +from terratorch.cli_tools import build_lightning_cli @pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) def test_finetune_multiple_backbones(model_name): @@ -21,11 +20,7 @@ def test_finetune_multiple_backbones(model_name): torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) # Running the terratorch CLI - command_str = f"terratorch fit -c tests/manufactured-finetune_{model_name}.yaml" - - command_out = subprocess.run(command_str, shell=True) - - assert not command_out.returncode - + command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}.yaml"] + _ = build_lightning_cli(command_list) From 957ea31d04556298d63326850ac7fb9371007f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 14:30:06 -0300 Subject: [PATCH 2/8] PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d7896ed3..b1bc2ba0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,4 +32,5 @@ jobs: run: pip list - name: Test with pytest run: | + export PYTHONPATH=. pytest -s tests From c709e6e6fcc1cd61fd20bef0f70147baee2c32ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 14:49:20 -0300 Subject: [PATCH 3/8] Alternative tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- .github/workflows/test.yaml | 1 - tests/test_finetune.py | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b1bc2ba0..d7896ed3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,5 +32,4 @@ jobs: run: pip list - name: Test with pytest run: | - export PYTHONPATH=. pytest -s tests diff --git a/tests/test_finetune.py b/tests/test_finetune.py index 1fc6be7a..a2001935 100644 --- a/tests/test_finetune.py +++ b/tests/test_finetune.py @@ -7,7 +7,7 @@ import os from terratorch.cli_tools import build_lightning_cli - +""" @pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) def test_finetune_multiple_backbones(model_name): @@ -22,5 +22,22 @@ def test_finetune_multiple_backbones(model_name): # Running the terratorch CLI command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}.yaml"] _ = build_lightning_cli(command_list) +""" + +@pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) +def test_finetune_multiple_backbones(model_name): + + model_instance = timm.create_model(model_name) + pretrained_bands = [0, 1, 2, 3, 4, 5] + model_bands = [0, 1, 2, 3, 4, 5] + + state_dict = model_instance.state_dict() + torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) + + # Running the terratorch CLI + command_str = f"python terratorch/__main__.py fit -c tests/manufactured-finetune_{model_name}.yaml" + command_out = subprocess.run(command_str, shell=True) + + assert not command_out.returncode From 1c7eec8bbc51e5ef91ea1ca6b1ea906b6875dcfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 14:53:34 -0300 Subject: [PATCH 4/8] PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d7896ed3..b1bc2ba0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,4 +32,5 @@ jobs: run: pip list - name: Test with pytest run: | + export PYTHONPATH=. pytest -s tests From 2efaac64f891abaf7a96f6daee6426d78720e84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 15:41:38 -0300 Subject: [PATCH 5/8] Set the cli back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- tests/test_finetune.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_finetune.py b/tests/test_finetune.py index a2001935..bb48b94e 100644 --- a/tests/test_finetune.py +++ b/tests/test_finetune.py @@ -7,7 +7,7 @@ import os from terratorch.cli_tools import build_lightning_cli -""" + @pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) def test_finetune_multiple_backbones(model_name): @@ -22,8 +22,8 @@ def test_finetune_multiple_backbones(model_name): # Running the terratorch CLI command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}.yaml"] _ = build_lightning_cli(command_list) -""" +""" @pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) def test_finetune_multiple_backbones(model_name): @@ -40,4 +40,4 @@ def test_finetune_multiple_backbones(model_name): command_out = subprocess.run(command_str, shell=True) assert not command_out.returncode - + """ From 5901c8ea6360a8e09b7550306a301e8b57618d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas=20de=20Sousa=20Almeida?= Date: Wed, 3 Jul 2024 16:22:11 -0300 Subject: [PATCH 6/8] No PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Lucas de Sousa Almeida Signed-off-by: Carlos Gomes --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b1bc2ba0..d7896ed3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,5 +32,4 @@ jobs: run: pip list - name: Test with pytest run: | - export PYTHONPATH=. pytest -s tests From 2a5fdd860c0bee303170e6b75065f94a341ca579 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Date: Thu, 4 Jul 2024 09:46:39 +0200 Subject: [PATCH 7/8] fix lightning in reqs Signed-off-by: Carlos Gomes --- pyproject.toml | 3 ++- requirements/required.txt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 505db965..d18c6bef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ dependencies = [ "h5py>=3.10.0", "geobench>=1.0.0", "mlflow>=2.12.1", - "lightning<=2.2.5" + # broken due to https://github.com/Lightning-AI/pytorch-lightning/issues/19977 + "lightning>=2, <=2.2.5" ] [project.optional-dependencies] diff --git a/requirements/required.txt b/requirements/required.txt index 80114f18..06dd4ef4 100644 --- a/requirements/required.txt +++ b/requirements/required.txt @@ -10,3 +10,4 @@ lightly==1.4.25 h5py==3.10.0 geobench==1.0.0 mlflow==2.12.1 +lightning==2.2.5 \ No newline at end of file From 11974fedc458048b50277e10bf1bf9addb7a3ce4 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Date: Thu, 4 Jul 2024 09:47:35 +0200 Subject: [PATCH 8/8] add dependabot yaml Signed-off-by: Carlos Gomes --- .github/dependabot.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/dependabot.yaml diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000..96812e26 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,24 @@ +# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file +# mostly from https://github.com/microsoft/torchgeo/blob/main/.github/dependabot.yml +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + groups: + # torchvision pins torch, must update in unison + torch: + patterns: + - "torch" + - "torchvision" + ignore: + # setuptools releases new versions almost daily + - dependency-name: "setuptools" + update-types: ["version-update:semver-patch"] + # segmentation-models-pytorch pins timm, must update in unison + - dependency-name: "timm" \ No newline at end of file