huggingface/transformers · error · ValueError
Model {cls.__name__} has no config class or model type
Error message
Model {cls.__name__} has no config class or model type What it means
In the module-fusion machinery, after discovering fusable modules and registering patch mappings, the code requires cls.config_class with a model_type attribute to key checkpoint conversion mappings. Model classes lacking a proper config class (or whose config class has no model_type) cannot participate in fusion.
Source
Thrown at src/transformers/fusion_mapping.py:211
"""Register one fusion family for `cls`.
This function updates the two global registries used by fused loading:
- the monkey-patching registry, so compatible module classes are replaced before initialization
- the checkpoint conversion mapping, so fused runtime modules still load from the original checkpoint layout
Notes:
- conflicting checkpoint transforms fail fast
"""
fusable_classes = _discover_fusable_modules(cls, config, fusion_name=fusion_name, spec=spec)
if not fusable_classes:
logger.info(spec.get_empty_log(cls.__name__))
return
register_patch_mapping(fusable_classes, overwrite=True)
if not hasattr(cls, "config_class") or not hasattr(cls.config_class, "model_type"):
raise ValueError(f"Model {cls.__name__} has no config class or model type")
model_type = cls.config_class.model_type
converters = spec.make_transforms(config)
existing_converters = get_checkpoint_conversion_mapping(model_type)
if existing_converters is not None:
# WeightConverter matching stops at the first matching source pattern, so
# conflicting converters must fail fast instead of being appended.
existing_converter_sources = {tuple(existing.source_patterns): existing for existing in existing_converters}
for converter in converters:
source_patterns = tuple(converter.source_patterns)
existing_converter = existing_converter_sources.get(source_patterns)
if existing_converter is not None:
raise ValueError(
f"Fusion {fusion_name} for model type {model_type} conflicts with an existing conversion mapping "
f"for source patterns {source_patterns}."
)
# TODO: allow compatible fusions mentioned https://github.com/huggingface/transformers/pull/45041#discussion_r3028989716View on GitHub (pinned to a597f97485)
Solutions
- Set cls.config_class = MyConfig on the model class and define MyConfig.model_type (e.g. 'my-model')
- Verify fusable modules were actually discovered first — the error only fires when fusable_classes is non-empty
- Do not enable fusion_config for model types that do not support fusion
Example fix
# before
class MyModel(PreTrainedModel):
config_class = None # fusion then fails
# after
class MyConfig(PretrainedConfig):
model_type = "my-model"
class MyModel(PreTrainedModel):
config_class = MyConfig Defensive patterns
Strategy: validation
Validate before calling
def supports_fusion(cls) -> bool:
return hasattr(cls, "config_class") and hasattr(cls.config_class, "model_type") Type guard
from transformers import PreTrainedModel, PretrainedConfig
def has_model_type(cls: type[PreTrainedModel]) -> bool:
cfg = getattr(cls, "config_class", None)
return isinstance(cfg, type) and issubclass(cfg, PretrainedConfig) and bool(getattr(cfg, "model_type", None)) Prevention
- Always define config_class and model_type on custom PreTrainedModel subclasses
- Only enable fusion_config on models documented to support fusion
When it happens
Trigger: Calling register_fusion_patches (directly or via model loading with a fusion_config) on a custom PreTrainedModel subclass whose config_class is missing or whose config class does not define model_type.
Common situations: Experimental/custom model implementations that skip config_class, or configs built from a plain dict without setting model_type before fusion is requested.
Related errors
- Fusion {fusion_name} for model type {model_type} conflicts w
- Unknown fusion type: {fusion_name}
- Invalid fusion config for {fusion_name}: expected `True`, `F
- Could not find `num_mtp_layers` in the model config. This mo
- Can't load feature extractor for '{pretrained_model_name_or_
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/8c8c22bf2c878d2e.
Report an issue: GitHub.