Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the allocation of extend_seq_lens_buffer and extend_start_loc_buffer in deepseek_v4_backend.py by moving it from a lazy-initialization helper directly into the __init__ method to avoid issues with in-place updates during CUDA-graph capture. The reviewer pointed out that this unconditional allocation will cause a startup crash when speculative decoding is disabled because self.speculative_num_draft_tokens is None. A guard condition was suggested to resolve this issue.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| num_reqs = self.req_to_token.shape[0] | ||
| self.extend_seq_lens_buffer = torch.full( | ||
| (num_reqs,), | ||
| self.speculative_num_draft_tokens, | ||
| **self.cuda_int32_kwargs, | ||
| ) | ||
| self.extend_start_loc_buffer = torch.zeros(num_reqs, **self.cuda_int32_kwargs) |
There was a problem hiding this comment.
Unconditional allocation of extend_seq_lens_buffer and extend_start_loc_buffer in __init__ will crash SGLang startup for DeepSeek V4 models when speculative decoding is not enabled. This is because self.speculative_num_draft_tokens is None in non-speculative mode, causing torch.full to raise a TypeError (as fill_value cannot be None).
Please guard this allocation with if self.speculative_num_draft_tokens: to ensure it only runs when speculative decoding is active.
| num_reqs = self.req_to_token.shape[0] | |
| self.extend_seq_lens_buffer = torch.full( | |
| (num_reqs,), | |
| self.speculative_num_draft_tokens, | |
| **self.cuda_int32_kwargs, | |
| ) | |
| self.extend_start_loc_buffer = torch.zeros(num_reqs, **self.cuda_int32_kwargs) | |
| if self.speculative_num_draft_tokens: | |
| num_reqs = self.req_to_token.shape[0] | |
| self.extend_seq_lens_buffer = torch.full( | |
| (num_reqs,), | |
| self.speculative_num_draft_tokens, | |
| **self.cuda_int32_kwargs, | |
| ) | |
| self.extend_start_loc_buffer = torch.zeros(num_reqs, **self.cuda_int32_kwargs) |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
/tag-and-rerun-ci |
Motivation
DSPARK target-verify buffers (
extend_seq_lens_buffer,extend_start_loc_buffer)were lazy-allocated by
_ensure_verify_bs_buffers()on first use. The first useis the FlashInfer autotune
_dummy_run, which wraps the forward insidetorch.inference_mode(). Tensors allocated there are tagged as inferencetensors, and subsequent CUDA-graph capture (outside inference_mode) fails with:
Modifications
DeepseekV4AttnBackend.__init__(runsoutside inference_mode).
_ensure_verify_bs_bufferslazy-init method.Checklist
pre-commit run --all-filesCI States
Latest PR Test (Base): ❌ Run #29077340808
Latest PR Test (Extra): ❌ Run #29077340909