Repository navigation
Description
Proposal to improve performance
SpecSampler.update_requests is the host-side update shared by every one-model speculative decoding mode (MTP, Eagle3 one-model, SA, PARD, DFlash, DSpark, draft-target one-model). It runs once per step after sampler_event.synchronize() and starts by converting the host copies of the sampler store to nested Python lists:
new_tokens = state.host.new_tokens.tolist() # [max_draft_len + 1, max_num_sequences, 1]
new_tokens_lens_list = state.host.new_tokens_lens.tolist() # [max_num_sequences]
next_draft_tokens_list = state.host.next_draft_tokens.tolist() # [max_num_sequences, max_total_draft_tokens]The store has one row per preallocated sequence slot (max_num_sequences, at least max_batch_size), but the loop that follows only reads the rows of the requests in state.requests. The conversion therefore costs the same on every step whether one request or the whole pool is running. With the default max_batch_size=2048 it adds about 1.1 ms per step with three draft tokens. Most DeepSeek-R1-0528 MTP configs under examples/configs/database (40 of 58) set max_batch_size: 512, including all concurrency-1 configs.
Proposal: index the host tensors with the slots of the batch's unfinished requests, convert only those rows, and read them by row in the loop. The device work, the D2H copies and the request updates stay the same.
Measurements
CPU only. Both versions of SpecSampler.update_requests (main 37e6e677 and the proposed change) ran on identical host tensors, with request stubs that implement add_new_token, get_num_tokens, get_tokens and finish_by, and the real handle_stop_criteria. Native bindings were stubbed for the import. Intel Xeon Platinum 8352Y, CPython 3.12.3, PyTorch 2.15.0+cpu, one pinned core; 20 warmups, then nine rounds of 15-50 timed calls. The table shows the median of the round medians.
| Slots | Active requests | Draft tokens | main | Proposed | Speedup |
|---|---|---|---|---|---|
| 256 | 1 | 3 | 129.6 us | 27.1 us | 4.8x |
| 256 | 256 | 3 | 651.4 us | 584.1 us | 1.1x |
| 512 | 1 | 3 | 256.1 us | 27.1 us | 9.5x |
| 512 | 16 | 3 | 289.1 us | 60.8 us | 4.8x |
| 2048 | 1 | 3 | 1086.3 us | 27.7 us | 39.2x |
| 2048 | 8 | 3 | 1108.4 us | 45.0 us | 24.6x |
| 2048 | 64 | 3 | 1249.0 us | 159.0 us | 7.9x |
| 2048 | 2048 | 3 | 5748.5 us | 4994.5 us | 1.2x |
| 2048 | 8 | 7 | 2223.6 us | 52.2 us | 42.6x |
A full store is not slower: each request's accepted tokens become one flat list instead of one single-element list per token.
A randomized differential check over 20,000 states (finished requests in the batch, ragged and uniform verification windows, runtime_draft_len above and below the store width, end-id, length and stop-word finishes, invalid windows) produced identical request updates and identical exceptions for both versions.
Misc discussion on performance
With the overlap scheduler this runs after the current forward is launched and before its sampling is launched, so it stays hidden only while the forward takes longer than the host work in between. Low-batch speculative decoding has short forwards, so that is where the cost is most likely to show up in the step time.
Your current environment
- OS: Linux x86_64
- Python: 3.12.3
- PyTorch: 2.15.0+cpu
- CPU: Intel Xeon Platinum 8352Y
- GPU: not used
- TensorRT-LLM: main at
37e6e677
Before submitting a new issue...
- I searched open and closed issues and pull requests, including recent speculative-decoding host-overhead work. Open PRs [None][perf] Stop paying speculative per-step overhead in the draft-0 band #18837 (skips the draft-token rows when the draft length is 0) and [TRTLLM-16622][feat] DeepSeek-V4.1: Perf optimizations for DS-V4.1-Flash-NVFP4 #21438 (inlines the stop checks) edit the same function; both still convert every slot.
AI assistance (Cursor) was used to investigate and benchmark this proposal.
Activity
[NVIDIA#22016][perf] Convert only the batch's slots in SpecSampler.up…