Skip to content

flashnext cuda: non-final one-rank prompt chunks skip the unread last MLP - #4885

Merged
ashhart merged 3 commits into
mainfrom
lead/flashnext-unread-last-mlp
Nov 24, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/flashnext-unread-last-mlp

Conversation

@ashhart

@ashhart ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

What changes

On one rank, a Flash Next CUDA prompt chunk before the last runs its head as .none when its pass has no streams, keep or moe_add hook. head(.none) returns before it reads the residual streams (cuda_batch_head.zig). Nothing read the last layer's MLP stream write-back and read-out, its experts or its MoE adds. The pass now stops after that layer's mixer, whose KV, GDN state and in-pass mark writes still run.

The guard (unreadTail) also requires m.collective == null. At TP=2, rank 0's MTP prefill asks for .streams, while rank 1 receives only the logits flag (cuda_rank_engine.zig). A one-sided skip would leave the ranks' MoE collectives out of step, so tensor-parallel passes keep the whole last layer.

This is not the TF_FLASHNEXT_READOUT_FUSED default flip, which is #4799. The serving pin for cuda_batch.zig moves to the new bytes.

Exactness

The skipped work had no reader. The write-back only reads part, and the mode-0 write-back at the next chunk's first layer writes pss without reading it. The zero-slice flag only falls when a lane writes part, so state left for the next chunk is consistent. Tokens keep their bits.

Checked

On a Linux x86_64 host with no GPU, using Zig 0.17.0, at this head:

  • zig fmt --check and zig ast-check on every changed Zig file; python3 tools/zig/lean_check.py: 165 problems, the same count as main; the push gate's scanner: safe.
  • zig build test-gradient-serving (the moved cuda_batch.zig pin): pass
  • zig build check-native-cuda-host: pass, and a compile probe in Pass.unreadTail confirmed the step reaches it

Not run

No device run. No host test drives Pass.chunk; the device cells decide.

Device cells that decide it

Run each as an A/B of main against this head, with an A/A first and a balanced order, dropping run 1. #4799 goes first.

Cell GPU Checkpoint What it covers
1 GB10, one GPU Qwen3.8-Flash-Next-NVFP4 cold prompts of 8K and 32K, drafts off (the skip) and on (MTP streams: no skip); TTFT, plus tokens equal to main
2 GB10, one GPU Qwen3.8-Flash-Next-MLX-4bit-MTP the same rows on the BF16/affine read-out
3 2x GB10, TP=2 Qwen3.8-Flash-Next-NVFP4 drafts on and off; tokens equal to main, no slower (the path is unchanged)

@ashhart
ashhart force-pushed the lead/flashnext-unread-last-mlp branch from 7716ca1 to 3317f02 Compare November 24, 2026 13:09
… MLP

On one rank, a prompt chunk before the last whose pass has no stream, keep
or MoE-add hook runs its head as .none, and head(.none) returns before it
reads the residual streams. Nothing read the last layer's MLP stream
write-back and read-out, its experts or its MoE adds. The pass now stops
after that layer's mixer, whose cache and state writes still run. Nothing
that is read changes, so tokens keep their bits.

Tensor-parallel passes keep the whole last layer. Rank 0's MTP prefill asks
for the streams while rank 1 sees only the logits flag, so a skip on one
rank alone would leave the ranks' MoE collectives out of step. A pass with
drafts, kept rows or training adds also runs the layer as before.

The serving pin for cuda_batch.zig moves to the new bytes.
@ashhart
ashhart force-pushed the lead/flashnext-unread-last-mlp branch from 3317f02 to c00cbc6 Compare November 24, 2026 23:38
@ashhart
ashhart merged commit 3e1c4c5 into main Nov 24, 2026
12 checks passed
@ashhart
ashhart deleted the lead/flashnext-unread-last-mlp branch November 24, 2026 23:38
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