Skip to content
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

Generate: left-padding test, revisited #29515

Merged
merged 2 commits into from
Mar 8, 2024
Merged

Conversation

gante
Copy link
Member

@gante gante commented Mar 7, 2024

What does this PR do?

Now that we understand why left-padding doesn't produce the exact same outputs (see comment), this PR revisits the left-padding test.

In a nutshell:

  • no more retry loop, instead sets a proper error tolerance for the test
  • adds an appropriate skip reason (when needed)
  • removes many model-specific skips -- these models either pass the updated test or fall under a skip rule

@gante
Copy link
Member Author

gante commented Mar 7, 2024

cc @zucchini-nlp -- this is a good example of us adding ugly flakiness-related loops because we didn't understand the cause for flakiness. Now that we understand that left-padding == not exactly the same results, we can write a clean test.

@gante gante requested a review from ArthurZucker March 7, 2024 14:10
next_logits_wo_padding = model(**model_kwargs).logits[:, -1, :]

# With left-padding (length 32)
pad_size = (input_ids.shape[0], 32)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the test is now much harder (padding size went from 1 to 32)

Copy link
Collaborator

Choose a reason for hiding this comment

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

💘

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Nice refactor!

tests/generation/test_utils.py Outdated Show resolved Hide resolved
tests/generation/test_utils.py Outdated Show resolved Hide resolved
next_logits_wo_padding = model(**model_kwargs).logits[:, -1, :]

# With left-padding (length 32)
pad_size = (input_ids.shape[0], 32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

💘

next_logits_with_padding = model(**model_kwargs).logits[:, -1, :]

# They should result in very similar logits
self.assertTrue(torch.allclose(next_logits_wo_padding, next_logits_with_padding, atol=1e-5))
Copy link
Collaborator

Choose a reason for hiding this comment

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

surprised that this is enough to make it pass!

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
@gante gante merged commit bc764f4 into huggingface:main Mar 8, 2024
18 checks passed
@gante gante deleted the left_padding_test branch March 8, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants