Skip to content

Route of per-channel gate in gated_delta_update fixed - #4766

Open
Exorust wants to merge 2 commits into
ml-explore:mainfrom
Exorust:fix/gated-delta-vector-gate-routing
Open

Exorust wants to merge 2 commits into
ml-explore:mainfrom
Exorust:fix/gated-delta-vector-gate-routing

Conversation

@Exorust

@Exorust Exorust commented Oct 25, 2026

Copy link
Copy Markdown
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: Used Claude Code to write the code

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.

Exorust and others added 2 commits October 24, 2026 19:25
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant