-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,26 +124,44 @@ def test_validate(self): | |
""" | ||
Tests that the `validate` method is working as expected. Note that `validate` is called at initialization time | ||
""" | ||
# Case 1: A correct configuration will not throw any warning | ||
# A correct configuration will not throw any warning | ||
with warnings.catch_warnings(record=True) as captured_warnings: | ||
GenerationConfig() | ||
self.assertEqual(len(captured_warnings), 0) | ||
|
||
# Case 2: Inconsequent but technically wrong configuration will throw a warning (e.g. setting sampling | ||
# Inconsequent but technically wrong configuration will throw a warning (e.g. setting sampling | ||
# 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) |
||
self.assertEqual(len(captured_warnings), 1) | ||
|
||
# Case 3: Impossible sets of contraints/parameters will raise an exception | ||
# Expanding on the case above, we can update a bad configuration to get rid of the warning. Ideally, | ||
# that is done by unsetting the parameter (i.e. setting it to None) | ||
generation_config_bad_temperature = GenerationConfig(do_sample=False, temperature=0.5) | ||
with warnings.catch_warnings(record=True) as captured_warnings: | ||
# BAD - 0.9 means it is still set, we should warn | ||
generation_config_bad_temperature.update(temperature=0.9) | ||
self.assertEqual(len(captured_warnings), 1) | ||
generation_config_bad_temperature = GenerationConfig(do_sample=False, temperature=0.5) | ||
with warnings.catch_warnings(record=True) as captured_warnings: | ||
# CORNER CASE - 1.0 is the default, we can't detect whether it is set by the user or not, we shouldn't warn | ||
generation_config_bad_temperature.update(temperature=1.0) | ||
self.assertEqual(len(captured_warnings), 0) | ||
generation_config_bad_temperature = GenerationConfig(do_sample=False, temperature=0.5) | ||
with warnings.catch_warnings(record=True) as captured_warnings: | ||
# OK - None means it is unset, nothing to warn about | ||
generation_config_bad_temperature.update(temperature=None) | ||
self.assertEqual(len(captured_warnings), 0) | ||
|
||
# Impossible sets of contraints/parameters will raise an exception | ||
with self.assertRaises(ValueError): | ||
GenerationConfig(num_return_sequences=2) | ||
GenerationConfig(do_sample=False, num_beams=1, num_return_sequences=2) | ||
|
||
# Case 4: Passing `generate()`-only flags to `validate` will raise an exception | ||
# Passing `generate()`-only flags to `validate` will raise an exception | ||
with self.assertRaises(ValueError): | ||
GenerationConfig(logits_processor="foo") | ||
|
||
# Case 5: Model-specific parameters will NOT raise an exception or a warning | ||
# Model-specific parameters will NOT raise an exception or a warning | ||
with warnings.catch_warnings(record=True) as captured_warnings: | ||
GenerationConfig(foo="bar") | ||
self.assertEqual(len(captured_warnings), 0) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.