sgl-project/sglang · critical · ImportError
Sparse Video Gen 2 attention backend requires svg package to
Error message
Sparse Video Gen 2 attention backend requires svg package to be installedPlease install it by following the instructions at https://github.com/svg-project/Sparse-VideoGen
What it means
The SVG2 backend is guarded by an availability check (svg2_available). If the optional 'svg' package (SparseVideoGen, github.com/svg-project/Sparse-VideoGen) is not installed, the constructor raises ImportError with install instructions.
Source
Thrown at python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py:199
class SparseVideoGen2AttentionImpl(AttentionImpl):
def __init__(
self,
num_heads: int,
head_size: int,
causal: bool,
softmax_scale: float,
num_kv_heads: int | None = None,
prefix: str = "",
**extra_impl_args,
) -> None:
if causal:
raise ValueError(
"Sparse Video Gen 2 attention does not support causal attention"
)
if not svg2_available:
raise ImportError(
"Sparse Video Gen 2 attention backend requires svg package to be installed"
"Please install it by following the instructions at "
"https://github.com/svg-project/Sparse-VideoGen"
)
self.prefix = prefix
self.layer_idx = self._get_layer_idx(prefix)
def _get_layer_idx(self, prefix: str) -> int:
parts = prefix.split(".")
if len(parts) < 3:
raise ValueError(
f"Invalid prefix for SparseVideoGen2AttentionImpl: {prefix}"
)
return int(parts[-3])
def kmeans_init(
self,
query: torch.Tensor,View on GitHub (pinned to 0132848349)
Solutions
- Install the svg package per https://github.com/svg-project/Sparse-VideoGen (usually pip install from the repo / provided wheel matching your CUDA+Torch version).
- If install claims it's present, test `import svg` in the same Python env — a failing import (missing .so, CUDA mismatch) also sets svg2_available=False; fix the underlying build issue.
- Fall back to a built-in attention backend (e.g. flashinfer/fa3) that doesn't need svg if you just need to run the model.
Example fix
# before: backend selected but svg missing -> ImportError # after pip install git+https://github.com/svg-project/Sparse-VideoGen.git python -c "import svg" # verify import works in the serving env
Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util
svg2_available = importlib.util.find_spec("svg") is not None
if not svg2_available:
# choose fallback backend or fail with a clear message before launch
backend = "flashinfer" Type guard
def svg2_installed() -> bool:
import importlib.util
return importlib.util.find_spec("svg") is not None Try / catch
try:
impl = SparseVideoGen2AttentionImpl(...)
except ImportError as e:
if "svg package" in str(e):
log.warning("svg missing; falling back to flashinfer attention")
impl = make_flashinfer_impl(...)
else:
raise Prevention
- Bake optional deps like svg into your Docker image and verify with `python -c 'import svg'` at container build time.
- Reinstall/rebuild svg wheels after CUDA or PyTorch upgrades.
- Make backend selection conditional on an availability probe instead of hardcoding svg2.
When it happens
Trigger: Selecting the SVG2 attention backend without having installed the svg package — e.g. --attention-backend svg2 on a fresh sglang install, or in a Docker image that only ships core dependencies.
Common situations: Fresh environments/CI images lacking optional deps; GPU/CUDA-specific svg build not compiled after a PyTorch or CUDA upgrade; the import of svg silently failing (which flips svg2_available to False) due to a missing shared library rather than the package itself.
Related errors
- Humming quantization requires `humming-kernels`. Please inst
- hf3fs_fuse.io is not available. Please install the hf3fs_fus
- LMCache is not installed. Please install it by running `pip
- Please install mooncake by following the instructions at htt
- The fastokens package is required when --tokenizer-backend=f
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/1ae8225584ce8aa4.
Report an issue: GitHub.