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

Fix ExponentialDecayLengthPenalty negative logits issue #25594

Merged
merged 7 commits into from
Sep 12, 2023

Conversation

pokjay
Copy link
Contributor

@pokjay pokjay commented Aug 18, 2023

What does this PR do?

In cases where the model logits are negative, ExponentialDecayLengthPenalty decreases the score of eos_token_id instead of increasing it.
To fix this issue we compute the penalty of the absolute value and add it to the original score, as described in #25416
The test was updated to check for negative logits.

In addition, this PR updates the class documentation and adds examples, as part of #24783

Fixes #25416

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@gante

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

Thank you for detecting the issue, proposing a solution, and implementing it @pokjay 🔥 Contributions like yours make the ecosystem thrive!

@gante gante requested a review from ArthurZucker August 21, 2023 12:18
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.

Looks good to me! Thanks for the contribution 🤗

@pokjay
Copy link
Contributor Author

pokjay commented Aug 21, 2023

Thanks @gante and @ArthurZucker !

Could you please approve the documentation workflow? I’d like to verify the documentation looks as expected

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@pokjay
Copy link
Contributor Author

pokjay commented Sep 2, 2023

@gante Do I need to do anything more to get this merged?

@ArthurZucker
Copy link
Collaborator

You could take into account the changes I suggested 😉 code related variable name are always put aroung codeblocks in our doc!

@pokjay
Copy link
Contributor Author

pokjay commented Sep 4, 2023

@ArthurZucker oops, totally missed those! Committed those fixes now, Thanks!

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.

CI should go green once you rebase to main!

pokjay and others added 6 commits September 5, 2023 08:22
Fix tests which were broken and add validation of negative scores.

Current test didn't take into account that ExponentialDecayLengthPenalty updates the score inplace, resulting in updates to base tested Tensor.

In addition, the gt assert had empty Tensors due to indexing along the batch dimension.

Test is currently expected to fail to show ExponentialDecayLengthPenalty issues with negative scores
In cases where the scores are negative, ExponentialDecayLengthPenalty decreases the score of eos_token_id instead of increasing it.
To fix this issue we compute the penalty of the absolute value and add it to the original score.
@pokjay pokjay force-pushed the fix-exp-decay-penalty-neg-logits branch from 188fb67 to e27c496 Compare September 5, 2023 05:25
@gante
Copy link
Member

gante commented Sep 5, 2023

@pokjay since we last spoke, we've added this file to the list of files to be doctested in our PR CI -- it seems like your example's outputs don't match the hardcoded outputs.

Would you be able to double-check that? :)

(as soon as this gets fixed, we can merge)

@pokjay
Copy link
Contributor Author

pokjay commented Sep 6, 2023

@gante Fixed the issues, all checks pass!

@gante
Copy link
Member

gante commented Sep 12, 2023

@pokjay thank you for iterating 💛

@gante gante merged commit 6acc27e into huggingface:main Sep 12, 2023
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
…25594)

* Fix issues in test_exponential_decay_length_penalty

Fix tests which were broken and add validation of negative scores.

Current test didn't take into account that ExponentialDecayLengthPenalty updates the score inplace, resulting in updates to base tested Tensor.

In addition, the gt assert had empty Tensors due to indexing along the batch dimension.

Test is currently expected to fail to show ExponentialDecayLengthPenalty issues with negative scores

* Fix ExponentialDecayLengthPenalty negative logits issue

In cases where the scores are negative, ExponentialDecayLengthPenalty decreases the score of eos_token_id instead of increasing it.
To fix this issue we compute the penalty of the absolute value and add it to the original score.

* Add examples for ExponentialDecayLengthPenalty

* Fix styling issue in ExponentialDecayLengthPenalty doc

* Apply suggestions from code review

Co-authored-by: Arthur <[email protected]>

* Style and quality fix

* Fix example outputs

---------

Co-authored-by: Arthur <[email protected]>
@pokjay pokjay deleted the fix-exp-decay-penalty-neg-logits branch December 8, 2023 14:49
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.

[BUG] ExponentialDecayLengthPenalty decreases negative scores
4 participants