-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Add generation config validation using Pydantic #35910
base: main
Are you sure you want to change the base?
Add generation config validation using Pydantic #35910
Conversation
cc @gante for generation config as well |
cc @LysandreJik as well! |
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.
At a first glance, big yes from me. It becomes immediately clear which values are allowed in each attribute, except for combinations of values.
All my comments are due to being inexperienced with pydantic
, otherwise LGTM
Most of the failing tests seem unrelated, will fix the unprotected import. |
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.
Very nice PR, cleaner validation of config is much needed. I just left a couple questions, just to be sure I understand it correctly
@Manalelaidouni added a bunch of comments with more precise limits :) LMK if you need help getting the CI green ✅ |
When working on the improtected import, I implemented the lazy code logic for Pydantic in the main init and the generation module’s init, however the dummy routing only works when importing from transformers top level and not the generation module’s level, because there are other non-pydantic dependent objects that directly import from This means I either need to move if is_pydantic_available():
from pydantic import BaseModel, ConfigDict, PrivateAttr, confloat, conint, model_validator
class GenerationConfig(BaseModel, PushToHubMixin):
... Although, this means the nice import error msg in Thank you guys and let me know what you think before I proceed :) |
@Manalelaidouni since the |
@Manalelaidouni We (me, @LysandreJik, and @ArthurZucker) discussed what to do regarding install requirements internally. Adding a mandatory requirement to a popular library like That being said, we want to add more validation to certain classes ( Here's what we're going to do: I'm going to open a GH issue (and share it on social media) to see what the community thinks and to try to anticipate problems. Then, in about a week, let's make an informed decision 🤗 |
Hey @Manalelaidouni 👋 Thank you for holding this discussion with us -- we've decided no NOT move forward with |
I opened huggingface/huggingface_hub#2895 as a suggestion on how to move forward with data validation in the HF ecosystem. Open to feedback and subject to change based on community requirements 🤗 |
What does this PR do?
Follow up to #34726
The goal of this PR is to add validation for generation config using Pydantic to fail early when invalid values are passed and not let things fail silently as suggested in issue #3690 .
ConfigDict
replaces the code responsible for setting additional attributes without default values.validate()
into the constructor.sequence_bias
docstring correction because it’s still referencing the older dictionary format which is confusing for users.Who can review?
@ArthurZucker @zucchini-nlp