Skip to content

perf: Flash Next decode 15-17% faster, byte-exact - #6

Merged
ashhart merged 1 commit into
mainfrom
flash-next-speed
Sep 26, 2026
Merged

ashhart merged 1 commit into
mainfrom
flash-next-speed

Conversation

@ashhart

@ashhart ashhart commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Flash Next (qwen4_exp) decodes 15-17% faster with byte-identical output and unchanged teacher-forced NLL.

What changed:

  • The family sets MLX_MAX_MB_PER_BUFFER and MLX_MAX_OPS_PER_BUFFER through MLX_ENV, and the fused decode submits each layer as it is built. Every expert kernel binds the 420 MB expert stacks; with MLX's default limit each one ended a command buffer.
  • Expert gate/up hands its routing to expert down instead of every down simdgroup redoing the top-10 selection. Per-slot expert kernels at every window width; down writes each slot's output and the next hyper-connection norm combines them with the same arithmetic.
  • a[0] indexing replaced by reshape views: MLX's a[0] is a gather that copied the DeltaNet state every step.
  • The n-gram embedding and the token embedding each in one lookup kernel (both match mx.dequantize bit for bit).
  • The MTP head's first draft for every verify row is drawn in the verify's GPU pass (skipped for streams with drafts off).

Measured on an M3 Ultra, in-engine tok/s (fixed prompts and seeds, output compared between variants):

before after
prose 92.4 106.9
code 100.2 115.7
23k-token agent prompt 96.6 113.3
file edit 119.5 137.1

Through the server: short answers 105-107, code 112, file edits 190, 18k context 98.5, the agent prompt 103-115. The README table and the recipe are updated; the hero image still shows the old Flash Next numbers.

Tests: 252 passed. On the model: serial bits in every verify window at the 2,048-key boundary and at 18k (including a window cut and continued); NLL 1.5443 at 18k, the same as before.

- The family sets MLX_MAX_MB_PER_BUFFER and MLX_MAX_OPS_PER_BUFFER (MLX_ENV); the fused decode submits each
  layer as it is built. Every expert kernel binds the 420 MB expert stacks, and with MLX's default limit each
  one ended a command buffer.
- Expert gate/up hands its routing (picks and weights) to expert down instead of every down simdgroup redoing
  the top-10 selection. Per-slot expert kernels at every window width; down writes each slot's output and the
  next hyper-connection norm combines them with the same arithmetic.
- a[0] indexing replaced by reshape views: MLX's a[0] is a gather that copied the DeltaNet state every step.
  Positions and the no-ids placeholder made once per forward.
- The n-gram embedding in one lookup kernel over 8 concatenated shard groups (was about 70 small operations),
  and the token embedding with its tiling into the four streams in one kernel; both match mx.dequantize bit for
  bit.
- The MTP head absorbs every verify row and draws each row's first draft in the verify's GPU pass; the rows past
  the kept ones are dropped from its cache afterwards. Skipped for streams with drafts off.

Output is byte-identical to serial decoding and teacher-forced NLL is unchanged. In-engine tok/s on an M3 Ultra:
prose 92.4 -> 106.9, code 100.2 -> 115.7, 23k-token agent prompt 96.6 -> 113.3, file edit 119.5 -> 137.1.
@ashhart
ashhart merged commit 8c1291c into main Sep 26, 2026
@ashhart
ashhart deleted the flash-next-speed branch October 4, 2026 19:54
bertholomus referenced this pull request in bertholomus/TensorFold Oct 7, 2026
…uest's "loop_guard"), default off

GitHub #6: a long agentic turn can loop in its reasoning ("OK. / Writing. / Let me write.") to max_tokens and answer
nothing. call_gate.ThinkLoop watches a thinking reply: when, in 3 windows of 1024 reply tokens in a row, fewer than 2 %
of the window's token 8-grams are new (GitHub #9's novelty signal, on token ids), the reply gets the thinking
budget's close (a newline, </think>, a blank line) and goes on to its answer (generate_gated's cut). A decision
on the committed tokens alone; replies that do not loop are untouched. Off by default: TF_LOOP_GUARD=1 makes it the
server's default, "loop_guard": true / false sets it a request. Not under a grammar or a thinking budget.
bertholomus referenced this pull request in bertholomus/TensorFold Oct 7, 2026
…ORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1)

GitHub #6: the recipe runs the engine in an nvcr.io/nvidia/pytorch container, which sets
TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1: every fp32 cuBLAS GEMM runs in TF32, here the prompt chunks' router
logits, indexer weights and mHC mixes. That gives other prompt bits than the reference and the gates, and so
other replies for a seed: with the override, the report's body at seed 3001 (T 0.6 / top_p 0.95) loops to
the 32,768-token cap with 112,801 reasoning chars, as reported; without it the reply answers in 1,077 tokens.
cuda_engine now sets the switch to 0 before the engine exists (torch reads it at its first cuBLAS handle;
a line says so when it was 1) and fp32_gemms() raises if fp32 GEMMs still run in TF32 (a 4096-term sum of
(1 + 2^-12)^2 is 4098 in fp32, 4096 in TF32). Servers started with the switch at 0 are unchanged.
joshuaswarren added a commit to joshuaswarren/TensorFold that referenced this pull request Nov 26, 2026
…dy shaders for ashhart#1544

Rewrites the omarchy-derived Vulkan compute shaders from the behavior spec,
from cast/copy through the gated-delta state machines to the argreduce pair.
omarchy_trig.h becomes vulkan_trig.h (single inv_freq helper, Synthena ashhart#6),
gated_delta_prefill_ash becomes gated_delta_prefill_oracle, accepting both
-DASH_QWEN35 and -DORACLE_QWEN35. PRESERVE_F32 requests OpExecutionMode
DenormPreserve (f32) via spirv_execution_mode; sdpa_decode_native pins the
single-key bit-exact V transport (Synthena ashhart#7) and the 7168-key shared bound.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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