fix(nemotron_h): correct inter-chunk SSM recurrence axis and dt clamping in torch_forward - #47513
Closed
adeev-mardia wants to merge 1 commit into
Closed
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: nemotron_h |
Contributor
CI recapDashboard: View test results in Grafana |
Member
|
This is just raw code agent output and there was another PR at #47250 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #47246.
What this PR does
Overrides
NemotronHMamba2Mixer.torch_forwardinmodular_nemotron_h.pyto fix two bugs in the slow (no-kernel) path that were inherited fromZamba2MambaMixerand never corrected for NemotronH.Bug 1 — wrong reduction axis in the inter-chunk SSM recurrence
The inherited Zamba2 code computes step 3 (inter-chunk A-terms) by permuting
states(swapping the batch/num-chunks axes) and reducing overdim=2:This collapses the wrong axis. The correct form — which matches canonical Mamba2 (fixed in #35154 for issue #34817) — transposes
decay_chunkinstead and reduces overdim=1:Impact: The bug produces incorrect layer outputs and corrupts the SSM cache state in every case except a fresh prefill with sequence length ≤
chunk_size(default 128). That single masked case is exactly what fast unit tests exercise, so the bug went undetected. It affects:The CUDA-kernel path (
cuda_kernels_forward) is correct and unaffected.Bug 2 —
dtclamped with only a lower bound on the slow pathThe inherited code calls:
cuda_kernels_forwardpassesdt_limit(a 2-tuple), so the slow path silently applies a 0.001 floor that the kernel path does not. Fixed to:Testing
The reproduction script from #47246 confirms the fix (runs on CPU, no model download needed):
The fixed form matches the brute-force reference exactly in all cases.
Related
NemotronHMamba2Mixer.torch_forward(slow path). the Mamba2 fix from #35154 was never propagated tonemotron_h#47246 — original report for NemotronHtorch_forwardreduction dimension possibly incorrect? #34817 — original report for canonical Mamba2Mamba2] Fix caching, slow path, and multi-gpu #35154 — the fix for canonical Mamba2 (this PR propagates it to NemotronH)