Skip to content

Conversation

@lfr-0531
Copy link
Collaborator

@lfr-0531 lfr-0531 commented Jan 5, 2026

Summary by CodeRabbit

  • Refactor
    • Optimized sparse attention indexer pipeline by streamlining Q/K projection and RoPE handling.
    • Improved parallel execution of normalization operations for enhanced performance.
    • Simplified forward computation path in attention backend.

✏️ Tip: You can customize this high-level summary in your review settings.

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)

  • 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

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@lfr-0531 lfr-0531 requested review from chang-l and kaiyux January 5, 2026 12:29
@lfr-0531 lfr-0531 marked this pull request as ready for review January 6, 2026 13:48
@lfr-0531 lfr-0531 requested a review from a team as a code owner January 6, 2026 13:48
@lfr-0531 lfr-0531 requested a review from QiJune January 6, 2026 13:48
@lfr-0531
Copy link
Collaborator Author

lfr-0531 commented Jan 6, 2026

/bot run

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

The pull request refactors the sparse attention implementation by removing the hidden_states parameter from sparse_attn_indexer, reworking _qk_projection_and_rope to accept and return queries and keys directly, and moving indexer_k normalization into parallel execution within the attention module.

Changes

Cohort / File(s) Summary
Sparse Attention Indexer Refactoring
tensorrt_llm/_torch/attention_backend/sparse/dsa.py
Removed hidden_states parameter from sparse_attn_indexer method signature; adjusted buffer allocation and initialization to use num_tokens directly. Changed _qk_projection_and_rope to accept k instead of indexer_k and return prepared q and k for direct downstream consumption. Updated forward method to consume q and k directly from projection output, removing parallel execution and separate k handling logic.
Parallel Normalization Integration
tensorrt_llm/_torch/modules/attention.py
Consolidated latent_cache computation with indexer_k normalization into a single maybe_execute_in_parallel block, with the normalization step now applied inside the parallel context. Removed inline TODO comment about fusing normalization operations. Maintained downstream indexer_k usage while now sourcing it from the parallel execution result.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is entirely composed of template boilerplate with all required sections empty (Description, Test Coverage, and checklist items incomplete), providing no actual implementation details or rationale. Fill in the Description section explaining the optimization rationale, list relevant tests in Test Coverage section, and complete all applicable PR checklist items with specific details.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: optimizing multi-stream handling for DSA in DeepSeek-V3.2 by refactoring method signatures and parallel execution paths.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a792c23 and 8c980ba.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/attention_backend/sparse/dsa.py
  • tensorrt_llm/_torch/modules/attention.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+
Indent Python code with 4 spaces. Do not use tabs
Always maintain the namespace when importing Python modules, even if only one class or function from a module is used
Python filenames should use snake_case (e.g., some_file.py)
Python classes should use PascalCase (e.g., class SomeClass)
Python functions and methods should use snake_case (e.g., def my_awesome_function():)
Python local variables should use snake_case, with prefix k for variable names that start with a number (e.g., k_99th_percentile)
Python global variables should use upper snake_case with prefix G (e.g., G_MY_GLOBAL)
Python constants should use upper snake_case (e.g., MY_CONSTANT)
Avoid shadowing variables declared in an outer scope in Python
Initialize all externally visible members of a Python class in the constructor
For Python interfaces that may be used outside a file, prefer docstrings over comments
Use comments in Python for code within a function, or interfaces that are local to a file
Use Google-style docstrings for Python classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with the format """<type>: Description"""
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except clause to the smallest set of errors possible
When using try-except blocks in Python to handle multiple possible variable types (duck-typing), keep the body of the try as small as possible and use the else block for the main logic

Files:

  • tensorrt_llm/_torch/modules/attention.py
  • tensorrt_llm/_torch/attention_backend/sparse/dsa.py
**/*.{cpp,cc,cxx,h,hpp,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification

Files:

  • tensorrt_llm/_torch/modules/attention.py
  • tensorrt_llm/_torch/attention_backend/sparse/dsa.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 6915
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:4010-4012
Timestamp: 2025-08-14T23:23:27.449Z
Learning: For MOE (Mixture of Experts) code reviews in TensorRT-LLM, avoid repeatedly suggesting finalize fusion validation checks and safety assertions. The user djns99 has indicated these suggestions are repetitive and unwanted across multiple MOE-related changes.
📚 Learning: 2025-08-14T21:04:50.248Z
Learnt from: thorjohnsen
Repo: NVIDIA/TensorRT-LLM PR: 6910
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-14T21:04:50.248Z
Learning: In KV cache onboarding logic during prefill in cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, when calculating which blocks fall within the attention window, use getTokensPerBlock() to advance token indices rather than block->getUniqueTokens().size(), because the calculation needs to consider the post-prefill state where blocks will be filled to capacity, not their current token count.

Applied to files:

  • tensorrt_llm/_torch/modules/attention.py
📚 Learning: 2025-08-15T06:46:53.813Z
Learnt from: eopXD
Repo: NVIDIA/TensorRT-LLM PR: 6767
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-15T06:46:53.813Z
Learning: In the TensorRT-LLM KV cache manager, SWA (Sliding Window Attention) combined with beam search is currently in a broken/non-functional state and is planned for future rework. During preparatory refactoring phases, code related to SWA+beam search may intentionally remain in a non-working state until the broader rework is completed.

Applied to files:

  • tensorrt_llm/_torch/modules/attention.py
📚 Learning: 2025-10-20T17:07:18.745Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/models/patches/nemotron_h.py:98-116
Timestamp: 2025-10-20T17:07:18.745Z
Learning: In NemotronH models (tensorrt_llm/_torch/auto_deploy/models/patches/nemotron_h.py), the gate (self.gate) returns topk_indices and topk_weights that are already in the correct shape to be passed directly to torch_ops.auto_deploy.torch_moe without needing to reshape them when hidden_states is flattened.

Applied to files:

  • tensorrt_llm/_torch/attention_backend/sparse/dsa.py
🧬 Code graph analysis (2)
tensorrt_llm/_torch/modules/attention.py (1)
tensorrt_llm/functional.py (1)
  • concat (2577-2636)
tensorrt_llm/_torch/attention_backend/sparse/dsa.py (4)
tensorrt_llm/llmapi/utils.py (1)
  • empty (388-389)
tensorrt_llm/_torch/attention_backend/interface.py (1)
  • num_tokens (276-277)
tensorrt_llm/_torch/models/modeling_deepseekv3.py (1)
  • split (194-199)
tensorrt_llm/_torch/utils.py (1)
  • split (394-402)
🔇 Additional comments (4)
tensorrt_llm/_torch/attention_backend/sparse/dsa.py (3)

1328-1350: LGTM: Clean refactoring of buffer allocation and signature.

The removal of the hidden_states parameter from sparse_attn_indexer is appropriate since it's no longer needed in this method. The buffer allocation now correctly uses num_tokens from metadata and q_fp8.device for device placement, maintaining consistency with the processed tensors.


1526-1539: LGTM: Improved return type makes data flow explicit.

The signature change to accept k (renamed from indexer_k) and return both q and k as a tuple makes the function's behavior clearer. Both tensors now follow the same processing pipeline (split, RoPE, FP8 quantization), and the explicit return eliminates ambiguity about what the function produces.


1557-1581: LGTM: Parallel execution and unpacking correctly implemented.

The forward flow properly handles the updated _qk_projection_and_rope return type, unpacking the (q, k) tuple and then extracting FP8 tensors and scales from each. The parallel execution of Q/K projection and weights computation is well-coordinated, and the subsequent call to sparse_attn_indexer correctly passes the processed tensors.

tensorrt_llm/_torch/modules/attention.py (1)

1374-1380: LGTM: Effective parallelization of normalization.

Moving indexer_k normalization into the parallel execution block alongside latent_cache computation is a good optimization. The normalized indexer_k is then correctly passed to the indexer (line 1389), which aligns with the updated _qk_projection_and_rope signature in dsa.py that now expects pre-processed k input. This change reduces sequential dependencies and improves throughput.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30741 [ run ] triggered by Bot. Commit: 8c980ba

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30741 [ run ] completed with state SUCCESS. Commit: 8c980ba
/LLM/main/L0_MergeRequest_PR pipeline #23724 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Signed-off-by: Fanrong Li <[email protected]>
Signed-off-by: Fanrong Li <[email protected]>
Signed-off-by: Fanrong Li <[email protected]>
Signed-off-by: Fanrong Li <[email protected]>
@lfr-0531 lfr-0531 force-pushed the user/fanrongl/multi_stream_for_dsa_norm branch from 8c980ba to abcf8cb Compare January 7, 2026 03:33
@lfr-0531
Copy link
Collaborator Author

lfr-0531 commented Jan 7, 2026

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30825 [ run ] triggered by Bot. Commit: 384e9e5

Copy link
Collaborator

@chang-l chang-l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30825 [ run ] completed with state SUCCESS. Commit: 384e9e5
/LLM/main/L0_MergeRequest_PR pipeline #23807 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

@lfr-0531
Copy link
Collaborator Author

lfr-0531 commented Jan 7, 2026

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30860 [ run ] triggered by Bot. Commit: 384e9e5

@tensorrt-cicd
Copy link
Collaborator

PR_Github #30860 [ run ] completed with state SUCCESS. Commit: 384e9e5
/LLM/main/L0_MergeRequest_PR pipeline #23828 completed with status: 'SUCCESS'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants