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

Document and validate typical_p in generation #19128

Merged
merged 3 commits into from
Sep 28, 2022

Conversation

mapmeld
Copy link
Contributor

@mapmeld mapmeld commented Sep 20, 2022

What does this PR do?

Throws a ValueError when typical_p argument is provided to text-generation, but its value or do_sample=False prevent typical decoding from happening as intended. Adds a line documenting typical decoding.

Most arguments to generate were previously covered in #18261 , but not typical_p.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 20, 2022

The documentation is not available anymore as the PR was closed or merged.

@LysandreJik LysandreJik requested a review from gante September 23, 2022 18:48
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.

Hi @mapmeld 👋

I've requested a few changes, mostly to comply with previous design decisions and future plans for generate 🙏

src/transformers/generation_utils.py Outdated Show resolved Hide resolved
src/transformers/generation_utils.py Outdated Show resolved Hide resolved
Comment on lines 1317 to 1321
elif do_sample is False:
raise ValueError(
"Decoder argument `typical_p` must be used in sampling mode. "
"Make sure that `do_sample` is set to `True`."
)
Copy link
Member

Choose a reason for hiding this comment

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

This is a problem for several other options, such as top_k or length_penalty, which have no effect in some generation modes.

Despite it being a correct check, we are assessing how to best handle it. We would like to avoid having an if/else branch for each input variable, as it would make generate even longer and less readable. Since it is harmless to have typical_p set with do_sample=False and we don't want to promote further checks of this kind, I'm going to ask to remove it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I do hope that the do_sample check can happen in the future because receiving typical_p but doing greedy or non-sampled beam decoding is, in my view, silently failing.

Removed this and committed requested changes ✅

src/transformers/generation_utils.py Outdated Show resolved Hide resolved
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 the changes <3

@gante gante merged commit 9c6aeba into huggingface:main Sep 28, 2022
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