From bc76a6b8193c2a7fce321c87ed893286019e68a6 Mon Sep 17 00:00:00 2001 From: Ziyi Xu <76582120+DarkSharpness@users.noreply.github.com> Date: Fri, 16 Oct 2026 03:45:56 +0800 Subject: [PATCH] [DSv4] Sparse prefill: build compressed lengths without a host sync (#44557) Co-authored-by: Claude Opus 5.5 --- .../sglang/srt/layers/attention/dsv4/sparse_prefill_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/layers/attention/dsv4/sparse_prefill_utils.py b/python/sglang/srt/layers/attention/dsv4/sparse_prefill_utils.py index 4266493ad0..de0ee7ac86 100644 --- a/python/sglang/srt/layers/attention/dsv4/sparse_prefill_utils.py +++ b/python/sglang/srt/layers/attention/dsv4/sparse_prefill_utils.py @@ -41,6 +41,7 @@ import triton from sglang.kernels.ops.attention.dsv4.dequant_k_cache import DIM_NOPE, DIM_ROPE from sglang.srt.utils import ceil_align +from sglang.srt.utils.common import async_h2d # FlashMLA sparse prefill asserts ``params.topk % B_TOPK == 0``. B_TOPK is 64 # for the h_q=64 kernel and 128 for h_q=128; pad to 128 to satisfy both. @@ -563,7 +564,7 @@ class SparsePrefillChunkCache: seq_lens_cpu = self.seq_lens.tolist() lengths_cpu = [int(length) // compress_ratio for length in seq_lens_cpu] total_compressed = sum(lengths_cpu) - lengths = torch.tensor(lengths_cpu, dtype=torch.int32, device=device) + lengths = async_h2d(lengths_cpu, dtype=torch.int32, device=device) ends = lengths.cumsum(0, dtype=torch.int32) compressed_base = ends - lengths swa_base = total_compressed + self.swa_offsets[:-1]