{"record":{"id":"6fd4f81adc515a1d","repo":"sgl-project/sglang","slug":"petit-is-not-installed-please-install-it-with-pi","errorCode":null,"errorMessage":"Petit is not installed. Please install it with `pip install petit-kernel`.","messagePattern":"Petit is not installed\\. Please install it with `pip install petit-kernel`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/layers/quantization/petit_utils.py","lineNumber":18,"sourceCode":"from typing import Optional\n\nimport torch\n\ntry:\n    from petit_kernel import mul_nvfp4_a16, process_nvfp4_scales, repack_nvfp4\nexcept ImportError:\n\n    def _check_petit_nvfp4_supported(\n        quant_method: str, group_size: Optional[int]\n    ) -> tuple[bool, Optional[str]]:\n        return (\n            False,\n            \"Petit is not installed. Please install it with `pip install petit-kernel`.\",\n        )\n\n    def prepare_nvfp4_layer_for_petit(layer: torch.nn.Module) -> None:\n        raise ValueError(\n            \"Petit is not installed. Please install it with `pip install petit-kernel`.\"\n        )\n\n    def apply_petit_nvfp4_linear(\n        input: torch.Tensor,\n        weight: torch.Tensor,\n        weight_scale: torch.Tensor,\n        weight_scale_2: torch.Tensor,\n        size_n: int,\n        size_k: int,\n        bias: Optional[torch.Tensor] = None,\n    ) -> torch.Tensor:\n        raise ValueError(\n            \"Petit is not installed. Please install it with `pip install petit-kernel`.\"\n        )\n\n\ndef _check_petit_nvfp4_supported(","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/petit_utils.py#L1-L36","documentation":"This ValueError is raised by the stub implementation of prepare_nvfp4_layer_for_petit that exists when the optional petit-kernel package is not installed. petit_utils.py guards all Petit NVFP4 code paths behind an import check and provides no-op/failing fallbacks, so calling the prepare function without the dependency immediately fails. It exists to make Petit an optional acceleration dependency.","triggerScenarios":"Calling prepare_nvfp4_layer_for_petit(layer) (directly or via a quantization config that enables Petit for NVFP4 layers) in an environment where `import petit_kernel` failed, i.e. petit-kernel is not pip-installed in the active Python/venv.","commonSituations":"Enabling Petit NVFP4 acceleration in sglang without installing petit-kernel; running in a container or venv missing the optional dependency; version upgrades where the dependency became optional; wrong Python environment (installed into a different interpreter than the one running the server).","solutions":["pip install petit-kernel into the same environment that runs sglang, then retry.","Verify with `python -c \"import petit_kernel\"` using the exact interpreter/venv used by the sglang server.","If Petit is not intended, disable the Petit path in your quantization/server args so prepare_nvfp4_layer_for_petit is never invoked.","Check for GPU/architecture requirements of petit-kernel if the install itself fails, and install a build matching your CUDA/torch version."],"exampleFix":"# before\nsglang server launched with petit NVFP4 path enabled; no petit-kernel installed -> ValueError\n\n# after\npip install petit-kernel\npython -c \"import petit_kernel; print(petit_kernel.__version__)\"","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"petit_kernel\") is None:\n    raise RuntimeError(\"petit-kernel not installed; run: pip install petit-kernel or disable Petit\")\nprepare_nvfp4_layer_for_petit(layer)","typeGuard":"def petit_available() -> bool:\n    return importlib.util.find_spec(\"petit_kernel\") is not None","tryCatchPattern":null,"preventionTips":["Check `python -c \"import petit_kernel\"` in the exact venv the server runs in before enabling Petit.","Pin petit-kernel in the same requirements set as other GPU kernel deps.","Make Petit opt-in via a flag validated at startup rather than silently enabled."],"tags":["quantization","nvfp4","petit","missing-dependency","python"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}