transformers - ✅(Solved) Fix Strict config prevents loading `granite_speech` config [1 pull requests, 4 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44877Fetched 2026-04-08 01:03:19
View on GitHub
Comments
4
Participants
2
Timeline
15
Reactions
0
Author
Timeline (top)
referenced ×5commented ×4cross-referenced ×2closed ×1

Error Message

Traceback (most recent call last): File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 148, in strict_setattr validator(value) File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 607, in validator type_validator(field.name, value, field.type) File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 474, in type_validator _validate_simple_type(name, value, expected_type) File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 597, in _validate_simple_type raise TypeError( TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "[sic]/demo_granite_4_1b_speech.py", line 4, in <module> config = AutoConfig.from_pretrained(model_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]/src/transformers/models/auto/configuration_auto.py", line 1486, in from_pretrained return config_class.from_dict(config_dict, **unused_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]/src/transformers/configuration_utils.py", line 757, in from_dict config = cls(**config_dict) ^^^^^^^^^^^^^^^^^^ File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate initial_init(self, *args, **kwargs) # type: ignore [call-arg] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 194, in init self.post_init(**additional_kwargs) File "[sic]/src/transformers/models/granite_speech/configuration_granite_speech.py", line 122, in post_init self.text_config = CONFIG_MAPPINGself.text_config["model_type"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate initial_init(self, *args, **kwargs) # type: ignore [call-arg] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 179, in init setattr(self, f.name, standard_kwargs[f.name]) File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 150, in strict_setattr raise StrictDataclassFieldValidationError(field=name, cause=e) from e huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'embedding_multiplier': TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)

Fix Action

Fixed

PR fix notes

PR #44904: fix(granite_speech): convert int to float for multiplier fields in text_config

Description (problem / solution / changelog)

Fix granite_speech config loading failure with int multiplier fields

Fixes #44877

Problem

Loading granite_speech configs fails with StrictDataclassFieldValidationError when multiplier fields (e.g., embedding_multiplier) are stored as integers in the Hub config but the underlying GraniteConfig expects floats:

from transformers import AutoConfig
config = AutoConfig.from_pretrained("ibm-granite/granite-4.0-1b-speech")
# ❌ StrictDataclassFieldValidationError: Field 'embedding_multiplier' expected float, got int (value: 12)

Root Cause

  • The model's config.json stores embedding_multiplier: 12 (integer, no decimal point)
  • GraniteConfig defines embedding_multiplier: float = 1.0
  • huggingface_hub's strict dataclass validation rejects the type mismatch

Solution

Convert int→float for multiplier fields before instantiating the nested text_config:

# In GraniteSpeechConfig.__post_init__()
float_fields = ["embedding_multiplier", "logits_scaling", "residual_multiplier", "attention_multiplier"]
for field in float_fields:
    if field in self.text_config and isinstance(self.text_config[field], int):
        self.text_config[field] = float(self.text_config[field])

Changes

  • File: src/transformers/models/granite_speech/configuration_granite_speech.py
  • Lines: 122-127 (added type conversion in __post_init__)

Safety

Non-breaking: Only converts when text_config is a dict AND field is an int
Preserves values: 1212.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:

>>> config = AutoConfig.from_pretrained("ibm-granite/granite-4.0-1b-speech")
StrictDataclassFieldValidationError: Field 'embedding_multiplier' expected float, got int (value: 12)

After:

>>> config = AutoConfig.from_pretrained("ibm-granite/granite-4.0-1b-speech")
>>> config.text_config.embedding_multiplier
12.0  # ✅ Successfully converted to float
>>> type(config.text_config.embedding_multiplier)
<class 'float'>

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

  • Original issue: #44877
  • Affected models: ibm-granite/granite-4.0-1b-speech, potentially other granite_speech variants
  • Similar pattern used in other multi-config models (e.g., CLIP, LLaVA)

Checklist:

  • Fix addresses the root cause
  • Minimal, focused change
  • Backward compatible
  • Clear commit message
  • Issue linked

cc @zucchini-nlp (mentioned in original issue)

Changed files

  • src/transformers/models/granite_speech/configuration_granite_speech.py (modified, +6/-0)
  • test_fix_44877.py (added, +43/-0)
  • test_fix_simple.py (added, +52/-0)

Code Example

from transformers import AutoConfig

model_name = "ibm-granite/granite-4.0-1b-speech"
config = AutoConfig.from_pretrained(model_name)

---

Traceback (most recent call last):
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 148, in __strict_setattr__
    validator(value)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 607, in validator
    type_validator(field.name, value, field.type)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 474, in type_validator
    _validate_simple_type(name, value, expected_type)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 597, in _validate_simple_type
    raise TypeError(
TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "[sic]/demo_granite_4_1b_speech.py", line 4, in <module>
    config = AutoConfig.from_pretrained(model_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/src/transformers/models/auto/configuration_auto.py", line 1486, in from_pretrained
    return config_class.from_dict(config_dict, **unused_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/src/transformers/configuration_utils.py", line 757, in from_dict
    config = cls(**config_dict)
             ^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate
    initial_init(self, *args, **kwargs)  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 194, in __init__
    self.__post_init__(**additional_kwargs)
  File "[sic]/src/transformers/models/granite_speech/configuration_granite_speech.py", line 122, in __post_init__
    self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)   
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate
    initial_init(self, *args, **kwargs)  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 179, in __init__
    setattr(self, f.name, standard_kwargs[f.name])
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 150, in __strict_setattr__
    raise StrictDataclassFieldValidationError(field=name, cause=e) from e
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'embedding_multiplier':
    TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)
RAW_BUFFERClick to expand / collapse

System Info

  • transformers version: 5.3.0.dev0
  • Platform: Windows-10-10.0.26200-SP0
  • Python version: 3.11.13
  • Huggingface_hub version: 1.7.1
  • Safetensors version: 0.6.2
  • Accelerate version: 1.11.0
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (accelerator?): 2.9.0+cu126 (CUDA)
  • Using distributed or parallel set-up in script?: No
  • Using GPU in script?: No
  • GPU type: NVIDIA GeForce RTX 3090

Who can help?

@zucchini-nlp

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers import AutoConfig

model_name = "ibm-granite/granite-4.0-1b-speech"
config = AutoConfig.from_pretrained(model_name)
Traceback (most recent call last):
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 148, in __strict_setattr__
    validator(value)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 607, in validator
    type_validator(field.name, value, field.type)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 474, in type_validator
    _validate_simple_type(name, value, expected_type)
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 597, in _validate_simple_type
    raise TypeError(
TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "[sic]/demo_granite_4_1b_speech.py", line 4, in <module>
    config = AutoConfig.from_pretrained(model_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/src/transformers/models/auto/configuration_auto.py", line 1486, in from_pretrained
    return config_class.from_dict(config_dict, **unused_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/src/transformers/configuration_utils.py", line 757, in from_dict
    config = cls(**config_dict)
             ^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate
    initial_init(self, *args, **kwargs)  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 194, in __init__
    self.__post_init__(**additional_kwargs)
  File "[sic]/src/transformers/models/granite_speech/configuration_granite_speech.py", line 122, in __post_init__
    self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)   
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 279, in init_with_validate
    initial_init(self, *args, **kwargs)  # type: ignore [call-arg]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 179, in __init__
    setattr(self, f.name, standard_kwargs[f.name])
  File "[sic]/Lib/site-packages/huggingface_hub/dataclasses.py", line 150, in __strict_setattr__
    raise StrictDataclassFieldValidationError(field=name, cause=e) from e
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'embedding_multiplier':
    TypeError: Field 'embedding_multiplier' expected float, got int (value: 12)

Expected behavior

For the config to load as normal.

  • Tom Aarsen

extent analysis

Fix Plan

To resolve the issue, we need to update the embedding_multiplier field in the model configuration to expect an integer value instead of a float.

Here are the steps to fix the issue:

  • Update the configuration_granite_speech.py file in the transformers library to change the type of embedding_multiplier from float to int.
  • Alternatively, you can modify the model configuration to pass the embedding_multiplier as a float.

Code Changes

You can modify the model configuration as follows:

from transformers import AutoConfig

model_name = "ibm-granite/granite-4.0-1b-speech"
config = AutoConfig.from_pretrained(model_name)

# Update the embedding_multiplier to a float
config.embedding_multiplier = float(config.embedding_multiplier)

However, this is not a recommended solution as it may cause issues with the model's performance.

A better solution would be to update the configuration_granite_speech.py file:

from dataclasses import dataclass, field
from typing import Optional

@dataclass
class GraniteSpeechConfig:
    # ...
    embedding_multiplier: int = field(
        default=12,
        metadata={
            "help": "The multiplier for the embedding size"
        }
    )

Verification

To verify that the fix worked, you can try loading the model configuration again:

from transformers import AutoConfig

model_name = "ibm-granite/granite-4.0-1b-speech"
config = AutoConfig.from_pretrained(model_name)
print(config.embedding_multiplier)  # Should print the updated value

Extra Tips

  • Make sure to update the transformers library to the latest version to ensure that you have the latest fixes and features.
  • If you are using a custom model, make sure to update the model configuration to match the changes made to the transformers library.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

For the config to load as normal.

  • Tom Aarsen

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix Strict config prevents loading `granite_speech` config [1 pull requests, 4 comments, 2 participants]