{"record":{"id":"a947857bdc4c9c23","repo":"sgl-project/sglang","slug":"type-self-name-does-not-implement-ring-kv-c","errorCode":null,"errorMessage":"{type(self).__name__} does not implement ring KV-chunk attention","messagePattern":"(.+?) does not implement ring KV-chunk attention","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/attention_backend.py","lineNumber":223,"sourceCode":"        max_seqlen: int,\n        cu_seqlens_host: tuple[int, ...] | None = None,\n    ) -> torch.Tensor:\n        raise NotImplementedError(\n            f\"{type(self).__name__} does not implement packed varlen attention\"\n        )\n\n    def forward_ring_kv_chunk(\n        self,\n        query: torch.Tensor,\n        key: torch.Tensor,\n        value: torch.Tensor,\n    ) -> tuple[torch.Tensor, torch.Tensor]:\n        \"\"\"Attend local queries to one rotated KV chunk for ring merging.\n\n        Inputs use packed ``[T, H, D]`` layout. The returned attention output\n        has the query shape and softmax LSE uses ``[H, Tq]`` layout.\n        \"\"\"\n        raise NotImplementedError(\n            f\"{type(self).__name__} does not implement ring KV-chunk attention\"\n        )\n\n\ndef wrap_attention_impl_forward(attn_impl: AttentionImpl) -> AttentionImpl:\n    return wrap_method_with_debug_kernel_once(\n        attn_impl,\n        \"forward\",\n        op_name=f\"diffusion.attn_impl.{attn_impl.__class__.__name__}.forward\",\n    )\n","sourceCodeStart":205,"sourceCodeEnd":234,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/attention_backend.py#L205-L234","documentation":"AttentionBackend.forward_ring_kv_chunk is the abstract hook for one-rotated-KV-chunk attention used by ring-attention KV merging; it must return (output [Tq,H,D], lse [H,Tq]). Backends without ring support raise NotImplementedError explicitly.","triggerScenarios":"Running _ring_attention_varlen with a backend that does not override forward_ring_kv_chunk, e.g. sage_attn3, sliding_tile, or a custom backend.","commonSituations":"Enabling ring/context-parallel attention on a configuration whose backend only supports local attention; an SGLang upgrade making ring merge the default path for a backend that never implemented it.","solutions":["Use a backend that implements ring KV-chunk attention (the flash_attn path with return_softmax_lse=True) for layers in ring merging","Disable ring attention / context-parallel KV merging for this backend in server args","Implement forward_ring_kv_chunk returning (output, lse[H, Tq]) if you own the backend"],"exampleFix":"# before\nout, lse = backend.forward_ring_kv_chunk(q, k_chunk, v_chunk)  # NotImplementedError\n# after\nif type(backend).forward_ring_kv_chunk is AttentionBackend.forward_ring_kv_chunk:\n    raise SystemExit(f\"{type(backend).__name__} cannot run ring attention; use flash_attn backend\")\nout, lse = backend.forward_ring_kv_chunk(q, k_chunk, v_chunk)","handlingStrategy":"type-guard","validationCode":"def supports_ring(backend) -> bool:\n    return type(backend).forward_ring_kv_chunk is not AttentionBackend.forward_ring_kv_chunk","typeGuard":"def implements_ring_kv_chunk(b: AttentionBackend) -> bool:\n    return type(b).forward_ring_kv_chunk is not AttentionBackend.forward_ring_kv_chunk","tryCatchPattern":"try:\n    out, lse = backend.forward_ring_kv_chunk(q, kc, vc)\nexcept NotImplementedError:\n    disable_ring_attention_for(backend)","preventionTips":["Validate backend capability before enabling ring/context-parallel attention","Default to flash_attn for layers participating in KV ring merge"],"tags":["attention-backend","ring-attention","not-implemented","distributed"],"backgroundTag":"not-implemented-abstract-method","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}