huggingface/transformers · error · ValueError

export_config_dict must contain key 'export_format' set to e

Error message

export_config_dict must contain key 'export_format' set to exporter name

What it means

AutoExportConfig.from_dict dispatches to the right exporter by reading the 'export_format' key of the supplied dict. If the key is absent (dict.get returns None), it raises ValueError — an export config without a format cannot be mapped to any exporter class.

Source

Thrown at src/transformers/exporters/auto.py:53

    "dynamo": DynamoConfig,
    "onnx": OnnxConfig,
}

logger = logging.get_logger(__name__)


class AutoExportConfig:
    """
    The Auto-HF export config class that takes care of automatically dispatching to the correct
    export config given an export config stored in a dictionary.
    """

    @classmethod
    def from_dict(cls, export_config_dict: dict):
        export_format = export_config_dict.get("export_format")

        if export_format is None:
            raise ValueError("export_config_dict must contain key 'export_format' set to exporter name")

        # Allow passing an ExportFormat enum value or a plain string
        if isinstance(export_format, ExportFormat):
            name = export_format.value
        else:
            name = export_format

        if name not in AUTO_EXPORT_CONFIG_MAPPING:
            raise ValueError(
                f"Unknown exporter type, got {name} - supported exporters are: {list(AUTO_EXPORT_CONFIG_MAPPING.keys())}"
            )

        target_cls = AUTO_EXPORT_CONFIG_MAPPING[name]
        return target_cls.from_dict(export_config_dict)


class AutoHfExporter:
    """

View on GitHub (pinned to a597f97485)

Solutions

  1. Add 'export_format' to the dict with a supported exporter name (a ExportFormat enum value or plain string, e.g. 'onnx').
  2. Prefer passing an ExportFormat enum (e.g. ExportFormat.ONNX) to avoid string typos.
  3. Use one of the names listed in AUTO_EXPORT_CONFIG_MAPPING; an unknown name raises the sibling error.

Example fix

# before
AutoExportConfig.from_dict({"per_channel": True})

# after
AutoExportConfig.from_dict({"export_format": "onnx", "per_channel": True})
Defensive patterns

Strategy: validation

Validate before calling

REQUIRED_KEY = "export_format"

def validate_export_config(cfg: dict) -> None:
    if REQUIRED_KEY not in cfg:
        raise ValueError(f"export config missing '{REQUIRED_KEY}'")

Type guard

def is_export_config_dict(cfg: object) -> bool:
    return isinstance(cfg, dict) and "export_format" in cfg

Try / catch

try:
    export_cfg = AutoExportConfig.from_dict(cfg)
except ValueError as e:
    if "export_format" in str(e):
        cfg = {"export_format": ExportFormat.ONNX, **cfg}
        export_cfg = AutoExportConfig.from_dict(cfg)
    else:
        raise

Prevention

When it happens

Trigger: Calling AutoExportConfig.from_dict({'per_channel': True, ...}) or passing a task-ish dict without 'export_format'; misspelling the key ('format', 'exporter').

Common situations: Building export configs programmatically and forgetting the key; copying a plain task dict where an export config dict is expected; key renamed between versions.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/251950bb42bbbeb9. Report an issue: GitHub.