Skip to content

Commit 664354f

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

File tree

4 files changed

+423
-41
lines changed

4 files changed

+423
-41
lines changed

.github/workflows/unit-tests.yml

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,44 +59,43 @@ 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
76+
**/uv.lock
77+
78+
- name: Check uv lock
79+
id: check-lock
80+
run: |
81+
uv lock --check
8482
85-
- run: pip install pip wheel setuptools -Uqq
83+
- name: Install dev tools
84+
run: uv pip install wheel setuptools -Uqq
8685

8786
- name: Install PyTorch
8887
if: ${{ matrix.pytorch-channel == 'pytorch' }}
89-
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
88+
run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
9089

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

9594
- name: Install dependencies
9695
run: |
97-
pip install -r requirements-dev.txt
98-
pip install .
99-
pip list
96+
uv pip install -r requirements-dev.txt
97+
uv pip install .
98+
uv pip list
10099
101100
- name: Check code formatting
102101
run: |
@@ -142,63 +141,63 @@ jobs:
142141
run: |
143142
# MNIST
144143
# 1) mnist.py
145-
python examples/mnist/mnist.py --epochs=1
144+
uv run python examples/mnist/mnist.py --epochs=1
146145
147146
- name: Run MNIST with loggers Examples
148147
if: ${{ matrix.os == 'ubuntu-latest' }}
149148
run: |
150149
# 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 &
150+
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
151+
uv run python -m visdom.server &
153152
sleep 10
154-
python examples/mnist/mnist_with_visdom.py --epochs=1
153+
uv run python examples/mnist/mnist_with_visdom.py --epochs=1
155154
kill %1
156155
# 3.1) mnist_with_tensorboard.py with tbX
157-
python examples/mnist/mnist_with_tensorboard.py --epochs=1
156+
uv run python examples/mnist/mnist_with_tensorboard.py --epochs=1
158157
# 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
158+
uv pip uninstall tensorboardX
159+
uv run python examples/mnist/mnist_with_tensorboard.py --epochs=1
161160
162161
- name: Run MNIST Example With Crash
163162
if: ${{ matrix.os == 'ubuntu-latest' }}
164163
continue-on-error: true
165164
run: |
166165
# 4) mnist_save_resume_engine.py
167-
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --crash_iteration 1100
166+
uv run python examples/mnist/mnist_save_resume_engine.py --epochs=2 --crash_iteration 1100
168167
169168
- name: Resume MNIST from previous crash
170169
if: ${{ matrix.os == 'ubuntu-latest' }}
171170
run: |
172-
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --resume_from=/tmp/mnist_save_resume/checkpoint_1.pt
171+
uv run python examples/mnist/mnist_save_resume_engine.py --epochs=2 --resume_from=/tmp/mnist_save_resume/checkpoint_1.pt
173172
174173
- name: Run GAN example
175174
if: ${{ matrix.os == 'ubuntu-latest' }}
176175
run: |
177176
# DCGAN
178-
python examples/gan/dcgan.py --dataset fake --dataroot /tmp/fakedata --output-dir /tmp/outputs-dcgan --batch-size 2 --epochs 2 --workers 0
177+
uv run python examples/gan/dcgan.py --dataset fake --dataroot /tmp/fakedata --output-dir /tmp/outputs-dcgan --batch-size 2 --epochs 2 --workers 0
179178
180179
- name: Run RL Examples
181180
if: ${{ matrix.os == 'ubuntu-latest' }}
182181
run: |
183182
# RL
184183
# 1) Actor-Critic
185-
python examples/reinforcement_learning/actor_critic.py --max-episodes=2
184+
uv run python examples/reinforcement_learning/actor_critic.py --max-episodes=2
186185
# 2) Reinforce
187-
python examples/reinforcement_learning/reinforce.py --max-episodes=2
186+
uv run python examples/reinforcement_learning/reinforce.py --max-episodes=2
188187
189188
- name: Run Neural Style Example
190189
if: ${{ matrix.os == 'ubuntu-latest' }}
191190
run: |
192191
#fast-neural-style
193192
#train
194193
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
194+
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
196195
- name: Run SR Example
197196
if: ${{ matrix.os == 'ubuntu-latest' }}
198197
run: |
199198
set -e
200199
echo "Testing Caltech101 dataset availability..."
201-
if python -c "import torchvision; torchvision.datasets.Caltech101(root='./data', download=True)"; then
200+
if uv run python -c "import torchvision; torchvision.datasets.Caltech101(root='./data', download=True)"; then
202201
echo "Caltech101 dataset downloaded successfully. Please remove this workaround and restore dataset check."
203202
exit 1
204203
# 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"

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)