Add device_name
classmethod in Accelerator
.
#16743
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test PyTorch | |
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows | |
on: | |
push: | |
branches: [master, "release/*"] | |
pull_request: | |
branches: [master, "release/*"] | |
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped | |
paths: | |
- ".actions/*" | |
- "requirements/ci.txt" | |
- "requirements/pytorch/**" | |
- "src/lightning/pytorch/**" | |
- "src/pytorch_lightning/*" | |
- "tests/tests_pytorch/**" | |
- "tests/legacy/**" | |
- "pyproject.toml" # includes pytest config | |
- ".github/workflows/ci-tests-pytorch.yml" | |
- "requirements/fabric/**" | |
- "src/lightning/fabric/**" | |
- "src/lightning_fabric/*" | |
- "!requirements/pytorch/docs.txt" | |
- "!*.md" | |
- "!**/*.md" | |
schedule: | |
# At the end of every day | |
- cron: "0 0 * * *" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }} | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
pl-cpu: | |
runs-on: ${{ matrix.os }} | |
if: github.event.pull_request.draft == false | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [macOS-14, ubuntu-22.04, windows-2022] | |
config: | |
# only run PyTorch latest | |
- { pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.1" } | |
- { pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.2.2" } | |
- { pkg-name: "lightning", python-version: "3.11", pytorch-version: "2.3" } | |
- { pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.4.1" } | |
- { pkg-name: "lightning", python-version: "3.12.7", pytorch-version: "2.5.1" } | |
# only run PyTorch latest with Python latest, use PyTorch scope to limit dependency issues | |
- { pkg-name: "pytorch", python-version: "3.12.7", pytorch-version: "2.6" } | |
# "pytorch" installs the standalone package | |
- { pkg-name: "pytorch", python-version: "3.10", pytorch-version: "2.7" } | |
# adding recently cut Torch 2.7 - FUTURE | |
- { pkg-name: "pytorch", python-version: "3.12", pytorch-version: "2.8" } | |
# "oldest" versions tests, only on minimum Python | |
- { pkg-name: "pytorch", pytorch-version: "2.1", requires: "oldest" } | |
timeout-minutes: 50 | |
env: | |
PACKAGE_NAME: ${{ matrix.config.pkg-name }} | |
TORCH_URL: "https://download.pytorch.org/whl/cpu/" | |
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/')) }} | |
# TODO: Remove this - Enable running MPS tests on this platform | |
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }} | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Install uv and set Python version | |
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 | |
run: uv pip install -q -r .actions/requirements.txt | |
- 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' }} | |
run: | | |
cd requirements/pytorch | |
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']" | |
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.config.requires != 'oldest' }} | |
run: | | |
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 }}; \ | |
done | |
cat requirements/pytorch/base.txt | |
- name: Env. variables | |
run: | | |
# Switch PyTorch URL between stable and test/future | |
python -c "print('TORCH_URL=' + str('${{env.TORCH_URL_TEST}}' if '${{ matrix.config.pytorch-version }}' == '2.7' else '${{env.TORCH_URL_STABLE}}'))" >> $GITHUB_ENV | |
# Switch coverage scope | |
python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.config.pkg-name}}' == 'lightning' else 'pytorch_lightning'))" >> $GITHUB_ENV | |
# if you install mono-package set dependency only for this subpackage | |
python -c "print('EXTRA_PREFIX=' + str('' if '${{matrix.config.pkg-name}}' != 'lightning' else 'pytorch-'))" >> $GITHUB_ENV | |
# Avoid issue on Windows with PyTorch 2.4: "RuntimeError: use_libuv was requested but PyTorch was build without libuv support" | |
python -c "print('USE_LIBUV=0' if '${{matrix.os}}' == 'windows-2022' and '${{matrix.config.pytorch-version}}' == '2.4' else '')" >> $GITHUB_ENV | |
- name: Install package & dependencies | |
timeout-minutes: 20 | |
run: | | |
uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \ | |
--upgrade \ | |
-r requirements/_integrations/accelerators.txt \ | |
--find-links="${TORCH_URL}" \ | |
--find-links="https://download.pytorch.org/whl/torch-tensorrt" | |
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 | |
run: uv pip uninstall lightning | |
- name: Drop PL for LAI | |
if: ${{ matrix.config.pkg-name == 'lightning' }} | |
run: uv pip uninstall pytorch-lightning | |
- name: Dump handy wheels | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
continue-on-error: true | |
uses: ./.github/actions/pip-wheels | |
with: | |
wheel-dir: ${{ env.PYPI_CACHE_DIR }} | |
torch-url: ${{ env.TORCH_URL }} | |
cache-key: "pypi_wheels" | |
- name: Cache datasets | |
uses: actions/cache@v4 | |
with: | |
path: Datasets | |
key: pl-dataset | |
- name: Sanity check | |
run: | | |
set -e | |
python requirements/pytorch/check-avail-extras.py | |
python -c "from torch import __version__ as ver; assert ver.startswith('${{ matrix.config.pytorch-version }}'), ver" | |
- name: Adjust tests / env. -> PL | |
if: ${{ matrix.config.pkg-name != 'lightning' }} | |
run: | | |
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \ | |
--source_import="lightning.fabric,lightning.pytorch" \ | |
--target_import="lightning_fabric,pytorch_lightning" | |
- name: Prevent using raw source | |
run: rm -rf src/ | |
- name: Get legacy checkpoints | |
run: | | |
bash .actions/pull_legacy_checkpoints.sh | |
cd tests/legacy | |
bash generate_checkpoints.sh | |
ls -l checkpoints/ | |
- name: Testing Warnings | |
working-directory: tests/tests_pytorch | |
# needs to run outside `pytest` | |
run: python utilities/test_warnings.py | |
- name: Testing PyTorch | |
working-directory: tests/tests_pytorch | |
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003 | |
run: | | |
echo $GITHUB_RUN_ID | |
python -m coverage run --source ${{ env.COVERAGE_SCOPE }} \ | |
-m pytest . -v --timeout=90 --durations=50 --random-order-seed=$GITHUB_RUN_ID \ | |
--junitxml=junit.xml -o junit_family=legacy # NOTE: for Codecov's test results | |
- name: Statistics | |
if: success() | |
working-directory: tests/tests_pytorch | |
run: | | |
coverage report | |
coverage xml | |
- name: Upload test results to Codecov | |
if: ${{ !cancelled() }} # Run even if tests fail | |
uses: codecov/test-results-action@v1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v5 | |
# see: https://github.com/actions/toolkit/issues/399 | |
continue-on-error: true | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
file: tests/tests_pytorch/coverage.xml | |
flags: ${{ env.COVERAGE_SCOPE }},cpu,pytest-full,python${{ matrix.config.python-version }},pytorch${{ matrix.config.pytorch-version }} | |
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 | |
if: always() | |
steps: | |
- run: echo "${{ needs.pl-cpu.result }}" | |
- name: failing... | |
if: needs.pl-cpu.result == 'failure' | |
run: exit 1 | |
- name: cancelled or skipped... | |
if: contains(fromJSON('["cancelled", "skipped"]'), needs.pl-cpu.result) | |
timeout-minutes: 1 | |
run: sleep 90 |