From c382d3a225d427852beb25bf2cbbc4a1b8f3e799 Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Mon, 1 Sep 2025 22:38:52 -0400 Subject: [PATCH 01/12] swap to uv --- .github/workflows/ci-tests-pytorch.yml | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index 197582740585a..729499f8555cf 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -35,6 +35,9 @@ defaults: run: shell: bash +env: + UV_SYSTEM_PYTHON: 1 + jobs: pl-cpu: runs-on: ${{ matrix.os }} @@ -69,33 +72,39 @@ jobs: TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/" TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/" FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }} - PYPI_CACHE_DIR: "_pip-wheels" + UV_CACHE_DIR: /tmp/.uv-cache # TODO: Remove this - Enable running MPS tests on this platform DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }} steps: - uses: actions/checkout@v5 - - name: Set up Python ${{ matrix.config.python-version }} - uses: actions/setup-python@v5 + - name: Install uv and set Python version + uses: astral-sh/setup-uv@v6 with: python-version: ${{ matrix.config.python-version || '3.9' }} - - name: basic setup - run: pip install -q -r .actions/requirements.txt + - name: Restore uv cache + uses: actions/cache@v4 + with: + path: ${{ env.UV_CACHE_DIR }} + key: uv-cache-${{ matrix.os }}-${{ matrix.config.python-version || '3.9' }} + + - name: Basic setup + run: uv pip install -q -r .actions/requirements.txt - name: Set min. dependencies if: ${{ matrix.requires == 'oldest' }} run: | cd requirements/pytorch - pip install -U "lightning-utilities[cli]" + uv pip install -U "lightning-utilities[cli]" python -m lightning_utilities.cli requirements set-oldest --req_files "['base.txt', 'extra.txt', 'strategies.txt', 'examples.txt', 'test.txt']" - pip install "cython<3.0" wheel - pip install "pyyaml==5.4" --no-build-isolation + uv pip install "cython<3.0" wheel + uv pip install "pyyaml==5.4" --no-build-isolation - name: Adjust PyTorch versions in requirements files if: ${{ matrix.requires != 'oldest' }} run: | - pip install -q -r requirements/ci.txt + uv pip install -q -r requirements/ci.txt python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py for fpath in `ls requirements/**/*.txt`; do \ python ./adjust-torch-versions.py $fpath ${{ matrix.config.pytorch-version }}; \ @@ -125,7 +134,7 @@ jobs: - name: Install package & dependencies timeout-minutes: 20 run: | - pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \ + uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \ -U --upgrade-strategy=eager --prefer-binary \ -r requirements/_integrations/accelerators.txt \ --extra-index-url="${TORCH_URL}" \ @@ -135,10 +144,12 @@ jobs: - name: Drop LAI from extensions if: ${{ matrix.config.pkg-name != 'lightning' }} # Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it - run: pip uninstall -y lightning + run: uv pip uninstall -y lightning + - name: Drop PL for LAI if: ${{ matrix.config.pkg-name == 'lightning' }} - run: pip uninstall -y pytorch-lightning + run: uv pip uninstall -y pytorch-lightning + - name: Dump handy wheels if: github.event_name == 'push' && github.ref == 'refs/heads/master' continue-on-error: true @@ -215,6 +226,9 @@ jobs: name: CPU-coverage fail_ci_if_error: false + - name: Minimize uv cache + run: uv cache prune --ci + pl-cpu-guardian: runs-on: ubuntu-latest needs: pl-cpu From 1489ff7633c55b213bbf80bf1e8a1476e91e2633 Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 09:17:05 -0400 Subject: [PATCH 02/12] no pip cache --- .github/workflows/ci-tests-pytorch.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index 729499f8555cf..62eadf1afd869 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -111,15 +111,6 @@ jobs: done cat requirements/pytorch/base.txt - - name: pip wheels cache - uses: actions/cache/restore@v4 - with: - path: ${{ env.PYPI_CACHE_DIR }} - key: pypi_wheels - - run: | - mkdir -p $PYPI_CACHE_DIR - ls -lh $PYPI_CACHE_DIR - - name: Env. variables run: | # Switch PyTorch URL between stable and test/future @@ -140,7 +131,8 @@ jobs: --extra-index-url="${TORCH_URL}" \ --find-links="${PYPI_CACHE_DIR}" \ --find-links="https://download.pytorch.org/whl/torch-tensorrt" - pip list + uv pip list + - name: Drop LAI from extensions if: ${{ matrix.config.pkg-name != 'lightning' }} # Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it From bfc47c1c6f9067412ea6a00a7dbe5086fc8f4adc Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 18:52:54 -0400 Subject: [PATCH 03/12] enable caching. use venv. --- .github/workflows/ci-tests-pytorch.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index e5315e22d26b3..c3bad6c53a3dc 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -35,9 +35,6 @@ defaults: run: shell: bash -env: - UV_SYSTEM_PYTHON: 1 - jobs: pl-cpu: runs-on: ${{ matrix.os }} @@ -82,12 +79,7 @@ jobs: uses: astral-sh/setup-uv@v6 with: python-version: ${{ matrix.config.python-version || '3.9' }} - - - name: Restore uv cache - uses: actions/cache@v4 - with: - path: ${{ env.UV_CACHE_DIR }} - key: uv-cache-${{ matrix.os }}-${{ matrix.config.python-version || '3.9' }} + enable-cache: true - name: Basic setup run: uv pip install -q -r .actions/requirements.txt From d668dafddb764c5f0f48c2175ab1fd354bfda9ce Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 19:33:16 -0400 Subject: [PATCH 04/12] activate environment --- .github/workflows/ci-tests-pytorch.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index c3bad6c53a3dc..4f0090608672b 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -69,7 +69,6 @@ jobs: TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/" TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/" FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }} - UV_CACHE_DIR: /tmp/.uv-cache # TODO: Remove this - Enable running MPS tests on this platform DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }} steps: @@ -79,6 +78,9 @@ jobs: uses: astral-sh/setup-uv@v6 with: python-version: ${{ matrix.config.python-version || '3.9' }} + # TODO: Avoid activating environment like this + # see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment + activate-environment: true enable-cache: true - name: Basic setup From bd8af9f74fd059dab65d7bcbdb2fe908c20ead7b Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 20:22:13 -0400 Subject: [PATCH 05/12] remove unavailable pip install options. update cache dir. --- .github/workflows/ci-tests-pytorch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index 4f0090608672b..4cd09402dab2f 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -120,10 +120,10 @@ jobs: timeout-minutes: 20 run: | uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \ - -U --upgrade-strategy=eager --prefer-binary \ + --upgrade \ -r requirements/_integrations/accelerators.txt \ --extra-index-url="${TORCH_URL}" \ - --find-links="${PYPI_CACHE_DIR}" \ + --find-links="${UV_CACHE_DIR}" \ --find-links="https://download.pytorch.org/whl/torch-tensorrt" uv pip list From 97290ddbdbcb468196b4d19e1c82ba6d4213c21f Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 21:07:28 -0400 Subject: [PATCH 06/12] fix uninstall --- .github/workflows/ci-tests-pytorch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index 4cd09402dab2f..382d760906a67 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -130,11 +130,11 @@ jobs: - name: Drop LAI from extensions if: ${{ matrix.config.pkg-name != 'lightning' }} # Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it - run: uv pip uninstall -y lightning + run: uv pip uninstall lightning - name: Drop PL for LAI if: ${{ matrix.config.pkg-name == 'lightning' }} - run: uv pip uninstall -y pytorch-lightning + run: uv pip uninstall pytorch-lightning - name: Dump handy wheels if: github.event_name == 'push' && github.ref == 'refs/heads/master' From 3c1736a310f0262a1b2dcc485c00ee79ff306dce Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 22:21:46 -0400 Subject: [PATCH 07/12] replace pip with uv --- tests/legacy/generate_checkpoints.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/legacy/generate_checkpoints.sh b/tests/legacy/generate_checkpoints.sh index 1d083a2a8e052..461cdd4afd197 100644 --- a/tests/legacy/generate_checkpoints.sh +++ b/tests/legacy/generate_checkpoints.sh @@ -9,18 +9,17 @@ set -e LEGACY_FOLDER=$(cd $(dirname $0); pwd -P) printf "LEGACY_FOLDER: $LEGACY_FOLDER" TESTS_FOLDER=$(dirname $LEGACY_FOLDER) -ENV_PATH=$LEGACY_FOLDER/vEnv +ENV_PATH=$LEGACY_FOLDER/.venv printf "ENV_PATH: $ENV_PATH" export PYTHONPATH=$TESTS_FOLDER # for `import tests_pytorch` printf "PYTHONPATH: $PYTHONPATH" rm -rf $ENV_PATH function create_and_save_checkpoint { - python --version - python -m pip --version - python -m pip list + uv --version + uv pip list - python $LEGACY_FOLDER/simple_classif_training.py $pl_ver + uv run $LEGACY_FOLDER/simple_classif_training.py $pl_ver cp $LEGACY_FOLDER/simple_classif_training.py $LEGACY_FOLDER/checkpoints/$pl_ver mv $LEGACY_FOLDER/checkpoints/$pl_ver/lightning_logs/version_0/checkpoints/*.ckpt $LEGACY_FOLDER/checkpoints/$pl_ver/ @@ -33,10 +32,10 @@ do printf "\n\n processing version: $pl_ver\n" # Don't install/update anything before activating venv to avoid breaking any existing environment. - python -m venv $ENV_PATH + uv venv $ENV_PATH source $ENV_PATH/bin/activate - python -m pip install "pytorch_lightning==$pl_ver" \ + uv pip install "pytorch_lightning==$pl_ver" \ -r $LEGACY_FOLDER/requirements.txt \ -r "$(dirname $TESTS_FOLDER)/requirements/pytorch/test.txt" \ -f https://download.pytorch.org/whl/cpu/torch_stable.html @@ -52,7 +51,7 @@ done if [[ -z "$@" ]]; then printf "\n\n processing local version\n" - python -m pip install \ + uv pip install \ -r $LEGACY_FOLDER/requirements.txt \ -r "$(dirname $TESTS_FOLDER)/requirements/pytorch/test.txt" \ -f https://download.pytorch.org/whl/cpu/torch_stable.html From 799170e3b97f39fa379a67c3e52e8e2a7cdca47a Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 22:27:36 -0400 Subject: [PATCH 08/12] run with python command --- tests/legacy/generate_checkpoints.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/legacy/generate_checkpoints.sh b/tests/legacy/generate_checkpoints.sh index 461cdd4afd197..d3cfa693c2906 100644 --- a/tests/legacy/generate_checkpoints.sh +++ b/tests/legacy/generate_checkpoints.sh @@ -7,19 +7,19 @@ set -e LEGACY_FOLDER=$(cd $(dirname $0); pwd -P) -printf "LEGACY_FOLDER: $LEGACY_FOLDER" +printf "LEGACY_FOLDER: $LEGACY_FOLDER\n" TESTS_FOLDER=$(dirname $LEGACY_FOLDER) ENV_PATH=$LEGACY_FOLDER/.venv -printf "ENV_PATH: $ENV_PATH" +printf "ENV_PATH: $ENV_PATH\n" export PYTHONPATH=$TESTS_FOLDER # for `import tests_pytorch` -printf "PYTHONPATH: $PYTHONPATH" +printf "PYTHONPATH: $PYTHONPATH\n" rm -rf $ENV_PATH function create_and_save_checkpoint { uv --version uv pip list - uv run $LEGACY_FOLDER/simple_classif_training.py $pl_ver + python $LEGACY_FOLDER/simple_classif_training.py $pl_ver cp $LEGACY_FOLDER/simple_classif_training.py $LEGACY_FOLDER/checkpoints/$pl_ver mv $LEGACY_FOLDER/checkpoints/$pl_ver/lightning_logs/version_0/checkpoints/*.ckpt $LEGACY_FOLDER/checkpoints/$pl_ver/ From ce0fdaaf67b7ec5fadec5f38fe5950187127cf61 Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 23:07:53 -0400 Subject: [PATCH 09/12] replace pip with uv --- .github/workflows/_legacy-checkpoints.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/_legacy-checkpoints.yml b/.github/workflows/_legacy-checkpoints.yml index 8cceb5870af8d..e4615aee4ff3a 100644 --- a/.github/workflows/_legacy-checkpoints.yml +++ b/.github/workflows/_legacy-checkpoints.yml @@ -57,9 +57,9 @@ jobs: steps: - uses: actions/checkout@v5 - - uses: actions/setup-python@v5 + - name: Install uv and set Python version + uses: astral-sh/setup-uv@v6 with: - # Python version here needs to be supported by all PL versions listed in back-compatible-versions.txt. python-version: "3.9" - name: Install PL from source @@ -67,18 +67,18 @@ jobs: PACKAGE_NAME: pytorch FREEZE_REQUIREMENTS: 1 timeout-minutes: 20 - run: pip install . --extra-index-url="${TORCH_URL}" + run: uv pip install . --extra-index-url="${TORCH_URL}" if: inputs.pl_version == '' - name: Install PL version timeout-minutes: 20 - run: pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}" + run: uv pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}" if: inputs.pl_version != '' - name: Adjust tests -> PL if: ${{ matrix.pkg-name != 'lightning' }} run: | - pip install -q -r .actions/requirements.txt + uv pip install -q -r .actions/requirements.txt python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ --source_import="lightning.fabric,lightning.pytorch" \ --target_import="lightning_fabric,pytorch_lightning" @@ -115,7 +115,7 @@ jobs: # export to env bool if secrets.AWS_REGION is not empty run: echo "WITH_SECRETS=$([ -n '${{ secrets.AWS_REGION }}' ] && echo 1 || echo 0)" >> $GITHUB_ENV - - run: pip install -r requirements/ci.txt + - run: uv pip install -r requirements/ci.txt - name: Upload checkpoints to S3 if: ${{ env.WITH_SECRETS == '1' }} working-directory: ${{ env.LEGACY_FOLDER }} From d2c4adf29907fe0590c9f72a9415225b896c05fc Mon Sep 17 00:00:00 2001 From: Shion Matsumoto Date: Tue, 2 Sep 2025 23:09:35 -0400 Subject: [PATCH 10/12] activate venv --- .github/workflows/_legacy-checkpoints.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/_legacy-checkpoints.yml b/.github/workflows/_legacy-checkpoints.yml index e4615aee4ff3a..6c37281fc04ec 100644 --- a/.github/workflows/_legacy-checkpoints.yml +++ b/.github/workflows/_legacy-checkpoints.yml @@ -61,6 +61,10 @@ jobs: uses: astral-sh/setup-uv@v6 with: python-version: "3.9" + # TODO: Avoid activating environment like this + # see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment + activate-environment: true + enable-cache: true - name: Install PL from source env: From 06c4515ab98058e5839284da4b21313660324348 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Wed, 3 Sep 2025 09:05:26 +0200 Subject: [PATCH 11/12] --find-links=... --- .github/workflows/ci-tests-pytorch.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index f7992475ae5fe..db9f0c2362cfb 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -126,8 +126,7 @@ jobs: uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \ --upgrade \ -r requirements/_integrations/accelerators.txt \ - --extra-index-url="${TORCH_URL}" \ - --find-links="${UV_CACHE_DIR}" \ + --find-links="${TORCH_URL}" \ --find-links="https://download.pytorch.org/whl/torch-tensorrt" uv pip list From 2c59a2a3ca2100f2c3dfdca2a6e3922d3ff215a3 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Wed, 3 Sep 2025 09:34:05 +0200 Subject: [PATCH 12/12] GLOO_SOCKET_IFNAME --- .github/workflows/ci-tests-pytorch.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-tests-pytorch.yml b/.github/workflows/ci-tests-pytorch.yml index db9f0c2362cfb..86f0a58089481 100644 --- a/.github/workflows/ci-tests-pytorch.yml +++ b/.github/workflows/ci-tests-pytorch.yml @@ -89,6 +89,9 @@ jobs: - name: Append Env. vars for Linux if: ${{ runner.os == 'Linux' }} run: echo "GLOO_SOCKET_IFNAME=eth0" >> $GITHUB_ENV + - name: Append Env. vars for MacOS + if: ${{ runner.os == 'macOS' }} + run: echo "GLOO_SOCKET_IFNAME=lo0" >> $GITHUB_ENV - name: Set min. dependencies if: ${{ matrix.config.requires == 'oldest' }}