{"record":{"id":"1ae8225584ce8aa4","repo":"sgl-project/sglang","slug":"sparse-video-gen-2-attention-backend-requires-svg","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py","lineNumber":199,"sourceCode":"\nclass SparseVideoGen2AttentionImpl(AttentionImpl):\n\n    def __init__(\n        self,\n        num_heads: int,\n        head_size: int,\n        causal: bool,\n        softmax_scale: float,\n        num_kv_heads: int | None = None,\n        prefix: str = \"\",\n        **extra_impl_args,\n    ) -> None:\n        if causal:\n            raise ValueError(\n                \"Sparse Video Gen 2 attention does not support causal attention\"\n            )\n        if not svg2_available:\n            raise ImportError(\n                \"Sparse Video Gen 2 attention backend requires svg package to be installed\"\n                \"Please install it by following the instructions at \"\n                \"https://github.com/svg-project/Sparse-VideoGen\"\n            )\n        self.prefix = prefix\n        self.layer_idx = self._get_layer_idx(prefix)\n\n    def _get_layer_idx(self, prefix: str) -> int:\n        parts = prefix.split(\".\")\n        if len(parts) < 3:\n            raise ValueError(\n                f\"Invalid prefix for SparseVideoGen2AttentionImpl: {prefix}\"\n            )\n        return int(parts[-3])\n\n    def kmeans_init(\n        self,\n        query: torch.Tensor,","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py#L181-L217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: backend selected but svg missing -> ImportError\n# after\npip install git+https://github.com/svg-project/Sparse-VideoGen.git\npython -c \"import svg\"  # verify import works in the serving env","handlingStrategy":"try-catch","validationCode":"import importlib.util\nsvg2_available = importlib.util.find_spec(\"svg\") is not None\nif not svg2_available:\n    # choose fallback backend or fail with a clear message before launch\n    backend = \"flashinfer\"","typeGuard":"def svg2_installed() -> bool:\n    import importlib.util\n    return importlib.util.find_spec(\"svg\") is not None","tryCatchPattern":"try:\n    impl = SparseVideoGen2AttentionImpl(...)\nexcept ImportError as e:\n    if \"svg package\" in str(e):\n        log.warning(\"svg missing; falling back to flashinfer attention\")\n        impl = make_flashinfer_impl(...)\n    else:\n        raise","preventionTips":["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."],"tags":["missing-dependency","installation","attention-backend","optional-package"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}