Lightning-AI / Lightning-AI/pytorch-lightning
Before/After dataloader batch callback hooks
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
## 🚀 Feature
I would like to have callback hooks (or module hooks) before and after we try to get the next batch from the torch dataloader, in order to know how much time is spent waiting for data to be loaded
### Motivation
I am frustrated with the lack of any ability to know how long it takes for a batch to be ready from the torch dataloader. In a pytorch script, I could simply time it takes in the training loop:
```
start = time.time()
for batch in dataloader:
time_taken = time.time() - start
start = time.time()
```
### Pitch
Callback hooks seem to be the right solution here.
### Alternatives
I subclassed the pytorch Dataloader object and replaced the iterator it returns decorated with a spooky function that replaces the __next__ call with a new function that returns __next__ while also timing.
### Additional context
If there is some way to do this that I am not seeing, please let me know
______________________________________________________________________
cc @awaelchli @ananthsub @rohitgr7
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
No project files or tests are named. Start by locating the training-loop integration around PyTorch DataLoader iteration and compare it with the timing example in the issue. Done means users can observe hooks immediately before and after waiting for the next batch, with the behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100