From 056a17ffd016f159210c69bbaa46f3b37f1f9b9b Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 11:26:32 +0000 Subject: [PATCH 01/15] uv in unit-tests.yml --- .github/workflows/unit-tests.yml | 35 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 211754cc1e5f..e8066ec0fad3 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -57,43 +57,35 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + cache: pip - - name: Get year & week number - id: get-date - run: | - echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT + - name: Install uv + uses: astral-sh/setup-uv@v5 - - name: Get pip cache dir + - name: Cache pip/uv dependencies id: pip-cache - run: | - pip install -U pip || python -m pip install -U pip - echo "pip_cache=$(pip cache dir)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 + uses: actions/cache@v3 with: - path: | - ${{ steps.pip-cache.outputs.pip_cache }} - key: ${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-${{ hashFiles('requirements-dev.txt') }} + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-${{ hashFiles('requirements-dev.txt') }} restore-keys: | - ${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}- - - - run: pip install pip wheel setuptools -Uqq + ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}- - name: Install PyTorch if: ${{ matrix.pytorch-channel == 'pytorch' }} - run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu + run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu - name: Install PyTorch (nightly) if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }} - run: pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre + run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre - name: Install dependencies run: | - pip install -r requirements-dev.txt - pip install . + uv pip install -r requirements-dev.txt + uv pip install -e . pip list - name: Check code formatting @@ -103,7 +95,6 @@ jobs: - name: Run Mypy # https://github.com/pytorch/ignite/pull/2780 - # if: ${{ matrix.os == 'ubuntu-latest' && matrix.pytorch-channel == 'pytorch-nightly'}} run: | bash ./tests/run_code_style.sh mypy From 3e395de5bc8119512f48dd3753531bfef5a6819d Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 11:32:03 +0000 Subject: [PATCH 02/15] install dependencies systemwide --- .github/workflows/unit-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e8066ec0fad3..69f5d8839a36 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -76,16 +76,16 @@ jobs: - name: Install PyTorch if: ${{ matrix.pytorch-channel == 'pytorch' }} - run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu + run: uv pip install --system torch torchvision --index-url https://download.pytorch.org/whl/cpu - name: Install PyTorch (nightly) if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }} - run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre + run: uv pip install --system torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre - name: Install dependencies run: | - uv pip install -r requirements-dev.txt - uv pip install -e . + uv pip install --system -r requirements-dev.txt + uv pip install --system -e . pip list - name: Check code formatting From c621021a205815b795b5a4a18d2feba9734fbbb7 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 13:37:20 +0000 Subject: [PATCH 03/15] install python with uv and set up cache --- .github/workflows/unit-tests.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 69f5d8839a36..c0f0aa568861 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -32,6 +32,8 @@ concurrency: jobs: cpu-tests: runs-on: ${{ matrix.os }} + env: + UV_SYSTEM_PIP: 1 timeout-minutes: 85 defaults: run: @@ -57,13 +59,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Install uv and Python + uses: astral-sh/setup-uv@v5 with: python-version: ${{ matrix.python-version }} - cache: pip - - - name: Install uv - uses: astral-sh/setup-uv@v5 - name: Cache pip/uv dependencies id: pip-cache From 5b0206e8b9f0cfe576c680326134932aae4ebe71 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 13:45:39 +0000 Subject: [PATCH 04/15] setup cache --- .github/workflows/unit-tests.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c0f0aa568861..a185676424c5 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -63,15 +63,7 @@ jobs: uses: astral-sh/setup-uv@v5 with: python-version: ${{ matrix.python-version }} - - - name: Cache pip/uv dependencies - id: pip-cache - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-${{ hashFiles('requirements-dev.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}- + cache: true - name: Install PyTorch if: ${{ matrix.pytorch-channel == 'pytorch' }} From c6085c709c96cd308464a891694216dd30870bb8 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 13:47:55 +0000 Subject: [PATCH 05/15] remove --system --- .github/workflows/unit-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a185676424c5..6e94e95ab4aa 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -67,16 +67,16 @@ jobs: - name: Install PyTorch if: ${{ matrix.pytorch-channel == 'pytorch' }} - run: uv pip install --system torch torchvision --index-url https://download.pytorch.org/whl/cpu + run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu - name: Install PyTorch (nightly) if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }} - run: uv pip install --system torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre + run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre - name: Install dependencies run: | - uv pip install --system -r requirements-dev.txt - uv pip install --system -e . + uv pip install -r requirements-dev.txt + uv pip install -e . pip list - name: Check code formatting From 342f441d821c274ac30be7ae93ad064eba071fc7 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 14:09:52 +0000 Subject: [PATCH 06/15] CLEARML_NO_DEFAULT_SERVER: 1 --- .github/workflows/unit-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 6e94e95ab4aa..b5eb66f1afe4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -34,6 +34,7 @@ jobs: runs-on: ${{ matrix.os }} env: UV_SYSTEM_PIP: 1 + CLEARML_NO_DEFAULT_SERVER: 1 timeout-minutes: 85 defaults: run: @@ -77,7 +78,7 @@ jobs: run: | uv pip install -r requirements-dev.txt uv pip install -e . - pip list + uv pip list - name: Check code formatting run: | From e3b5925431e887c6178a0e989f6f7d026e0f72c9 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 14:20:32 +0000 Subject: [PATCH 07/15] install mypy --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b5eb66f1afe4..377c1b7853c4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -85,12 +85,12 @@ jobs: bash ./tests/run_code_style.sh install bash ./tests/run_code_style.sh lint + - name: Ensure mypy is installed in uv environment + run: uv pip install mypy - name: Run Mypy - # https://github.com/pytorch/ignite/pull/2780 if: ${{ matrix.os == 'ubuntu-latest' && matrix.pytorch-channel == 'pytorch-nightly'}} run: | bash ./tests/run_code_style.sh mypy - # Download MNIST: https://github.com/pytorch/ignite/issues/1737 # to "/tmp" for unit tests - name: Download MNIST From bf5d050b16026a25e87a519807b9cd4e4b3cef92 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Thu, 1 May 2025 14:47:05 +0000 Subject: [PATCH 08/15] clearml --- .github/workflows/unit-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 377c1b7853c4..ca6483ad5c57 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -35,6 +35,9 @@ jobs: env: UV_SYSTEM_PIP: 1 CLEARML_NO_DEFAULT_SERVER: 1 + CLEARML_API_HOST: "http://localhost" + CLEARML_WEB_HOST: "http://localhost" + CLEARML_FILES_HOST: "http://localhost" timeout-minutes: 85 defaults: run: From 6953611731c9956a73a7a977c54d179a213f690f Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 2 May 2025 07:22:51 +0000 Subject: [PATCH 09/15] mypy install --- .github/workflows/unit-tests.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ca6483ad5c57..b10ba868e586 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -34,10 +34,7 @@ jobs: runs-on: ${{ matrix.os }} env: UV_SYSTEM_PIP: 1 - CLEARML_NO_DEFAULT_SERVER: 1 - CLEARML_API_HOST: "http://localhost" - CLEARML_WEB_HOST: "http://localhost" - CLEARML_FILES_HOST: "http://localhost" + CLEARML_OFFLINE_MODE: 1 timeout-minutes: 85 defaults: run: @@ -85,11 +82,8 @@ jobs: - name: Check code formatting run: | - bash ./tests/run_code_style.sh install + uv pip install --upgrade flake8 "black==24.10.0" "usort==1.0.8.post1" "ufmt==2.7.3" "mypy" bash ./tests/run_code_style.sh lint - - - name: Ensure mypy is installed in uv environment - run: uv pip install mypy - name: Run Mypy if: ${{ matrix.os == 'ubuntu-latest' && matrix.pytorch-channel == 'pytorch-nightly'}} run: | From 23d6c6eaba53e8d1ac6837337f4504996bba7687 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 2 May 2025 07:39:46 +0000 Subject: [PATCH 10/15] clearml --- .github/workflows/unit-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b10ba868e586..eebd306144d2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -35,6 +35,9 @@ jobs: env: UV_SYSTEM_PIP: 1 CLEARML_OFFLINE_MODE: 1 + CLEARML_API_HOST: http://localhost + CLEARML_WEB_HOST: http://localhost + CLEARML_FILES_HOST: http://localhost timeout-minutes: 85 defaults: run: From 2e07c011095d5423d9b2ddc36e6b38b4fcde5e20 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 9 May 2025 08:20:58 +0000 Subject: [PATCH 11/15] use pre-commit instead of manual checks --- .github/workflows/unit-tests.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index eebd306144d2..ce6f91babbb3 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -81,16 +81,12 @@ jobs: run: | uv pip install -r requirements-dev.txt uv pip install -e . + uv pip install pre-commit uv pip list - - name: Check code formatting - run: | - uv pip install --upgrade flake8 "black==24.10.0" "usort==1.0.8.post1" "ufmt==2.7.3" "mypy" - bash ./tests/run_code_style.sh lint - - name: Run Mypy - if: ${{ matrix.os == 'ubuntu-latest' && matrix.pytorch-channel == 'pytorch-nightly'}} - run: | - bash ./tests/run_code_style.sh mypy + - name: Run pre-commit checks + run: pre-commit run --all-files + # Download MNIST: https://github.com/pytorch/ignite/issues/1737 # to "/tmp" for unit tests - name: Download MNIST From 39ef4a281774b48ff83cb3ffb5eb7c435641097a Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 9 May 2025 08:31:49 +0000 Subject: [PATCH 12/15] Lint only changed files --- .github/workflows/unit-tests.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ce6f91babbb3..ebaa2c459f88 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -84,8 +84,14 @@ jobs: uv pip install pre-commit uv pip list - - name: Run pre-commit checks - run: pre-commit run --all-files + - name: Lint only changed files + run: | + # fetch the target branch so origin/${{ github.event.pull_request.base.ref }} exists + git fetch origin ${{ github.event.pull_request.base.ref }} + # run hooks in “diff” mode + pre-commit run --show-diff-on-failure \ + --from-ref origin/${{ github.event.pull_request.base.ref }} \ + --to-ref ${{ github.event.pull_request.head.sha }} # Download MNIST: https://github.com/pytorch/ignite/issues/1737 # to "/tmp" for unit tests From f0ea4af9759ab2d56fb25f8f61c202d566df4b69 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 9 May 2025 08:37:49 +0000 Subject: [PATCH 13/15] Lint only changed files --- .github/workflows/unit-tests.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ebaa2c459f88..25fe77d5e2b4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -86,12 +86,13 @@ jobs: - name: Lint only changed files run: | - # fetch the target branch so origin/${{ github.event.pull_request.base.ref }} exists - git fetch origin ${{ github.event.pull_request.base.ref }} - # run hooks in “diff” mode + BASE=${{ github.event.pull_request.base.ref }} + # fetch that branch’s tip + git fetch origin $BASE + # diff from base → HEAD pre-commit run --show-diff-on-failure \ - --from-ref origin/${{ github.event.pull_request.base.ref }} \ - --to-ref ${{ github.event.pull_request.head.sha }} + --from-ref origin/$BASE \ + --to-ref HEAD # Download MNIST: https://github.com/pytorch/ignite/issues/1737 # to "/tmp" for unit tests From 8366c2c894300f33b094806525cfe5ad8e48f961 Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 9 May 2025 09:31:13 +0000 Subject: [PATCH 14/15] Lint only changed files --- tests/ignite/metrics/test_fake.py | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/ignite/metrics/test_fake.py diff --git a/tests/ignite/metrics/test_fake.py b/tests/ignite/metrics/test_fake.py new file mode 100644 index 000000000000..ad41df2dc590 --- /dev/null +++ b/tests/ignite/metrics/test_fake.py @@ -0,0 +1,40 @@ +import pytest +import torch + +from ignite.metrics import Fbeta, Precision, Recall + +torch.manual_seed(12) + + +# FIXME: the file needs to be removed +def test_wrong_inputs(): + with pytest.raises(ValueError, match=r"Beta should be a positive integer"): + Fbeta(0.0) + + with pytest.raises(ValueError, match=r"Input precision metric should have average=False"): + p = Precision(average="micro") + Fbeta(1.0, precision=p) + + with pytest.raises(ValueError, match=r"Input recall metric should have average=False"): + r = Recall(average="samples") + Fbeta(1.0, recall=r) + + with pytest.raises(ValueError, match=r"If precision argument is provided, device should be None"): + p = Precision(average=False) + Fbeta(1.0, precision=p, device="cpu") + + with pytest.raises(ValueError, match=r"If precision argument is provided, output_transform should be None"): + p = Precision(average=False) + Fbeta(1.0, precision=p, output_transform=lambda x: x) + + with pytest.raises(ValueError, match=r"If recall argument is provided, device should be None"): + r = Recall(average=False) + Fbeta(1.0, recall=r, device="cpu") + + with pytest.raises(ValueError, match=r"If recall argument is provided, output_transform should be None"): + r = Recall(average=False) + Fbeta(1.0, recall=r, output_transform=lambda x: x) + + +def _output_transform(output): + return output["y_pred"], output["y"] From 6ff119ffa9550ccfda68a93f89cafb66673ba12c Mon Sep 17 00:00:00 2001 From: BanzaiTokyo Date: Fri, 9 May 2025 09:35:48 +0000 Subject: [PATCH 15/15] remove fake test --- tests/ignite/metrics/test_fake.py | 40 ------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 tests/ignite/metrics/test_fake.py diff --git a/tests/ignite/metrics/test_fake.py b/tests/ignite/metrics/test_fake.py deleted file mode 100644 index ad41df2dc590..000000000000 --- a/tests/ignite/metrics/test_fake.py +++ /dev/null @@ -1,40 +0,0 @@ -import pytest -import torch - -from ignite.metrics import Fbeta, Precision, Recall - -torch.manual_seed(12) - - -# FIXME: the file needs to be removed -def test_wrong_inputs(): - with pytest.raises(ValueError, match=r"Beta should be a positive integer"): - Fbeta(0.0) - - with pytest.raises(ValueError, match=r"Input precision metric should have average=False"): - p = Precision(average="micro") - Fbeta(1.0, precision=p) - - with pytest.raises(ValueError, match=r"Input recall metric should have average=False"): - r = Recall(average="samples") - Fbeta(1.0, recall=r) - - with pytest.raises(ValueError, match=r"If precision argument is provided, device should be None"): - p = Precision(average=False) - Fbeta(1.0, precision=p, device="cpu") - - with pytest.raises(ValueError, match=r"If precision argument is provided, output_transform should be None"): - p = Precision(average=False) - Fbeta(1.0, precision=p, output_transform=lambda x: x) - - with pytest.raises(ValueError, match=r"If recall argument is provided, device should be None"): - r = Recall(average=False) - Fbeta(1.0, recall=r, device="cpu") - - with pytest.raises(ValueError, match=r"If recall argument is provided, output_transform should be None"): - r = Recall(average=False) - Fbeta(1.0, recall=r, output_transform=lambda x: x) - - -def _output_transform(output): - return output["y_pred"], output["y"]