Skip to content

Commit abd2dda

Browse files
committed
Use astral uv on CI testing. Add uv lock and lock check
1 parent 66201c4 commit abd2dda

File tree

7 files changed

+106
-63
lines changed

7 files changed

+106
-63
lines changed

.github/workflows/mps-tests.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ jobs:
7676
run: |
7777
conda shell.bash hook
7878
conda activate $CONDA_ENV
79-
pip install -U torch torchvision
79+
pip install uv
80+
uv pip install torch torchvision
8081
8182
- name: Install PyTorch (nightly)
8283
if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }}
8384
shell: bash -l {0}
8485
run: |
8586
conda shell.bash hook
8687
conda activate $CONDA_ENV
87-
pip install --pre -U torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
88+
uv pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
8889
8990
- name: Install dependencies
9091
shell: bash -l {0}
@@ -94,11 +95,11 @@ jobs:
9495
# TODO: We add set -xe to explicitly fail the CI if one of the commands is failing.
9596
# Somehow the step is passing even if a subcommand failed
9697
set -xe
97-
pip install -r requirements-dev.txt
98+
uv pip install -r requirements-dev.txt
9899
echo "1 returned code: $?"
99-
pip install -e .
100+
uv pip install -e .
100101
echo "2 returned code: $?"
101-
pip list
102+
uv pip list
102103
echo "3 returned code: $?"
103104
104105
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
@@ -132,4 +133,4 @@ jobs:
132133
working-directory: ${{ github.repository }}
133134
run: |
134135
conda activate $CONDA_ENV
135-
python examples/mnist/mnist.py --epochs=1
136+
uv run python examples/mnist/mnist.py --epochs=1

.github/workflows/tpu-tests.yml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- "*.*.*"
77
paths:
88
- "ignite/**"
9+
- "pyproject.toml"
910
- "tests/ignite/**"
1011
- "tests/run_tpu_tests.sh"
1112
- "tests/run_code_style.sh"
@@ -14,6 +15,7 @@ on:
1415
pull_request:
1516
paths:
1617
- "ignite/**"
18+
- "pyproject.toml"
1719
- "tests/ignite/**"
1820
- "tests/run_tpu_tests.sh"
1921
- "tests/run_code_style.sh"
@@ -32,25 +34,33 @@ jobs:
3234
strategy:
3335
fail-fast: false
3436
matrix:
35-
xla-version: [nightly]
37+
xla-version: ["nightly"]
38+
PYTHON_VERSION: ["3.10"]
3639

3740
steps:
3841
- uses: actions/checkout@v4
39-
- name: Set up Python 3.10
40-
uses: actions/setup-python@v5
41-
with:
42-
python-version: "3.10"
43-
architecture: "x64"
4442

4543
- name: Get year & week number
4644
id: get-date
4745
run: echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT
4846
shell: bash -l {0}
4947

48+
- name: Set up Python 3.10
49+
uses: astral-sh/setup-uv@v6
50+
with:
51+
# architecture: "x64"
52+
version: "latest"
53+
python-version: "${{ matrix.PYTHON_VERSION }}"
54+
activate-environment: true
55+
enable-cache: true
56+
cache-suffix: "${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}"
57+
cache-dependency-glob: |
58+
**/requirements-dev.txt
59+
**/pyproject.toml
60+
5061
- name: Get pip cache dir
5162
id: pip-cache
5263
run: |
53-
pip3 install -U "pip<24"
5464
echo "pip_cache=$(pip cache dir)" >> $GITHUB_OUTPUT
5565
shell: bash -l {0}
5666

@@ -67,18 +77,19 @@ jobs:
6777
6878
## Install mkl (alternative approach to https://github.com/pytorch/xla/blob/b0ba29f98a695671972d4a4cc07441014dba2892/.kokoro/common.sh#L31-L32)
6979
sudo apt-get update && sudo apt-get install -y libopenblas-dev libomp5
70-
pip install mkl==2021.4.0
80+
uv pip install mkl==2021.4.0
7181
7282
## Install torch & xla and torchvision
73-
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
74-
pip install https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-nightly-cp310-cp310-linux_x86_64.whl
83+
uv pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
84+
# https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-nightly-cp310-cp310-linux_x86_64.whl
85+
uv run python scripts/install_torch_xla.py "${{ matrix.PYTHON_VERSION }}" "${{ matrix.xla-version }}"
7586
7687
# Check installation
77-
python -c "import torch"
88+
uv run python -c "import torch"
7889
7990
## Install test deps and Ignite
80-
pip install -r requirements-dev.txt
81-
pip install .
91+
uv pip install -r requirements-dev.txt
92+
uv pip install .
8293
8394
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
8495
# to "/tmp" for tpu tests
@@ -94,7 +105,7 @@ jobs:
94105
timeout_minutes: 25
95106
shell: bash
96107
command: |
97-
python -c "import torch_xla; print('torch xla version:', torch_xla.__version__)"
108+
uv run python -c "import torch_xla; print('torch xla version:', torch_xla.__version__)"
98109
bash tests/run_tpu_tests.sh
99110
new_command_on_retry: USE_LAST_FAILED=1 bash tests/run_tpu_tests.sh
100111
env:

.github/workflows/unit-tests.yml

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,44 +59,37 @@ jobs:
5959

6060
steps:
6161
- uses: actions/checkout@v4
62-
- uses: actions/setup-python@v5
63-
with:
64-
python-version: ${{ matrix.python-version }}
65-
6662
- name: Get year & week number
6763
id: get-date
6864
run: |
6965
echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT
70-
71-
- name: Get pip cache dir
72-
id: pip-cache
73-
run: |
74-
pip install -U pip || python -m pip install -U pip
75-
echo "pip_cache=$(pip cache dir)" >> $GITHUB_OUTPUT
76-
77-
- uses: actions/cache@v4
66+
- uses: astral-sh/setup-uv@v6
7867
with:
79-
path: |
80-
${{ steps.pip-cache.outputs.pip_cache }}
81-
key: ${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-${{ hashFiles('requirements-dev.txt') }}
82-
restore-keys: |
83-
${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-
68+
version: "latest"
69+
python-version: ${{ matrix.python-version }}
70+
activate-environment: true
71+
enable-cache: true
72+
cache-suffix: "${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}"
73+
cache-dependency-glob: |
74+
**/requirements-dev.txt
75+
**/pyproject.toml
8476
85-
- run: pip install pip wheel setuptools -Uqq
77+
- name: Install dev tools
78+
run: uv pip install wheel setuptools -Uqq
8679

8780
- name: Install PyTorch
8881
if: ${{ matrix.pytorch-channel == 'pytorch' }}
89-
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
82+
run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
9083

9184
- name: Install PyTorch (nightly)
9285
if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }}
93-
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre
86+
run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre
9487

9588
- name: Install dependencies
9689
run: |
97-
pip install -r requirements-dev.txt
98-
pip install .
99-
pip list
90+
uv pip install -r requirements-dev.txt
91+
uv pip install .
92+
uv pip list
10093
10194
- name: Check code formatting
10295
run: |
@@ -142,63 +135,63 @@ jobs:
142135
run: |
143136
# MNIST
144137
# 1) mnist.py
145-
python examples/mnist/mnist.py --epochs=1
138+
uv run python examples/mnist/mnist.py --epochs=1
146139
147140
- name: Run MNIST with loggers Examples
148141
if: ${{ matrix.os == 'ubuntu-latest' }}
149142
run: |
150143
# 2) mnist_with_visdom.py
151-
python -c "from visdom.server.build import download_scripts; download_scripts()" # download scripts : https://github.com/facebookresearch/visdom/blob/master/py/server.py#L929
152-
python -m visdom.server &
144+
uv run python -c "from visdom.server.build import download_scripts; download_scripts()" # download scripts : https://github.com/facebookresearch/visdom/blob/master/py/server.py#L929
145+
uv run python -m visdom.server &
153146
sleep 10
154-
python examples/mnist/mnist_with_visdom.py --epochs=1
147+
uv run python examples/mnist/mnist_with_visdom.py --epochs=1
155148
kill %1
156149
# 3.1) mnist_with_tensorboard.py with tbX
157-
python examples/mnist/mnist_with_tensorboard.py --epochs=1
150+
uv run python examples/mnist/mnist_with_tensorboard.py --epochs=1
158151
# 3.2) mnist_with_tensorboard.py with native torch tb
159-
pip uninstall -y tensorboardX
160-
python examples/mnist/mnist_with_tensorboard.py --epochs=1
152+
uv pip uninstall tensorboardX
153+
uv run python examples/mnist/mnist_with_tensorboard.py --epochs=1
161154
162155
- name: Run MNIST Example With Crash
163156
if: ${{ matrix.os == 'ubuntu-latest' }}
164157
continue-on-error: true
165158
run: |
166159
# 4) mnist_save_resume_engine.py
167-
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --crash_iteration 1100
160+
uv run python examples/mnist/mnist_save_resume_engine.py --epochs=2 --crash_iteration 1100
168161
169162
- name: Resume MNIST from previous crash
170163
if: ${{ matrix.os == 'ubuntu-latest' }}
171164
run: |
172-
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --resume_from=/tmp/mnist_save_resume/checkpoint_1.pt
165+
uv run python examples/mnist/mnist_save_resume_engine.py --epochs=2 --resume_from=/tmp/mnist_save_resume/checkpoint_1.pt
173166
174167
- name: Run GAN example
175168
if: ${{ matrix.os == 'ubuntu-latest' }}
176169
run: |
177170
# DCGAN
178-
python examples/gan/dcgan.py --dataset fake --dataroot /tmp/fakedata --output-dir /tmp/outputs-dcgan --batch-size 2 --epochs 2 --workers 0
171+
uv run python examples/gan/dcgan.py --dataset fake --dataroot /tmp/fakedata --output-dir /tmp/outputs-dcgan --batch-size 2 --epochs 2 --workers 0
179172
180173
- name: Run RL Examples
181174
if: ${{ matrix.os == 'ubuntu-latest' }}
182175
run: |
183176
# RL
184177
# 1) Actor-Critic
185-
python examples/reinforcement_learning/actor_critic.py --max-episodes=2
178+
uv run python examples/reinforcement_learning/actor_critic.py --max-episodes=2
186179
# 2) Reinforce
187-
python examples/reinforcement_learning/reinforce.py --max-episodes=2
180+
uv run python examples/reinforcement_learning/reinforce.py --max-episodes=2
188181
189182
- name: Run Neural Style Example
190183
if: ${{ matrix.os == 'ubuntu-latest' }}
191184
run: |
192185
#fast-neural-style
193186
#train
194187
mkdir -p ~/.cache/torch/checkpoints/ && wget "https://download.pytorch.org/models/vgg16-397923af.pth" -O ~/.cache/torch/checkpoints/vgg16-397923af.pth
195-
python examples/fast_neural_style/neural_style.py train --epochs 1 --cuda 0 --dataset test --dataroot . --image_size 32 --style_image examples/fast_neural_style/images/style_images/mosaic.jpg --style_size 32
188+
uv run python examples/fast_neural_style/neural_style.py train --epochs 1 --cuda 0 --dataset test --dataroot . --image_size 32 --style_image examples/fast_neural_style/images/style_images/mosaic.jpg --style_size 32
196189
- name: Run SR Example
197190
if: ${{ matrix.os == 'ubuntu-latest' }}
198191
run: |
199192
set -e
200193
echo "Testing Caltech101 dataset availability..."
201-
if python -c "import torchvision; torchvision.datasets.Caltech101(root='./data', download=True)"; then
194+
if uv run python -c "import torchvision; torchvision.datasets.Caltech101(root='./data', download=True)"; then
202195
echo "Caltech101 dataset downloaded successfully. Please remove this workaround and restore dataset check."
203196
exit 1
204197
# python examples/super_resolution/main.py --upscale_factor 3 --crop_size 180 --batch_size 4 --test_batch_size 100 --n_epochs 1 --lr 0.001 --threads 2 --debug

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ license-files = ["LICENSE"]
1414
classifiers = [
1515
"Programming Language :: Python :: 3",
1616
]
17+
requires-python = ">=3.9,<3.13"
1718
dependencies = [
1819
"torch>=1.3,<3",
1920
"packaging"

scripts/install_torch_xla.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
import tempfile
4+
import zipfile
5+
from pathlib import Path
6+
from urllib.request import urlopen
7+
8+
9+
def main(python_version: str, xla_version: str) -> None:
10+
temp_dir = Path(tempfile.mkdtemp()) / "torch_xla"
11+
temp_dir.mkdir(parents=True, exist_ok=True)
12+
pyver = python_version.replace(".", "")
13+
url = f"https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-{xla_version}-cp{pyver}-cp{pyver}-linux_x86_64.whl"
14+
suffix = f"-cp{pyver}-cp{pyver}-linux_x86_64.whl"
15+
r = urlopen(url)
16+
wheel_path = temp_dir / "torch_xla.zip"
17+
18+
with open(wheel_path, "b+w") as f:
19+
f.write(r.read())
20+
21+
with zipfile.ZipFile(wheel_path, "r") as zip_ref:
22+
zip_ref.extractall(wheel_path.parent)
23+
24+
dist = [p for p in os.listdir(temp_dir) if "dist-info" in p]
25+
if dist:
26+
pkg_name = dist[0].split(".dist-info")[0]
27+
wheel_path = wheel_path.rename(f"{pkg_name}{suffix}")
28+
cmd = ["uv", "pip", "install", str(wheel_path)]
29+
os.system(" ".join(cmd))
30+
31+
32+
if __name__ == "__main__":
33+
if len(sys.argv) == 3:
34+
python_version = sys.argv[1]
35+
xla_version = sys.argv[2]
36+
37+
main(python_version, xla_version)

tests/common_test_functionality.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ run_tests() {
102102

103103
# Run the command
104104
if [ "$trap_deselected_exit_code" -eq "1" ]; then
105-
eval "pytest ${pytest_args}" || { exit_code=$?; if [ "$exit_code" -eq ${last_failed_no_failures_code} ]; then echo "All tests deselected"; else exit $exit_code; fi; }
105+
eval "uv run pytest ${pytest_args}" || { exit_code=$?; if [ "$exit_code" -eq ${last_failed_no_failures_code} ]; then echo "All tests deselected"; else exit $exit_code; fi; }
106106
else
107-
eval "pytest ${pytest_args}"
107+
eval "uv run pytest ${pytest_args}"
108108
fi
109109
}

tests/run_code_style.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
set -xeu
44

55
if [ $1 = "lint" ]; then
6-
flake8 ignite tests examples --config setup.cfg
6+
uv run flake8 ignite tests examples --config setup.cfg
77
ufmt diff .
88
elif [ $1 = "fmt" ]; then
9-
ufmt format .
9+
uv run ufmt format .
1010
elif [ $1 = "mypy" ]; then
11-
mypy --config-file mypy.ini
11+
uv run mypy --config-file mypy.ini
1212
elif [ $1 = "install" ]; then
13-
pip install --upgrade flake8 "black==24.10.0" "usort==1.0.8.post1" "ufmt==2.7.3" "mypy"
13+
uv pip install flake8 "black==24.10.0" "usort==1.0.8.post1" "ufmt==2.7.3" "mypy"
1414
fi

0 commit comments

Comments
 (0)