Skip to content

Respect each example requirements and use uv #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2025
Merged

Conversation

dvrogozh
Copy link
Contributor

For: #1329

This commit introduces few changes to CI by modifying run_*_examples.sh and respective github workflows:

  • Switched to uv
  • Added tearup and teardown stages for tests (start() and stop() methods wrapping up test bodies - these are called automatically)
  • Tearup (start()) installs example dependencies and, optionally (if VIRTUAL_ENV=.venv is passed), creates uv virtual environment
  • Teardown (stop()) removes uv virtual environment if it was created (to save space)
  • If no VIRTUAL_ENV set, then scripts expect to be executed in the existing virtual environment. These can be python -m venv, uv env or conda env. In this case example dependencies will be installed in this environment potentially reinstalling existing packages (including torch!).
  • Dropped automated detection of CUDA platform. Now scripts require USE_CUDA=True to be passed explicitly
  • Added PIP_INSTALL_ARGS environment variable to be passed to uv pip install calls for each example dependencies. This allows to adjust torch indices and other options.

Execute all tests in current virtual environment (might rewrite packages):

./run_distributed_examples.sh

Execute all tests creating separate environment for each example:

VIRTUAL_ENV=.venv ./run_distributed_examples.sh

Run with CUDA:

USE_CUDA=True ./run_distributed_examples.sh

Adjust index:

PIP_INSTALL_ARGS="--pre -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html" \
    ./run_distributed_examples.sh

Few changes were required in examples requirements.txt files:

  • Added requirements to few examples which were missing them
  • Changes reinforcement_learning requirement for number to be <2 due to:
AttributeError: module 'numpy' has no attribute 'bool8'. Did you mean: 'bool'?
  • Changed time_sequence_prediction and word_language_model requirement for torch to be <2.6 due to:
  File "/pytorch/examples/time_sequence_prediction/train.py", line 47, in <module>
    data = torch.load('traindata.pt')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/pytorch/examples/time_sequence_prediction/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1524, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None

CC: @msaroufim, @malfet, @atalman

Current version of the example requires `numpy<2` otherwise the following
error can be seen:
```
AttributeError: module 'numpy' has no attribute 'bool8'. Did you mean: 'bool'?
```

Signed-off-by: Dmitry Rogozhkin <[email protected]>
Current version of examples require `torch<2.6` otherwise the following
error can be seen:
```
  File "/pytorch/examples/time_sequence_prediction/train.py", line 47, in <module>
    data = torch.load('traindata.pt')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/pytorch/examples/time_sequence_prediction/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1524, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
```

Signed-off-by: Dmitry Rogozhkin <[email protected]>
This commit introduces few changes to CI by modifying `run_*_examples.sh`
and respective github workflows:

* Switched to uv
* Added tearup and teardown stages for tests (`start()` and `stop()` methods
  wrapping up test bodies - these are called automatically)
* Tearup (`start()`) installs example dependencies and, optionally (if `VIRTUAL_ENV=.venv`
  is passed), creates uv virtual environment
* Teardown (`stop()`) removes uv virtual environment if it was created (to
  save space)
* If no `VIRTUAL_ENV` set, then scripts expect to be executed in the existing
  virtual environment. These can be `python -m venv`, `uv env` or `conda env`.
  In this case example dependencies will be installed in this environment
  potentially reinstalling existing packages (including `torch`!).
* Dropped automated detection of CUDA platform. Now scripts require `USE_CUDA=True`
  to be passed explicitly
* Added `PIP_INSTALL_ARGS` environment variable to be passed to `uv pip install` calls
  for each example dependencies. This allows to adjust torch indices and other options.

Execute all tests in current virtual environment (might rewrite packages):
```
./run_distributed_examples.sh
```

Execute all tests creating separate environment for each example:
```
VIRTUAL_ENV=.venv ./run_distributed_examples.sh
```

Run with CUDA:
```
USE_CUDA=True ./run_distributed_examples.sh
```

Adjust index:
```
PIP_INSTALL_ARGS="--pre -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html" \
   ./run_distributed_examples.sh
```

Signed-off-by: Dmitry Rogozhkin <[email protected]>
Copy link

netlify bot commented Apr 26, 2025

Deploy Preview for pytorch-examples-preview canceled.

Name Link
🔨 Latest commit 1203511
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-examples-preview/deploys/680c2a369975b90008fe6fb8

@msaroufim
Copy link
Member

Nice! It's promising that CI is green. Will review asap

@msaroufim msaroufim merged commit 00ef8a7 into pytorch:main Apr 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants