[DCP] Drop two per-layer launches from the MLA target-verify path (#34240)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khoa Pham
2026-08-10 17:11:03 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent 2d5009d130
commit 0967885121
5 changed files with 50 additions and 28 deletions
@@ -168,6 +168,36 @@ class TestGetDcpLens(CustomTestCase):
self.assertTrue(torch.equal(kernel_k[0], k[:, 0:1]))
self.assertTrue(torch.equal(out, q))
def test_dense_q_indptr_matches_the_arange_it_replaces(self):
from sglang.srt.layers.attention.trtllm_mla_backend import TRTLLMMLABackend
max_bs = 16
for num_draft_tokens in (1, 2, 8):
backend = object.__new__(TRTLLMMLABackend)
backend.q_indptr_decode = torch.arange(0, max_bs + 1, dtype=torch.int32)
backend.num_draft_tokens = num_draft_tokens
backend.dense_q_indptr_verify = backend.q_indptr_decode * num_draft_tokens
# Equal hits the precomputed buffer, +1 hits the fallback.
for draft_token_num in (num_draft_tokens, num_draft_tokens + 1):
for bs in (1, 3, max_bs):
with self.subTest(
num_draft_tokens=num_draft_tokens,
draft_token_num=draft_token_num,
bs=bs,
):
got = backend._dense_q_indptr(bs, draft_token_num)
expected = torch.arange(
0,
(bs + 1) * draft_token_num,
draft_token_num,
dtype=torch.int32,
)
self.assertEqual(got.dtype, torch.int32)
self.assertTrue(
torch.equal(got, expected),
f"{got.tolist()} != {expected.tolist()}",
)
def test_paged_allocator_exposes_dcp_virtual_capacity(self):
real_kv_size = 1024
dcp_size = 4
@@ -265,13 +265,17 @@ class TestCPUReference(CustomTestCase):
self.assertFalse(torch.allclose(result_e, result_2, atol=1e-3))
def test_flashmla_selects_natural_log_lse(self):
def test_natural_log_lse_backends(self):
from sglang.srt.models.deepseek_common.attention_forward_methods.forward_mla import (
is_mla_dcp_lse_base_on_e,
)
self.assertTrue(is_mla_dcp_lse_base_on_e("flashmla"))
self.assertTrue(is_mla_dcp_lse_base_on_e("cutedsl_mla"))
self.assertFalse(is_mla_dcp_lse_base_on_e("flashinfer_mla"))
self.assertFalse(is_mla_dcp_lse_base_on_e("tokenspeed_mla"))
self.assertFalse(is_mla_dcp_lse_base_on_e("trtllm_mla"))
self.assertFalse(is_mla_dcp_lse_base_on_e(None))
def test_nan_lse_handled(self):
from sglang.kernels.ops.attention.dcp_kernels import _lse_weighted_combine_cpu