Skip to content

Flash Next on M5: kept DeltaNet states and half nibbles, 6.5% faster decode, same tokens - #3271

Merged
ashhart merged 3 commits into
mainfrom
lead/m5-kept-nibbles
Nov 20, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/m5-kept-nibbles

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Two decode choices that M1-M4 already make were switched off on Macs with tensor units (M5). This turns them on there too. Replies are unchanged, and one stream is about 6.5% faster on main's default M5 path.

  • Kept DeltaNet states. keepStates and keepLoneStates (engine_rounds.zig) returned early on tensorUnits(). An M5 therefore wrote every window row's DeltaNet state each round and then copied the kept one. Now it keeps one state per layer and replays the kept rows, as M1-M4 have since October.
  • Half nibbles. rows_w.nib gave generation 17 the plain converts, so the 4/32 expert, dense-row and hyper-connection kernels converted each code to float one at a time. Now M5 takes the half path that M3 and M4 use, two codes per half operation with the same values in the same order. M1 and M2 keep the exponent trick.
  • Prompt kernels and the tensor-unit decode kernels are not touched.

Measured on an M5 Ultra (512 GB), Qwen3.8-Flash-Next MLX 4-bit MTP at 2b170fa6, one server per arm, main/new/new/main, 16 prompts (tools/bench_prompts.json) of 512 tokens:

One stream main this PR
Greedy, mean tok/s 206.4 220.2 (+6.6%)
Sampled (T 1.0, seed 1234), mean tok/s 184.5 196.6 (+6.5%)
"draft": false, mean tok/s 109.1 111.3 (+2.0%)
  • No prompt was slower. Tokens equal main on 32 of 32 replies (greedy and sampled), and drafted equals "draft": false on 16 of 16.
  • At --parallel 4 with distinct prompts staggered 150 ms (bench_concurrent.py --alone), every concurrent reply equals its solo run. Totals at 1, 2 and 4 streams: sampled +5.0 / +4.7 / +0.8%, greedy +7.2 / +3.5 / +4.9%.
  • With the opt-in from Flash Next on M5: TF_FLASHNEXT_M5_ROWS=1 decodes on the pre-M5 path, 16% faster at one stream #3227 (TF_FLASHNEXT_M5_ROWS=1) on top, the same 16 prompts go from 238.8 to 254.1 greedy (+6.4%) and from 215.6 to 229.2 sampled (+6.3%), tokens equal on 32 of 32. The two changes don't touch the same files.
  • Tested separately, each part is about half the gain: kept states +3.1% greedy and half nibbles +3.8% on the default path.

zig build test-native passes on an M5 Max, and lean reports no new problems. The changelog line goes under a new ## Unreleased, since main is at the 1.2.8 release commit.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/m5-kept-nibbles branch 2 times, most recently from 67bc418 to 338ce88 Compare November 19, 2026 01:51
Two choices M1-M4 already make were switched off on GPUs with tensor units:
- keepStates and keepLoneStates returned early on tensorUnits(), so an M5
  wrote every window row's DeltaNet state each round and then copied the kept
  one, instead of keeping one state a layer and replaying the kept rows.
- rows_w.nib gave generation 17 the plain converts, so the 4/32 expert, dense
  row and hyper-connection kernels converted each code to float one at a time
  instead of two a half operation.
Both now apply on M5 as on M3 and M4. M1 and M2 keep the exponent trick.

Replies are unchanged. On an M5 Ultra (Qwen3.8-Flash-Next MLX 4-bit MTP, one
stream, 16 prompts of 512 tokens, main/new/new/main):
- greedy 206.4 -> 220.2 tok/s (+6.6%), sampled 184.5 -> 196.6 (+6.5%),
  "draft": false 109.1 -> 111.3 (+2.0%), no prompt slower
- tokens equal to main on 32 of 32 replies; drafted == "draft": false 16 of 16
- --parallel 4, distinct prompts staggered: every concurrent reply equals its
  solo run; sampled 1/2/4 streams +5.0/+4.7/+0.8%, greedy +7.2/+3.5/+4.9%
zig build test-native passes on an M5 Max; lean 0 new.
@ashhart
ashhart force-pushed the lead/m5-kept-nibbles branch from 338ce88 to dd3eb30 Compare November 20, 2026 10:12
@ashhart
ashhart merged commit f794b26 into main Nov 20, 2026
2 of 11 checks passed
@ashhart
ashhart deleted the lead/m5-kept-nibbles branch November 20, 2026 10:12
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