fix(granite_speech): convert int to float for multiplier fields in text_config#44904
Closed
vivekvar-dl wants to merge 1 commit intohuggingface:mainfrom
Closed
fix(granite_speech): convert int to float for multiplier fields in text_config#44904vivekvar-dl wants to merge 1 commit intohuggingface:mainfrom
vivekvar-dl wants to merge 1 commit intohuggingface:mainfrom
Conversation
…xt_config Fixes huggingface#44877 When loading granite_speech models (e.g., ibm-granite/granite-4.0-1b-speech), the config loading fails with StrictDataclassFieldValidationError because embedding_multiplier and similar fields are stored as integers in config.json but GraniteConfig expects them as floats. This commit adds type conversion from int to float for the following fields before instantiating the text_config: - embedding_multiplier - logits_scaling - residual_multiplier - attention_multiplier The conversion only happens when text_config is a dict (not an already instantiated config object) and only for fields that exist and are ints. Root cause: huggingface_hub's strict dataclass validation rejects type mismatches, and config.json values are deserialized as ints when they don't have decimal points. Test: Verified config loads successfully with embedding_multiplier=12 (int) which gets converted to 12.0 (float) before validation.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: granite_speech |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix granite_speech config loading failure with int multiplier fields
Fixes #44877
Problem
Loading
granite_speechconfigs fails withStrictDataclassFieldValidationErrorwhen multiplier fields (e.g.,embedding_multiplier) are stored as integers in the Hub config but the underlyingGraniteConfigexpects floats:Root Cause
config.jsonstoresembedding_multiplier: 12(integer, no decimal point)GraniteConfigdefinesembedding_multiplier: float = 1.0huggingface_hub's strict dataclass validation rejects the type mismatchSolution
Convert int→float for multiplier fields before instantiating the nested
text_config:Changes
src/transformers/models/granite_speech/configuration_granite_speech.py__post_init__)Safety
✅ Non-breaking: Only converts when
text_configis a dict AND field is an int✅ Preserves values:
12→12.0(semantically identical)✅ Minimal scope: Only affects 4 known float fields in GraniteConfig
✅ Backward compatible: Doesn't change existing behavior for valid configs
Testing
Before:
After:
Why Not Fix the Hub Config?
Fixing the JSON on the Hub wouldn't help users with existing cached configs or custom configs stored with integers. This fix handles the issue at load time, making the library more robust.
Related
granite_speechconfig #44877ibm-granite/granite-4.0-1b-speech, potentially other granite_speech variantsChecklist:
cc @zucchini-nlp (mentioned in original issue)