diff --git a/.azure/gpu-tests-fabric.yml b/.azure/gpu-tests-fabric.yml index cb98c001c0..3393c5d1ac 100644 --- a/.azure/gpu-tests-fabric.yml +++ b/.azure/gpu-tests-fabric.yml @@ -91,8 +91,10 @@ jobs: - bash: | PYTORCH_VERSION=$(python -c "import torch; print(torch.__version__.split('+')[0])") + pip install -q wget packaging + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do \ - python ./requirements/pytorch/adjust-versions.py $fpath ${PYTORCH_VERSION}; \ + python ./adjust-torch-versions.py $fpath ${PYTORCH_VERSION}; \ done displayName: 'Adjust dependencies' diff --git a/.azure/gpu-tests-pytorch.yml b/.azure/gpu-tests-pytorch.yml index 137f066a26..860afcab5b 100644 --- a/.azure/gpu-tests-pytorch.yml +++ b/.azure/gpu-tests-pytorch.yml @@ -98,8 +98,10 @@ jobs: - bash: | PYTORCH_VERSION=$(python -c "import torch; print(torch.__version__.split('+')[0])") + pip install -q wget packaging + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do \ - python ./requirements/pytorch/adjust-versions.py $fpath ${PYTORCH_VERSION}; \ + python ./adjust-torch-versions.py $fpath ${PYTORCH_VERSION}; \ done # prune packages with installation issues pip install -q -r .actions/requirements.txt diff --git a/.github/workflows/ci-tests-fabric.yml b/.github/workflows/ci-tests-fabric.yml index 8db2de1f8a..0b8c562f6a 100644 --- a/.github/workflows/ci-tests-fabric.yml +++ b/.github/workflows/ci-tests-fabric.yml @@ -84,8 +84,10 @@ jobs: - name: Adjust PyTorch versions in requirements files if: ${{ matrix.requires != 'oldest' && matrix.release != 'pre' }} run: | + pip install -q wget packaging + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do \ - python ./requirements/pytorch/adjust-versions.py $fpath ${{ matrix.pytorch-version }}; \ + python ./adjust-torch-versions.py $fpath ${{ matrix.pytorch-version }}; \ done cat requirements/fabric/base.txt diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index 92155fcc85..9ee1ffb47f 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -88,8 +88,10 @@ jobs: - name: Adjust PyTorch versions in requirements files if: ${{ matrix.requires != 'oldest' && matrix.release != 'pre' }} run: | + pip install -q wget packaging + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do \ - python ./requirements/pytorch/adjust-versions.py $fpath ${{ matrix.pytorch-version }}; \ + python ./adjust-torch-versions.py $fpath ${{ matrix.pytorch-version }}; \ done cat requirements/pytorch/base.txt diff --git a/.github/workflows/tpu-tests.yml b/.github/workflows/tpu-tests.yml index 32593a3783..168d3cb78b 100644 --- a/.github/workflows/tpu-tests.yml +++ b/.github/workflows/tpu-tests.yml @@ -153,7 +153,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 - # see: https://github.com/actions/toolkit/issues/399 continue-on-error: true with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/dockers/base-cuda/Dockerfile b/dockers/base-cuda/Dockerfile index f3051aaca1..0d24bd0d0d 100644 --- a/dockers/base-cuda/Dockerfile +++ b/dockers/base-cuda/Dockerfile @@ -88,8 +88,10 @@ RUN \ # Disable cache \ pip config set global.cache-dir false && \ # set particular PyTorch version \ + pip install -q wget packaging && \ + python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py && \ for fpath in `ls requirements/**/*.txt`; do \ - python ./requirements/pytorch/adjust-versions.py $fpath ${PYTORCH_VERSION}; \ + python ./adjust-torch-versions.py $fpath ${PYTORCH_VERSION}; \ done && \ CUDA_VERSION_MM=${CUDA_VERSION%.*} && \ pip install \ diff --git a/requirements/pytorch/adjust-versions.py b/requirements/pytorch/adjust-versions.py deleted file mode 100644 index 1ef74af646..0000000000 --- a/requirements/pytorch/adjust-versions.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import re -import sys -from typing import Dict, Optional - -# IMPORTANT: this list needs to be sorted in reverse -VERSIONS = [ - {"torch": "2.1.0", "torchvision": "0.16.0"}, # nightly - {"torch": "2.0.0", "torchvision": "0.15.1"}, # stable - {"torch": "1.13.1", "torchvision": "0.14.1"}, - {"torch": "1.13.0", "torchvision": "0.14.0"}, - {"torch": "1.12.1", "torchvision": "0.13.1"}, - {"torch": "1.12.0", "torchvision": "0.13.0"}, - {"torch": "1.11.0", "torchvision": "0.12.0"}, -] - - -def find_latest(ver: str) -> Dict[str, str]: - # drop all except semantic version - ver = re.search(r"([\.\d]+)", ver).groups()[0] - # in case there remaining dot at the end - e.g "1.9.0.dev20210504" - ver = ver[:-1] if ver[-1] == "." else ver - print(f"\n\n\nfinding ecosystem versions for: {ver}") - - # find first match - for option in VERSIONS: - if option["torch"].startswith(ver): - return option - - raise ValueError(f"Missing {ver} in {VERSIONS}") - - -def replace(req: str, torch_version: Optional[str] = None) -> str: - if not torch_version: - import torch - - torch_version = torch.__version__ - assert torch_version, f"invalid torch: {torch_version}" # noqa: S101 - - # remove comments and strip whitespace - req = re.sub(rf"\s*#.*{os.linesep}", os.linesep, req).strip() - - latest = find_latest(torch_version) - for lib, version in latest.items(): - replace = f"{lib}=={version}" if version else "" - req = re.sub(rf"\b{lib}(?!\w).*", replace, req) - - return req - - -if __name__ == "__main__": - if len(sys.argv) == 3: - requirements_path, torch_version = sys.argv[1:] - else: - requirements_path, torch_version = sys.argv[1], None - print(f"requirements_path='{requirements_path}' with torch_version='{torch_version}'") - - with open(requirements_path) as fp: - requirements = fp.read() - requirements = replace(requirements, torch_version) - print(requirements) # on purpose - to debug - with open(requirements_path, "w") as fp: - fp.write(requirements) diff --git a/tests/tests_fabric/run_tpu_tests.sh b/tests/tests_fabric/run_tpu_tests.sh index c9d5b6bb33..5cae4d7c15 100644 --- a/tests/tests_fabric/run_tpu_tests.sh +++ b/tests/tests_fabric/run_tpu_tests.sh @@ -13,8 +13,10 @@ fi echo "--- Install packages ---" # set particular PyTorch version +pip install -q wget packaging +python3 -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do - python3 requirements/pytorch/adjust-versions.py $fpath {PYTORCH_VERSION}; + python3 adjust-torch-versions.py $fpath {PYTORCH_VERSION}; done pip install .[fabric-test] pytest-timeout pip list diff --git a/tests/tests_pytorch/run_tpu_tests.sh b/tests/tests_pytorch/run_tpu_tests.sh index 5d658d17e1..1005276ff5 100644 --- a/tests/tests_pytorch/run_tpu_tests.sh +++ b/tests/tests_pytorch/run_tpu_tests.sh @@ -13,8 +13,10 @@ fi echo "--- Install packages ---" # set particular PyTorch version +pip install -q wget packaging +python3 -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do - python3 requirements/pytorch/adjust-versions.py $fpath {PYTORCH_VERSION}; + python3 adjust-torch-versions.py $fpath {PYTORCH_VERSION}; done pip install .[pytorch-extra,pytorch-test] pytest-timeout pip list