huggingface/transformers · error · TypeError
Expected config to be a DynamoConfig or dict, got {type(conf
Error message
Expected config to be a DynamoConfig or dict, got {type(config)} What it means
DynamoExporter.export accepts config only as a DynamoConfig instance or as a plain dict of its fields (which it converts via DynamoConfig(**config)). Any other type — an OnnxConfig/ExecutorchConfig, a string, None — raises this TypeError before any tracing starts.
Source
Thrown at src/transformers/exporters/exporter_dynamo.py:96
>>> exported = exporter.export(model, inputs, config=DynamoConfig(dynamic=True))
>>> outputs = exported.module()(**inputs)
```
"""
required_packages = ["torch"]
min_versions = {"torch": "2.11.0"}
tested_versions = {"torch": "2.12.0"}
def export(
self,
model: PreTrainedModel,
sample_inputs: MutableMapping[str, Any],
config: DynamoConfig | dict[str, Any],
) -> ExportedProgram:
if isinstance(config, dict):
config = DynamoConfig(**config)
elif not isinstance(config, DynamoConfig):
raise TypeError(f"Expected config to be a DynamoConfig or dict, got {type(config)}")
model, sample_inputs, output_flags = prepare_for_export(model, sample_inputs)
dynamic_shapes = config.dynamic_shapes
if config.dynamic and dynamic_shapes is None:
logger.warning_once(
"`dynamic=True` with no explicit `dynamic_shapes` marks every input axis `Dim.AUTO`, so "
"torch.export resolves symbolic shapes for all of them — including axes that are actually "
"fixed (batch, a size-1 decode step, num_heads/head_dim). Passing explicit `dynamic_shapes` "
"that mark only the axes which vary bypasses that symbolic-shape resolution and exports "
"significantly faster."
)
dynamic_shapes = get_auto_dynamic_shapes(sample_inputs)
register_cache_pytrees_for_model(model)
with (
apply_patches("dynamo"),View on GitHub (pinned to a597f97485)
Solutions
- Pass a DynamoConfig: DynamoExporter().export(model, inputs, config=DynamoConfig(dynamic=True)).
- Or pass its fields as a dict: config={"dynamic": True, "dynamic_shapes": {...}}.
- If dispatching by backend, build the matching config class per exporter (or use AutoHfExporter.from_config).
Example fix
# before DynamoExporter().export(model, inputs, config=OnnxConfig()) # TypeError # after from transformers.exporters.exporter_dynamo import DynamoConfig DynamoExporter().export(model, inputs, config=DynamoConfig(dynamic=True))
Defensive patterns
Strategy: type-guard
Validate before calling
from transformers.exporters.exporter_dynamo import DynamoConfig
if not isinstance(config, DynamoConfig):
config = DynamoConfig(**config) # normalize dicts; anything else fails loudly here, not mid-export
DynamoExporter().export(model, inputs, config) Type guard
def is_dynamo_config_like(cfg) -> bool:
from transformers.exporters.exporter_dynamo import DynamoConfig
return isinstance(cfg, DynamoConfig) or isinstance(cfg, dict) Prevention
- Construct the config class that matches the exporter class in the same line of code
- Centralize backend dispatch through AutoHfExporter.from_config so mismatches cannot happen
When it happens
Trigger: Passing OnnxConfig or ExecutorchConfig to DynamoExporter.export; passing config=None expecting defaults; passing a config dataclass from a custom backend; mixing up kwargs order so another object lands in the config slot.
Common situations: Copy-pasting an ONNX example into a dynamo export; a dispatch layer that forwards one config object to every exporter regardless of backend.
Related errors
- Expected config to be an ExecutorchConfig or dict, got {type
- 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
- Can only set a dictionary as `pp_plan`
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/d2f549ef0e5160b5.
Report an issue: GitHub.