[DataPipe] Adding LengthSetterIterDataPipe#747
Closed
NivekT wants to merge 3 commits intogh/NivekT/90/basefrom
Closed
[DataPipe] Adding LengthSetterIterDataPipe#747NivekT wants to merge 3 commits intogh/NivekT/90/basefrom
NivekT wants to merge 3 commits intogh/NivekT/90/basefrom
Conversation
[ghstack-poisoned]
This was referenced Aug 18, 2022
ejguan
reviewed
Aug 19, 2022
Contributor
Author
|
Per @ejguan 's request, I am adding this to core as an alternative to this PR: pytorch/pytorch#83750 I will close this one if we decide the other PR is better. |
This DataPipe allows users to manually set length of an `IterDataPipe` with no other side effect. This is useful for DataPipes whose final length cannot be known in advance (e.g. ``filter``). If you know the final length with certainty, you can manually set it for usages by DataLoader or other DataPipes. Previously, users theoretically could use `.header(length)` to manually set length. However, the UX is suboptimal in that 1) the name is not obvious, and 2) warnings are raised unless the HeaderDataPipe has been fully traversed once to confirm the length. [ghstack-poisoned]
Contributor
Author
|
We will be landing this PR instead of pytorch/pytorch#83750. |
Contributor
Author
|
@NivekT has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
ejguan
approved these changes
Aug 24, 2022
Contributor
ejguan
left a comment
There was a problem hiding this comment.
One nit comment. Otherwise, LGTM. Thank you
|
|
||
| def __init__(self, source_datapipe: IterDataPipe[T_co], length: int) -> None: | ||
| self.source_datapipe: IterDataPipe[T_co] = source_datapipe | ||
| self.length: int = length |
Contributor
There was a problem hiding this comment.
Could we add one validation on the length >= 0.
This DataPipe allows users to manually set length of an `IterDataPipe` with no other side effect. This is useful for DataPipes whose final length cannot be known in advance (e.g. ``filter``). If you know the final length with certainty, you can manually set it for usages by DataLoader or other DataPipes. Previously, users theoretically could use `.header(length)` to manually set length. However, the UX is suboptimal in that 1) the name is not obvious, and 2) warnings are raised unless the HeaderDataPipe has been fully traversed once to confirm the length. Differential Revision: [D38989359](https://our.internmc.facebook.com/intern/diff/D38989359) [ghstack-poisoned]
Contributor
Author
|
@NivekT has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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:
This DataPipe allows users to manually set length of an
IterDataPipewith no other side effect. This is useful for DataPipes whose final length cannot be known in advance (e.g.filter). If you know the final length with certainty, you can manually set it for usages by DataLoader or other DataPipes.Previously, users theoretically could use
.header(length)to manually set length. However, the UX is suboptimal in that 1) the name is not obvious, and 2) warnings are raised unless the HeaderDataPipe has been fully traversed once to confirm the length.Differential Revision: D38989359