sgl-project/sglang · error · ValueError
Petit is not installed. Please install it with `pip install
Error message
Petit is not installed. Please install it with `pip install petit-kernel`.
What it means
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.
Source
Thrown at python/sglang/srt/layers/quantization/petit_utils.py:18
from typing import Optional
import torch
try:
from petit_kernel import mul_nvfp4_a16, process_nvfp4_scales, repack_nvfp4
except ImportError:
def _check_petit_nvfp4_supported(
quant_method: str, group_size: Optional[int]
) -> tuple[bool, Optional[str]]:
return (
False,
"Petit is not installed. Please install it with `pip install petit-kernel`.",
)
def prepare_nvfp4_layer_for_petit(layer: torch.nn.Module) -> None:
raise ValueError(
"Petit is not installed. Please install it with `pip install petit-kernel`."
)
def apply_petit_nvfp4_linear(
input: torch.Tensor,
weight: torch.Tensor,
weight_scale: torch.Tensor,
weight_scale_2: torch.Tensor,
size_n: int,
size_k: int,
bias: Optional[torch.Tensor] = None,
) -> torch.Tensor:
raise ValueError(
"Petit is not installed. Please install it with `pip install petit-kernel`."
)
def _check_petit_nvfp4_supported(View on GitHub (pinned to 0132848349)
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.
Example fix
# before sglang server launched with petit NVFP4 path enabled; no petit-kernel installed -> ValueError # after pip install petit-kernel python -c "import petit_kernel; print(petit_kernel.__version__)"
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("petit_kernel") is None:
raise RuntimeError("petit-kernel not installed; run: pip install petit-kernel or disable Petit")
prepare_nvfp4_layer_for_petit(layer) Type guard
def petit_available() -> bool:
return importlib.util.find_spec("petit_kernel") is not None Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- {error_msg}
- Online MXFP4 requantization from compressed-tensors NVFP4 ch
- MIXED_PRECISION checkpoint has no NVFP4 layers to requantize
- Type must match: {self.a_dtype} != {self.b_dtype}
- nvfp4_gemm_swiglu_nvfp4_quant currently supports NVFP4 input
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/6fd4f81adc515a1d.
Report an issue: GitHub.