Skip to content

fix(metal): correct SSM scan token-block reduction indexing - #1171

Merged
0xShug0 merged 1 commit into
mainfrom
fix/metal-ssm-scan-reduction
Nov 2, 2026
Merged

0xShug0 merged 1 commit into
mainfrom
fix/metal-ssm-scan-reduction

Conversation

@0xShug0

@0xShug0 0xShug0 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fix Metal SSM scan reduction indexing: partial sums are stored per token block, but were read using the absolute token offset. After the first block, this reads incorrect shared-memory slots and can go out of bounds.

Use the block-local SIMD-group index instead. Other backends and operation handlers are unchanged.

Validation

  • Added an extended Metal test with 96 shapes covering Mamba-1/2, state sizes 16-128, token lengths 1-257, grouped heads, strided B/C and remapped initial states.
  • Checks all outputs and final states against an independent double-precision recurrence, including an exact binary-rational case; three changing patterns and repeatability checks.
  • The test fails on main with two tokens: actual 0, expected -0.291016. All cases pass with the fix.
  • Existing F32 matmul tests pass. Both test targets complete in approximately 1.3 seconds on M4 Pro.

@0xShug0
0xShug0 force-pushed the fix/metal-ssm-scan-reduction branch from b7ba362 to b4dbaa4 Compare November 2, 2026 05:26
@0xShug0
0xShug0 merged commit b2bfede into main Nov 2, 2026
7 checks passed
@0xShug0
0xShug0 deleted the fix/metal-ssm-scan-reduction branch November 2, 2026 05:35
@0xShug0 0xShug0 added the ggml label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant