{"record":{"id":"f83272bc76c079dd","repo":"hiyouga/LlamaFactory","slug":"sglang-not-install-you-may-need-to-run-pip-insta","errorCode":null,"errorMessage":"SGLang not install, you may need to run `pip install sglang[all]`\nor try to use HuggingFace backend: --infer_backend huggingface","messagePattern":"SGLang not install, you may need to run `pip install sglang\\[all\\]`\nor try to use HuggingFace backend: --infer_backend huggingface","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/chat/chat_model.py","lineNumber":70,"sourceCode":"\n            self.engine: BaseEngine = HuggingfaceEngine(model_args, data_args, finetuning_args, generating_args)\n        elif model_args.infer_backend == EngineName.VLLM:\n            try:\n                from .vllm_engine import VllmEngine\n\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,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/chat/chat_model.py#L52-L88","documentation":"ImportError raised by ChatModel.__init__ when infer_backend is sglang but importing SGLangEngine fails. SGLang is an optional dependency; the original ImportError is chained. The message directs you to install sglang[all] or switch to the HuggingFace backend.","triggerScenarios":"ChatModel(...) / CLI chat with --infer_backend sglang where the sglang package is missing or its import fails (missing CUDA kernels, dependency conflicts).","commonSituations":"Skipping the sglang extra during install; mixing sglang with an incompatible torch or transformers version; CPU-only environments.","solutions":["Install sglang with extras: pip install 'sglang[all]' matching this repo's pinned requirements.","Or use --infer_backend huggingface to proceed without sglang.","Reproduce the underlying failure: `python -c \"from llamafactory.chat.sglang_engine import SGLangEngine\"`.","Check sglang's CUDA/flashinfer prerequisites on your driver version."],"exampleFix":"# before\nChatModel({...,'infer_backend': 'sglang'})  # sglang not installed\n# after\npip install 'sglang[all]'\n# or\nChatModel({...,'infer_backend': 'huggingface'})","handlingStrategy":"fallback","validationCode":"def sglang_importable():\n    try:\n        import sglang  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nbackend = \"sglang\" if sglang_importable() else \"huggingface\"","typeGuard":null,"tryCatchPattern":"try { model = ChatModel({..., 'infer_backend': 'sglang'}) } except ImportError as e: if 'SGLang not install' in str(e): model = ChatModel({..., 'infer_backend': 'huggingface'}) else: raise","preventionTips":["Detect sglang availability before selecting the backend.","Install sglang[all] with the repo's pinned versions.","Smoke-test engine construction at deploy time, not first request."],"tags":["installation","sglang","backend","import-error","inference"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}