Skip to content

Make HeaderIterDataPipe with limit=None a no-op#908

Closed
felix-newman wants to merge 2 commits intometa-pytorch:mainfrom
felix-newman:feature762
Closed

Make HeaderIterDataPipe with limit=None a no-op#908
felix-newman wants to merge 2 commits intometa-pytorch:mainfrom
felix-newman:feature762

Conversation

@felix-newman
Copy link

Fixes #762

Changes

  • Passing limit=None makes the HeaderIterDataPipe a no-op

@facebook-github-bot
Copy link
Contributor

Hi @felix-newman!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 25, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

break
self.length = min(i, self.limit) # We know length with certainty when we reach here
# We know length with certainty when we reach here
self.length = i if self.limit is None else min(i, self.limit)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be simplified to using just i without a min. As incrementing is done before yielding or breaking, the length is i-1.

The following test case should be added: use a generator (has no len function) with some yields, drain it and assert self.length afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I think self.length should even be eliminated here for the reason that the DataPipe graph for each epoch might have different lengths as users can always alter the graph after one epoch ends.
We can simply rely on limit and len(self.source_datapipe) IMHO

break
self.length = min(i, self.limit) # We know length with certainty when we reach here
# We know length with certainty when we reach here
self.length = i if self.limit is None else min(i, self.limit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I think self.length should even be eliminated here for the reason that the DataPipe graph for each epoch might have different lengths as users can always alter the graph after one epoch ends.
We can simply rely on limit and len(self.source_datapipe) IMHO

* Reraise TypeError with additional warning
* Remove self.length as we can instead rely on limit and len(self.sourcedatapipe)
* Use Optional instead of Union
Copy link
Contributor

@NivekT NivekT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing

@facebook-github-bot
Copy link
Contributor

@NivekT has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Header(limit=None) ?

5 participants