[https://nvbugs/6535874][fix] Size DFlash/DSpark worker slot buffers from num_seq_slots - #17154
Open
trtllm-agent wants to merge 1 commit into
Open
[https://nvbugs/6535874][fix] Size DFlash/DSpark worker slot buffers from num_seq_slots#17154trtllm-agent wants to merge 1 commit into
trtllm-agent wants to merge 1 commit into
Conversation
…slot range The DFlash and DSpark workers allocate their per-request context pools once, lazily, on the first drafting forward and then reuse them for every later batch shape. Both sized the pool from spec_metadata.max_num_requests, which create_cuda_graph_metadata overwrites with the captured graph bucket size. Whichever bucket drafts first therefore pinned the pool to that bucket, leaving the scratch slot (_dummy_slot / _scratch_slot) inside the range real requests draw from, so CUDA-graph padding writes could overwrite a live request's context. Read num_seq_slots instead: it spans the full seq-slot pool and is left untouched by the graph copy, which is the same reason prepare_rejection_sampling_buffers derives its slot capacity from it. The DFlash and DSpark metadata constructions did not forward num_seq_slots, so the field defaulted to 0 and any bound derived from it silently collapsed back to max_num_requests; plumb it through as the MTP-Eagle path already does. Both halves are load-bearing. This does not change the pool size on either path today: num_seq_slots is non-None only under should_enable_dsv4_overlap_headroom, which requires is_mtp_eagle_one_model(), so it resolves to exactly max_num_requests here. test_seed_context_windows_preserves_state_across_prefill_chunks built its metadata as a bare SimpleNamespace carrying only three attributes, so it could not survive _lazy_init reading any further sizing field. Switch it to the real DSparkSpecMetadata via the file's own _make_metadata helper, as the other ten _lazy_init call sites in that file already do. The two test_dflash_qwen3_5_4b waivers are stale: the SSM-pool ValueError they were filed against was fixed by 7f7dccf, which landed after the waivers, so they were never re-evaluated. Remove them. Leaves batch_indices_cuda (metadata-owned, reallocated by the graph copy's __post_init__) and the eagle3 padding computation (must track the current batch shape) unchanged. Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
trtllm-agent
requested review from
QiJune,
ZhanruiSunCh,
allisonlim-nv,
cascade812,
crazydemo,
mzweilz and
schetlur-nv
August 1, 2026 03:04
Contributor
WalkthroughDFlash and DSpark now receive sequence-slot metadata and size internal storage from that capacity, with ChangesSpeculative decoding slot-pool sizing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Contributor
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unittest/_torch/speculative/hw_agnostic/test_dspark_worker.py (1)
195-200: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExercise the
num_seq_slotsallocation path.
- Modified test:
test_seed_context_windows_preserves_state_across_prefill_chunks.- Test-list membership: covered by
tests/integration/test_lists/test-db/l0_h100.ymlthroughunittest/_torch/speculative/hw_agnostic.- Coverage verdict: insufficient.
_make_metadata()does not exposenum_seq_slots, so this test covers only themax_num_requestsfallback.- Add
num_seq_slots=4withmax_num_requests=1. Assert_kv_windows.shape[0] == 5,_batch_to_slot.shape[0] == 4, and_scratch_slot == 4.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unittest/_torch/speculative/hw_agnostic/test_dspark_worker.py` around lines 195 - 200, Update test_seed_context_windows_preserves_state_across_prefill_chunks to construct metadata with num_seq_slots=4 alongside max_num_requests=1, exercising the slot-allocation path instead of its fallback. Add assertions that _kv_windows.shape[0] is 5, _batch_to_slot.shape[0] is 4, and _scratch_slot equals 4.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unittest/_torch/speculative/hw_agnostic/test_dspark_worker.py`:
- Around line 195-200: Update
test_seed_context_windows_preserves_state_across_prefill_chunks to construct
metadata with num_seq_slots=4 alongside max_num_requests=1, exercising the
slot-allocation path instead of its fallback. Add assertions that
_kv_windows.shape[0] is 5, _batch_to_slot.shape[0] is 4, and _scratch_slot
equals 4.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0d3549f4-1254-41d0-a83e-773695ac6aa0
📒 Files selected for processing (5)
tensorrt_llm/_torch/speculative/dflash.pytensorrt_llm/_torch/speculative/dspark.pytensorrt_llm/_torch/speculative/utils.pytests/integration/test_lists/waives.txttests/unittest/_torch/speculative/hw_agnostic/test_dspark_worker.py
💤 Files with no reviewable changes (1)
- tests/integration/test_lists/waives.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DFlashWorker._lazy_initandDSparkWorker._lazy_initsized their once-allocated, worker-owned context/window buffers fromspec_metadata.max_num_requests, butcreate_cuda_graph_metadatashrinks that field to the captured graph bucket. Because those buffers are allocated once and then reused for every subsequent batch shape, whichever CUDA-graph bucket drafts first would pin the slot pool to its own (smaller) size, leaving_dummy_slotaliasing a live request's row instead of spanning the full seq-slot pool. The reportedValueErrorfrom the SSM state-pool floor was independently fixed upstream by7f7dccf991, so the target test already passes on HEAD.num_seq_slotsis now threaded throughget_spec_metadatainto both DFlash and DSpark metadata, and each worker sizes its buffer fromspec_metadata.num_seq_slots or spec_metadata.max_num_requests— an inline read rather than a class-levelslot_capacityproperty, which would have broken two unwaivedl0_h100.ymltests (a duck-typed stub fixture, andtest_rejection_buffers_guard.py, which callsprepare_rejection_sampling_buffersunbound on aSimpleNamespacewhere a property is unreachable). The DSpark worker unit test was switched from a sparseSimpleNamespaceto the real metadata factory so newly added sizing fields cannot be silently omitted, and the twotest_dflash_qwen3_5_4bwaiver lines are removed now that both params pass.Test plan
Links
Dev Engineer Review
num_seq_slots, with fallback tomax_num_requests.num_seq_slotsacross CUDA graph metadata copies.num_seq_slotsis unavailable.QA Engineer Review
DSparkSpecMetadatafrom the real metadata factory.get_hidden_statesoverride.