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: unset GenerationConfig parameters do not raise warning #29119

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

gante
Copy link
Member

@gante gante commented Feb 19, 2024

What does this PR do?:

Thank you @fxmarty for raising this issue.

This PR allows users to unset (= set to None) unused parameters to ensure generation_config.validate() doesn't throw a warning. Previously, this was not possible when a parameter had a non-None default.

For instance, the following snippet would throw a warning before this PR:

from transformers import GenerationConfig

generation_config = GenerationConfig()
generation_config.update(temperature=None)
generation_config.validate()
# "... UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `None` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`."

@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

@fxmarty fxmarty 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 a lot for the fix

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for adding! Just a question about the removal of some validation, as the checks on none look like they should be enough to resolve

@@ -330,7 +330,6 @@ def generate(

generation_config = copy.deepcopy(generation_config)
model_kwargs = generation_config.update(**kwargs) # All unused kwargs must be model kwargs
generation_config.validate()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why get rid of these validations here (and in the other utils files)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I've added the .validate() call to .update(), which is the line that precedes all these removals :) It makes more sense to validate at update time, rather than relying on the user to manually validate.

tests/generation/test_configuration_utils.py Outdated Show resolved Hide resolved
# parameters with `do_sample=False`). May be escalated to an error in the future.
with warnings.catch_warnings(record=True) as captured_warnings:
GenerationConfig(temperature=0.5)
GenerationConfig(do_sample=False, temperature=0.5)
Copy link
Member Author

Choose a reason for hiding this comment

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

This commit I've made a few implicit parameters explicit, to make reading the test easier :)

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

@gante gante merged commit a7755d2 into huggingface:main Feb 20, 2024
21 checks passed
@gante gante deleted the allow_none_config branch February 20, 2024 11:34
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.

None yet

4 participants