Lightning-AI / Lightning-AI/pytorch-lightning
self.log(.., on_epoch=True) runs extremely slow
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Bug description
When using
`self.log("train/loss", batch_loss, prog_bar=True, on_epoch=True, on_step=True, logger=True, sync_dist=True)`,
it took ~5s to finish this command, slowing down the training extremely.
When I switched to
`self.log("train/loss", batch_loss, prog_bar=True, on_step=True, logger=True, sync_dist=True)`,
the slow behavior went away.
### What version are you seeing the problem on?
v2.0
### How to reproduce the bug
```python
`self.log("train/loss", batch_loss, prog_bar=True, on_epoch=True, on_step=True, logger=True, sync_dist=True)`
with both wandb and tensorboard loggers enabled.
I found the same slowdown when disabling any of the two loggers.
```
### Error messages and logs
```
# Error messages and logs here please
```
There is no error message but a very slow logging operation.
### Environment
Current environment
```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```
### More info
_No response_
cc @carmocca @Blaizzy @borda
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported self.log call with on_epoch=True, on_step=True, sync_dist=True, and logger enabled, comparing it with the on_step-only call. Investigate the logging path responsible for the slowdown and define done as eliminating the excessive delay while preserving epoch and step logging, with a regression test for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- observability, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100