Skip to content

Commit 8c868a6

Browse files
matsumotosanlantiga
authored andcommitted
uv for pytorch tests (#21148)
* swap to uv * no pip cache * enable caching. use venv. * activate environment * fix uninstall * replace pip with uv * activate venv * --find-links=... * GLOO_SOCKET_IFNAME --------- Co-authored-by: Nicki Skafte Detlefsen <[email protected]> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Jirka B <[email protected]> (cherry picked from commit 29e8ce4)
1 parent 773482a commit 8c868a6

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

.github/workflows/_legacy-checkpoints.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,32 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v5
5959

60-
- uses: actions/setup-python@v5
60+
- name: Install uv and set Python version
61+
uses: astral-sh/setup-uv@v6
6162
with:
62-
# Python version here needs to be supported by all PL versions listed in back-compatible-versions.txt.
6363
python-version: "3.9"
64+
# TODO: Avoid activating environment like this
65+
# see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment
66+
activate-environment: true
67+
enable-cache: true
6468

6569
- name: Install PL from source
6670
env:
6771
PACKAGE_NAME: pytorch
6872
FREEZE_REQUIREMENTS: 1
6973
timeout-minutes: 20
70-
run: pip install . --extra-index-url="${TORCH_URL}"
74+
run: uv pip install . --extra-index-url="${TORCH_URL}"
7175
if: inputs.pl_version == ''
7276

7377
- name: Install PL version
7478
timeout-minutes: 20
75-
run: pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}"
79+
run: uv pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}"
7680
if: inputs.pl_version != ''
7781

7882
- name: Adjust tests -> PL
7983
if: ${{ matrix.pkg-name != 'lightning' }}
8084
run: |
81-
pip install -q -r .actions/requirements.txt
85+
uv pip install -q -r .actions/requirements.txt
8286
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
8387
--source_import="lightning.fabric,lightning.pytorch" \
8488
--target_import="lightning_fabric,pytorch_lightning"
@@ -115,7 +119,7 @@ jobs:
115119
# export to env bool if secrets.AWS_REGION is not empty
116120
run: echo "WITH_SECRETS=$([ -n '${{ secrets.AWS_REGION }}' ] && echo 1 || echo 0)" >> $GITHUB_ENV
117121

118-
- run: pip install -r requirements/ci.txt
122+
- run: uv pip install -r requirements/ci.txt
119123
- name: Upload checkpoints to S3
120124
if: ${{ env.WITH_SECRETS == '1' }}
121125
working-directory: ${{ env.LEGACY_FOLDER }}

.github/workflows/ci-tests-pytorch.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,49 @@ jobs:
6969
TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/"
7070
TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/"
7171
FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
72-
PYPI_CACHE_DIR: "_pip-wheels"
7372
# TODO: Remove this - Enable running MPS tests on this platform
7473
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }}
7574
steps:
7675
- uses: actions/checkout@v5
7776

78-
- name: Set up Python ${{ matrix.config.python-version }}
79-
uses: actions/setup-python@v5
77+
- name: Install uv and set Python version
78+
uses: astral-sh/setup-uv@v6
8079
with:
8180
python-version: ${{ matrix.config.python-version || '3.9' }}
81+
# TODO: Avoid activating environment like this
82+
# see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment
83+
activate-environment: true
84+
enable-cache: true
8285

83-
- name: basic setup
84-
run: pip install -q -r .actions/requirements.txt
86+
- name: Basic setup
87+
run: uv pip install -q -r .actions/requirements.txt
8588

8689
- name: Append Env. vars for Linux
8790
if: ${{ runner.os == 'Linux' }}
8891
run: echo "GLOO_SOCKET_IFNAME=eth0" >> $GITHUB_ENV
92+
- name: Append Env. vars for MacOS
93+
if: ${{ runner.os == 'macOS' }}
94+
run: echo "GLOO_SOCKET_IFNAME=lo0" >> $GITHUB_ENV
8995

9096
- name: Set min. dependencies
9197
if: ${{ matrix.config.requires == 'oldest' }}
9298
run: |
9399
cd requirements/pytorch
94-
pip install -U "lightning-utilities[cli]"
100+
uv pip install -U "lightning-utilities[cli]"
95101
python -m lightning_utilities.cli requirements set-oldest --req_files "['base.txt', 'extra.txt', 'strategies.txt', 'examples.txt', 'test.txt']"
96-
pip install "cython<3.0" wheel
97-
pip install "pyyaml==5.4" --no-build-isolation
102+
uv pip install "cython<3.0" wheel
103+
uv pip install "pyyaml==5.4" --no-build-isolation
98104
99105
- name: Adjust PyTorch versions in requirements files
100106
if: ${{ matrix.config.requires != 'oldest' }}
101107
run: |
102-
pip install -q -r requirements/ci.txt
108+
uv pip install -q -r requirements/ci.txt
103109
python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
104110
for fpath in `ls requirements/**/*.txt`; do \
105111
python ./adjust-torch-versions.py $fpath ${{ matrix.config.pytorch-version }}; \
106112
done
107113
cat requirements/pytorch/base.txt
108114
109-
- name: pip wheels cache
110-
uses: actions/cache/restore@v4
111-
with:
112-
path: ${{ env.PYPI_CACHE_DIR }}
113-
key: pypi_wheels
114-
- run: |
115-
mkdir -p $PYPI_CACHE_DIR
116-
ls -lh $PYPI_CACHE_DIR
117-
118115
- name: Env. variables
119116
run: |
120117
# Switch PyTorch URL between stable and test/future
@@ -129,19 +126,21 @@ jobs:
129126
- name: Install package & dependencies
130127
timeout-minutes: 20
131128
run: |
132-
pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
133-
-U --upgrade-strategy=eager --prefer-binary \
129+
uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
130+
--upgrade \
134131
-r requirements/_integrations/accelerators.txt \
135-
--extra-index-url="${TORCH_URL}" \
136-
--find-links="${PYPI_CACHE_DIR}"
137-
pip list
132+
--find-links="${TORCH_URL}"
133+
uv pip list
134+
138135
- name: Drop LAI from extensions
139136
if: ${{ matrix.config.pkg-name != 'lightning' }}
140137
# Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it
141-
run: pip uninstall -y lightning
138+
run: uv pip uninstall lightning
139+
142140
- name: Drop PL for LAI
143141
if: ${{ matrix.config.pkg-name == 'lightning' }}
144-
run: pip uninstall -y pytorch-lightning
142+
run: uv pip uninstall pytorch-lightning
143+
145144
- name: Dump handy wheels
146145
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
147146
continue-on-error: true
@@ -218,6 +217,9 @@ jobs:
218217
name: CPU-coverage
219218
fail_ci_if_error: false
220219

220+
- name: Minimize uv cache
221+
run: uv cache prune --ci
222+
221223
pl-cpu-guardian:
222224
runs-on: ubuntu-latest
223225
needs: pl-cpu

tests/legacy/generate_checkpoints.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
set -e
88

99
LEGACY_FOLDER=$(cd $(dirname $0); pwd -P)
10-
printf "LEGACY_FOLDER: $LEGACY_FOLDER"
10+
printf "LEGACY_FOLDER: $LEGACY_FOLDER\n"
1111
TESTS_FOLDER=$(dirname $LEGACY_FOLDER)
12-
ENV_PATH=$LEGACY_FOLDER/vEnv
13-
printf "ENV_PATH: $ENV_PATH"
12+
ENV_PATH=$LEGACY_FOLDER/.venv
13+
printf "ENV_PATH: $ENV_PATH\n"
1414
export PYTHONPATH=$TESTS_FOLDER # for `import tests_pytorch`
15-
printf "PYTHONPATH: $PYTHONPATH"
15+
printf "PYTHONPATH: $PYTHONPATH\n"
1616
rm -rf $ENV_PATH
1717

1818
function create_and_save_checkpoint {
19-
python --version
20-
python -m pip --version
21-
python -m pip list
19+
uv --version
20+
uv pip list
2221

2322
python $LEGACY_FOLDER/simple_classif_training.py $pl_ver
2423

@@ -33,10 +32,10 @@ do
3332
printf "\n\n processing version: $pl_ver\n"
3433

3534
# Don't install/update anything before activating venv to avoid breaking any existing environment.
36-
python -m venv $ENV_PATH
35+
uv venv $ENV_PATH
3736
source $ENV_PATH/bin/activate
3837

39-
python -m pip install "pytorch_lightning==$pl_ver" \
38+
uv pip install "pytorch_lightning==$pl_ver" \
4039
-r $LEGACY_FOLDER/requirements.txt \
4140
-r "$(dirname $TESTS_FOLDER)/requirements/pytorch/test.txt" \
4241
-f https://download.pytorch.org/whl/cpu/torch_stable.html
@@ -52,7 +51,7 @@ done
5251
if [[ -z "$@" ]]; then
5352
printf "\n\n processing local version\n"
5453

55-
python -m pip install \
54+
uv pip install \
5655
-r $LEGACY_FOLDER/requirements.txt \
5756
-r "$(dirname $TESTS_FOLDER)/requirements/pytorch/test.txt" \
5857
-f https://download.pytorch.org/whl/cpu/torch_stable.html

0 commit comments

Comments
 (0)