fix: correct type annotations across config classes for @strict validation#45007
fix: correct type annotations across config classes for @strict validation#45007Krishnachaitanyakc wants to merge 4 commits intohuggingface:mainfrom
Conversation
…ation Fix bool fields mistyped as int (would fail @strict validation): - BigBird, Cohere2: use_cache: int → bool - MBart, M2M100: scale_embedding: int → bool - OLMo, OLMo2, OLMo3, OLMoE, PhiMoE, Eurobert, PaddleOCR-VL: tie_word_embeddings: int → bool - DAB-DETR, MVP, EncoderDecoder, SpeechEncoderDecoder: is_encoder_decoder: int → bool - Ernie4.5-MoE, Ernie4.5-VL-MoE: use_bias: int → bool - Falcon-H1, Ernie4.5, PaddleOCR-VL: use_cache: int → bool - Chameleon: attention_bias: int → bool - GroundingDINO: two_stage: int → bool - OmDet-Turbo: learn_initial_query: int → bool Fix 336 dropout/rate/multiplier/scaling fields from bare float to float | int across 163 config files and 14 modular source files. This prevents @strict TypeError when hub configs store these values as integers (e.g., dropout: 0 instead of dropout: 0.0). Follows the existing pattern used by LlamaConfig, MistralConfig, AlbertConfig, and DistilBertConfig which already use float | int. Both generated configuration files and their modular source files are updated to ensure make fix-repo consistency.
|
Oh nice, since you already for a PR, can I ask to also update these fields to be an For context - #45019 (review) I am planning to do it in any case so it's fine if you can't :) |
| initializer_range: float = 0.02 | ||
| layer_norm_eps: float = 1e-5 | ||
| use_cache: int = True | ||
| use_cache: bool = True |
There was a problem hiding this comment.
I wonder why the tests didn't complain, because we have use_cache set to integer 🤔
There was a problem hiding this comment.
isinstance(True, int) == True 🫠 nice, i'll check if we can upstream this to type validator
There was a problem hiding this comment.
fixed on hub repo, though it will take time to upsteam it. I'll review and merge your PR today :)
|
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. |
|
@bot /repo |
|
Repo. Consistency bot fixed some files and pushed the changes. |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: align, altclip, audio_spectrogram_transformer, beit, bert, bert_generation, big_bird, biogpt, bit, blip, blip_2, bridgetower, bros, camembert, canine, chameleon |
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45007&sha=88b8f9 |
|
repo bot fixing everything, and not the actual modular diff 😿 |
Summary
Fix type annotation bugs across config classes that cause
@strictvalidation errors fromhuggingface_hub.Bool fields mistyped as
int(22 fixes)Fields with boolean defaults (
True/False) were annotated asintinstead ofbool. While this does not crash at runtime (sinceboolis a subclass ofintin Python), it is semantically wrong and confuses type checkers.use_cache: int = True->bool = True(BigBird, Cohere2, Falcon-H1, Ernie4.5, PaddleOCR-VL)scale_embedding: int = False->bool = False(MBart, M2M-100)tie_word_embeddings: int = False->bool = False(OLMo, OLMo2, OLMo3, OLMoE, PhiMoE, Eurobert, PaddleOCR-VL)is_encoder_decoder: int = True->bool = True(DAB-DETR, MVP, EncoderDecoder, SpeechEncoderDecoder)use_bias,attention_bias,two_stage,learn_initial_queryFloat fields that should accept int (336 fixes)
Dropout, rate, multiplier, and scaling fields annotated as bare
floatare rejected by@strictvalidation when users pass integer values like0instead of0.0:Changed 336 such fields from
floattofloat | intacross 163 config files. This follows the existing pattern already used byLlamaConfig,MistralConfig,AlbertConfig, andDistilBertConfig.Modular source files updated
14 modular source files (
modular_*.py) were also updated to ensure changes survivemake fix-reporegeneration.AI Assistance Disclosure
This PR was developed with AI assistance. All changes have been manually reviewed and verified.
Test Plan
BertConfig(hidden_dropout_prob=0)andGPT2Config(resid_pdrop=0)accept int valuesBigBirdConfig(use_cache=True)returnsbooltype