Skip to content

fix(inference): preserve batch invariance for Nemotron Nano - #6893

Merged
wdykas merged 1 commit into
NVIDIA:mainfrom
wdykas:batch-invariant-nemotron-nano
Aug 26, 2026
Merged

fix(inference): preserve batch invariance for Nemotron Nano#6893
wdykas merged 1 commit into
NVIDIA:mainfrom
wdykas:batch-invariant-nemotron-nano

Conversation

@wdykas

@wdykas wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

Summary

This is a targeted follow-up to #6521, which introduced batch-invariant CUDA-graph token alignment and enabled the vLLM
fused-MoE backend under batch-invariant mode.

That MR intentionally pads token counts to 64-token boundaries while leaving request metadata unchanged. For Nemotron Nano, this exposed two missing cases:

  • Decode attention and SSM treated token-only padding rows as real request tokens, causing invalid reshape/input dimensions.
  • The vLLM squared-ReLU MoE path did not reproduce the activation, routing-probability, and rounding sequence used by the training TEGroupedMLP path, breaking bitwise
    generation/training parity.

we could get rid of this and just us the version where I overwrite the Rmsnorms with our triton kernel but this is much faster. The rmsnorm is 2x slower in triton so I would like to keep this path.

Changes

  • Exclude batch-invariant token-only padding before decode attention and SSM kernels, then restore zero padding before their output projections.
  • Pin the vLLM MoE K-reduction recipe under batch-invariant mode.
  • Match training-side routing-probability application and BF16 rounding for both squared-ReLU and SwiGLU.
  • Match the invariant training unpermute with an unweighted FP64 within-rank reduction.
  • Keep every behavioral change explicitly gated by batch-invariant mode; ordinary inference behavior is unchanged.

The token alignment introduced by #6521 remains intact—the consumers now correctly distinguish aligned token rows from actual requests.

@wdykas
wdykas requested review from a team as code owners August 26, 2026 15:42
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5eb83f5

@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@utkarsh530 In case you need for your work.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 26, 2026 15:55
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@santhnm2 santhnm2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to consolidate the new unit tests into existing files?

@wdykas
wdykas marked this pull request as ready for review August 26, 2026 16:52
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Aug 26, 2026
@wdykas
wdykas force-pushed the batch-invariant-nemotron-nano branch from 5eb83f5 to 1961b5e Compare August 26, 2026 17:13
@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1961b5e

@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/claude review

@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a01cc0d

Comment thread tests/unit_tests/ssm/test_gdp_dynamic_inference.py Outdated
claude[bot]

This comment was marked as resolved.

Signed-off-by: wdykas <wdykas@nvidia.com>
@wdykas
wdykas force-pushed the batch-invariant-nemotron-nano branch from a01cc0d to c837c0a Compare August 26, 2026 17:58
@wdykas

wdykas commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c837c0a

@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Aug 26, 2026
@utkarsh530

Copy link
Copy Markdown
Contributor

@wdykas Thanks! This is quite helpful

@wdykas
wdykas added this pull request to the merge queue Aug 26, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/33013279273

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 26, 2026
@wdykas
wdykas added this pull request to the merge queue Aug 26, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/33018285931

Merged via the queue into NVIDIA:main with commit ad740d8 Aug 26, 2026
95 of 97 checks passed
@wdykas
wdykas deleted the batch-invariant-nemotron-nano branch August 26, 2026 23:26
ksivaman pushed a commit to ksivaman/Megatron-LM that referenced this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants