From b670fac8e23f42c8b00880f336e3d9893a562cfc Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+borda@users.noreply.github.com> Date: Tue, 17 Oct 2023 18:00:11 +0200 Subject: [PATCH] ci: proper setting oldest/latest for integrations & `PL>=1.9` (#2129) (cherry picked from commit 045431a55c2976508e5e7c260fc3307de7c8d555) --- .azure/gpu-integrations.yml | 18 +++++++++++----- .azure/gpu-unittests.yml | 9 +++----- .github/actions/pull-caches/action.yml | 5 +++-- .github/assistant.py | 1 + .github/workflows/ci-integrate.yml | 29 ++++++++++++++------------ .github/workflows/ci-tests.yml | 6 ------ requirements/_integrate.txt | 5 ++++- src/torchmetrics/__init__.py | 10 ++++++++- 8 files changed, 49 insertions(+), 34 deletions(-) diff --git a/.azure/gpu-integrations.yml b/.azure/gpu-integrations.yml index 8182deeb84f..1f3a1796e77 100644 --- a/.azure/gpu-integrations.yml +++ b/.azure/gpu-integrations.yml @@ -20,6 +20,7 @@ jobs: "oldest": docker-image: "pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime" torch-ver: "1.11.0" + requires: "oldest" "latest": docker-image: "pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime" torch-ver: "2.1.0" @@ -46,6 +47,8 @@ jobs: CUDA_version_mm="${CUDA_version//'.'/''}" echo "##vso[task.setvariable variable=CUDA_VERSION_MM]$CUDA_version_mm" echo "##vso[task.setvariable variable=TORCH_URL]https://download.pytorch.org/whl/cu${CUDA_version_mm}/torch_stable.html" + # packages for running assistant + pip install -q packaging fire requests wget displayName: "set Env. vars" - bash: | @@ -63,13 +66,18 @@ jobs: - bash: | set -e - pip install -q packaging fire requests wget - python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py - python adjust-torch-versions.py requirements/base.txt $(torch-ver) - python adjust-torch-versions.py requirements/_integrate.txt $(torch-ver) - # FixMe: this shall not be for all integrations/cases python .github/assistant.py set-oldest-versions --req_files='["requirements/_integrate.txt"]' cat requirements/_integrate.txt + condition: eq(variables['requires'], 'oldest') + displayName: "Setting oldest req." + + - bash: | + set -e + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py + for fpath in `ls requirements/*.txt`; do + # torch version shall be sourced based on the used docker + python adjust-torch-versions.py $fpath + done displayName: "Adjust versions" - bash: | diff --git a/.azure/gpu-unittests.yml b/.azure/gpu-unittests.yml index 17f7b24cc7b..0e2de365473 100644 --- a/.azure/gpu-unittests.yml +++ b/.azure/gpu-unittests.yml @@ -24,18 +24,16 @@ jobs: torch-ver: "1.8.1" "PyTorch | 1.X": docker-image: "pytorchlightning/torchmetrics:ubuntu22.04-cuda11.8.0-py3.9-torch1.13" - agent-pool: "lit-rtx-3090" torch-ver: "1.13.1" "PyTorch | 2.X": docker-image: "pytorchlightning/torchmetrics:ubuntu22.04-cuda12.1.0-py3.11-torch2.1" - agent-pool: "lit-rtx-3090" torch-ver: "2.1.0" # how long to run the job before automatically cancelling timeoutInMinutes: "120" # how much time to give 'run always even if cancelled tasks' before stopping them cancelTimeoutInMinutes: "2" - pool: "$(agent-pool)" + pool: "lit-rtx-3090" variables: DEVICES: $( python -c 'name = "$(Agent.Name)" ; gpus = name.split("_")[-1] if "_" in name else "0,1"; print(gpus)' ) @@ -81,11 +79,10 @@ jobs: - bash: | pip install -q packaging wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py - python adjust-torch-versions.py requirements.txt $(torch-ver) for fpath in `ls requirements/*.txt`; do - python adjust-torch-versions.py $fpath $(torch-ver) + # torch version shall be sourced based on the used docker + python adjust-torch-versions.py $fpath done - # FixMe: missing setting minumal configurations for testing displayName: "Adjust versions" - bash: | diff --git a/.github/actions/pull-caches/action.yml b/.github/actions/pull-caches/action.yml index 91afb6f4be0..f8ca37fde1f 100644 --- a/.github/actions/pull-caches/action.yml +++ b/.github/actions/pull-caches/action.yml @@ -19,13 +19,14 @@ runs: using: "composite" steps: - name: install assistant's deps - run: pip install -q fire requests packaging + run: pip install -q fire requests packaging wget shell: bash - name: Set PyTorch version if: inputs.pytorch-version != '' run: | - curl https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py -o adjust-torch-versions.py + pip install wget + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py python adjust-torch-versions.py requirements/base.txt ${{ inputs.pytorch-version }} shell: bash diff --git a/.github/assistant.py b/.github/assistant.py index f2f20699a5e..f9eb521bec6 100644 --- a/.github/assistant.py +++ b/.github/assistant.py @@ -103,6 +103,7 @@ def set_oldest_versions(req_files: List[str] = REQUIREMENTS_FILES) -> None: """Set the oldest version for requirements.""" AssistantCLI.set_min_torch_by_python() for fpath in req_files: + logging.info(f"processing req: `{fpath}`") AssistantCLI.replace_min_requirements(fpath) @staticmethod diff --git a/.github/workflows/ci-integrate.yml b/.github/workflows/ci-integrate.yml index c52527fa877..684ee29ad06 100644 --- a/.github/workflows/ci-integrate.yml +++ b/.github/workflows/ci-integrate.yml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macOS-11, windows-2022] + os: ["ubuntu-22.04", "macOS-12", "windows-2022"] python-version: ["3.8", "3.10"] requires: ["oldest", "latest"] exclude: @@ -53,23 +53,26 @@ jobs: - name: source cashing uses: ./.github/actions/pull-caches - with: - requires: ${{ matrix.requires }} - - - name: Freeze PIL (hotfix) - # import of PILLOW_VERSION which they recently removed in v9.0 in favor of __version__ - run: pip install "Pillow<9.0" # It messes with torchvision + - name: set oldest if/only for integrations + if: matrix.requires == 'oldest' + run: python .github/assistant.py set-oldest-versions --req_files='["requirements/_integrate.txt"]' - name: Install all dependencies run: | - set -e - curl https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py -o adjust-torch-versions.py - pip install -r requirements/_tests.txt -r requirements/_integrate.txt \ - --find-links $PYTORCH_URL -f $PYPI_CACHE --upgrade-strategy eager + # this was updated in `source cashing` by optional oldest + cat requirements/_integrate.txt + # to have install pyTorch + pip install -e . --find-links=${PYTORCH_URL} + + # adjust version to PT ecosystem based on installed TM + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py python adjust-torch-versions.py requirements/base.txt python adjust-torch-versions.py requirements/image.txt - cat requirements/base.txt - pip install -e . --find-links $PYTORCH_URL -f $PYPI_CACHE + + # install package and dependencies + pip install -e . -r requirements/_tests.txt -r requirements/_integrate.txt \ + --find-links=${PYTORCH_URL} --find-links=${PYPI_CACHE} \ + --upgrade-strategy eager pip list - name: Integrations diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 633d483d8b0..fbef75eb5de 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -99,7 +99,6 @@ jobs: pip install -r requirements/_doctest.txt -U -f $PYPI_CACHE pip list - # todo: copy this to install checks - name: DocTests timeout-minutes: 25 working-directory: ./src @@ -108,11 +107,6 @@ jobs: # NOTE: run coverage on tests does not propagate failure status for Win, https://github.com/nedbat/coveragepy/issues/1003 run: python -m pytest torchmetrics --reruns 3 --reruns-delay 2 - - name: Freeze PIL (hotfix) - if: ${{ matrix.python-version != '3.11' }} - # import of PILLOW_VERSION which they recently removed in v9.0 in favor of __version__ - run: pip install "Pillow<9.0" # It messes with torchvision - - name: Install all dependencies run: | curl https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py -o adjust-torch-versions.py diff --git a/requirements/_integrate.txt b/requirements/_integrate.txt index 3e21166acef..8d01c876c2e 100644 --- a/requirements/_integrate.txt +++ b/requirements/_integrate.txt @@ -1 +1,4 @@ -pytorch-lightning >=1.6.0, <2.1.0 +# contentiously validated integration with these expected ranges + +# ToDo: investigate and add validation with 2.0+ on GPU +pytorch-lightning >=1.9.0, <2.0.0 diff --git a/src/torchmetrics/__init__.py b/src/torchmetrics/__init__.py index 3d478df15fc..bac9a534556 100644 --- a/src/torchmetrics/__init__.py +++ b/src/torchmetrics/__init__.py @@ -1,7 +1,9 @@ -r"""Root package info.""" +"""Root package info.""" import logging as __logging import os +from lightning_utilities.core.imports import package_available + from torchmetrics.__about__ import * # noqa: F403 _logger = __logging.getLogger("torchmetrics") @@ -11,6 +13,12 @@ _PACKAGE_ROOT = os.path.dirname(__file__) _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT) +if package_available("PIL"): + import PIL + + if not hasattr(PIL, "PILLOW_VERSION"): + PIL.PILLOW_VERSION = PIL.__version__ + from torchmetrics import functional # noqa: E402 from torchmetrics.aggregation import ( # noqa: E402 CatMetric,