Skip to content

Conversation

yuxianq
Copy link
Collaborator

@yuxianq yuxianq commented Sep 30, 2025

Summary by CodeRabbit

  • New Features
    • Added support for attention output gating.
    • Enabled flexibility to handle both fused and split QKV inputs in RoPE/QK-norm attention, improving compatibility with more models and runtimes.
  • Refactor
    • Streamlined attention input handling and control flow for more robust execution paths.

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

  • 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.

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.

@yuxianq yuxianq requested review from a team as code owners September 30, 2025 08:02
@yuxianq
Copy link
Collaborator Author

yuxianq commented Sep 30, 2025

/bot run --disable-fail-fast

Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

📝 Walkthrough

Walkthrough

Updates adjust Q/K/V handling and RoPE application control flow. Attention.forward now conditionally splits fused QKV based on attn_output_gate; otherwise it passes qkv with k, v as None. apply_rope in qk_norm_attention now supports both pre-concatenated qkv and separate q, k, v by conditionally constructing qkv before applying normalization and RoPE.

Changes

Cohort / File(s) Summary
Attention gating and QKV split handling
tensorrt_llm/_torch/modules/attention.py
Made QKV split conditional on attn_output_gate. If true, split into q_gate, k, v; else set q, k, v = qkv, None, None. Updated inline comments/flow; subsequent apply_rope and convert_qkv calls adapt to new provisioning.
RoPE application with optional pre-concatenated QKV
tensorrt_llm/_torch/modules/qk_norm_attention.py
In apply_rope, when k and v exist, build qkv = torch.concat([q, k, v], dim=...) and call apply_qk_norm_rope. Replaced assertion that required k and v to be None with conditional concatenation path. No API signature changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Attention.forward
  participant RoPE as apply_rope
  participant Conv as convert_qkv

  Caller->>Attention.forward: input (qkv, attn_output_gate, ...)
  alt attn_output_gate == True
    Attention.forward->>Attention.forward: split qkv -> q_gate, k, v
    Attention.forward->>RoPE: apply_rope(q=q_gate, k=k, v=v, ...)
  else attn_output_gate == False
    Attention.forward->>Attention.forward: set q=qkv, k=None, v=None
    Attention.forward->>RoPE: apply_rope(q=q, k=None, v=None, ...)
  end
  RoPE-->>Attention.forward: processed q(/k/v or qkv)
  Attention.forward->>Conv: convert_qkv(processed tensors, ...)
  Conv-->>Caller: attention outputs
Loading
sequenceDiagram
  autonumber
  participant Caller as Attention.forward
  participant RoPE as apply_rope
  participant Kernel as apply_qk_norm_rope

  Caller->>RoPE: q, k, v (k/v may be None)
  alt k and v provided
    RoPE->>RoPE: concat q,k,v -> qkv
    RoPE->>Kernel: apply_qk_norm_rope(qkv, ...)
  else only q provided
    RoPE->>Kernel: apply_qk_norm_rope(q (or qkv), ...)
  end
  Kernel-->>RoPE: processed tensor(s)
  RoPE-->>Caller: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description includes only the template placeholders without any actual content in the Description, Test Coverage, or checklist sections, so it fails to explain the problem, the solution, or the tests that verify the changes. Please populate the Description section with a brief summary of what the change does and why it was made, add the relevant test cases under Test Coverage, and ensure the PR Checklist items accurately reflect any updates or verifications performed for this fix.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[None][fix] Avoid unnecessary concat in attn_output_gate case.” accurately reflects the primary change by specifying that the fix prevents an unneeded concatenation when the attention output gate is used, follows the project’s ticket and type formatting, and is concise and clear for reviewers scanning the commit history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 948b8b9 and c409456.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/modules/attention.py (1 hunks)
  • tensorrt_llm/_torch/modules/qk_norm_attention.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • tensorrt_llm/_torch/modules/qk_norm_attention.py
  • tensorrt_llm/_torch/modules/attention.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

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

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • tensorrt_llm/_torch/modules/qk_norm_attention.py
  • tensorrt_llm/_torch/modules/attention.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (2)
tensorrt_llm/_torch/modules/qk_norm_attention.py (1)

256-258: LGTM! Flexible input handling supports both pre-concatenated and separate Q/K/V.

The conditional concatenation correctly handles two input patterns:

  1. Pre-concatenated: q contains fused QKV, k and v are None (avoids unnecessary concat)
  2. Separate: q, k, v are all provided and concatenated here

This aligns with the PR objective to avoid unnecessary concatenation when attn_output_gate is False.

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

540-541: LGTM! Efficiently avoids unnecessary split/concat when attn_output_gate is False.

By assigning q, k, v = qkv, None, None, this change keeps the fused representation intact when the output gate is not used. The subsequent apply_rope and convert_qkv calls (lines 543-544) correctly handle this fused input format, avoiding the overhead of splitting and re-concatenating.

This optimization aligns with the PR title and works correctly with the updated apply_rope in qk_norm_attention.py.


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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20353 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20353 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15355 completed with status: 'FAILURE'

@yuxianq
Copy link
Collaborator Author

yuxianq commented Sep 30, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20392 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20392 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15386 completed with status: 'FAILURE'

@yuxianq
Copy link
Collaborator Author

yuxianq commented Oct 1, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20434 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20434 [ run ] completed with state DISABLED
L0 testing is limited to prioritized users. User yuxianq is not in the prioritized list. L0 testing cannot be triggered.

@yuxianq
Copy link
Collaborator Author

yuxianq commented Oct 1, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20472 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20472 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15437 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

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.

4 participants