pytorch-lightning
221 строка · 9.2 Кб
1name: Test PyTorch
2
3# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
4on:
5push:
6branches: [master, "release/*"]
7pull_request:
8branches: [master, "release/*"]
9types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
10paths:
11- ".actions/*"
12- "requirements/ci.txt"
13- "requirements/pytorch/**"
14- "src/lightning/pytorch/**"
15- "src/pytorch_lightning/*"
16- "tests/tests_pytorch/**"
17- "tests/legacy/**"
18- "pyproject.toml" # includes pytest config
19- ".github/workflows/ci-tests-pytorch.yml"
20- "requirements/fabric/**"
21- "src/lightning/fabric/**"
22- "src/lightning_fabric/*"
23- "!requirements/pytorch/docs.txt"
24- "!*.md"
25- "!**/*.md"
26schedule:
27# At the end of every day
28- cron: "0 0 * * *"
29
30concurrency:
31group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
32cancel-in-progress: ${{ github.event_name == 'pull_request' }}
33
34defaults:
35run:
36shell: bash
37
38jobs:
39pl-cpu:
40runs-on: ${{ matrix.os }}
41if: github.event.pull_request.draft == false
42strategy:
43fail-fast: false
44matrix:
45include:
46- { os: "macOS-11", pkg-name: "lightning", python-version: "3.10", pytorch-version: "1.13" }
47- { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.10", pytorch-version: "1.13" }
48- { os: "windows-2022", pkg-name: "lightning", python-version: "3.10", pytorch-version: "1.13" }
49# only run PyTorch latest
50- { os: "macOS-11", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.1" }
51- { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.1" }
52- { os: "windows-2022", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.1" }
53- { os: "macOS-11", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.2" }
54- { os: "ubuntu-20.04", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.2" }
55- { os: "windows-2022", pkg-name: "lightning", python-version: "3.10", pytorch-version: "2.2" }
56# only run PyTorch latest with Python latest, use PyTorch scope to limit dependency issues
57- { os: "macOS-12", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.0" }
58- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.0" }
59- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.0" }
60- { os: "macOS-12", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.1" }
61- { os: "ubuntu-22.04", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.1" }
62- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.11", pytorch-version: "2.1" }
63# "oldest" versions tests, only on minimum Python
64- {
65os: "macOS-11",
66pkg-name: "lightning",
67python-version: "3.8",
68pytorch-version: "1.13",
69requires: "oldest",
70}
71- {
72os: "ubuntu-20.04",
73pkg-name: "lightning",
74python-version: "3.8",
75pytorch-version: "1.13",
76requires: "oldest",
77}
78- {
79os: "windows-2022",
80pkg-name: "lightning",
81python-version: "3.8",
82pytorch-version: "1.13",
83requires: "oldest",
84}
85# "pytorch" installs the standalone package
86- { os: "macOS-11", pkg-name: "pytorch", python-version: "3.8", pytorch-version: "1.13" }
87- { os: "ubuntu-20.04", pkg-name: "pytorch", python-version: "3.8", pytorch-version: "1.13" }
88- { os: "windows-2022", pkg-name: "pytorch", python-version: "3.8", pytorch-version: "1.13" }
89timeout-minutes: 50
90env:
91PACKAGE_NAME: ${{ matrix.pkg-name }}
92TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html"
93TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/torch_stable.html"
94TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/torch_test.html"
95FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
96PYPI_CACHE_DIR: "_pip-wheels"
97steps:
98- uses: actions/checkout@v4
99
100- name: Set up Python ${{ matrix.python-version }}
101uses: actions/setup-python@v5
102with:
103python-version: ${{ matrix.python-version }}
104
105- name: basic setup
106run: pip install -q -r .actions/requirements.txt
107
108- name: Set min. dependencies
109if: ${{ matrix.requires == 'oldest' }}
110run: python .actions/assistant.py replace_oldest_ver
111
112- name: Adjust PyTorch versions in requirements files
113if: ${{ matrix.requires != 'oldest' }}
114run: |
115pip install -q -r requirements/ci.txt
116python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
117for fpath in `ls requirements/**/*.txt`; do \
118python ./adjust-torch-versions.py $fpath ${{ matrix.pytorch-version }}; \
119done
120cat requirements/pytorch/base.txt
121
122- name: pip wheels cache
123uses: actions/cache/restore@v4
124with:
125path: ${{ env.PYPI_CACHE_DIR }}
126key: pypi_wheels
127- run: |
128mkdir -p $PYPI_CACHE_DIR
129ls -lh $PYPI_CACHE_DIR
130
131- name: Env. variables
132run: |
133# Switch PyTorch URL
134python -c "print('TORCH_URL=' + str('${{env.TORCH_URL_TEST}}' if '${{ matrix.pytorch-version }}' == '2.2' else '${{env.TORCH_URL_STABLE}}'))" >> $GITHUB_ENV
135# Switch coverage scope
136python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.pkg-name}}' == 'lightning' else 'pytorch_lightning'))" >> $GITHUB_ENV
137# if you install mono-package set dependency only for this subpackage
138python -c "print('EXTRA_PREFIX=' + str('' if '${{matrix.pkg-name}}' != 'lightning' else 'pytorch-'))" >> $GITHUB_ENV
139
140- name: Install package & dependencies
141timeout-minutes: 20
142run: |
143pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" -U --prefer-binary \
144-r requirements/_integrations/accelerators.txt \
145--find-links="${TORCH_URL}" --find-links="${PYPI_CACHE_DIR}"
146pip list
147- name: Drop LAI from extensions
148if: ${{ matrix.pkg-name != 'lightning' }}
149# Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it
150run: pip uninstall -y lightning
151- name: Drop PL for LAI
152if: ${{ matrix.pkg-name == 'lightning' }}
153run: pip uninstall -y pytorch-lightning
154- name: Dump handy wheels
155if: github.event_name == 'push' && github.ref == 'refs/heads/master'
156continue-on-error: true
157uses: ./.github/actions/pip-wheels
158with:
159wheel-dir: ${{ env.PYPI_CACHE_DIR }}
160torch-url: ${{ env.TORCH_URL }}
161cache-key: "pypi_wheels"
162
163- name: Cache datasets
164uses: actions/cache@v4
165with:
166path: Datasets
167key: pl-dataset
168
169- name: Sanity check
170run: |
171set -e
172python requirements/pytorch/check-avail-extras.py
173python -c "from torch import __version__ as ver; assert ver.startswith('${{ matrix.pytorch-version }}'), ver"
174
175- name: Adjust tests / env. -> PL
176if: ${{ matrix.pkg-name != 'lightning' }}
177run: |
178python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
179--source_import="lightning.fabric,lightning.pytorch" \
180--target_import="lightning_fabric,pytorch_lightning"
181
182- name: Prevent using raw source
183run: rm -rf src/
184
185- name: Get legacy checkpoints
186run: |
187bash .actions/pull_legacy_checkpoints.sh
188cd tests/legacy
189bash generate_checkpoints.sh
190ls -l checkpoints/
191
192- name: Testing Warnings
193working-directory: tests/tests_pytorch
194# needs to run outside `pytest`
195run: python utilities/test_warnings.py
196
197- name: Testing PyTorch
198working-directory: tests/tests_pytorch
199# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
200run: |
201echo $GITHUB_RUN_ID
202python -m coverage run --source ${{ env.COVERAGE_SCOPE }} \
203-m pytest . -v --timeout=60 --durations=50 --random-order-seed=$GITHUB_RUN_ID
204
205- name: Statistics
206if: success()
207working-directory: tests/tests_pytorch
208run: |
209coverage report
210coverage xml
211
212- name: Upload coverage to Codecov
213uses: codecov/codecov-action@v4
214# see: https://github.com/actions/toolkit/issues/399
215continue-on-error: true
216with:
217token: ${{ secrets.CODECOV_TOKEN }}
218file: tests/tests_pytorch/coverage.xml
219flags: ${{ env.COVERAGE_SCOPE }},cpu,pytest-full,python${{ matrix.python-version }},pytorch${{ matrix.pytorch-version }}
220name: CPU-coverage
221fail_ci_if_error: false
222