diff --git a/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py b/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py index d03288e070..08f69c058b 100644 --- a/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py +++ b/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py @@ -1191,6 +1191,7 @@ class PrefillCudaGraphRunner(BaseCudaGraphRunner): padded_view.extend_seq_lens = s["extend_seq_lens"][:r] padded_view.extend_prefix_lens = s["extend_prefix_lens"][:r] padded_view.max_seq_len_override = static_forward_batch.max_seq_len_override + padded_view.input_ids = static_forward_batch.input_ids attn_backend.init_forward_metadata_out_graph(padded_view) return if not self.use_captured_attn_metadata: diff --git a/test/registered/unit/model_executor/runner/test_prefill_cuda_graph_padding.py b/test/registered/unit/model_executor/runner/test_prefill_cuda_graph_padding.py index ed9ebdeda7..b6d4187bdb 100644 --- a/test/registered/unit/model_executor/runner/test_prefill_cuda_graph_padding.py +++ b/test/registered/unit/model_executor/runner/test_prefill_cuda_graph_padding.py @@ -127,8 +127,19 @@ class TestPrefillCudaGraphPadding(CustomTestCase): seq_lens_sum=int(seq_lens.sum()), ) + static_batch = ForwardBatch( + forward_mode=ForwardMode.EXTEND, + batch_size=4, + input_ids=torch.arange(16), + req_pool_indices=static_slots, + seq_lens=static_lens, + seq_lens_cpu=static_lens, + out_cache_loc=torch.arange(16), + seq_lens_sum=int(static_lens.sum()), + ) + runner._prepare_forward_metadata_for_replay( - batch, batch, shape_key=ShapeKey(size=16) + batch, static_batch, shape_key=ShapeKey(size=16) ) attn_backend.init_forward_metadata_out_graph.assert_called_once() @@ -136,6 +147,7 @@ class TestPrefillCudaGraphPadding(CustomTestCase): self.assertIsInstance(padded, ForwardBatch) self.assertIsNot(padded, batch) self.assertEqual(padded.batch_size, 4) + self.assertIs(padded.input_ids, static_batch.input_ids) torch.testing.assert_close(padded.seq_lens_cpu, static_lens) torch.testing.assert_close(padded.req_pool_indices, static_slots) if has_mirror: @@ -147,6 +159,7 @@ class TestPrefillCudaGraphPadding(CustomTestCase): else: self.assertIsNone(padded.req_pool_indices_cpu) self.assertEqual(batch.batch_size, batch_size) + self.assertEqual(batch.input_ids.numel(), batch_size) torch.testing.assert_close(batch.seq_lens_cpu, seq_lens) attn_backend.init_forward_metadata.assert_not_called()