Repository navigation
flashnext cuda: non-final one-rank prompt chunks skip the unread last MLP - #4885
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/flashnext-unread-last-mlp
branch
from
November 24, 2026 13:09
7716ca1 to
3317f02
Compare
… 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
force-pushed
the
lead/flashnext-unread-last-mlp
branch
from
November 24, 2026 23:38
3317f02 to
c00cbc6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
On one rank, a Flash Next CUDA prompt chunk before the last runs its head as
.nonewhen its pass has nostreams,keepormoe_addhook.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 requiresm.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_FUSEDdefault 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 writespsswithout reading it. The zero-slice flag only falls when a lane writespart, 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 --checkandzig ast-checkon 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): passzig build check-native-cuda-host: pass, and a compile probe inPass.unreadTailconfirmed the step reaches itNot 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.