[4/4][DataPipe] Remove iterator depletion in Zipper#89974
Closed
ejguan wants to merge 3 commits intogh/ejguan/46/basefrom
Closed
[4/4][DataPipe] Remove iterator depletion in Zipper#89974ejguan wants to merge 3 commits intogh/ejguan/46/basefrom
ejguan wants to merge 3 commits intogh/ejguan/46/basefrom
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/89974
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 48da34b: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Nov 30, 2022
NivekT
approved these changes
Dec 1, 2022
Contributor
NivekT
left a comment
There was a problem hiding this comment.
Agree that we have to trust the source DataPipes to clean up.
wenleix
approved these changes
Dec 2, 2022
Fixes: meta-pytorch/data#865 I will add another PR in torchdata to validate this change would solve the infinite datapipe problem (I have tested locally). This is one of the most annoying stack of PRs cause by separation between TorchData and PyTorch. There is a case that `file.close` is never called because when generator function has never reached to the end. A simple example would be `zip` two datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up by `gc`. So, the line of `file.close` is not executed. (This is the reason that Vitaly has to create this [hack](https://github.com/pytorch/pytorch/blob/4451eb24e6287dff62ff8a7ec0eda6a6998807b0/torch/utils/data/datapipes/iter/combining.py#L573-L583) to retrieve all remaining data to make sure generator function is fully executed) However, this hack introduces another problem where an infinite datapipe would make `zip` never end as it would try to deplete the infinite iterator. See: meta-pytorch/data#865 So, in this PR, I am adding a `try-finally` clause to make sure the `file.close` is always executed during the destruction of `generator` object. Then, we don't need the hack within `zip` any more. [ghstack-poisoned]
Fixes: meta-pytorch/data#865 I will add another PR in torchdata to validate this change would solve the infinite datapipe problem (I have tested locally). This is one of the most annoying stack of PRs cause by separation between TorchData and PyTorch. There is a case that `file.close` is never called because when generator function has never reached to the end. A simple example would be `zip` two datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up by `gc`. So, the line of `file.close` is not executed. (This is the reason that Vitaly has to create this [hack](https://github.com/pytorch/pytorch/blob/4451eb24e6287dff62ff8a7ec0eda6a6998807b0/torch/utils/data/datapipes/iter/combining.py#L573-L583) to retrieve all remaining data to make sure generator function is fully executed) However, this hack introduces another problem where an infinite datapipe would make `zip` never end as it would try to deplete the infinite iterator. See: meta-pytorch/data#865 So, in this PR, I am adding a `try-finally` clause to make sure the `file.close` is always executed during the destruction of `generator` object. Then, we don't need the hack within `zip` any more. [ghstack-poisoned]
Contributor
Author
|
@ejguan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
|
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
facebook-github-bot
pushed a commit
to meta-pytorch/data
that referenced
this pull request
Dec 5, 2022
Summary: There is a case that `file.close` is never called because when generator function has never reached to the end. A simple example would be `zip` two datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up by `gc`. So, the line of `file.close` is not executed. (This is the reason that Vitaly has to create this [hack](https://github.com/pytorch/pytorch/blob/4451eb24e6287dff62ff8a7ec0eda6a6998807b0/torch/utils/data/datapipes/iter/combining.py#L573-L583) to retrieve all remaining data to make sure generator function is fully executed) However, this hack introduces another problem where an infinite datapipe would make `zip` never end as it would try to deplete the infinite iterator. See: #865 So, in this PR, I am adding a `try-finally` clause to make sure the `file.close` is always executed during the destruction of `generator` object. Then, we don't need the hack within `zip` any more. - pytorch/pytorch#89973 - pytorch/vision#6997 - pytorch/pytorch#89974 Pull Request resolved: #910 Reviewed By: wenleix, NivekT Differential Revision: D41633909 Pulled By: ejguan fbshipit-source-id: 5613e131dc8b2962c22d2bc7e3a4bb3039440c48
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
facebook-github-bot
pushed a commit
to meta-pytorch/data
that referenced
this pull request
Dec 6, 2022
… input (#912) Summary: Add a few tests to validate the iterator is properly cleanup at the end of iteration, when the combining `DataPipe` takes input with infinite length like`cycle(None)` Those tests should be timed out until pytorch/pytorch#89974 is promoted to the nightly releases. Pull Request resolved: #912 Reviewed By: NivekT Differential Revision: D41740935 Pulled By: ejguan fbshipit-source-id: b501ea4290f5d75984f12f9e2fb3d3897297de2b
kulinseth
pushed a commit
to kulinseth/pytorch
that referenced
this pull request
Dec 10, 2022
Fixes: meta-pytorch/data#865 I will add another PR in torchdata to validate this change would solve the infinite datapipe problem (I have tested locally). This is one of the most annoying stack of PRs cause by separation between TorchData and PyTorch. There is a case that `file.close` is never called because when generator function has never reached to the end. A simple example would be `zip` two datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up by `gc`. So, the line of `file.close` is not executed. (This is the reason that Vitaly has to create this [hack](https://github.com/pytorch/pytorch/blob/4451eb24e6287dff62ff8a7ec0eda6a6998807b0/torch/utils/data/datapipes/iter/combining.py#L573-L583) to retrieve all remaining data to make sure generator function is fully executed) However, this hack introduces another problem where an infinite datapipe would make `zip` never end as it would try to deplete the infinite iterator. See: meta-pytorch/data#865 So, in this PR, I am adding a `try-finally` clause to make sure the `file.close` is always executed during the destruction of `generator` object. Then, we don't need the hack within `zip` any more. Differential Revision: [D41699469](https://our.internmc.facebook.com/intern/diff/D41699469) Pull Request resolved: pytorch#89974 Approved by: https://github.com/NivekT, https://github.com/wenleix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack:
Fixes: meta-pytorch/data#865
I will add another PR in torchdata to validate this change would solve the infinite datapipe problem (I have tested locally). This is one of the most annoying stack of PRs cause by separation between TorchData and PyTorch.
There is a case that
file.closeis never called because when generator function has never reached to the end. A simple example would beziptwo datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up bygc. So, the line offile.closeis not executed. (This is the reason that Vitaly has to create this hack to retrieve all remaining data to make sure generator function is fully executed)However, this hack introduces another problem where an infinite datapipe would make
zipnever end as it would try to deplete the infinite iterator. See: meta-pytorch/data#865So, in this PR, I am adding a
try-finallyclause to make sure thefile.closeis always executed during the destruction ofgeneratorobject. Then, we don't need the hack withinzipany more.Differential Revision: D41699469