{"record":{"id":"c0035231b0752342","repo":"huggingface/transformers","slug":"unsupported-backend-config-backend-for-executorc","errorCode":null,"errorMessage":"Unsupported backend {config.backend} for ExecuTorch export","messagePattern":"Unsupported backend (.+?) for ExecuTorch export","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/exporter_executorch.py","lineNumber":140,"sourceCode":"\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\n        return executorch_programs_manager\n\n\ndef _get_edge_compile_config() -> EdgeCompileConfig:","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/exporter_executorch.py#L122-L158","documentation":"ExecutorchExporter.export looks up config.backend in the _BACKEND_PREPARE registry (which maps backend names to preparation functions; 'xnnpack' and 'cuda' are the shipped entries). An unknown backend name has no preparation/partitioner pipeline, so the export is rejected immediately with this ValueError.","triggerScenarios":"Setting ExecutorchConfig(backend=\"coreml\"), \"qnn\", \"mps\", \"vulkan\", or any typo like \"XNNPACK\" (case-sensitive) — no prepare function exists for it.","commonSituations":"Porting an ExecuTorch tutorial that targets a backend transformers does not ship prepare hooks for; casing mismatches; assuming every executorch backend from the upstream delegate list is supported.","solutions":["Use a shipped backend: backend=\"xnnpack\" (CPU) or backend=\"cuda\" (GPU via AOTInductor).","Check spelling/case — keys are lowercase in _BACKEND_PREPARE.","For an unshipped backend, export with DynamoExporter first and lower to your backend with the raw torch.export/ExecuTorch API, or contribute a prepare function and extend _BACKEND_PREPARE."],"exampleFix":"# before\nExecutorchConfig(backend=\"XNNPACK\")  # ValueError: Unsupported backend\n\n# after\nExecutorchConfig(backend=\"xnnpack\")","handlingStrategy":"validation","validationCode":"from transformers.exporters.exporter_executorch import _BACKEND_PREPARE\n\nbackend = cfg.get(\"backend\", \"xnnpack\") if isinstance(cfg, dict) else cfg.backend\nif backend not in _BACKEND_PREPARE:\n    raise SystemExit(f\"backend must be one of {sorted(_BACKEND_PREPARE)}, got {backend!r}\")","typeGuard":"def is_supported_executorch_backend(backend: str) -> bool:\n    from transformers.exporters.exporter_executorch import _BACKEND_PREPARE\n    return backend in _BACKEND_PREPARE","tryCatchPattern":"try:\n    ExecutorchExporter().export(model, inputs, cfg)\nexcept ValueError as e:\n    if \"Unsupported backend\" in str(e):\n        cfg = ExecutorchConfig(**{**vars(cfg) if hasattr(cfg, \"__dict__\") else cfg, \"backend\": \"xnnpack\"})\n        ExecutorchExporter().export(model, inputs, cfg)  # fall back to CPU backend\n    else:\n        raise","preventionTips":["Read supported backends from _BACKEND_PREPARE instead of upstream ExecuTorch docs","Backend names are lowercase strings; validate user-supplied backend names at your CLI boundary"],"tags":["export","executorch","backend","config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}