Cpu memory accumulation bug
What does this PR do?
This PR addresses the memory leak issue during prediction in PyTorch Lightning. It adds proper memory management when return_predictions=False and includes comprehensive tests to verify the fix.
Fixes #19398
Key Changes:
- Added garbage collection in prediction loop when
return_predictions=False - Implemented memory leak tests with large dataset simulation
- Added environment variable cleanup in tests
- Fixed pre-commit formatting issues
Before submitting
- Was this discussed/agreed via a GitHub issue? (not for typos and docs)
- Yes, discussed in #19398
- [x] Did you read the contributor guideline, Pull Request section?
- [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
- Did you make sure to update the documentation with your changes? (if necessary)
- No documentation changes needed
- Did you write any new necessary tests? (not for typos and docs)
- Yes, added memory leak tests
- [x] Did you verify new and existing tests pass locally with your changes?
- Did you list all the breaking changes introduced by this pull request?
- No breaking changes
- Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)
- Yes, will add entry for memory leak fix
PR review
Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
Reviewer checklist
- [x] Is this pull request ready for review? (if not, please submit in draft mode)
- [x] Check that all items from Before submitting are resolved
- [x] Make sure the title is self-explanatory and the description concisely explains the PR
- [x] Add labels and milestones (and optionally projects) to the PR so it can be classified
📚 Documentation preview 📚: https://pytorch-lightning--20730.org.readthedocs.build/en/20730/
- Implemented memory leak tests with large dataset simulation
- Added environment variable cleanup in tests
seems this is not included in this PR yet
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://lightning.ai/docs/pytorch/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Discord. Thank you for your contributions.