Skip to content

Commit bf2e4af

Browse files
authored
Merge branch 'master' into ci/fabric-T4_x_4
2 parents 0b0233a + 92544c3 commit bf2e4af

File tree

30 files changed

+498
-81
lines changed

30 files changed

+498
-81
lines changed

.lightning/workflows/fabric.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
trigger:
22
push:
3-
branches: ["master"]
3+
branches: ["master", "release/stable"]
44
pull_request:
5-
branches: ["master"]
5+
branches: ["master", "release/stable"]
66

77
timeout: "55" # minutes
88
parametrize:

.lightning/workflows/pytorch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
trigger:
22
push:
3-
branches: ["master"]
3+
branches: ["master", "release/stable"]
44
pull_request:
5-
branches: ["master"]
5+
branches: ["master", "release/stable"]
66

77
timeout: "55" # minutes
88
parametrize:

Makefile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ clean:
4545
rm -rf src/lightning_fabric/*/
4646
rm -rf src/pytorch_lightning/*/
4747

48-
test: clean
48+
test: clean setup
4949
# Review the CONTRIBUTING documentation for other ways to test.
50-
pip install -e . \
51-
-r requirements/pytorch/base.txt \
52-
-r requirements/fabric/base.txt \
53-
-r requirements/pytorch/test.txt \
5450

5551
# run tests with coverage
5652
python -m coverage run --source src/lightning/pytorch -m pytest src/lightning/pytorch tests/tests_pytorch -v
@@ -59,18 +55,18 @@ test: clean
5955

6056
docs: docs-pytorch
6157

62-
sphinx-theme:
63-
pip install -q awscli
58+
sphinx-theme: setup
59+
uv pip install -q awscli
6460
mkdir -p dist/
6561
aws s3 sync --no-sign-request s3://sphinx-packages/ dist/
66-
pip install lai-sphinx-theme -f dist/
62+
uv pip install lai-sphinx-theme -f dist/
6763

6864
docs-fabric: clean sphinx-theme
69-
pip install -e .[all] --quiet -r requirements/fabric/docs.txt
65+
uv pip install -e '.[all]' --quiet -r requirements/fabric/docs.txt
7066
cd docs/source-fabric && $(MAKE) html --jobs $(nproc)
7167

7268
docs-pytorch: clean sphinx-theme
73-
pip install -e .[all] --quiet -r requirements/pytorch/docs.txt
69+
uv pip install -e '.[all]' --quiet -r requirements/pytorch/docs.txt
7470
cd docs/source-pytorch && $(MAKE) html --jobs $(nproc)
7571

7672
update:

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/trainer.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,23 @@ val_check_interval
991991
:muted:
992992

993993
How often within one training epoch to check the validation set.
994-
Can specify as float or int.
994+
Can specify as float, int, or a time-based duration.
995995

996996
- pass a ``float`` in the range [0.0, 1.0] to check after a fraction of the training epoch.
997997
- pass an ``int`` to check after a fixed number of training batches. An ``int`` value can only be higher than the number of training
998998
batches when ``check_val_every_n_epoch=None``, which validates after every ``N`` training batches across epochs or iteration-based training.
999+
- pass a ``string`` duration in the format "DD:HH:MM:SS", a ``datetime.timedelta`` object, or a ``dictionary`` of keyword arguments that can be passed
1000+
to ``datetime.timedelta`` for time-based validation. When using a time-based duration, validation will trigger once the elapsed wall-clock time
1001+
since the last validation exceeds the interval. The validation check occurs after the current batch completes, the validation loop runs, and
1002+
the timer resets.
1003+
1004+
**Time-based validation behavior with check_val_every_n_epoch:** When used together with ``val_check_interval`` (time-based) and
1005+
``check_val_every_n_epoch > 1``, validation is aligned to epoch multiples:
1006+
1007+
- If the time-based interval elapses **before** the next multiple-N epoch, validation runs at the start of that epoch (after the first batch),
1008+
and the timer resets.
1009+
- If the interval elapses **during** a multiple-N epoch, validation runs after the current batch.
1010+
- For cases where ``check_val_every_n_epoch=None`` or ``1``, the time-based behavior of ``val_check_interval`` applies without additional alignment.
9991011

10001012
.. testcode::
10011013

@@ -1013,10 +1025,25 @@ Can specify as float or int.
10131025
# (ie: production cases with streaming data)
10141026
trainer = Trainer(val_check_interval=1000, check_val_every_n_epoch=None)
10151027

1028+
# check validation every 15 minutes of wall-clock time using a string-based approach
1029+
trainer = Trainer(val_check_interval="00:00:15:00")
1030+
1031+
# check validation every 15 minutes of wall-clock time using a dictionary-based approach
1032+
trainer = Trainer(val_check_interval={"minutes": 15})
1033+
1034+
# check validation every 1 hour of wall-clock time using a dictionary-based approach
1035+
trainer = Trainer(val_check_interval={"hours": 1})
1036+
1037+
# check validation every 1 hour of wall-clock time using a datetime.timedelta object
1038+
from datetime import timedelta
1039+
trainer = Trainer(val_check_interval=timedelta(hours=1))
1040+
1041+
10161042

10171043
.. code-block:: python
10181044
10191045
# Here is the computation to estimate the total number of batches seen within an epoch.
1046+
# This logic applies when `val_check_interval` is specified as an integer or a float.
10201047
10211048
# Find the total number of train batches
10221049
total_train_batches = total_train_samples // (train_batch_size * world_size)

requirements/fabric/extra.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# NOTE: the upper bound for the package version is only set for CI stability, and it is dropped while installing this package
2+
# in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment
3+
4+
hydra-core >=1.2.0, <1.4.0

src/lightning/__setup__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _prepare_extras() -> dict[str, Any]:
4141
}
4242

4343
# project specific extras groups
44-
extras["fabric-all"] = extras["fabric-strategies"] + extras["fabric-examples"]
44+
extras["fabric-all"] = extras["fabric-extra"] + extras["fabric-strategies"] + extras["fabric-examples"]
4545
extras["fabric-dev"] = extras["fabric-all"] + extras["fabric-test"]
4646
extras["pytorch-all"] = extras["pytorch-extra"] + extras["pytorch-strategies"] + extras["pytorch-examples"]
4747
extras["pytorch-dev"] = extras["pytorch-all"] + extras["pytorch-test"]

src/lightning/fabric/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2222

2323
### Changed
2424

25-
-
25+
- let `_get_default_process_group_backend_for_device` support more hardware platforms (
26+
[#21057](https://github.com/Lightning-AI/pytorch-lightning/pull/21057), [#21093](https://github.com/Lightning-AI/pytorch-lightning/pull/21093))
2627

2728

2829
### Fixed
2930

3031
- Fixed with adding a missing device id for pytorch 2.8 ([#21105](https://github.com/Lightning-AI/pytorch-lightning/pull/21105))
3132

3233

34+
- Respect `verbose=False` in `seed_everything` when no seed is provided
35+
36+
3337
---
3438

3539
## [2.5.4] - 2025-08-29

src/lightning/fabric/strategies/ddp.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ def barrier(self, *args: Any, **kwargs: Any) -> None:
160160
if torch.distributed.get_backend() == "nccl":
161161
torch.distributed.barrier(device_ids=self._determine_ddp_device_ids())
162162
else:
163-
torch.distributed.barrier()
163+
# Handle PyTorch bug where barrier() fails on CPU with "PrivateUse1HooksInterface" error
164+
try:
165+
torch.distributed.barrier()
166+
except RuntimeError as e:
167+
if "PrivateUse1HooksInterface" in str(e):
168+
# Fallback: Use all_reduce as barrier - all processes must participate
169+
# This achieves the same synchronization effect as barrier()
170+
dummy_tensor = torch.tensor(0.0, device=self.root_device)
171+
torch.distributed.all_reduce(dummy_tensor)
172+
else:
173+
raise
164174

165175
@override
166176
def broadcast(self, obj: TBroadcast, src: int = 0) -> TBroadcast:

src/lightning/fabric/utilities/distributed.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ def _destroy_dist_connection() -> None:
319319

320320

321321
def _get_default_process_group_backend_for_device(device: torch.device) -> str:
322-
return "nccl" if device.type == "cuda" else "gloo"
322+
"""Return corresponding distributed backend for a given device."""
323+
device_backend_map = torch.distributed.Backend.default_device_backend_map
324+
if device.type in device_backend_map:
325+
return device_backend_map[device.type]
326+
return "gloo"
323327

324328

325329
class _DatasetSamplerWrapper(Dataset):

0 commit comments

Comments
 (0)