Fix Mamba2.step() handling of D when D_has_hdim=True#901
Closed
Chessing234 wants to merge 1 commit into
Closed
Conversation
When D_has_hdim=True, self.D has shape (nheads * headdim,) instead of
(nheads,). The forward() method correctly reshapes D from (h*p,) to
(h, p) in this case, but step() always treated D as if it had shape
(nheads,), leading to incorrect results during autoregressive decoding.
Fix both code paths in step() (with and without selective_state_update)
to use rearrange("(h p) -> h p") when D_has_hdim=True, consistent with
forward().
Fixes #887
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Closing in favor of #903 (duplicate) |
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.
Summary
Mamba2.step()to correctly handleself.DwhenD_has_hdim=True, whereDhas shape(nheads * headdim,)instead of(nheads,)step()(with and withoutselective_state_update) now userearrange("(h p) -> h p")whenD_has_hdim=True, consistent withforward()D_has_hdim=TruebecauseDis misinterpreted as per-head rather than per-head-dimFixes #887
Test plan
step()output matchesforward()output for a single token whenD_has_hdim=TrueD_has_hdim=False(default behavior unchanged)selective_state_updateavailable and with the fallback path🤖 Generated with Claude Code