{"record":{"id":"804c2bb4ada74850","repo":"huggingface/transformers","slug":"expected-config-to-be-an-onnxconfig-or-dict-got","errorCode":null,"errorMessage":"Expected config to be an OnnxConfig or dict, got {type(config)}","messagePattern":"Expected config to be an OnnxConfig or dict, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/exporter_onnx.py","lineNumber":114,"sourceCode":"    >>> onnx_program = exporter.export(model, inputs, config=OnnxConfig(dynamic=True))\n    >>> outputs = onnx_program(**inputs)  # run in-memory\n    >>> exporter.export(model, inputs, config=OnnxConfig(output_path=\"model.onnx\"))  # save to disk\n    ```\n    \"\"\"\n\n    required_packages = [\"torch\", \"onnx\", \"onnxscript\"]\n    tested_versions = {\"torch\": \"2.12.0\", \"onnx\": \"1.21.0\", \"onnxscript\": \"0.7.0\"}\n\n    def export(\n        self,\n        model: PreTrainedModel,\n        sample_inputs: MutableMapping[str, Any],\n        config: OnnxConfig | dict[str, Any],\n    ) -> ONNXProgram:\n        if isinstance(config, dict):\n            config = OnnxConfig(**config)\n        elif type(config) is not OnnxConfig:\n            raise TypeError(f\"Expected config to be an OnnxConfig or dict, got {type(config)}\")\n\n        with patch_model_outputs(model) as (inputs_names, outputs_names), apply_patches(\"onnx\"):\n            exported_program: ExportedProgram = super().export(model, sample_inputs, config=config)\n            inputs_names, outputs_names = disambiguate_io_names(inputs_names, outputs_names)\n            apply_fx_node_fixes(\"onnx\", exported_program.graph_module)\n            onnx_program: ONNXProgram = torch.onnx.export(\n                exported_program,\n                args=(),\n                f=config.output_path,\n                input_names=inputs_names,\n                output_names=outputs_names,\n                kwargs=copy.deepcopy(dict(sample_inputs)),\n                custom_translation_table=_ONNX_TRANSLATION_TABLE,\n                opset_version=config.opset_version,\n                external_data=config.external_data,\n                export_params=config.export_params,\n                optimize=config.optimize,\n            )","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/exporter_onnx.py#L96-L132","documentation":"OnnxExporter.export accepts config only as an OnnxConfig instance or a plain dict of its fields (converted via OnnxConfig(**config)); the check is an exact-type check, so subclasses of OnnxConfig are rejected too. Anything else raises this TypeError before the ONNX translation pipeline starts.","triggerScenarios":"Passing DynamoConfig or ExecutorchConfig to OnnxExporter.export; passing a subclass of OnnxConfig with extra fields; passing config=None or a file path string.","commonSituations":"A multi-backend export loop forwarding one config to all exporters; subclassing OnnxConfig to add fields (must use a dict instead); swapping exporters in existing code without swapping the config.","solutions":["Pass an OnnxConfig: OnnxExporter().export(model, inputs, config=OnnxConfig(output_path=\"model.onnx\")).","For custom/extra fields pass a dict: config={\"output_path\": \"model.onnx\", ...extras}.","If dispatching by format, build the per-format config class (or use AutoHfExporter.from_config)."],"exampleFix":"# before\nOnnxExporter().export(model, inputs, config=DynamoConfig())  # TypeError\n\n# after\nfrom transformers.exporters.exporter_onnx import OnnxConfig\nOnnxExporter().export(model, inputs, config=OnnxConfig(output_path=\"model.onnx\"))","handlingStrategy":"type-guard","validationCode":"from transformers.exporters.exporter_onnx import OnnxConfig\n\nif type(config) is not OnnxConfig:\n    config = OnnxConfig(**config)\nOnnxExporter().export(model, inputs, config)","typeGuard":"def is_onnx_config_like(cfg) -> bool:\n    from transformers.exporters.exporter_onnx import OnnxConfig\n    return type(cfg) is OnnxConfig or isinstance(cfg, dict)","tryCatchPattern":null,"preventionTips":["Exact-type check: OnnxConfig subclasses are rejected — pass extra options as a dict","Keep one config-builder function per backend so exporter/config pairs never cross"],"tags":["export","onnx","type-error","config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}