huggingface/transformers · error · TypeError
Expected config to be an ExecutorchConfig or dict, got {type
Error message
Expected config to be an ExecutorchConfig or dict, got {type(config)} What it means
ExecutorchExporter.export accepts config only as an ExecutorchConfig instance or a plain dict of its fields (converted via ExecutorchConfig(**config)); the check is strict (type(config) is not ExecutorchConfig), so even subclasses of ExecutorchConfig are rejected. Anything else raises this TypeError before backend preparation begins.
Source
Thrown at src/transformers/exporters/exporter_executorch.py:136
>>> et_program = exporter.export(model, inputs, config=ExecutorchConfig(backend="xnnpack"))
>>> et_program.write_to_file("model.pte")
```
"""
required_packages = ["torch", "executorch"]
tested_versions = {"torch": "2.12.0", "executorch": "1.3.1"}
def export(
self,
model: PreTrainedModel,
sample_inputs: MutableMapping[str, Any],
config: ExecutorchConfig | dict[str, Any],
) -> ExecutorchProgramManager:
"""Export a model to ExecuTorch, applying backend preparation and torch op patches."""
if isinstance(config, dict):
config = ExecutorchConfig(**config)
elif type(config) is not ExecutorchConfig:
raise TypeError(f"Expected config to be an ExecutorchConfig or dict, got {type(config)}")
prepare_for_backend = _BACKEND_PREPARE.get(config.backend)
if prepare_for_backend is None:
raise ValueError(f"Unsupported backend {config.backend} for ExecuTorch export")
model, sample_inputs, partitioner = prepare_for_backend(model, sample_inputs)
with apply_patches("executorch"), apply_patches(f"executorch.{config.backend}"):
exported_program: ExportedProgram = super().export(model, sample_inputs, config=config)
apply_fx_program_fixes("executorch", exported_program)
apply_fx_node_fixes("executorch", exported_program.graph_module)
edge_program_manager: EdgeProgramManager = to_edge_transform_and_lower(
exported_program, partitioner=partitioner, compile_config=_get_edge_compile_config()
)
executorch_programs_manager: ExecutorchProgramManager = edge_program_manager.to_executorch(
config=_get_backend_config(config)
)
View on GitHub (pinned to a597f97485)
Solutions
- Pass an ExecutorchConfig: ExecutorchExporter().export(model, inputs, config=ExecutorchConfig(backend="xnnpack")).
- For extra/custom fields, pass a dict: config={"backend": "xnnpack", ...my_extra_fields} — dicts are splatted into the constructor.
- Verify with type(config) is ExecutorchConfig before the call if dispatching dynamically.
Example fix
# before ExecutorchExporter().export(model, inputs, config=DynamoConfig()) # TypeError # after from transformers.exporters.exporter_executorch import ExecutorchConfig ExecutorchExporter().export(model, inputs, config=ExecutorchConfig(backend="xnnpack"))
Defensive patterns
Strategy: type-guard
Validate before calling
from transformers.exporters.exporter_executorch import ExecutorchConfig
if type(config) is not ExecutorchConfig:
config = ExecutorchConfig(**config) # dicts OK; subclasses/other types are rejected by the exporter
ExecutorchExporter().export(model, inputs, config) Type guard
def is_executorch_config_like(cfg) -> bool:
from transformers.exporters.exporter_executorch import ExecutorchConfig
return type(cfg) is ExecutorchConfig or isinstance(cfg, dict) Prevention
- Note the exact-type check: subclassing ExecutorchConfig is not allowed — extend via dicts
- Pair each exporter with its own config class in one helper function to avoid mix-ups
When it happens
Trigger: Passing a DynamoConfig or OnnxConfig to ExecutorchExporter.export; passing a subclass of ExecutorchConfig; passing a string/None/path in the config slot.
Common situations: Reusing one config object across backends in a multi-format export script; extending ExecutorchConfig with extra fields via subclassing (blocked by the exact-type check — use a dict instead).
Related errors
- Expected config to be a DynamoConfig or dict, got {type(conf
- Unsupported backend {config.backend} for ExecuTorch export
- Expected config to be an OnnxConfig or dict, got {type(confi
- out_indices must be a list, got {type(self._out_indices)}
- You can only update int, float, bool or string values in the
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/6e7ea4c8f2673c39.
Report an issue: GitHub.