Lightning-AI / Lightning-AI/pytorch-lightning
Stream outputs from Trainer.predict()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Description & Motivation
I would like to request a feature that allows streaming the outputs from `Trainer.predict()` so that they can be processed one by one. This would enable more efficient handling of predictions, especially for large datasets.
### Pitch
It would be perfect if `Trainer.predict()` could just `yield` intermediate results if an optional kwarg is given, e.g. `stream_outputs=True`.
### Alternatives
Post-process the results in prediction_step(). However, it would be nice to have the flexibility to also do this outside of prediction_step(), e.g., if you have different types of aggregations.
### Additional context
In my use case, the activations of a certain hidden layer are sparse, and I would like to collect the sparsified activations to reduce memory usage.
cc @lantiga @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
Start with the Trainer.predict() entry point and prediction_step(), the two locations named in the issue. Determine how an optional stream_outputs=True mode should expose intermediate results and preserve the existing prediction behavior. Done means predictions can be processed one by one without collecting the full output in memory, with coverage for the new option.
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
- 35/100