From 572924634b9f18ea86da039929db4337508c89af Mon Sep 17 00:00:00 2001 From: Xingyu Liu <38244988+charlotte12l@users.noreply.github.com> Date: Mon, 3 Aug 2026 18:55:03 -0700 Subject: [PATCH] [mem_cache] Build empty-prefix last_loc sentinel on-device to avoid per-call H2D sync (#32575) Signed-off-by: xingyuliu --- python/sglang/srt/mem_cache/allocation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/sglang/srt/mem_cache/allocation.py b/python/sglang/srt/mem_cache/allocation.py index d87482278..9605c9e3b 100644 --- a/python/sglang/srt/mem_cache/allocation.py +++ b/python/sglang/srt/mem_cache/allocation.py @@ -352,7 +352,7 @@ def alloc_for_extend( else: # Paged allocation - build last_loc last_loc = [ - (t[-1:] if len(t) > 0 else torch.tensor([-1], device=batch.device)) + (t[-1:] if len(t) > 0 else torch.full((1,), -1, device=batch.device)) for t in prefix_tensors ] out_cache_loc = alloc_paged_token_slots_extend(