fix: use del instead of explicit shutdown in CombinedLoader.reset()#21708
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #21708 +/- ##
=========================================
- Coverage 87% 79% -8%
=========================================
Files 270 267 -3
Lines 23973 23914 -59
=========================================
- Hits 20748 18801 -1947
- Misses 3225 5113 +1888 |
2ef830b to
b4aba16
Compare
b4aba16 to
4e02938
Compare
|
Hi @deependujha, thanks for the green light on this, let me know if anything is missing 🙏 |
|
Hi @deependujha, is there anything missing from this PR in order for a merge? |
What does this PR do?
The PR replaces the usages of explicit usage of
dataloadet._iterator._shutdown_wokers()withdel dataloadet._iterator.This is the expected way to shutdown mutliprocessing iterator in pytorch:
https://github.com/pytorch/pytorch/blob/main/torch/utils/data/dataloader.py#L1685
They also mention that del should be the way to shutdown in the _MultiProcessingDataLoaderIter shutdown design note:
https://github.com/pytorch/pytorch/blob/main/torch/utils/data/dataloader.py#L787
Since errors may occur during shutdown_workers lightning is expected to mask them as pytorch does, by calling
_shutdown_workersin the context of__del__which suppresses errors (https://docs.python.org/3/reference/datamodel.html#object.__del__)calling _shutdown_workers() explicitly raises any exceptions raised by the shutdown process and results in exit code 1, which defers from pytorch behavior where same reproduce script will exit with exit code 0.
test_loops had to be changed since asserted shutdown_workers called twice with persistent workers once in teardown and once in del (as expected), in the new implementation its called once in del
Fixes #21703
Before submitting
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
📚 Documentation preview 📚: https://pytorch-lightning--21708.org.readthedocs.build/en/21708/