{"record":{"id":"d2f549ef0e5160b5","repo":"huggingface/transformers","slug":"expected-config-to-be-a-dynamoconfig-or-dict-got","errorCode":null,"errorMessage":"Expected config to be a DynamoConfig or dict, got {type(config)}","messagePattern":"Expected config to be a DynamoConfig or dict, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/exporter_dynamo.py","lineNumber":96,"sourceCode":"    >>> exported = exporter.export(model, inputs, config=DynamoConfig(dynamic=True))\n    >>> outputs = exported.module()(**inputs)\n    ```\n    \"\"\"\n\n    required_packages = [\"torch\"]\n    min_versions = {\"torch\": \"2.11.0\"}\n    tested_versions = {\"torch\": \"2.12.0\"}\n\n    def export(\n        self,\n        model: PreTrainedModel,\n        sample_inputs: MutableMapping[str, Any],\n        config: DynamoConfig | dict[str, Any],\n    ) -> ExportedProgram:\n        if isinstance(config, dict):\n            config = DynamoConfig(**config)\n        elif not isinstance(config, DynamoConfig):\n            raise TypeError(f\"Expected config to be a DynamoConfig or dict, got {type(config)}\")\n\n        model, sample_inputs, output_flags = prepare_for_export(model, sample_inputs)\n\n        dynamic_shapes = config.dynamic_shapes\n        if config.dynamic and dynamic_shapes is None:\n            logger.warning_once(\n                \"`dynamic=True` with no explicit `dynamic_shapes` marks every input axis `Dim.AUTO`, so \"\n                \"torch.export resolves symbolic shapes for all of them — including axes that are actually \"\n                \"fixed (batch, a size-1 decode step, num_heads/head_dim). Passing explicit `dynamic_shapes` \"\n                \"that mark only the axes which vary bypasses that symbolic-shape resolution and exports \"\n                \"significantly faster.\"\n            )\n            dynamic_shapes = get_auto_dynamic_shapes(sample_inputs)\n\n        register_cache_pytrees_for_model(model)\n\n        with (\n            apply_patches(\"dynamo\"),","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/exporter_dynamo.py#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting an ONNX example into a dynamo export; a dispatch layer that forwards one config object to every exporter regardless of backend.","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)."],"exampleFix":"# before\nDynamoExporter().export(model, inputs, config=OnnxConfig())  # TypeError\n\n# after\nfrom transformers.exporters.exporter_dynamo import DynamoConfig\nDynamoExporter().export(model, inputs, config=DynamoConfig(dynamic=True))","handlingStrategy":"type-guard","validationCode":"from transformers.exporters.exporter_dynamo import DynamoConfig\n\nif not isinstance(config, DynamoConfig):\n    config = DynamoConfig(**config)  # normalize dicts; anything else fails loudly here, not mid-export\nDynamoExporter().export(model, inputs, config)","typeGuard":"def is_dynamo_config_like(cfg) -> bool:\n    from transformers.exporters.exporter_dynamo import DynamoConfig\n    return isinstance(cfg, DynamoConfig) or isinstance(cfg, dict)","tryCatchPattern":null,"preventionTips":["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"],"tags":["export","dynamo","type-error","config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}