Skip to content

Commit 39ef688

Browse files
committed
Profile dataloader initialization and update profiler docs
1 parent fe6b1cc commit 39ef688

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

docs/source-pytorch/tuning/profiler_basic.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Once the **.fit()** function has completed, you'll see an output like this:
8080
8181
Profiler Report
8282
83-
Profile stats for: get_train_batch
83+
Profile stats for: setup_train_dataloader
8484
4869394 function calls (4863767 primitive calls) in 18.893 seconds
8585
Ordered by: cumulative time
8686
List reduced from 76 to 10 due to restriction <10>

src/lightning/pytorch/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2424

2525
### Fixed
2626

27+
- Fixed PyTorch Lightning profiler not capturing dataloader worker initialization time ([#21771](https://github.com/Lightning-AI/pytorch-lightning/issues/21771))
28+
2729
- Fixed non-zero process exits in `CombinedLoader.reset()` with large tensors and persistent spawned workers by avoiding explicit `_shutdown_workers()` calls and relying on iterator cleanup via `del` [#21708](https://github.com/Lightning-AI/pytorch-lightning/issues/21708)
2830

2931
- Fixed `SIGTERMException` producing a zero exit code instead of 143 (128 + SIGTERM) ([#21623](https://github.com/Lightning-AI/pytorch-lightning/issues/21623))

src/lightning/pytorch/loops/fit_loop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def setup_data(self) -> None:
272272

273273
self._data_fetcher = _select_data_fetcher(trainer, RunningStage.TRAINING)
274274
self._data_fetcher.setup(combined_loader)
275-
iter(self._data_fetcher) # creates the iterator inside the fetcher
275+
with trainer.profiler.profile("setup_train_dataloader"):
276+
iter(self._data_fetcher) # creates the iterator inside the fetcher
276277
max_batches = sized_len(combined_loader)
277278
self.max_batches = max_batches if max_batches is not None else float("inf")
278279
has_len_all_ranks_ = has_len_all_ranks(combined_loader, trainer.strategy, allow_zero_length)

tests/tests_pytorch/profilers/test_profiler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,14 @@ def test_profiler_invalid_table_kwargs(tmp_path):
731731
with pytest.raises(KeyError) as exc_info:
732732
PyTorchProfiler(table_kwargs={key: None}, dirpath=tmp_path, filename="profile")
733733
assert exc_info.value.args[0].startswith(f"Found invalid table_kwargs key: {key}.")
734+
735+
736+
@skip_advanced_profiler_py312
737+
def test_setup_train_dataloader_profiled_actions(tmp_path):
738+
"""Ensure that the 'setup_train_dataloader' action is successfully recorded in the profiler."""
739+
profiler = AdvancedProfiler(dirpath=tmp_path, filename="profiler")
740+
model = BoringModel()
741+
trainer = Trainer(default_root_dir=tmp_path, fast_dev_run=2, profiler=profiler)
742+
trainer.fit(model)
743+
744+
assert "setup_train_dataloader" in profiler.profiled_actions

0 commit comments

Comments
 (0)