{"record":{"id":"6e7ea4c8f2673c39","repo":"huggingface/transformers","slug":"expected-config-to-be-an-executorchconfig-or-dict","errorCode":null,"errorMessage":"Expected config to be an ExecutorchConfig or dict, got {type(config)}","messagePattern":"Expected config to be an ExecutorchConfig or dict, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/exporter_executorch.py","lineNumber":136,"sourceCode":"    >>> et_program = exporter.export(model, inputs, config=ExecutorchConfig(backend=\"xnnpack\"))\n    >>> et_program.write_to_file(\"model.pte\")\n    ```\n    \"\"\"\n\n    required_packages = [\"torch\", \"executorch\"]\n    tested_versions = {\"torch\": \"2.12.0\", \"executorch\": \"1.3.1\"}\n\n    def export(\n        self,\n        model: PreTrainedModel,\n        sample_inputs: MutableMapping[str, Any],\n        config: ExecutorchConfig | dict[str, Any],\n    ) -> ExecutorchProgramManager:\n        \"\"\"Export a model to ExecuTorch, applying backend preparation and torch op patches.\"\"\"\n        if isinstance(config, dict):\n            config = ExecutorchConfig(**config)\n        elif type(config) is not ExecutorchConfig:\n            raise TypeError(f\"Expected config to be an ExecutorchConfig or dict, got {type(config)}\")\n\n        prepare_for_backend = _BACKEND_PREPARE.get(config.backend)\n        if prepare_for_backend is None:\n            raise ValueError(f\"Unsupported backend {config.backend} for ExecuTorch export\")\n\n        model, sample_inputs, partitioner = prepare_for_backend(model, sample_inputs)\n\n        with apply_patches(\"executorch\"), apply_patches(f\"executorch.{config.backend}\"):\n            exported_program: ExportedProgram = super().export(model, sample_inputs, config=config)\n            apply_fx_program_fixes(\"executorch\", exported_program)\n            apply_fx_node_fixes(\"executorch\", exported_program.graph_module)\n            edge_program_manager: EdgeProgramManager = to_edge_transform_and_lower(\n                exported_program, partitioner=partitioner, compile_config=_get_edge_compile_config()\n            )\n            executorch_programs_manager: ExecutorchProgramManager = edge_program_manager.to_executorch(\n                config=_get_backend_config(config)\n            )\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/exporter_executorch.py#L118-L154","documentation":"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.","triggerScenarios":"Passing a DynamoConfig or OnnxConfig to ExecutorchExporter.export; passing a subclass of ExecutorchConfig; passing a string/None/path in the config slot.","commonSituations":"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).","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."],"exampleFix":"# before\nExecutorchExporter().export(model, inputs, config=DynamoConfig())  # TypeError\n\n# after\nfrom transformers.exporters.exporter_executorch import ExecutorchConfig\nExecutorchExporter().export(model, inputs, config=ExecutorchConfig(backend=\"xnnpack\"))","handlingStrategy":"type-guard","validationCode":"from transformers.exporters.exporter_executorch import ExecutorchConfig\n\nif type(config) is not ExecutorchConfig:\n    config = ExecutorchConfig(**config)  # dicts OK; subclasses/other types are rejected by the exporter\nExecutorchExporter().export(model, inputs, config)","typeGuard":"def is_executorch_config_like(cfg) -> bool:\n    from transformers.exporters.exporter_executorch import ExecutorchConfig\n    return type(cfg) is ExecutorchConfig or isinstance(cfg, dict)","tryCatchPattern":null,"preventionTips":["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"],"tags":["export","executorch","type-error","config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}