Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions python/sglang/srt/layers/attention/dsa_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,28 @@ def _forward_fa3(
logit_cap: float,
page_size: int,
) -> torch.Tensor:
# Sparse DSA represents each query token as a one-token FA3 sequence.
# MoE synchronization can pad length metadata, while the prefill graph
# attention bridge narrows Q and the page table to real query tokens.
# Remove only trailing metadata padding to match that narrowed layout.
if max_seqlen_q == 1 and q_nope.ndim == 3:
num_queries = q_nope.shape[0]
if cache_seqlens.shape[0] > num_queries:
if (
page_table.shape[0] != num_queries
or cu_seqlens_q.shape[0] != cache_seqlens.shape[0] + 1
or cu_seqlens_k.shape[0] != cache_seqlens.shape[0] + 1
):
raise ValueError(
"Inconsistent padded DSA FA3 metadata: "
f"q={tuple(q_nope.shape)}, page_table={tuple(page_table.shape)}, "
f"cache_seqlens={tuple(cache_seqlens.shape)}, "
f"cu_q={tuple(cu_seqlens_q.shape)}, "
f"cu_k={tuple(cu_seqlens_k.shape)}"
)
cache_seqlens = cache_seqlens[:num_queries]
cu_seqlens_q = cu_seqlens_q[: num_queries + 1]
cu_seqlens_k = cu_seqlens_k[: num_queries + 1]
k_rope_cache = kv_cache[:, :, v_head_dim:]
c_kv_cache = kv_cache[:, :, :v_head_dim]
qk_rope_dim = k_rope_cache.shape[-1]
Expand Down
Loading