Skip to content

Fixes issue #1868 regarding TypeError: ZipperIterDataPipe #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

otioss
Copy link
Contributor

@otioss otioss commented Jun 22, 2022

This fixes issue #1868:

TypeError: ZipperIterDataPipe instance doesn't have valid length

@facebook-github-bot
Copy link
Contributor

Hi @otioss!

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@fb.com. Thanks!

@netlify
Copy link

netlify bot commented Jun 22, 2022

Deploy Preview for pytorch-tutorials-preview ready!

Name Link
🔨 Latest commit 5256a4f
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/63472b58e709dd000813c536
😎 Deploy Preview https://deploy-preview-1954--pytorch-tutorials-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@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!

@svekars svekars requested a review from parmeet July 29, 2022 21:27
Copy link

@hudeven hudeven left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -303,7 +303,7 @@ def train_epoch(model, optimizer):
optimizer.step()
losses += loss.item()

return losses / len(train_dataloader)
return losses / len(list(train_dataloader))
Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to append a LenthSetterDataPipe at the end of each Dataset within TorchText with a known length. For Zipper in torchdata, it's for general usage that requires the prior DataPipe provides valid length.

Copy link

Choose a reason for hiding this comment

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

cc: @Nayef211

Copy link
Contributor

Choose a reason for hiding this comment

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

@ejguan if my understanding is correct, calling list(train_dataloader) would cause all data in the dataset to materialize right? I thought this is something we'd want to avoid given the fact that this can lead to OOMs for very large datasets.

It's better to append a LenthSetterDataPipe at the end of each Dataset within TorchText with a known length.

If we do this, can we avoid the data materialization issue I mentioned above?

Copy link
Contributor

@ejguan ejguan Oct 12, 2022

Choose a reason for hiding this comment

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

Correct, we shouldn't do materialization here. If this Dataset has a known length, we can add a DataPipe:

class LenSetter(IterDataPipe):
    def __init__(self, datapipe, length):
        self.datapipe = datapipe
        self.length = length

    def __iter__(self):
        yield from self.datapipe

    def __len__(self):
        self.length = lenth

This would prevent any pre-materialization before data iterated. IterDataPipe itself doesn't guarantee to provide a __len__ function because there might DataPipe operations introduce the dynamic length (filter)

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, just created an issue to track this pytorch/text#1943. Will merge this PR for now

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

Successfully merging this pull request may close these issues.

5 participants