[Fix] Use int64 seq_lens across all CUDA graph runners and backends (#27840)

This commit is contained in:
Cheng Wan
2026-06-10 19:54:58 -07:00
committed by GitHub
parent b4bed8c398
commit f4f30d7d23
12 changed files with 42 additions and 36 deletions
@@ -1535,6 +1535,8 @@ class DeepseekV4AttnBackend(
) -> DSV4AttnMetadata: ) -> DSV4AttnMetadata:
assert self.swa_page_size == SWA_WINDOW assert self.swa_page_size == SWA_WINDOW
seq_lens_casual = seq_lens_casual.to(torch.int32)
swa_page_indices = self.get_swa_page_indices( swa_page_indices = self.get_swa_page_indices(
seq_lens_casual=seq_lens_casual, seq_lens_casual=seq_lens_casual,
req_pool_indices_repeated=req_pool_indices_repeated, req_pool_indices_repeated=req_pool_indices_repeated,
@@ -1426,6 +1426,8 @@ class DeepseekV4HipRadixBackend(
) -> DSV4AttnMetadata: ) -> DSV4AttnMetadata:
assert self.swa_page_size == SWA_WINDOW assert self.swa_page_size == SWA_WINDOW
seq_lens_casual = seq_lens_casual.to(torch.int32)
swa_page_indices = self.get_swa_page_indices( swa_page_indices = self.get_swa_page_indices(
seq_lens_casual=seq_lens_casual, seq_lens_casual=seq_lens_casual,
req_pool_indices_repeated=req_pool_indices_repeated, req_pool_indices_repeated=req_pool_indices_repeated,
@@ -472,7 +472,7 @@ class FlashInferMLAAttnBackend(AttentionBackend):
""" """
if forward_mode.is_decode_or_idle(): if forward_mode.is_decode_or_idle():
assert seq_lens_cpu is not None assert seq_lens_cpu is not None
kv_len_arr_cpu = seq_lens_cpu[:bs] kv_len_arr_cpu = seq_lens_cpu[:bs].to(torch.int32)
self.cuda_graph_kv_indptr_cpu[1 : bs + 1] = torch.cumsum( self.cuda_graph_kv_indptr_cpu[1 : bs + 1] = torch.cumsum(
kv_len_arr_cpu, dim=0 kv_len_arr_cpu, dim=0
) )
@@ -570,7 +570,7 @@ def build_decode_registry(
GraphSlot( GraphSlot(
"seq_lens", "seq_lens",
_bs, _bs,
torch.int32, torch.int64,
axis="bs", axis="bs",
padding_policy=PaddingPolicy.FILL_SENTINEL, padding_policy=PaddingPolicy.FILL_SENTINEL,
pad_value=seq_len_fill_value, pad_value=seq_len_fill_value,
@@ -578,7 +578,7 @@ def build_decode_registry(
GraphSlot( GraphSlot(
"seq_lens_cpu", "seq_lens_cpu",
_bs, _bs,
torch.int32, torch.int64,
axis="bs", axis="bs",
device=torch.device("cpu"), device=torch.device("cpu"),
padding_policy=PaddingPolicy.FILL_SENTINEL, padding_policy=PaddingPolicy.FILL_SENTINEL,
@@ -3212,7 +3212,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
forward_batch: ForwardBatch, forward_batch: ForwardBatch,
pp_proxy_tensors=None, pp_proxy_tensors=None,
) -> Union[LogitsProcessorOutput, PPProxyTensors]: ) -> Union[LogitsProcessorOutput, PPProxyTensors]:
if not self.server_args.enable_pdmux and self.device == "cuda": if not self.server_args.enable_pdmux:
forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors) forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors)
# Set extra arguments # Set extra arguments
pdmux_override = False pdmux_override = False
@@ -3302,7 +3302,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
ret = self.prefill_cuda_graph_runner.replay(forward_batch, **kwargs) ret = self.prefill_cuda_graph_runner.replay(forward_batch, **kwargs)
return (ret, can_run_graph) return (ret, can_run_graph)
if not self.server_args.enable_pdmux and self.device == "cuda": if not self.server_args.enable_pdmux:
forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors) forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors)
# Launch model forward # Launch model forward
@@ -3363,7 +3363,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
# called from the idle path can re-read a prior batch's req_pool # called from the idle path can re-read a prior batch's req_pool
# indices and trigger SWA mapping use-after-free. # indices and trigger SWA mapping use-after-free.
if forward_batch.batch_size > 0: if forward_batch.batch_size > 0:
if not self.server_args.enable_pdmux and self.device == "cuda": if not self.server_args.enable_pdmux:
forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors) forward_batch = self._eager_fb_view(forward_batch, pp_proxy_tensors)
self.attn_backend.init_forward_metadata(forward_batch) self.attn_backend.init_forward_metadata(forward_batch)
else: else:
@@ -197,7 +197,7 @@ def _allocate_decode_buffers(
input_ids = torch.zeros((max_num_token,), dtype=torch.int64) input_ids = torch.zeros((max_num_token,), dtype=torch.int64)
input_embeds = torch.zeros((max_num_token, hidden_size), dtype=dtype) input_embeds = torch.zeros((max_num_token, hidden_size), dtype=dtype)
req_pool_indices = torch.zeros((max_bs,), dtype=torch.int64) req_pool_indices = torch.zeros((max_bs,), dtype=torch.int64)
seq_lens = torch.full((max_bs,), seq_len_fill_value, dtype=torch.int32) seq_lens = torch.full((max_bs,), seq_len_fill_value, dtype=torch.int64)
out_cache_loc = torch.zeros((max_num_token,), dtype=cache_loc_dtype) out_cache_loc = torch.zeros((max_num_token,), dtype=cache_loc_dtype)
positions = torch.zeros((max_num_token,), dtype=torch.int64) positions = torch.zeros((max_num_token,), dtype=torch.int64)
mrope_positions = torch.zeros((3, max_num_token), dtype=torch.int64) mrope_positions = torch.zeros((3, max_num_token), dtype=torch.int64)
@@ -269,7 +269,7 @@ def _allocate_decode_buffers(
seq_lens_cpu = torch.full( seq_lens_cpu = torch.full(
(max_bs,), (max_bs,),
seq_len_fill_value, seq_len_fill_value,
dtype=torch.int32, dtype=torch.int64,
device="cpu", device="cpu",
) )
@@ -99,7 +99,7 @@ class DecodeInputBuffers(ForwardInputBuffers):
input_ids = torch.zeros((max_num_token,), dtype=torch.int64) input_ids = torch.zeros((max_num_token,), dtype=torch.int64)
input_embeds = torch.zeros((max_num_token, hidden_size), dtype=dtype) input_embeds = torch.zeros((max_num_token, hidden_size), dtype=dtype)
req_pool_indices = torch.zeros((max_bs,), dtype=torch.int64) req_pool_indices = torch.zeros((max_bs,), dtype=torch.int64)
seq_lens = torch.full((max_bs,), seq_len_fill_value, dtype=torch.int32) seq_lens = torch.full((max_bs,), seq_len_fill_value, dtype=torch.int64)
out_cache_loc = torch.zeros((max_num_token,), dtype=cache_loc_dtype) out_cache_loc = torch.zeros((max_num_token,), dtype=cache_loc_dtype)
out_cache_loc_swa = ( out_cache_loc_swa = (
torch.zeros((max_num_token,), dtype=torch.int64) torch.zeros((max_num_token,), dtype=torch.int64)
@@ -177,7 +177,7 @@ class DecodeInputBuffers(ForwardInputBuffers):
seq_lens_cpu = torch.full( seq_lens_cpu = torch.full(
(max_bs,), (max_bs,),
seq_len_fill_value, seq_len_fill_value,
dtype=torch.int32, dtype=torch.int64,
device="cpu", device="cpu",
) )
@@ -170,7 +170,7 @@ class EAGLEDraftCudaGraphRunner(DecodeCudaGraphRunner):
else None else None
) )
seq_lens = torch.full( seq_lens = torch.full(
(self.max_bs,), self.seq_len_fill_value, dtype=torch.int32 (self.max_bs,), self.seq_len_fill_value, dtype=torch.int64
) )
extend_seq_lens = torch.ones((self.max_bs,), dtype=torch.int32) extend_seq_lens = torch.ones((self.max_bs,), dtype=torch.int32)
topk_p = torch.zeros((self.max_bs, self.topk), dtype=torch.float32) topk_p = torch.zeros((self.max_bs, self.topk), dtype=torch.float32)
@@ -204,7 +204,7 @@ class EAGLEDraftCudaGraphRunner(DecodeCudaGraphRunner):
global_num_tokens_for_logprob_gpu = None global_num_tokens_for_logprob_gpu = None
seq_lens_cpu = torch.full( seq_lens_cpu = torch.full(
(self.max_bs,), self.seq_len_fill_value, dtype=torch.int32, device="cpu" (self.max_bs,), self.seq_len_fill_value, dtype=torch.int64, device="cpu"
) )
self.buffers = EagleDraftInputBuffers( self.buffers = EagleDraftInputBuffers(
@@ -167,7 +167,7 @@ class EAGLEDraftExtendCudaGraphRunner(DecodeCudaGraphRunner):
self.model_runner.attn_backend.get_cuda_graph_seq_len_fill_value() self.model_runner.attn_backend.get_cuda_graph_seq_len_fill_value()
) )
seq_lens = torch.full( seq_lens = torch.full(
(self.max_bs,), self.seq_len_fill_value, dtype=torch.int32 (self.max_bs,), self.seq_len_fill_value, dtype=torch.int64
) )
extend_seq_lens = torch.full( extend_seq_lens = torch.full(
(self.max_bs,), self.num_tokens_per_bs, dtype=torch.int32 (self.max_bs,), self.num_tokens_per_bs, dtype=torch.int32
@@ -221,7 +221,7 @@ class EAGLEDraftExtendCudaGraphRunner(DecodeCudaGraphRunner):
) )
seq_lens_cpu = torch.full( seq_lens_cpu = torch.full(
(self.max_bs,), self.seq_len_fill_value, dtype=torch.int32, device="cpu" (self.max_bs,), self.seq_len_fill_value, dtype=torch.int64, device="cpu"
) )
self.buffers = EagleDraftExtendInputBuffers( self.buffers = EagleDraftExtendInputBuffers(
+3 -3
View File
@@ -117,7 +117,7 @@ class EagleVerifyInput(SpecInput, EagleVerifyInputV2Mixin):
spec_steps=spec_steps, spec_steps=spec_steps,
capture_hidden_mode=CaptureHiddenMode.FULL, capture_hidden_mode=CaptureHiddenMode.FULL,
seq_lens_sum=0, seq_lens_sum=0,
seq_lens_cpu=torch.empty((0,), dtype=torch.int32), seq_lens_cpu=torch.empty((0,), dtype=torch.int64),
) )
def prepare_for_verify(self, batch: ScheduleBatch, page_size: int): def prepare_for_verify(self, batch: ScheduleBatch, page_size: int):
@@ -935,8 +935,8 @@ class EagleDraftExtendInput(SpecInput):
num_accept_tokens=torch.empty((0,), device=device, dtype=torch.int32), num_accept_tokens=torch.empty((0,), device=device, dtype=torch.int32),
num_accept_tokens_cpu=[], num_accept_tokens_cpu=[],
input_ids=torch.empty((0,), device=device, dtype=torch.long), input_ids=torch.empty((0,), device=device, dtype=torch.long),
seq_lens=torch.empty((0,), device=device, dtype=torch.int32), seq_lens=torch.empty((0,), device=device, dtype=torch.int64),
seq_lens_cpu=torch.empty((0,), dtype=torch.int32), seq_lens_cpu=torch.empty((0,), dtype=torch.int64),
req_pool_indices=torch.empty((0,), device=device, dtype=torch.int64), req_pool_indices=torch.empty((0,), device=device, dtype=torch.int64),
capture_hidden_mode=capture_hidden_mode, capture_hidden_mode=capture_hidden_mode,
) )
@@ -98,7 +98,7 @@ class FrozenKVMTPCudaGraphRunner:
self.draft_attn_backend.get_cuda_graph_seq_len_fill_value() self.draft_attn_backend.get_cuda_graph_seq_len_fill_value()
) )
seq_lens_cpu = torch.full( seq_lens_cpu = torch.full(
(self.max_num_token,), self.seq_len_fill_value, dtype=torch.int32 (self.max_num_token,), self.seq_len_fill_value, dtype=torch.int64
) )
if self.enable_torch_compile: if self.enable_torch_compile:
@@ -109,7 +109,7 @@ class FrozenKVMTPCudaGraphRunner:
positions = torch.zeros((self.max_num_token,), dtype=torch.int64) positions = torch.zeros((self.max_num_token,), dtype=torch.int64)
mrope_positions = torch.zeros((3, self.max_num_token), dtype=torch.int64) mrope_positions = torch.zeros((3, self.max_num_token), dtype=torch.int64)
seq_lens = torch.full( seq_lens = torch.full(
(self.max_num_token,), self.seq_len_fill_value, dtype=torch.int32 (self.max_num_token,), self.seq_len_fill_value, dtype=torch.int64
) )
topk_p = torch.zeros((self.max_bs, self.topk), dtype=torch.float32) topk_p = torch.zeros((self.max_bs, self.topk), dtype=torch.float32)
topk_index = torch.zeros((self.max_bs, self.topk), dtype=torch.int64) topk_index = torch.zeros((self.max_bs, self.topk), dtype=torch.int64)
@@ -819,8 +819,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.tensor([0, 1], dtype=torch.int64), positions=torch.tensor([0, 1], dtype=torch.int64),
out_cache_loc=torch.tensor([100, 101], dtype=torch.int64), out_cache_loc=torch.tensor([100, 101], dtype=torch.int64),
req_pool_indices=torch.tensor([1, 2], dtype=torch.int64), req_pool_indices=torch.tensor([1, 2], dtype=torch.int64),
seq_lens=torch.tensor([7, 8], dtype=torch.int32), seq_lens=torch.tensor([7, 8], dtype=torch.int64),
seq_lens_cpu=torch.tensor([7, 8], dtype=torch.int32), seq_lens_cpu=torch.tensor([7, 8], dtype=torch.int64),
mrope_positions=torch.tensor([[0, 1], [0, 1], [0, 1]], dtype=torch.int64), mrope_positions=torch.tensor([[0, 1], [0, 1], [0, 1]], dtype=torch.int64),
) )
# Poison tails so resets are observable. # Poison tails so resets are observable.
@@ -847,14 +847,16 @@ class TestBuildDecodeRegistry(unittest.TestCase):
self.assertTrue(torch.equal(rp[2:4], torch.tensor([0, 0]))) self.assertTrue(torch.equal(rp[2:4], torch.tensor([0, 0])))
# FILL_SENTINEL: head copied, tail = seq_len_fill_value. # FILL_SENTINEL: head copied, tail = seq_len_fill_value.
sl = reg.get_slot("seq_lens").buffer sl = reg.get_slot("seq_lens").buffer
self.assertTrue(torch.equal(sl[:2], torch.tensor([7, 8], dtype=torch.int32))) self.assertEqual(sl.dtype, torch.int64)
self.assertTrue(torch.equal(sl[:2], torch.tensor([7, 8], dtype=torch.int64)))
self.assertTrue( self.assertTrue(
torch.equal(sl[2:4], torch.tensor([FILL, FILL], dtype=torch.int32)) torch.equal(sl[2:4], torch.tensor([FILL, FILL], dtype=torch.int64))
) )
slc = reg.get_slot("seq_lens_cpu").buffer slc = reg.get_slot("seq_lens_cpu").buffer
self.assertEqual(slc.device.type, "cpu") self.assertEqual(slc.device.type, "cpu")
self.assertEqual(slc.dtype, torch.int64)
self.assertTrue( self.assertTrue(
torch.equal(slc[2:4], torch.tensor([FILL, FILL], dtype=torch.int32)) torch.equal(slc[2:4], torch.tensor([FILL, FILL], dtype=torch.int64))
) )
# 2D mrope via slice_fn. # 2D mrope via slice_fn.
mr = reg.get_slot("mrope_positions").buffer mr = reg.get_slot("mrope_positions").buffer
@@ -879,8 +881,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.zeros(8, dtype=torch.int64), positions=torch.zeros(8, dtype=torch.int64),
out_cache_loc=torch.zeros(8, dtype=torch.int64), out_cache_loc=torch.zeros(8, dtype=torch.int64),
req_pool_indices=torch.zeros(4, dtype=torch.int64), req_pool_indices=torch.zeros(4, dtype=torch.int64),
seq_lens=torch.full((4,), 5, dtype=torch.int32), seq_lens=torch.full((4,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((4,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((4,), 5, dtype=torch.int64),
mrope_positions=torch.zeros((3, 8), dtype=torch.int64), mrope_positions=torch.zeros((3, 8), dtype=torch.int64),
global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32),
global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32),
@@ -915,8 +917,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.zeros(8, dtype=torch.int64), positions=torch.zeros(8, dtype=torch.int64),
out_cache_loc=torch.zeros(8, dtype=torch.int64), out_cache_loc=torch.zeros(8, dtype=torch.int64),
req_pool_indices=torch.zeros(4, dtype=torch.int64), req_pool_indices=torch.zeros(4, dtype=torch.int64),
seq_lens=torch.full((4,), 5, dtype=torch.int32), seq_lens=torch.full((4,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((4,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((4,), 5, dtype=torch.int64),
mrope_positions=torch.zeros((3, 8), dtype=torch.int64), mrope_positions=torch.zeros((3, 8), dtype=torch.int64),
num_token_non_padded=ntnp, num_token_non_padded=ntnp,
global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32),
@@ -976,8 +978,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.arange(2, dtype=torch.int64), positions=torch.arange(2, dtype=torch.int64),
out_cache_loc=torch.arange(2, dtype=torch.int64), out_cache_loc=torch.arange(2, dtype=torch.int64),
req_pool_indices=torch.zeros(2, dtype=torch.int64), req_pool_indices=torch.zeros(2, dtype=torch.int64),
seq_lens=torch.full((2,), 5, dtype=torch.int32), seq_lens=torch.full((2,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((2,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((2,), 5, dtype=torch.int64),
global_num_tokens_gpu=gnt, global_num_tokens_gpu=gnt,
global_num_tokens_for_logprob_gpu=gntlp, global_num_tokens_for_logprob_gpu=gntlp,
) )
@@ -1014,8 +1016,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.zeros(8, dtype=torch.int64), positions=torch.zeros(8, dtype=torch.int64),
out_cache_loc=torch.zeros(8, dtype=torch.int64), out_cache_loc=torch.zeros(8, dtype=torch.int64),
req_pool_indices=torch.zeros(4, dtype=torch.int64), req_pool_indices=torch.zeros(4, dtype=torch.int64),
seq_lens=torch.full((4,), 5, dtype=torch.int32), seq_lens=torch.full((4,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((4,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((4,), 5, dtype=torch.int64),
mrope_positions=torch.zeros((3, 8), dtype=torch.int64), mrope_positions=torch.zeros((3, 8), dtype=torch.int64),
global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32),
global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32),
@@ -1062,8 +1064,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.zeros(8, dtype=torch.int64), positions=torch.zeros(8, dtype=torch.int64),
out_cache_loc=torch.zeros(8, dtype=torch.int64), out_cache_loc=torch.zeros(8, dtype=torch.int64),
req_pool_indices=torch.zeros(4, dtype=torch.int64), req_pool_indices=torch.zeros(4, dtype=torch.int64),
seq_lens=torch.full((4,), 5, dtype=torch.int32), seq_lens=torch.full((4,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((4,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((4,), 5, dtype=torch.int64),
mrope_positions=torch.zeros((3, 8), dtype=torch.int64), mrope_positions=torch.zeros((3, 8), dtype=torch.int64),
global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32),
global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32),
@@ -1110,8 +1112,8 @@ class TestBuildDecodeRegistry(unittest.TestCase):
positions=torch.zeros(8, dtype=torch.int64), positions=torch.zeros(8, dtype=torch.int64),
out_cache_loc=torch.zeros(8, dtype=torch.int64), out_cache_loc=torch.zeros(8, dtype=torch.int64),
req_pool_indices=torch.zeros(4, dtype=torch.int64), req_pool_indices=torch.zeros(4, dtype=torch.int64),
seq_lens=torch.full((4,), 5, dtype=torch.int32), seq_lens=torch.full((4,), 5, dtype=torch.int64),
seq_lens_cpu=torch.full((4,), 5, dtype=torch.int32), seq_lens_cpu=torch.full((4,), 5, dtype=torch.int64),
mrope_positions=torch.zeros((3, 8), dtype=torch.int64), mrope_positions=torch.zeros((3, 8), dtype=torch.int64),
global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_gpu=torch.zeros(1, dtype=torch.int32),
global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32), global_num_tokens_for_logprob_gpu=torch.zeros(1, dtype=torch.int32),