{"record":{"id":"86c4f4d05d229bff","repo":"sgl-project/sglang","slug":"sparse-video-gen-2-attention-does-not-support-caus","errorCode":null,"errorMessage":"Sparse Video Gen 2 attention does not support causal attention","messagePattern":"Sparse Video Gen 2 attention does not support causal attention","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py","lineNumber":195,"sourceCode":"            frame_size=frame_size,\n            cache=cache,\n        )\n\n\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])","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sparse_video_gen_2_attn.py#L177-L213","documentation":"SparseVideoGen2AttentionImpl is a bidirectional (non-causal) attention used in video DiT backbones. Its constructor explicitly rejects causal=True because the SVG2 kernel/metadata only supports full (non-causal) attention over tokens.","triggerScenarios":"Constructing SparseVideoGen2AttentionImpl with causal=True — typically because a generic attention factory passes the model's causal flag through to every backend, or a config copied from a causal LM/text model.","commonSituations":"Wiring the SVG2 backend into a shared attention-creation path that defaults causal=True for most layers; using a text-model attention config template for a video DiT; misunderstanding that DiT double/single-stream blocks use bidirectional attention.","solutions":["Pass causal=False (or omit the causal flag) when instantiating this backend — video DiT blocks are bidirectional.","In a shared factory, only select the SVG2 backend for non-causal layers and route causal layers to a flash/fa3-style backend.","Audit the layer config that forwards the causal flag and correct it for the video backbone."],"exampleFix":"# before\nimpl = SparseVideoGen2AttentionImpl(..., causal=True, ...)\n\n# after\nimpl = SparseVideoGen2AttentionImpl(..., causal=False, ...)","handlingStrategy":"validation","validationCode":"assert not causal, \"SVG2 attention is bidirectional only\"\nimpl = SparseVideoGen2AttentionImpl(..., causal=False, ...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In attention factories, route causal layers away from SVG2 explicitly.","Keep video-DiT layer configs separate from text LM configs.","Add a unit test asserting the backend is only created with causal=False."],"tags":["causal-mask","attention-backend","config"],"backgroundTag":"unsupported-argument-combination","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}