Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
ChangesSpeculative sampler request updates
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Refactor · Severity of issue fixed: Medium Suggested reviewers: Merge Risk:
|
JunyiXu-nv
left a comment
There was a problem hiding this comment.
Runtime part LGTM. The compact rows match the per-slot reads (new_tokens[step][slot][beam], new_tokens_lens and next_draft_tokens by slot) on random shapes and slot subsets, add_token did only the read plus add_new_token, and _request_common_handling has no other caller. The new cpu_only test runs via l0_cpu.yml's speculative/hw_agnostic entry.
|
Could you please rebase this branch onto the latest upstream |
…date_requests Index the host copies of the one-model speculative sampler store with the slots of the batch's unfinished requests before converting them to Python lists. The store holds one row per preallocated sequence slot, so converting all of it made the per-step cost grow with max_num_sequences instead of the batch. AI assistance (Cursor) was used for this change. Co-authored-by: Cursor <[email protected]> Signed-off-by: YangHaoooooo <[email protected]>
afb753f to
da82467
Compare
|
Rebased onto current main ( |
|
Thanks @JunyiXu-nv for the review. When someone has a moment, could you trigger CI for this PR and for #21981 and #22093, which are also approved? I can't start it as an external contributor. |
Preserve the inlined upstream stop criteria while reading only active slot rows. AI assistance (OpenAI Codex) was used for this change. Signed-off-by: YangHaoooooo <[email protected]>
Dev Engineer Review
SpecSampler.update_requestsbuildsactive_requestsfrom requests not inGENERATION_COMPLETE. It converts only those slots' rows fromnew_tokens,new_tokens_lens, andnext_draft_tokens. The diff confirms this.token_windows[request_index]anddraft_lens[req_idx]keep request-position indexing. The loops read compact rows byrow.assert seq_slot is not Nonecheck is removed. The diff does not show an equivalent check. Confirm thatpy_seq_slotcannot beNonefor active requests.add_tokenremoval and the_request_common_handlingsignature change, stated in the earlier summary, do not appear in this diff. Treat those claims as unverified and do not rely on them.QA Engineer Review
Test files changed:
tests/unittest/_torch/speculative/hw_agnostic/test_spec_sampler_update_requests.py(+110 lines). It has one parameterized test withverify_lensset toNoneor[3, 2, 1, 2]. It is markedcpu_only.The test covers:
Test-list membership: not established. The grep result did not return in the evidence. The test is a CPU unit test, so
test-db/andqa/listing may not apply.Coverage verdict: needs follow-up. The test does not cover GPU execution, end-to-end serving, or real stop-criteria paths, because
handle_stop_criteriais stubbed. Current-head CI results are not available.Per-File QA Perspective
tensorrt_llm/_torch/speculative/spec_sampler_base.py: Verify updates for active requests with scattered slots and batches that include completed requests. Verify verification-window bounds and stop handling.tests/unittest/_torch/speculative/hw_agnostic/test_spec_sampler_update_requests.py: Adds a CPU-only unit test for row selection and request updates. Its list membership is not established.Description
SpecSampler.update_requestsruns once per step for every one-model speculative decoding mode. Aftersampler_event.synchronize()it converted the host copies of the whole sampler store to nested Python lists:new_tokens([max_draft_len + 1, max_num_sequences, 1]),new_tokens_lensandnext_draft_tokens. The store has one row per preallocated sequence slot, but the loop only reads the rows of the batch's requests, so the conversion cost depended onmax_num_sequencesrather than on the batch.This change indexes the three host tensors with the slots of the batch's unfinished requests, converts only those rows, and reads them by row position in the validation and update loops.
token_windowsanddraft_lensare still indexed by request position._request_common_handlingnow receives the request's own draft row. Device work, the D2H copies and the request updates are unchanged.Closes #22016.
Benchmark
CPU only, main
37e6e677against this change (spec_sampler_base.pyis identical on the current base70fe2b2a6). Both versions ofupdate_requestsran on identical host tensors, with request stubs implementingadd_new_token,get_num_tokens,get_tokensandfinish_by, and the realhandle_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, median of the round medians.2048 is the default
max_batch_size; most DeepSeek-R1-0528 MTP configs underexamples/configs/databaseuse 512, including all concurrency-1 configs. A full store is not slower, because each request's tokens become one flat list instead of one single-element list per token.Test Coverage
tests/unittest/_torch/speculative/hw_agnostic/test_spec_sampler_update_requests.py(cpu_only): requests on scattered slots of a 16-slot store, with a finished request between them so that row positions differ from request positions, for uniform and ragged verification windows. It checks the appended tokens, the accepted/verified/rewind counts and the next draft tokens against each request's slot row. 2 passed, on this branch and on main.tests/unittest/_torch/speculative/hw_agnostic/test_ragged_spec_sampler.py, which drivesupdate_requeststhroughsample_async(verify windows, pending steps, slot reuse): 85 passed.runtime_draft_lenabove and below the store width, end-id, length and stop-word finishes, invalid windows) gave identical request updates and identical exceptions.pre-commit run --fileson both files: all hooks passed, including Ruff, ruff-format, codespell, the test-list AST check and Pyrefly (no diagnostics).Local test runs used
--noconftestwith an in-process stub for the native bindings; this machine has no usable GPU or TensorRT-LLM build. Thel0_cpulist already includesunittest/_torch/speculative/hw_agnostic. Not run: GPU tests and end-to-end serving benchmarks.PR Checklist
AI assistance (Cursor) was used for this change.