Repository navigation
Conversation
The fused Metal kernels (forward and VJP) read the gate as [B, T, Hv]. A per-channel gate [B, T, Hv, Dk] that passes the head and dim checks was dispatched to them anyway and read with the wrong layout, giving silently wrong outputs and gradients. The ops fallback already handles both gate ranks, so route a 4-D gate there. Adds a test that compares the default stream against the CPU stream for a 4-D gate at a shape the fused kernels accept; it fails before this change and passes after it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
initial_state and final_state are [B, Hv, Dv, Dk], as the C++ op and the tests use, not [B, T, Hk, Dv]. Document the per-channel gate rank. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
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 issue: #4763
What was wrong:
So, the check that chooses GPU kernels looks at the head count, head size, mask but not gate shape (in
mlx/fast.cpp)This affects 6 of the supported shapes. Dk = Dv = 128, with (Hk, Hv) = (24,24), (32,32), (16,32), (16,48), (16,16) or (16,64).
Introduces: 3e-2 error in the ourtput which will compoud.
The fix:
Added condition in mlx/fast.cpp if g.ndim() == 4 to skip the gpu kernels.
The general code already handles the gateshapes
Test: It compares the CPU & GPU for a per-channel gate.