Add KV-canary SWA + DeepSeek-V4 pool support (#26810)

This commit is contained in:
fzyzcjy
2026-05-31 09:55:34 +08:00
committed by GitHub
parent 9ecf314970
commit e188745ee0
10 changed files with 334 additions and 3 deletions
@@ -0,0 +1,21 @@
from __future__ import annotations
import unittest
from test.registered.kv_canary.test_self_e2e_baseline import _BaselineBase
from sglang.test.kv_canary.consts import (
DSV4_POOL_SERVER_ARGS,
DSV4_POOL_SERVER_ENV,
)
class TestBaselineDsv4(_BaselineBase):
__test__ = True
model_mode = "dsv4"
extra_server_args = DSV4_POOL_SERVER_ARGS
extra_env = DSV4_POOL_SERVER_ENV
if __name__ == "__main__":
unittest.main()
@@ -4,6 +4,7 @@ import unittest
from sglang.srt.kv_canary.config import CanaryMode
from sglang.test.ci.ci_register import register_cuda_ci
from sglang.test.kv_canary.consts import SWA_POOL_SERVER_ARGS
from sglang.test.kv_canary.e2e_base import CanaryE2EBase
register_cuda_ci(est_time=60, stage="extra-a", runner_config="1-gpu-small")
@@ -33,5 +34,10 @@ class TestBaselineMha(_BaselineBase):
model_mode = "mha"
class TestBaselineSwa(_BaselineBase):
model_mode = "swa"
extra_server_args = SWA_POOL_SERVER_ARGS
if __name__ == "__main__":
unittest.main()
@@ -10,6 +10,7 @@ from sglang.test.kv_canary.fixtures import (
DEFAULT_DEVICE,
make_base_config,
make_mha_pool,
make_swa_pool,
)
from sglang.test.test_utils import CustomTestCase
@@ -41,6 +42,22 @@ class TestAttachCanaryBuffers(PoolPatcherHelper, CustomTestCase):
self.assertIsNotNone(group.v_tail)
self.assertEqual(group.v_head.shape, (16, CANARY_SLOT_BYTES))
def test_canary_buffer_group_allocate_full_and_swa(self):
"""Verify SWA pools allocate full and SWA canary buffers."""
pool = make_swa_pool(self.device, full_slots=16, swa_slots=8)
groups_tuple = attach_canary_buffers(
pool=pool,
config=self.config,
device=self.device,
kv_token_id_vs_position_offset=0,
)
groups = {g.kind: g for g in groups_tuple}
self.assertEqual(set(groups.keys()), {PoolKind.FULL, PoolKind.SWA})
self.assertEqual(groups[PoolKind.FULL].k_head.shape[0], 16)
self.assertEqual(groups[PoolKind.SWA].k_head.shape[0], 8)
self.assertIsNotNone(groups[PoolKind.SWA].swa_index_lut)
self.assertIsNone(groups[PoolKind.FULL].swa_index_lut)
class TestPoolPatcherBufferInfos(PoolPatcherHelper, CustomTestCase):
def test_get_contiguous_buf_infos_inserts_canary_entries(self):
@@ -64,6 +81,24 @@ class TestPoolPatcherBufferInfos(PoolPatcherHelper, CustomTestCase):
ptrs_after, _, _ = pool.get_contiguous_buf_infos()
self.assertEqual(ptrs_after, ptrs_before)
def test_swa_attach_splices_full_into_contiguous_and_swa_into_state(self):
"""Verify SWA patching splices canary buffers into both buffer lists."""
pool = make_swa_pool(self.device, full_slots=16, swa_slots=8)
contiguous_before, _, _ = pool.get_contiguous_buf_infos()
state_before, _, _ = pool.get_state_buf_infos()
attach_canary_buffers(
pool=pool,
config=self.config,
device=self.device,
kv_token_id_vs_position_offset=0,
)
contiguous_after, _, _ = pool.get_contiguous_buf_infos()
state_after, _, _ = pool.get_state_buf_infos()
self.assertEqual(len(contiguous_after), len(contiguous_before) + 4)
self.assertEqual(len(state_after), len(state_before) + 4)
def test_pd_layout_canary_inserted_correctly(self):
"""Verify PD (prefill-decode disaggregation) canary buffers are inserted in layout order."""
pool = make_mha_pool(self.device, num_slots=16, dim=8, layer_num=2)