Fix Mamba-3 decode path: forward() to step() shape handling#978
Open
sanowl wants to merge 1 commit into
Open
Conversation
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.
Mamba3.forward() routes to step() during autoregressive decode (seqlen_offset > 0),
passing the (batch, 1, dim) tensor it receives. step() expects (batch, dim):
_preprocess uses 2-axis einops patterns such as rearrange(x, "b (h p) -> b h p").
Decoding through the module crashes at the first generated token. Even without the
crash, the previous
return outreturns 2D while the prefill path returns 3D.Mamba2.step() handles this by squeezing the input and unsqueezing the output;
Mamba3 did neither.
the Fix
assert seqlen == 1 guard (single-token decode, matching Mamba2).
through the seqlen_offset > 0 branch, and check parity against the direct-step
reference (SISO and MIMO, out-norm on and off).
I have not run this. No NVIDIA GPU available locally (the CUTE step kernel requires
H100). The change is verified by code review and matches the existing Mamba-2
convention; the added test should validate it on CUDA / CI.