Skip to content

Comments

[https://nvbugs/5624818][fix] Work around accuracy issue by enforcing paged_context_fmha on Hopper for fmha_v2#11192

Merged
eopXD merged 1 commit intoNVIDIA:mainfrom
eopXD:nvbugs5624818
Feb 4, 2026
Merged

[https://nvbugs/5624818][fix] Work around accuracy issue by enforcing paged_context_fmha on Hopper for fmha_v2#11192
eopXD merged 1 commit intoNVIDIA:mainfrom
eopXD:nvbugs5624818

Conversation

@eopXD
Copy link
Collaborator

@eopXD eopXD commented Feb 2, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enabled paged context FMHA optimization on SM90 GPUs to improve performance on latest hardware architectures.

Description

As topic, we currently have an accuracy issue on the prefill computation of the fmha_v2 kernels on Hopper. For now as a workaround we should enforce paged_context_fmha to ensure correctness of the inference.

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.

@eopXD eopXD requested a review from a team as a code owner February 2, 2026 12:53
@eopXD eopXD requested a review from yuxianq February 2, 2026 12:53
@eopXD
Copy link
Collaborator Author

eopXD commented Feb 2, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34471 [ run ] triggered by Bot. Commit: 16dbea5

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

A guarded CUDA driver import was added to the attention backend module. A runtime check was introduced to automatically enable paged context FMHA on SM90 GPUs (compute capability major == 9) across multiple attention wrapper methods, creating a new conditional execution path when this condition is met.

Changes

Cohort / File(s) Summary
SM90 FMHA Workaround
tensorrt_llm/_torch/attention_backend/trtllm.py
Added guarded CUDA driver import with fallback, and introduced SM90-specific runtime checks in TrtllmAttentionWrapper.use_nvfp4_output, TrtllmAttentionWrapper.forward, and TrtllmAttention.forward methods to automatically enable paged_context_fmha on compute capability 9 GPUs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description includes the main issue and workaround solution but lacks details on test coverage, which is required by the template. Add specific test cases or testing strategy under the 'Test Coverage' section to demonstrate how the paged_context_fmha enforcement is validated on Hopper.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix with NVBugs ticket reference and specifically describes the workaround: enforcing paged_context_fmha on Hopper for fmha_v2 accuracy issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/attention_backend/trtllm.py (1)

1-1: ⚠️ Potential issue | 🟡 Minor

Add the NVIDIA copyright header for this source file.

This file now includes meaningful 2026 changes but still lacks the standard NVIDIA header at the top. Please add the repo-standard header and update the year to 2026.

As per coding guidelines, 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.

🤖 Fix all issues with AI agents
In `@tensorrt_llm/_torch/attention_backend/trtllm.py`:
- Around line 1669-1678: The SM90 workaround unconditionally forces
use_paged_context_fmha = True, which overrides the prior MLA-specific disabling;
modify the condition so it only flips use_paged_context_fmha when SM90 and the
model is not MLA—e.g., change the if to check sm_major == 9 and NOT the MLA
branch that previously set use_paged_context_fmha False (the code that detects
MLA and sets use_paged_context_fmha), ensuring you reference the same MLA
detection/flag used earlier so MLA continues to have paged_context_fmha
disabled.
- Around line 1556-1565: The code currently hardcodes GPU 0 via
cuda.cuDeviceGet(0), assigns unused err, and uses non-snake-case cuDevice;
update the detection to query the current CUDA device (e.g., use
cuda.cuCtxGetDevice or equivalent to get the active device) and pass that device
to cuda.cuDeviceGetAttribute to compute sm_major, rename cuDevice to cu_device,
and remove the unused err variable; make the same replacement for the other
occurrence of this pattern (the block using cuDeviceGet/ cuDeviceGetAttribute
around sm_major detection later in the file) and keep the conditional logic that
forces use_paged_context_fmha when sm_major == 9.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34471 [ run ] completed with state SUCCESS. Commit: 16dbea5
/LLM/main/L0_MergeRequest_PR pipeline #26595 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

@yuxianq yuxianq requested a review from PerkzZheng February 3, 2026 03:07
@yuxianq
Copy link
Collaborator

yuxianq commented Feb 3, 2026

@PerkzZheng I am not sure whether it is a proper WAR, please see nvbug for more details.

@eopXD
Copy link
Collaborator Author

eopXD commented Feb 3, 2026

@yuxianq I believe this should be a temporary workaround (though I still need @PerkzZheng to confirm if this is a reasonable one). @pengbowang-nv and I are working on rootcausing what is actually behind the accuracy problem regarding the paged_context_fmha knob and will proceed to fix it correctly without the workaround.

@eopXD
Copy link
Collaborator Author

eopXD commented Feb 3, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34563 [ run ] triggered by Bot. Commit: 6072cc8

@eopXD
Copy link
Collaborator Author

eopXD commented Feb 3, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34596 [ run ] triggered by Bot. Commit: 40ff80e

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34596 [ run ] completed with state FAILURE. Commit: 40ff80e
/LLM/main/L0_MergeRequest_PR pipeline #26695 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

@eopXD
Copy link
Collaborator Author

eopXD commented Feb 4, 2026

/bot run --disable-fail-fast

1 similar comment
@eopXD
Copy link
Collaborator Author

eopXD commented Feb 4, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34725 [ run ] triggered by Bot. Commit: 40ff80e

@tensorrt-cicd
Copy link
Collaborator

PR_Github #34725 [ run ] completed with state SUCCESS. Commit: 40ff80e
/LLM/main/L0_MergeRequest_PR pipeline #26794 completed with status: 'SUCCESS'

@eopXD eopXD merged commit f6fff18 into NVIDIA:main Feb 4, 2026
5 checks passed
SchumiDing pushed a commit to SchumiDing/TensorRT-LLM that referenced this pull request Feb 6, 2026
… paged_context_fmha on Hopper for fmha_v2 (NVIDIA#11192)

Signed-off-by: eopXD <yuehtingc@nvidia.com>
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