[TRTLLM-14551][perf] avoid GDN state reset host synchronization - #16716
Conversation
|
/bot run --disable-fail-fast |
|
PR_Github #60933 [ run ] triggered by Bot. Commit: |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe GDN mixer adds a Triton helper to reset selected SSM and convolution cache states, replaces inline tensor assignments in ChangesGDN state reset
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Qwen3NextGatedDeltaNet
participant _reset_gdn_states
participant _reset_gdn_states_kernel
participant StateBuffers
Qwen3NextGatedDeltaNet->>_reset_gdn_states: pass state buffers, indices, and initial-state flags
_reset_gdn_states->>_reset_gdn_states_kernel: launch masked reset
_reset_gdn_states_kernel->>StateBuffers: zero selected SSM and convolution slots
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
PR_Github #60933 [ run ] completed with state
|
f8026d7 to
57f5e21
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #61176 [ run ] triggered by Bot. Commit: |
|
PR_Github #61176 [ run ] completed with state
|
57f5e21 to
2bd3f1e
Compare
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #61475 [ run ] triggered by Bot. Commit: |
|
PR_Github #61475 [ run ] completed with state
|
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #61562 [ run ] triggered by Bot. Commit: |
|
PR_Github #61562 [ run ] completed with state
|
2bd3f1e to
5699bbc
Compare
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #61810 [ run ] triggered by Bot. Commit: |
|
PR_Github #61810 [ run ] completed with state
|
GDN prefill reset currently selects cache slots with a CUDA boolean mask before assigning zeros. The boolean-indexed selection has a data-dependent output shape, which forces the host to obtain the selected element count and introduces a stream synchronization for every GDN layer. Replace the two indexed assignments with a fixed-shape Triton launch. Each program reads the request's cache index and initialization flag on device, validates the cache slot, and clears both the SSM and convolution state rows in one kernel. Requests with initialized state or invalid sentinel indices remain untouched. Compute the state row offsets explicitly in int64. Recurrent-state views stride across the interleaved SSM and convolution pool, so multiplying an int32 cache index by either stride is not guaranteed to fit in int32 for a large pool. Add a CUDA unit test covering reset slots, preserved initialized slots, untouched unrelated slots, and the negative invalid-index sentinel. Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
5699bbc to
3a00456
Compare
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #62115 [ run ] triggered by Bot. Commit: |
|
PR_Github #62115 [ run ] completed with state
|
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #62196 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast --add-multi-gpu-test |
|
PR_Github #62474 [ run ] triggered by Bot. Commit: |
|
PR_Github #62196 [ run ] completed with state |
|
PR_Github #62474 [ run ] completed with state |
GDN prefill reset currently selects cache slots with a CUDA boolean mask before assigning zeros. The boolean-indexed selection has a data-dependent output shape, which forces the host to obtain the selected element count and introduces a stream synchronization for every GDN layer.
Replace the two indexed assignments with a fixed-shape Triton launch. Each program reads the request's cache index and initialization flag on device, validates the cache slot, and clears both the SSM and convolution state rows in one kernel. Requests with initialized state or invalid sentinel indices remain untouched.
Add a CUDA unit test covering reset slots, preserved initialized slots, untouched unrelated slots, and the negative invalid-index sentinel.
Dev Engineer Review
Qwen3NextGatedDeltaNet.forward_corewith an on-device fixed-shape Triton kernel reset path:state_indices = mamba_metadata.state_indices[: num_prefills + num_decodes], splits intostate_indices_p(prefills) and decode portion.num_prefills > 0, calls_reset_gdn_states(ssm_states, conv_states, state_indices_p, has_initial_states_p)wherehas_initial_states_p = mamba_metadata.has_initial_states[:num_prefills]._reset_gdn_states_kerneland wrapper_reset_gdn_statesintensorrt_llm/_torch/modules/mamba/gdn_mixer.pyto clear GDN state cache rows without host synchronization:request_idx:state_idx = state_indices[request_idx]andhas_initial_states[request_idx].needs_reset = ~has_initial_states(reset only when initial state is not present).state_idxwithvalid_state = (state_idx >= 0) & (state_idx < NUM_CACHE_LINES)so sentinel-1is treated as invalid.ssm_statesandconv_statesrows via maskedtl.store:needs_reset & valid_state(offsets < SSM_STATE_SIZE)/(offsets < CONV_STATE_SIZE)._reset_gdn_states:ssm_state_size = ssm_states.numel() // ssm_states.shape[0]andconv_state_sizesimilarly.(num_requests, triton.cdiv(max(ssm_state_size, conv_state_size), block_size))withblock_size=256.ssm_states.stride(0)/conv_states.stride(0)andNUM_CACHE_LINES = ssm_states.shape[0].QA Engineer Review
test_reset_gdn_states_preserves_initialized_and_invalid_slotsintests/unittest/_torch/modules/mamba/test_gdn_kernel_optimizations.py.state_indices=[1,...],has_initial_states=False→state_pool[1]becomes zero).state_indices=[3,...],has_initial_states=True→state_pool[3]unchanged).state_pool[0],state_pool[2]unchanged).state_indices includes -1→ no reset performed).tests/integration/test_lists// test-db / qa coverage inputs).Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.