Skip to content

Fix GraniteConfig type hints to accept int for multiplier fields#45019

Merged
zucchini-nlp merged 2 commits intohuggingface:mainfrom
javierdejesusda:fix/granite-config-int-type-hints
Mar 27, 2026
Merged

Fix GraniteConfig type hints to accept int for multiplier fields#45019
zucchini-nlp merged 2 commits intohuggingface:mainfrom
javierdejesusda:fix/granite-config-int-type-hints

Conversation

@javierdejesusda
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #44877

Loading ibm-granite/granite-4.0-1b-speech fails with
StrictDataclassFieldValidationError because its config.json stores
embedding_multiplier and logits_scaling as integers (e.g. 12, 8),
but GraniteConfig declares them as float.

The fix updates the type hints for all four multiplier fields to float | int,
matching the pattern already used for attention_dropout in the same class.

  • I confirm that this is not a pure code agent PR.
  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@Rocketknight1
Copy link
Copy Markdown
Member

cc @tomaarsen @zucchini-nlp from #44877

@tomaarsen
Copy link
Copy Markdown
Member

This strikes me as a good fix, although I haven't tried it locally. I'm personally a fan of expanding the config type hints a bit with float/int rather than requiring model authors to update their ints to floats.

  • Tom Aarsen

logits_scaling: float = 1.0
residual_multiplier: float = 1.0
attention_multiplier: float = 1.0
embedding_multiplier: float | int = 1.0
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.

there are more Granite models with xxx_multiplier, xan you update all of them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated GraniteMoe and GraniteMoeShared. GraniteMoeHybrid already supports int | float | None.

Let me know if you spot any other fixes or anything else to add!

@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: granite, granitemoe, granitemoeshared

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.

Thanks, I will update other similar fields in separate PR

For context, we decided with Lucain that we don't want to force cast as pydantic does because we want the validation be a lightweight dependency. So instead I will check what other fields could be potentially both and update annotations (already did that for all dropouts)

@zucchini-nlp zucchini-nlp enabled auto-merge March 27, 2026 09:11
@zucchini-nlp zucchini-nlp added this pull request to the merge queue Mar 27, 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.

Merged via the queue into huggingface:main with commit 05514c4 Mar 27, 2026
22 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Mar 27, 2026
…gingface#45019)

* Fix GraniteConfig type hints to accept int for multiplier fields

Fixes huggingface#44877

* Also update granitemoe and granitemoeshared multiplier type hints
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.

Strict config prevents loading granite_speech config

5 participants