Skip to content

fix(flash next cuda): both ranks stop a reply when its caller asks - #231

Closed
plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:fix/flashnext-tp2-stop-vote
Closed

plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:fix/flashnext-tp2-stop-vote

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

On two ranks, Flash Next throws away on_tokens' True (generate: on_tokens = lambda new: (emit(new), False)[1] # both ranks decode to the end), and rank 1's follow decodes with no callback. So when the client leaves, a stop string matches or a gate cuts the reply, both ranks decode on to max_tokens. Only rank 0 sees the client, so rank 0 can't stop alone: rank 1 would wait in the next round's collectives.

This is @pulseandthread's stop vote from #194 (GLM), ported to Flash Next at his suggestion. StopVote all-gathers rank 0's stop (one int, sticky) after each round, and both ranks end after the same round. Rank 1's follow passes a vote that never asks. The decode loops already break on True. One GPU is unchanged.

Two DGX Sparks, Flash Next (Vontra MLX 4-bit), --tp 2 --context 16384, v0.6.1 against v0.6.1 + this PR, and with #218:

v0.6.1 + this PR + this PR + #218
reply with a stop string (28 tokens, max_tokens 3,000) 38.7 s to the reply 0.50 s 0.49 s
client leaves after 3 s, socket below fd 1024 pair busy 46.7 s free in 0.25 s free in 0.25 s
client leaves after 3 s, socket past fd 1023 busy 46.6 s, 46.9 s busy 47.2 s, 47.4 s free in 0.25 s
9 replies (3 prompts × greedy, seeded, "draft": false), token_sha 9/9 equal to v0.6.1 9/9 equal
decode, 512-token greedy reply (3 runs) 75.7–75.9 tok/s 73.1–74.3 74.5–76.0
  • The stop string is the user-visible part: on v0.6.1 the reply was complete after 28 tokens, but the response came only after both ranks had decoded all 3,000.
  • Past fd 1023 rank 0 doesn't see the client leave without fix(server): the client-gone check sees descriptors past 1023 #218, so the pair needs both, as on GLM.
  • The vote costs one int a round. Across the two runs with it, decode is 0–3 % below v0.6.1.
  • After every run a follow-up request needing both ranks was answered in 0.7 s with the same reply; neither rank logged errors.

Tests. tests/test_flashnext_stop_vote.py, from #194's GLM test: two ranks in lockstep both stop after the round rank 0 asks, and a vote stays asked. tests/test_flashnext_message_points.py's follower test builds a bare engine, so it now sets the gather follow uses. The Flash Next and qwen4 CPU tests: 100 passed, 14 skipped, and 1 failure that v0.6.1 has too (test_flash_next_pass_rows.py::test_a_rounds_pass_keeps_decoding_its_share).

Not covered. --parallel on two ranks (#141) goes through the scheduler, not this path; I didn't change or test it. #219 keeps comm.all_gather, which is all the vote uses, so either merge order works (as @pulseandthread noted on #218).

On two ranks Flash Next threw away on_tokens' True (the client left, a stop string, a gate cut the reply)
and both ranks decoded on to max_tokens. On two DGX Sparks a 4,000-token reply whose client left after
3 s kept the pair busy 46 s. Only rank 0 sees the client, so rank 0 alone can't stop: rank 1 would wait
in the next round's collectives.

StopVote all-gathers rank 0's stop (one int, sticky) after each round, and both ranks end after the
same round; rank 1's follow now passes a vote that never asks. The decode loops already break on True.

The design is pulseandthread's stop vote for GLM in ashhart#194.
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. You found a real cost, a 28-token reply that took 38.7 s because both ranks decoded all 3,000 tokens after a stop string.

The Zig engine stops both sides together. Its cluster is leader-driven. Followers run only what rank 0 broadcasts, and a release frees the slot on every rank. Flash Next on two Macs, the new speed-up mode, sends rank 0's stop decision, a stop string or a cancel, to rank 1 at every step, so both Macs end on the same round. That is the fix your PR makes for the Python engine's two Sparks.

The Python engine is frozen (#286), so this PR closes with that. Thanks for measuring it so clearly.

@ashhart ashhart closed this Oct 6, 2026
grearjake-star added a commit to grearjake-star/TensorFold that referenced this pull request Oct 8, 2026
On two ranks Flash Next threw away on_tokens' True ("both ranks decode to the end") and rank 1 followed
with no callback, so when a client left, a stop string matched or a gate cut the reply, both ranks
decoded on to max_tokens (a 28-token reply took 38.7 s on two Sparks). A StopVote all-gathers rank
0's sticky stop, one int a round, and both ranks end after the same round; rank 1's follower passes a
vote that never asks. One GPU is unchanged: the vote is only built when tp == 2.

Upstream: ashhart#231 (GLM's stop vote from ashhart#194 ported to Flash Next), closed unmerged with
the Python engine frozen. Host tests only here; the fork's gate runs one GPU, so two-rank serving is
not exercised by it.

Co-authored-by: plotarmordev <[email protected]>
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.

2 participants