huggingface/transformers · error · TypeError
Export config must extend ExportConfigMixin
Error message
Export config must extend ExportConfigMixin
What it means
The @register_export_config(name) decorator raises TypeError when the decorated class is not a subclass of ExportConfigMixin. Config classes in the AUTO_EXPORT_CONFIG_MAPPING must support to_dict()/from_dict() round-tripping, which the mixin provides; registering a bare class would break AutoExportConfig.from_dict.
Source
Thrown at src/transformers/exporters/auto.py:177
def register_exporter(name: str):
def register_exporter_fn(cls):
if name in AUTO_EXPORTER_MAPPING:
logger.warning(f"Exporter '{name}' is already registered and will be overwritten.")
if not issubclass(cls, HfExporter):
raise TypeError("Exporter must extend HfExporter")
AUTO_EXPORTER_MAPPING[name] = cls
return cls
return register_exporter_fn
def register_export_config(name: str):
def register_export_config_fn(cls):
if name in AUTO_EXPORT_CONFIG_MAPPING:
logger.warning(f"Export config '{name}' is already registered and will be overwritten.")
if not issubclass(cls, ExportConfigMixin):
raise TypeError("Export config must extend ExportConfigMixin")
AUTO_EXPORT_CONFIG_MAPPING[name] = cls
return cls
return register_export_config_fn
def get_hf_exporter(export_config) -> HfExporter:
return AutoHfExporter.from_config(export_config)
View on GitHub (pinned to a597f97485)
Solutions
- Inherit from ExportConfigMixin (directly or via an existing config class) before registering.
- Set the class attribute export_format so to_dict() emits the registry name.
- Verify with issubclass(cls, ExportConfigMixin) in a test.
Example fix
# before
@register_export_config("trt")
@dataclass
class TrtConfig: # TypeError
precision: str = "fp16"
# after
from transformers.exporters.configs import ExportConfigMixin
@register_export_config("trt")
@dataclass
class TrtConfig(ExportConfigMixin):
export_format = "trt"
precision: str = "fp16" Defensive patterns
Strategy: type-guard
Validate before calling
from transformers.exporters.configs import ExportConfigMixin
assert issubclass(MyConfig, ExportConfigMixin), "export configs must subclass ExportConfigMixin"
register_export_config("mybackend")(MyConfig) Type guard
def is_valid_export_config(cls) -> bool:
from transformers.exporters.configs import ExportConfigMixin
return isinstance(cls, type) and issubclass(cls, ExportConfigMixin) Prevention
- Subclass an existing config (OnnxConfig/DynamoConfig/ExecutorchConfig) — they already carry the mixin
- Set the export_format attribute on the config class so round-tripping works
When it happens
Trigger: Applying @register_export_config("mybackend") to a plain dataclass or dict-like class that does not inherit ExportConfigMixin.
Common situations: Adding a custom backend alongside a custom exporter and forgetting the config half; subclassing one of the existing config classes (e.g. OnnxConfig) — note OnnxConfig already inherits the mixin, so this only fires for from-scratch classes.
Related errors
- Exporter must extend HfExporter
- Unknown exporter type, got {name} - supported exporters are:
- Unsupported export config: {export_config_dict!r}. Registere
- {type(self).__name__} does not implement `export`. Pick a co
- Expected config to be a DynamoConfig or dict, got {type(conf
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/47262abe9f2aff71.
Report an issue: GitHub.