Skip to content

fix: correct type annotations across config classes for @strict validation#45007

Open
Krishnachaitanyakc wants to merge 4 commits intohuggingface:mainfrom
Krishnachaitanyakc:fix/config-type-annotations
Open

fix: correct type annotations across config classes for @strict validation#45007
Krishnachaitanyakc wants to merge 4 commits intohuggingface:mainfrom
Krishnachaitanyakc:fix/config-type-annotations

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

Summary

Fix type annotation bugs across config classes that cause @strict validation errors from huggingface_hub.

Bool fields mistyped as int (22 fixes)

Fields with boolean defaults (True/False) were annotated as int instead of bool. While this does not crash at runtime (since bool is a subclass of int in 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)
  • Other: use_bias, attention_bias, two_stage, learn_initial_query

Float fields that should accept int (336 fixes)

Dropout, rate, multiplier, and scaling fields annotated as bare float are rejected by @strict validation when users pass integer values like 0 instead of 0.0:

BertConfig(hidden_dropout_prob=0)  # StrictDataclassFieldValidationError!

Changed 336 such fields from float to float | int across 163 config files. This follows the existing pattern already used by LlamaConfig, MistralConfig, AlbertConfig, and DistilBertConfig.

Modular source files updated

14 modular source files (modular_*.py) were also updated to ensure changes survive make fix-repo regeneration.

AI Assistance Disclosure

This PR was developed with AI assistance. All changes have been manually reviewed and verified.

Test Plan

  • Autonomous test suite: 2098 config instantiation tests passed, 0 failures
  • Verified BertConfig(hidden_dropout_prob=0) and GPT2Config(resid_pdrop=0) accept int values
  • Verified save/load roundtrip with int dropout values
  • Verified BigBirdConfig(use_cache=True) returns bool type
  • Reviewed by 3 personas (maintainer, user, QA) - all feedback addressed

…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.
@zucchini-nlp
Copy link
Copy Markdown
Member

zucchini-nlp commented Mar 27, 2026

Oh nice, since you already for a PR, can I ask to also update these fields to be an int and float: drop_path_rate/drop_connect_rate/drop_path_p? And since checking with AI is faster, all left-out dropout/pdrop/drop_p/et" fields that can be names differently in the codebase

For context - #45019 (review)

I am planning to do it in any case so it's fine if you can't :)

@Krishnachaitanyakc Krishnachaitanyakc marked this pull request as ready for review March 27, 2026 14:01
initializer_range: float = 0.02
layer_norm_eps: float = 1e-5
use_cache: int = True
use_cache: bool = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder why the tests didn't complain, because we have use_cache set to integer 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isinstance(True, int) == True 🫠 nice, i'll check if we can upstream this to type validator

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fixed on hub repo, though it will take time to upsteam it. I'll review and merge your PR today :)

Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Nice, thanks a lot!

@zucchini-nlp zucchini-nlp enabled auto-merge March 30, 2026 15:04
@zucchini-nlp zucchini-nlp added this pull request to the merge queue Mar 30, 2026
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2026
@zucchini-nlp
Copy link
Copy Markdown
Member

@bot /repo

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Repo. Consistency bot fixed some files and pushed the changes.

@github-actions
Copy link
Copy Markdown
Contributor

[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

@zucchini-nlp zucchini-nlp enabled auto-merge March 30, 2026 15:43
@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45007&sha=88b8f9

@zucchini-nlp
Copy link
Copy Markdown
Member

repo bot fixing everything, and not the actual modular diff 😿

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.

3 participants