Skip to content

[https://nvbugs/6901613][fix] Two-pass variance in the same kernel: reduce and share the mean, then sum… - #20092

Merged
schetlur-nv merged 1 commit into
NVIDIA:release/1.3from
tensorrt-cicd:repair-bot-bug6901613-release-1.3-cb2b0e3d6f12
Oct 23, 2026
Merged

schetlur-nv merged 1 commit into
NVIDIA:release/1.3from
tensorrt-cicd:repair-bot-bug6901613-release-1.3-cb2b0e3d6f12

Conversation

@trtllm-agent

@trtllm-agent trtllm-agent commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: One-pass FP32 variance E[x²] − mean² cancels when |mean| is much larger than the spread, goes negative, and rsqrtf(var + eps) returns NaN for the whole row.
  • Fix: Two-pass variance in the same kernel: reduce and share the mean, then sum squared differences from it and take rsqrtf(s2c/D + eps); added a regression test with an FP64 reference.
  • Original test: bash .repair-bot/run_repro.sh
  • Automated fix generated by repair-bot

Test plan

  • Verify fix on the same GPU type as the original failure
  • Check for regressions in related tests

Links

Reproduction comparison

  • Failed commit: skipped_on_failed_commit
    Not run: the NVBug report states the failure ToT reproduced (DRIVER_RESULT=product_failure rep=1 passes_before=0 required=10)
  • ToT: repro_on_tot at c008883
    Signature: DRIVER_RESULT=product_failure rep=1 passes_before=0 required=10
  • Signature relation: same (NVBug report vs. ToT signature; failed leg not run)

Dev Engineer Review

The kernel now computes the mean and then sums squared deviations from it. This avoids the cancellation risk in E[x²] − mean² for rows with large means and small variance. No public API changes are reported.

QA Engineer Review

The new regression test covers BF16 rows with large means and small variance. It checks plain, affine, and modulation modes at two epsilon values against a two-pass FP64 reference. It also checks finite output and numerical closeness. The test-list search result was not available, so CI and manual-QA listing status is unconfirmed. Coverage verdict: needs follow-up to confirm appropriate test-list inclusion and test execution.

Per-File QA Perspective

  • cpp/tensorrt_llm/kernels/fusedAdaptiveLayerNormKernel.cu: Verify normalized outputs for rows with large means and small variance. The kernel now uses a two-pass variance calculation with blockReduceSum.
  • tests/unittest/_torch/visual_gen/kernels/parallel/test_fused_dit_layernorm_shift_scale.py: Adds test_bf16_large_mean_small_variance for plain, affine, and modulation modes. Test-list inclusion and execution status are unconfirmed.

… adaptive LayerNorm

The FP32 one-pass E[x^2] - mean^2 variance cancels catastrophically for
rows whose mean is large relative to their spread (e.g. 2 x 15.6875 then
5118 x 15.75 at D=5120), going negative so rsqrtf(var + eps) turns the
whole row into NaN. Reduce the mean first, then the sum of squares of the
register-cached values centered on it. Add a regression test for the
reported row in plain, affine and modulation modes.

Signed-off-by: trtllm-agent <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/TensorRT-LLM/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: f768a1d0-0c03-4816-8dc5-4aa88d336410

📥 Commits

Reviewing files that changed from the base of the PR and between c008883 and e8fa456.


📒 Files selected for processing (2)
  • cpp/tensorrt_llm/kernels/fusedAdaptiveLayerNormKernel.cu
  • tests/unittest/_torch/visual_gen/kernels/parallel/test_fused_dit_layernorm_shift_scale.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.



Walkthrough

The fused LayerNorm kernel now computes mean and centered variance in two reduction passes. A BF16 regression test checks output accuracy for large-mean, small-variance inputs across normalization modes and epsilon values.

Changes

Fused LayerNorm statistics

Layer / File(s) Summary
Centered variance calculation and validation
cpp/tensorrt_llm/kernels/fusedAdaptiveLayerNormKernel.cu, tests/unittest/_torch/visual_gen/kernels/parallel/test_fused_dit_layernorm_shift_scale.py
The kernel uses two blockReduceSum passes to compute the mean and centered variance, replacing the warp-level sum and sum-of-squares reductions. The new CUDA-only BF16 test compares outputs with an FP64 centered-variance reference across two epsilon values and three normalization modes.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: o-stoner

Merge Risk: ⚪ Minimal · up to e8fa4

This change fixes NaN outputs in fused LayerNorm for rows with a large mean and small spread, and adds a regression test for plain, affine and modulation modes. No outstanding merge-blocking risk was found.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title is concise, specific, and follows the required NVBugs ID and lowercase fix format. It accurately summarizes the two-pass variance change.
Description check Passed The description clearly explains the root cause, solution, regression test, test plan, bug link, and reproduction results. It does not reproduce the template's full PR Checklist, but the main required…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@karljang karljang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM;

@karljang

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77688 [ run ] triggered by Bot. Commit: e8fa456 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77688 [ run ] completed with state SUCCESS. Commit: e8fa456
/LLM/release-1.3/L0_MergeRequest_PR pipeline #201 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@BowenFu

BowenFu commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Bug engineer ownership

@o-stoner, as the engineer assigned to the linked bug, you are responsible for driving this bot PR to resolution. Please coordinate review, address feedback and required code changes, get CI passing, and verify the original failure before driving it to merge. If the PR is obsolete or superseded, close it with a reason. Keep this PR updated with blockers and the next step.

@schetlur-nv
schetlur-nv merged commit 70ce973 into NVIDIA:release/1.3 Oct 23, 2026
2 checks passed
ll2088 added a commit to ll2088/sglang that referenced this pull request Oct 30, 2026
Ported from NVIDIA/TensorRT-LLM#20092
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Oct 30, 2026
Ported from NVIDIA/TensorRT-LLM#20092
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Oct 30, 2026
Ported from NVIDIA/TensorRT-LLM#20092
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Oct 30, 2026
Ported from NVIDIA/TensorRT-LLM#20092
Generated by autojump (AI); review before merging.
ll2088 added a commit to ll2088/sglang that referenced this pull request Oct 30, 2026
Ported from NVIDIA/TensorRT-LLM#20092
Generated by autojump (AI); review before merging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants