-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Update config validation #34726
Update config validation #34726
Conversation
The failing tests seem unrelated to my changes and all tests passed locally for me, is there something I'm missing here? |
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.
Cool, thanks for working on this! The tests failing are not related and re-trigerring run should help :)
Hey @zucchini-nlp thanks! I’ve added extra validations for the remaining generation parameters. I also validated For now, I’ve left the |
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.
Wow, an extensive validation list! Thanks!
I was considering removing it since it’s now redundant
No, I think we still need it because the logits processors can be initialized before generate()
call and doesn't necessarily require a generation config.
Adding a few tests should be enough at this point :)
Thanks @zucchini-nlp ! I believe all generation parameters are validated now |
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.
@Manalelaidouni cool, LGTM! As said before adding a few tests should be enough at this point :)
You can add them in tests/generation/test_configuration_utils.py
to make sure that incorrect variable through an error when passed to generation config. LMK if you need help with tests. Then feel free to tag the core maintainer @ ArthurZucker for final review
Thank you @zucchini-nlp for reviewing, when adding tests I also made updates to some existing ones:
Finally, I’m not entirely sure about how to address |
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.
Thanks so much for iterating on this!
since _convert_list_arguments_into_dict() in SequenceBiasLogitsProcessor is used for background compatibilty, the _validate_arguments() should raise a ValueError if the input is not in the list format,
No, if we are keeping BC and the changes were done recently, we will not raise error if users pass in the old-style dict. It should be converted to the correct format to be used by logit processor at the end. But I see what you mean here, we won't be able to serialize the old dict format, so that means we'd need to convert_to_list
in configuration here, which ensure that specific values are converted to serializable format in below code. Let's keep this for another PR, as the current one is getting big and should only check that correct values are passed
def to_json_string(self, use_diff: bool = True, ignore_metadata: bool = False) -> str: |
bad_words_ids in the failing CI/CD tests
The token id in these args can be also a numpy int, see how we check the values here
transformers/src/transformers/generation/logits_process.py
Lines 1307 to 1310 in 0b5b5e6
if any( | |
any((not isinstance(token_id, (int, np.integer)) or token_id < 0) for token_id in bad_word_ids) | |
for bad_word_ids in bad_words_ids | |
): |
e4cccd6
to
7250e2f
Compare
cc @ArthurZucker whenever you have a moment, I'd appreciate your review, I wanted to see those CI tests green 😅 but it seems unrelated. Thanks! |
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. |
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.
Hey! Thanks for the PR, this seems to be quite inflated 😓
This is mostly not scalable 😢 so we should find another tool / effiecient way to define boundaries ands etc. Dataclasses might help!
@@ -587,17 +589,213 @@ def validate(self, is_init=False): | |||
""" | |||
|
|||
# Validation of individual attributes | |||
pos_int_args = [ |
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.
pos_int_args = [ | |
pos_init_args = [ |
was probably intended?
Thanks for reviewing this @ArthurZucker!
class _ConfigValidator:
VALIDATORS = {
"pos_int_arg": (lambda x: isinstance(x, int) and x >= 0,
"`{arg}` must be a positive integer, but got {value}."),
"probability_arg": (lambda x: isinstance(x, (int, float)) and 0.0 <= x <= 1.0,
"`{arg}` must be a float between 0 and 1, but got {value}."),
... }
CONFIG_TYPES = {
"top_k": "pos_int_arg",
"top_p": "probability_arg",
...}
class GenerationConfig:
....
def validate(self):
for arg, value in self.__dict__.items():
if arg in _ConfigValidator.CONFIG_TYPES:
key = _ConfigValidator.CONFIG_TYPES[arg]
validator, error_message = _ConfigValidator.VALIDATORS[key]
if value is not None and not validator(value):
raise ValueError(error_message.format(arg=arg, value=value))
|
I really don't mind using pydantic, it's become quite important and we have so many configs that we need to validate! Do you mind drafting a PR for that? 🤗 |
Hey @ArthurZucker, apologies for the delayed response, I just opened a PR for it! |
@Manalelaidouni this PR is orthogonal to the pydantic PR, correct? Or should we merge one before the other? |
@gante they're indeed orthogonal this was the original plan, so I'll close this PR :) |
What does this PR do?
Fixes #33690
This PR adds extra validation for generation parameters to fail early when invalid values are passed and not let things fail silently as suggested in the issue.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@gante @zucchini-nlp