{"record":{"id":"67a2b6a9cbe30113","repo":"hiyouga/LlamaFactory","slug":"unknown-backend-model-args-infer-backend","errorCode":null,"errorMessage":"Unknown backend: {model_args.infer_backend}","messagePattern":"Unknown backend: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/chat/chat_model.py","lineNumber":75,"sourceCode":"\n                self.engine: BaseEngine = VllmEngine(model_args, data_args, finetuning_args, generating_args)\n            except ImportError as e:\n                raise ImportError(\n                    \"vLLM not install, you may need to run `pip install vllm`\\n\"\n                    \"or try to use HuggingFace backend: --infer_backend huggingface\"\n                ) from e\n        elif model_args.infer_backend == EngineName.SGLANG:\n            try:\n                from .sglang_engine import SGLangEngine\n\n                self.engine: BaseEngine = SGLangEngine(model_args, data_args, finetuning_args, generating_args)\n            except ImportError as e:\n                raise ImportError(\n                    \"SGLang not install, you may need to run `pip install sglang[all]`\\n\"\n                    \"or try to use HuggingFace backend: --infer_backend huggingface\"\n                ) from e\n        else:\n            raise NotImplementedError(f\"Unknown backend: {model_args.infer_backend}\")\n\n        self._loop = asyncio.new_event_loop()\n        self._thread = Thread(target=_start_background_loop, args=(self._loop,), daemon=True)\n        self._thread.start()\n\n    def chat(\n        self,\n        messages: list[dict[str, str]],\n        system: Optional[str] = None,\n        tools: Optional[str] = None,\n        images: Optional[list[\"ImageInput\"]] = None,\n        videos: Optional[list[\"VideoInput\"]] = None,\n        audios: Optional[list[\"AudioInput\"]] = None,\n        **input_kwargs,\n    ) -> list[\"Response\"]:\n        r\"\"\"Get a list of responses of the chat model.\"\"\"\n        task = asyncio.run_coroutine_threadsafe(\n            self.achat(messages, system, tools, images, videos, audios, **input_kwargs), self._loop","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/chat/chat_model.py#L57-L93","documentation":"NotImplementedError raised by ChatModel.__init__ when model_args.infer_backend matches none of the supported engines (huggingface, vllm, sglang). Typically the result of a typo or a config value from a different version's enum.","triggerScenarios":"infer_backend set to 'vllm ' (trailing space), 'VLLM' (wrong case — note the enum comparison is exact), 'tensorrt', or any string not in EngineName; YAML configs copied from newer/older docs with backend names this version does not know.","commonSituations":"Hand-edited YAML typos; enum value drift across LlamaFactory versions; programmatic configs injecting unvalidated strings.","solutions":["Set infer_backend to one of: 'huggingface', 'vllm', 'sglang' (exact lowercase as defined in EngineName).","Check src/llamafactory/extras/constants.py EngineName for the accepted values in your installed version.","Trim/normalize config strings (strip whitespace, lowercase) before building ChatModel."],"exampleFix":"# before\nChatModel({..., 'infer_backend': 'VLLM'})\n# after\nChatModel({..., 'infer_backend': 'vllm'})","handlingStrategy":"type-guard","validationCode":"VALID_BACKENDS = {\"huggingface\", \"vllm\", \"sglang\"}\nassert args[\"infer_backend\"] in VALID_BACKENDS, f\"pick from {VALID_BACKENDS}\"","typeGuard":"const VALID = new Set(['huggingface', 'vllm', 'sglang']);\nconst isValidBackend = (b) => VALID.has(b);","tryCatchPattern":"try { ChatModel(cfg) } catch (e) { if (e instanceof NotImplementedError && e.message.startsWith('Unknown backend')) { cfg.infer_backend = 'huggingface'; return ChatModel(cfg); } throw e; }","preventionTips":["Normalize backend strings (strip + lowercase) at config load time.","Validate config against the installed version's EngineName enum.","Fail config parsing with a helpful message before constructing ChatModel."],"tags":["configuration","backend","enum","validation"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}