Skip to content

Commit 2ae8072

Browse files
authored
Merge branch 'master' into bugfix/gan-ddp-training
2 parents a58039e + 1fc077b commit 2ae8072

34 files changed

+667
-147
lines changed

.github/workflows/_legacy-checkpoints.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,32 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v5
5959

60-
- uses: actions/setup-python@v5
60+
- name: Install uv and set Python version
61+
uses: astral-sh/setup-uv@v6
6162
with:
62-
# Python version here needs to be supported by all PL versions listed in back-compatible-versions.txt.
6363
python-version: "3.9"
64+
# TODO: Avoid activating environment like this
65+
# see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment
66+
activate-environment: true
67+
enable-cache: true
6468

6569
- name: Install PL from source
6670
env:
6771
PACKAGE_NAME: pytorch
6872
FREEZE_REQUIREMENTS: 1
6973
timeout-minutes: 20
70-
run: pip install . --extra-index-url="${TORCH_URL}"
74+
run: uv pip install . --extra-index-url="${TORCH_URL}"
7175
if: inputs.pl_version == ''
7276

7377
- name: Install PL version
7478
timeout-minutes: 20
75-
run: pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}"
79+
run: uv pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}"
7680
if: inputs.pl_version != ''
7781

7882
- name: Adjust tests -> PL
7983
if: ${{ matrix.pkg-name != 'lightning' }}
8084
run: |
81-
pip install -q -r .actions/requirements.txt
85+
uv pip install -q -r .actions/requirements.txt
8286
python .actions/assistant.py copy_replace_imports --source_dir="./tests" \
8387
--source_import="lightning.fabric,lightning.pytorch" \
8488
--target_import="lightning_fabric,pytorch_lightning"
@@ -115,7 +119,7 @@ jobs:
115119
# export to env bool if secrets.AWS_REGION is not empty
116120
run: echo "WITH_SECRETS=$([ -n '${{ secrets.AWS_REGION }}' ] && echo 1 || echo 0)" >> $GITHUB_ENV
117121

118-
- run: pip install -r requirements/ci.txt
122+
- run: uv pip install -r requirements/ci.txt
119123
- name: Upload checkpoints to S3
120124
if: ${{ env.WITH_SECRETS == '1' }}
121125
working-directory: ${{ env.LEGACY_FOLDER }}

.github/workflows/ci-tests-fabric.yml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,49 +62,57 @@ jobs:
6262
env:
6363
PACKAGE_NAME: ${{ matrix.config.pkg-name }}
6464
FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
65-
PYPI_CACHE_DIR: "_pip-wheels"
6665
TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/"
6766
TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/"
6867
# TODO: Remove this - Enable running MPS tests on this platform
6968
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }}
7069
steps:
7170
- uses: actions/checkout@v5
7271

73-
- name: Set up Python ${{ matrix.config.python-version }}
74-
uses: actions/setup-python@v5
72+
- name: Install uv and set Python version
73+
uses: astral-sh/setup-uv@v6
7574
with:
7675
python-version: ${{ matrix.config.python-version || '3.9' }}
76+
# TODO: Avoid activating environment like this
77+
# see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment
78+
activate-environment: true
79+
enable-cache: true
7780

78-
- name: basic setup
79-
run: pip install -q -r .actions/requirements.txt
81+
- name: Basic setup
82+
run: uv pip install -q -r .actions/requirements.txt
83+
84+
- name: Append Env. vars for Linux
85+
if: ${{ runner.os == 'Linux' }}
86+
run: echo "GLOO_SOCKET_IFNAME=eth0" >> $GITHUB_ENV
87+
88+
- name: Append Env. vars for MacOS
89+
if: ${{ runner.os == 'macOS' }}
90+
run: echo "GLOO_SOCKET_IFNAME=lo0" >> $GITHUB_ENV
91+
92+
- name: Append Env. vars for Windows
93+
if: ${{ runner.os == 'windows' }}
94+
run: |
95+
# Avoid issue on Windows with PyTorch 2.4: "RuntimeError: use_libuv was requested but PyTorch was build without libuv support"
96+
echo "USE_LIBUV=0" >> $GITHUB_ENV
8097
8198
- name: Set min. dependencies
8299
if: ${{ matrix.config.requires == 'oldest' }}
83100
run: |
84101
cd requirements/fabric
85-
pip install -U "lightning-utilities[cli]"
102+
uv pip install -U "lightning-utilities[cli]"
86103
python -m lightning_utilities.cli requirements set-oldest --req_files "['base.txt', 'strategies.txt', 'test.txt']"
87-
pip install "cython<3.0" wheel
88-
pip install "pyyaml==5.4" --no-build-isolation
104+
uv pip install "cython<3.0" wheel
105+
uv pip install "pyyaml==5.4" --no-build-isolation
89106
90107
- name: Adjust PyTorch versions in requirements files
91108
if: ${{ matrix.config.requires != 'oldest' }}
92109
run: |
93-
pip install -q -r requirements/ci.txt
110+
uv pip install -q -r requirements/ci.txt
94111
python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
95112
for fpath in `ls requirements/**/*.txt`; do \
96113
python ./adjust-torch-versions.py $fpath ${{ matrix.config.pytorch-version }}; \
97114
done
98115
99-
- name: pip wheels cache
100-
uses: actions/cache/restore@v4
101-
with:
102-
path: ${{ env.PYPI_CACHE_DIR }}
103-
key: pypi_wheels
104-
- run: |
105-
mkdir -p $PYPI_CACHE_DIR
106-
ls -lh $PYPI_CACHE_DIR
107-
108116
- name: Expand Env. variables
109117
run: |
110118
# Switch PyTorch URL between stable and test/future
@@ -113,25 +121,15 @@ jobs:
113121
python -c "print('COVERAGE_SCOPE=' + str('lightning' if '${{matrix.config.pkg-name}}' == 'lightning' else 'lightning_fabric'))" >> $GITHUB_ENV
114122
# if you install mono-package set dependency only for this subpackage
115123
python -c "print('EXTRA_PREFIX=' + str('' if '${{matrix.config.pkg-name}}' != 'lightning' else 'fabric-'))" >> $GITHUB_ENV
116-
- name: Append Env. vars for MacOS
117-
if: ${{ runner.os == 'macOS' }}
118-
run: |
119-
# trying to avoid "gloo" issue with SIGABRT
120-
echo "GLOO_SOCKET_IFNAME=lo0" >> $GITHUB_ENV
121-
- name: Append Env. vars for Windows
122-
if: ${{ runner.os == 'windows' }}
123-
run: |
124-
# Avoid issue on Windows with PyTorch 2.4: "RuntimeError: use_libuv was requested but PyTorch was build without libuv support"
125-
echo "USE_LIBUV=0" >> $GITHUB_ENV
126124
127125
- name: Install package & dependencies
128126
timeout-minutes: 20
129127
run: |
130-
pip install -e ".[${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
131-
-U --upgrade-strategy=eager --prefer-binary \
132-
--extra-index-url="${TORCH_URL}" \
133-
--find-links="${PYPI_CACHE_DIR}"
134-
pip list
128+
uv pip install ".[${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
129+
--upgrade \
130+
--find-links="${TORCH_URL}"
131+
uv pip list
132+
135133
- name: Dump handy wheels
136134
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
137135
continue-on-error: true
@@ -179,6 +177,9 @@ jobs:
179177
name: CPU-coverage
180178
fail_ci_if_error: false
181179

180+
- name: Minimize uv cache
181+
run: uv cache prune --ci
182+
182183
fabric-cpu-guardian:
183184
runs-on: ubuntu-latest
184185
needs: fabric-cpu

.github/workflows/ci-tests-pytorch.yml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,50 @@ jobs:
6969
TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/"
7070
TORCH_URL_TEST: "https://download.pytorch.org/whl/test/cpu/"
7171
FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
72-
PYPI_CACHE_DIR: "_pip-wheels"
7372
# TODO: Remove this - Enable running MPS tests on this platform
7473
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }}
7574
steps:
7675
- uses: actions/checkout@v5
7776

78-
- name: Set up Python ${{ matrix.config.python-version }}
79-
uses: actions/setup-python@v5
77+
- name: Install uv and set Python version
78+
uses: astral-sh/setup-uv@v6
8079
with:
8180
python-version: ${{ matrix.config.python-version || '3.9' }}
81+
# TODO: Avoid activating environment like this
82+
# see: https://github.com/astral-sh/setup-uv/tree/v6/?tab=readme-ov-file#activate-environment
83+
activate-environment: true
84+
enable-cache: true
8285

83-
- name: basic setup
84-
run: pip install -q -r .actions/requirements.txt
86+
- name: Basic setup
87+
run: uv pip install -q -r .actions/requirements.txt
8588

8689
- name: Append Env. vars for Linux
8790
if: ${{ runner.os == 'Linux' }}
8891
run: echo "GLOO_SOCKET_IFNAME=eth0" >> $GITHUB_ENV
8992

93+
- name: Append Env. vars for MacOS
94+
if: ${{ runner.os == 'macOS' }}
95+
run: echo "GLOO_SOCKET_IFNAME=lo0" >> $GITHUB_ENV
96+
9097
- name: Set min. dependencies
9198
if: ${{ matrix.config.requires == 'oldest' }}
9299
run: |
93100
cd requirements/pytorch
94-
pip install -U "lightning-utilities[cli]"
101+
uv pip install -U "lightning-utilities[cli]"
95102
python -m lightning_utilities.cli requirements set-oldest --req_files "['base.txt', 'extra.txt', 'strategies.txt', 'examples.txt', 'test.txt']"
96-
pip install "cython<3.0" wheel
97-
pip install "pyyaml==5.4" --no-build-isolation
103+
uv pip install "cython<3.0" wheel
104+
uv pip install "pyyaml==5.4" --no-build-isolation
98105
99106
- name: Adjust PyTorch versions in requirements files
100107
if: ${{ matrix.config.requires != 'oldest' }}
101108
run: |
102-
pip install -q -r requirements/ci.txt
109+
uv pip install -q -r requirements/ci.txt
103110
python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
104111
for fpath in `ls requirements/**/*.txt`; do \
105112
python ./adjust-torch-versions.py $fpath ${{ matrix.config.pytorch-version }}; \
106113
done
107114
cat requirements/pytorch/base.txt
108115
109-
- name: pip wheels cache
110-
uses: actions/cache/restore@v4
111-
with:
112-
path: ${{ env.PYPI_CACHE_DIR }}
113-
key: pypi_wheels
114-
- run: |
115-
mkdir -p $PYPI_CACHE_DIR
116-
ls -lh $PYPI_CACHE_DIR
117-
118116
- name: Env. variables
119117
run: |
120118
# Switch PyTorch URL between stable and test/future
@@ -129,20 +127,22 @@ jobs:
129127
- name: Install package & dependencies
130128
timeout-minutes: 20
131129
run: |
132-
pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
133-
-U --upgrade-strategy=eager --prefer-binary \
130+
uv pip install ".[${EXTRA_PREFIX}extra,${EXTRA_PREFIX}test,${EXTRA_PREFIX}strategies]" \
131+
--upgrade \
134132
-r requirements/_integrations/accelerators.txt \
135-
--extra-index-url="${TORCH_URL}" \
136-
--find-links="${PYPI_CACHE_DIR}" \
133+
--find-links="${TORCH_URL}" \
137134
--find-links="https://download.pytorch.org/whl/torch-tensorrt"
138-
pip list
135+
uv pip list
136+
139137
- name: Drop LAI from extensions
140138
if: ${{ matrix.config.pkg-name != 'lightning' }}
141139
# Lightning is dependency of Habana or other accelerators/integrations so in case we test PL we need to remove it
142-
run: pip uninstall -y lightning
140+
run: uv pip uninstall lightning
141+
143142
- name: Drop PL for LAI
144143
if: ${{ matrix.config.pkg-name == 'lightning' }}
145-
run: pip uninstall -y pytorch-lightning
144+
run: uv pip uninstall pytorch-lightning
145+
146146
- name: Dump handy wheels
147147
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
148148
continue-on-error: true
@@ -219,6 +219,9 @@ jobs:
219219
name: CPU-coverage
220220
fail_ci_if_error: false
221221

222+
- name: Minimize uv cache
223+
run: uv cache prune --ci
224+
222225
pl-cpu-guardian:
223226
runs-on: ubuntu-latest
224227
needs: pl-cpu

docs/source-fabric/guide/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Build your own Trainer
7878
<div class="row">
7979

8080
.. displayitem::
81-
:header: Organize your model code with with LightningModule
81+
:header: Organize your model code with LightningModule
8282
:description: Organize your code in a LightningModule and use it with Fabric
8383
:button_link: lightning_module.html
8484
:col_css: col-md-4

docs/source-fabric/levels/intermediate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Intermediate skills
1919
<div class="row">
2020

2121
.. displayitem::
22-
:header: Organize your model code with with LightningModule
22+
:header: Organize your model code with LightningModule
2323
:description: Organize your code in a LightningModule and use it with Fabric
2424
:button_link: ../guide/lightning_module.html
2525
:col_css: col-md-4

docs/source-pytorch/advanced/speed.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ Validation Within Training Epoch
297297

298298
For large datasets, it's often desirable to check validation multiple times within a training epoch.
299299
Pass in a float to check that often within one training epoch. Pass in an int ``K`` to check every ``K`` training batch.
300-
Must use an ``int`` if using an :class:`~torch.utils.data.IterableDataset`.
300+
Must use an ``int`` if using an :class:`~torch.utils.data.IterableDataset`. Alternatively, pass a string ("DD:HH:MM:SS"),
301+
a dict of ``datetime.timedelta`` kwargs, or a ``datetime.timedelta`` to check validation after a given amount of wall-clock time.
301302

302303
.. testcode::
303304

@@ -310,6 +311,16 @@ Must use an ``int`` if using an :class:`~torch.utils.data.IterableDataset`.
310311
# check every 100 train batches (ie: for IterableDatasets or fixed frequency)
311312
trainer = Trainer(val_check_interval=100)
312313

314+
# check validation every 15 minutes of wall-clock time
315+
trainer = Trainer(val_check_interval="00:00:15:00")
316+
317+
# alternatively, pass a dict of timedelta kwargs
318+
trainer = Trainer(val_check_interval={"minutes": 1})
319+
320+
# or use a timedelta object directly
321+
from datetime import timedelta
322+
trainer = Trainer(val_check_interval=timedelta(hours=1))
323+
313324
Learn more in our :ref:`trainer_flags` guide.
314325

315326

docs/source-pytorch/common/hooks.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,30 @@ with the source of each hook indicated:
8383
trainer.fit()
8484
8585
├── setup(stage="fit")
86-
│ └── [Callbacks only]
87-
88-
├── on_fit_start()
86+
│ ├── [LightningDataModule]
8987
│ ├── [Callbacks]
9088
│ ├── [LightningModule]
89+
│ ├── [LightningModule.configure_shared_model()]
90+
│ ├── [LightningModule.configure_model()]
91+
│ ├── Strategy.restore_checkpoint_before_setup
92+
│ │ ├── [LightningModule.on_load_checkpoint()]
93+
│ │ ├── [LightningModule.load_state_dict()]
94+
│ │ ├── [LightningDataModule.load_state_dict()]
95+
│ │ ├── [Callbacks.on_load_checkpoint()]
96+
│ │ └── [Callbacks.load_state_dict()]
9197
│ └── [Strategy]
9298
99+
├── on_fit_start()
100+
│ ├── [Callbacks]
101+
│ └── [LightningModule]
102+
103+
├── Strategy.restore_checkpoint_after_setup
104+
│ ├── [LightningModule.on_load_checkpoint()]
105+
│ ├── [LightningModule.load_state_dict()]
106+
│ ├── [LightningDataModule.load_state_dict()]
107+
│ ├── [Callbacks.on_load_checkpoint()]
108+
│ └── [Callbacks.load_state_dict()]
109+
93110
├── on_sanity_check_start()
94111
│ ├── [Callbacks]
95112
│ ├── [LightningModule]

0 commit comments

Comments
 (0)