Skip to content

feat(flash next cuda): --parallel N on two ranks - #141

Closed
BHCC2025 wants to merge 1 commit into
ashhart:mainfrom
BHCC2025:flash-next-tp2-parallel
Closed

BHCC2025 wants to merge 1 commit into
ashhart:mainfrom
BHCC2025:flash-next-tp2-parallel

Conversation

@BHCC2025

@BHCC2025 BHCC2025 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Follows up #123. Flash Next with --tp 2 served one request at a time and refused --parallel. This lets both ranks share each round between several requests. Measured with your tools/bench_concurrent.py, 8 users get 2.4-3.4x the total throughput and every reply keeps its solo run's token ids. A single request under --parallel gives up 2-4%, which we left as is (details below).

What changes

  • Rank 0 plans, rank 1 runs that plan. Only rank 0 schedules. It sends rank 1 each admission, round, completion and drop, in the order it runs them, over one TCP connection. The connection uses TCP_NODELAY, and its ephemeral port on the --master address is published through the rendezvous store. An admission carries the slot rank 0 chose and the kept prompt end it resumes from, and rank 1 takes exactly those instead of choosing.
  • The ranks can't drift apart unnoticed, and neither is left waiting. Before each admission and each round, both ranks confirm the plan in one small all-gather. For an admission that's the stream, slot, resume point, prompt and sampling. For a round it's the live streams, their lengths, drafts and slots. If the plans ever differ, both ranks raise OutOfStep at the same point, before any of that step's collectives. The requests in that step fail with the error and serving goes on. Checking over the socket alone would have left rank 0 inside NCCL, which has no timeout, if rank 1 stopped. At startup both ranks must also agree on --parallel, beside the settings already checked.
  • A request that ends on rank 0 alone (the client left) is named in the next round message, so rank 1 ends it too before the check. It is then finished on both ranks as usual.
  • Sampling over the split vocabulary per stream. choose_gathered_streams picks every stream's tokens from the step's gathered candidates with one read-back. A rule wider than the gathered candidates goes through tp_sample_rows, and drafts do the same (_picks_tp).
  • A lone stream replays the one-stream CUDA graphs, as feat: Qwen3.6-35B-A3B serves --parallel N on CUDA, each reply equal to its solo run #84 does for Qwen3.6. The graphs' State is one of the slots. A stream left decoding alone moves into it with State.copy_from, which copies in place and keeps the captured addresses. This helps one GPU as well.
  • Admission: indexed_stream_geometry(world=...). The graphs' buffers are counted as one more stream, which is generous.
  • Structured output under --tp 2 --parallel is refused with an HTTP 400 before anything is generated. The message says why and what to do instead, and the startup line says so too. Images were already refused because Flash Next on CUDA is text-only. One GPU, and two ranks without --parallel, are unchanged.

The checks you listed

Check Where
Rank 0 plans each round and rank 1 runs the same plan follow runs rank 0's ops in order, with rank 0's slot and resume point. test_tp_rank_1_takes_rank_0s_slot_and_resume_point_or_both_refuse_the_admission and test_tp_ranks_planning_a_different_round_both_refuse_it_and_serve_on put rank 1 out of step on purpose: both ranks refuse that step, the request gets OutOfStep, the next request is exact, and every slot on rank 1 is free at the end
Every reply equals its "draft": false run and its solo run by token ids at 1, 2, 4 and 8 users test_tp_every_reply_equals_its_serial_run_and_its_solo_run_at_1_2_4_8_users, greedy and 7 sampling rules mixed; on two Sparks, below
A resumed prompt equals a fresh one test_tp_a_resumed_prompt_equals_the_same_prompt_fresh (same prompt resumed from a kept slot, fresh on a new decoder, and serial); on two Sparks, below
A cancel or disconnect during prefill or decode leaves neither rank hanging test_tp_a_client_leaving_in_prefill_or_decode_leaves_neither_rank_hanging through the real Scheduler, and test_tp_a_stream_rank_0_ends_at_its_first_token_..., which failed with "out of step" before the round-message change above; both assert every slot free on rank 1 at the end
Structured output and images refused, not served one at a time test_an_engine_refusing_structured_output_says_why_before_generating; on two Sparks, below

Evidence

Measured with your concurrency bench, tools/bench_concurrent.py, as docs/recipes/README.md describes: --levels 1,2,4,8 --alone --serial --reps 3 (256 tokens, ignore_eos), unchanged from 0.5.0. Setup: two DGX Sparks, Qwen3.8 Flash Next MLX 4-bit, --tp 2 --context 65536, int8 KV. We compared 0.5.0 without --parallel against this branch with --parallel 8. Figures are aggregate tok/s, 0.5.0 → this PR, medians of 3:

Users code greedy code sampled chat greedy chat sampled
1 107.1 → 104.9 105.6 → 101.4 86.0 → 83.9 84.0 → 80.7
2 104.5 → 173.2 97.1 → 126.5 85.2 → 139.7 85.8 → 113.3
4 103.8 → 258.5 101.4 → 171.8 84.4 → 209.2 82.1 → 146.8
8 103.6 → 345.4 101.9 → 223.7 84.0 → 283.8 78.7 → 185.5

The tool's own checks passed in every cell on both versions. Each concurrent reply had the same token ids as its solo run: 45/45 in each of the 4 cells, 180 in all. Each solo run matched "draft": false.

A single request is 2-4% slower than 0.5.0 when the server runs with --parallel, going through the lone-stream path: 104.9 against 107.1 tok/s for code greedy, and 80.7 against 84.0 for chat sampled. We did not try to close that gap in this PR. Our own 512-token greedy run agrees, at about 107.5 against 111 tok/s. Serving without --parallel is unchanged. Happy to look into it separately if it matters to you. On one Spark, a lone stream ran at 81.4 tok/s against 81.9 before, and two streams ran 19% faster.

Our own end-to-end checks on the two Sparks, beside your bench. Each reply was compared by token ids, using the token_sha every reply carries in tensorfold, with the same request's "draft": false reply on the same server. Its text was also compared with the serial replies recorded on unmodified 0.5.0. The script is exact3.py; we can add it under tools/ if that helps your run.

  • 1, 2, 4 and 8 users at once, 8 cases (greedy, and top_k 20 and 0, mixed): 15/15 equal to serial by token ids, 15/15 equal to the solo run, and 15/15 equal to 0.5.0's text.
  • Resumed against fresh: 6 second turns, each sent first with nothing kept (cached 0), then after its first turn, resuming from 21-29 kept tokens. All 12 equal to serial by token ids. All 6 sent at once: 6/6 equal. Three of them resumed; the other three found their kept slots taken by the requests arriving with them and prefilled fresh.
  • Hang-ups, twice over: 2 clients closed 0.4 s into a ~20K-token prefill and 2 mid-reply, beside 4 live requests. The live 8/8 equal by token ids, then 8 at once afterwards 8/8 equal. Neither rank logged an error.
  • Our wider suite (exact2.py), 16 cases: greedy, top_k 20/0/50, min_p, ignore_eos, stop strings, a 2K-token reply and a ~20K-token prompt. They were run alone, all 16 at once (more than the slots), staggered, mixed with hang-ups and invalid requests, and at once again. All 80 replies and the 4 multi-turn conversations were identical.
  • response_format, streamed or not, and guided_regex gave an HTTP 400 with the reason, in under 10 ms. An image gave a 400 too.

Checks

  • tests/cuda/test_flashnext_tp_multi.py is new. It runs two ranks in two threads, as test_flashnext_tp.py does, with the same fakes.
  • The Flash Next CUDA tests, tests/test_cuda_response_format.py and tests/test_cuda_server*.py give 342 passed, 18 skipped. The skips are the xgrammar cases, which aren't installed in our container.
  • ruff check adds no findings on the changed files, compared with main.
  • Not in this PR: grammar under two-rank --parallel. One more thing: a failure inside a step on one rank only, such as running out of memory on one Spark mid-prefill, still leaves the other rank waiting in NCCL, as it does on the serial two-rank path today.

We're happy to rework any of it, for example sending the plan through the store or a collective instead of the socket, if you'd rather.

Rank 0 plans every admission and round and sends each admission (with the slot and resume point it chose),
round, completion and drop to rank 1 over one TCP connection (port published through the rendezvous store);
rank 1 runs that plan. Before each admission and round both ranks confirm the plan in one small all-gather,
and both refuse a step whose plans differ (OutOfStep: its requests fail, serving goes on, neither rank waits
on the other). A stream rank 0 ended alone is named in the next round. Sampling over the
split vocabulary per stream (choose_gathered_streams, tp_sample_rows, _picks_tp). A stream decoding alone
replays the one-stream CUDA graphs (State.copy_from into the graphs' slot), on one GPU too. Structured
output under --tp 2 --parallel is refused with a 400 before generating.
@BHCC2025
BHCC2025 force-pushed the flash-next-tp2-parallel branch from 0b40c8e to c0aaeff Compare September 30, 2026 14:01
@ashhart

ashhart commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Thank you, this is excellent work, and the evidence is exactly what we asked for: the rank 0 plan with a checked round on both ranks, 180/180 replies equal to their solo runs, and hang-ups that leave neither rank waiting.

One thing on our side: 0.6.0 reworked Flash Next's CUDA rounds since 0.5.0 (shared DeltaNet and attention launches, prompt passes inside rounds, caches that grow with use, and #124's prompt states kept one token early), so your change needs porting onto that before it can run. It's first in line for 0.6.1: we'll port it keeping your commit and authorship, run it on two Sparks, and post the numbers here. If anything in the port changes your design, we'll say what and why.

@ashhart

ashhart commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Thanks. It's ported onto 0.6.1 and the host checks pass (192). Our single-Spark run found one mismatch in the port: a greedy reply with the int8 KV cache changed at token 22 when a stream went from alone to mixed and back. The released 0.6.0 passes the same schedule, so the bug was ours, and the fixed port now matches serial there. The last step is the two-rank run, which needs a second Spark. We'll post the results here when it's done.

@jschmied

jschmied commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

One finding on the 0.6.1 port (cb5101d, one GB10): every resize of the solo slot drops its graphs (_grow/_shrink → _state_changed). The slot starts at 256 rows and shrinks after each request, so a lone request on --parallel 4 recaptures 23 graphs mid-reply. That makes it 18.4 ms/token, against 12.2 on --parallel 1 and 13.6 on 0.6.0. Two and four streams lose 8–11 %. Replies are byte-identical.

#180 is a fix against pr-141-0.6.1: the slot keeps its rows until memory is short, and grows by doubling. With it, no captures happen during replies, and every case is back to --parallel 1 / 0.6.0 speed. Numbers and tests are in the PR.

Written with AI assistance (Claude Code).

@BHCC2025

BHCC2025 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Ran the two-rank side on two Sparks (GB10 x2, TP2 over the direct link): Flash Next MLX 4-bit, --context 65536, int8 KV, MTP drafts on.

pr-141-0.6.1 + #180 (6a3a8b1)

tools/bench_concurrent.py --levels 1,2,4,8 --alone --serial --reps 3 (aggregate tok/s; every reply equal to its alone and serial reply in every cell, all three builds)

prompt temp users 0.6.0 cb5101d --parallel 8 + #180 --parallel 8
code 0 1 106.4 98.8 94.7
code 0 2 104.7 170.9 163.6
code 0 4 104.5 267.7 268.5
code 0 8 103.6 404.6 394.1
chat 0 1 88.9 75.1 76.8
chat 0 8 86.8 343.7 337.7
code 1 1 113.4 106.5 100.9
code 1 8 101.4 224.3 220.4
chat 1 1 77.1 69.6 67.6
chat 1 8 76.9 190.0 184.6

One thing left on two ranks: a lone request on --parallel 8 runs about 11% slower than on 0.6.0, while the same build on --parallel 1 matches 0.6.0 (code greedy 94.7 vs 106.4 / 106.7, chat greedy 76.8 vs 88.9 / 88.1). #180 doesn't change it at TP2. On 0.5.0 the same gap was about 2%. Happy to run anything else on the pair, and the logs and bench JSONs are here if useful.

@jschmied

jschmied commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for the two-rank run. It found a bug in #180. On two ranks, rank 0 plans on Shadows of the slots, and
dec.solo.st is itself a Shadow there. _is_solo unwrapped only its argument, so it was never true while planning.
#180 therefore changed nothing on your pair except the warm-up order. That also means the cb5101d and + #180
columns ran the same path, so their −5…+2 % spread is run-to-run variation, not an effect.

The lone-request gap on --parallel 8 (≈11 %) looks like the same recapture we measured on one GPU (+35–50 % there,
with 512-token replies). It's smaller on yours, presumably because the replies are longer per capture.

Follow-up on #180: 6ada832. _is_solo now compares the slots the Shadows stand for, and an idle graph slot can be
released under memory pressure while planning too (recorded for rank 1 like any other resize). It adds a host test
through a Shadow, which fails on 6a3a8b1. One GPU only here. Would you rerun the 1-user cells (code and chat,
greedy) on the pair with it?

Written with AI assistance (Claude Code).

@plotarmordev

Copy link
Copy Markdown
Contributor

Ran pr-141-0.6.1 at cb5101db (#141's port 3854dc42 + your coordination fix) on two DGX Sparks, against the same branch just below #141 (e5f50dd) as the baseline.

Setup: 2x GB10 (driver 580.173.02), direct 200G RoCE link (NCCL over IB/RoCE v2), NGC pytorch:26.07-py3 (torch 2.13.0a0+nv26.07, CUDA 13.3, Triton 3.7.1). Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP @ dadefa80, sha256-verified on both ranks. --tp 2 --context 65536, int8 KV, --parallel 8 for the PR (baseline without --parallel, which it refuses on two ranks). The installed tensorfold/*.py hash was identical on both ranks for each commit. Startup estimate 42.6-42.8 GiB within ~103 GiB a rank.

Your bench, tools/bench_concurrent.py --levels 1,2,4,8 --alone --serial --reps 3 (256 tokens, ignore_eos), aggregate tok/s, medians of 3, baseline → PR:

Users code greedy code sampled chat greedy chat sampled
1 112.1 → 106.5 124.0 → 111.3 94.0 → 86.4 82.8 → 78.6
2 111.8 → 193.9 112.0 → 121.6 92.4 → 159.0 85.6 → 108.0
4 111.6 → 337.0 106.3 → 169.4 91.3 → 277.9 83.8 → 156.7
8 110.4 → 536.0 107.7 → 264.2 93.1 → 461.3 83.0 → 227.3

With bf16 KV (--parallel 8): 107.2 / 112.0 / 83.2 / 76.9 at 1 user, 558.3 / 233.8 / 453.8 / 225.0 at 8.

Exactness, by token_sha: in every cell of all three runs each concurrent reply equalled its solo run and each solo run equalled "draft": false (180 alone-checks and 72 serial-checks a run, 0 unequal, 0 failed).

One thing to look at: a single request is 5-10% slower under --parallel here (code sampled 124.0 → 111.3, chat greedy 94.0 → 86.4), more than the 2-4% in the PR description. One run of 3 reps per cell, so treat it as a lead rather than a measurement.

Extra checks (a small script beside the bench, same token-id comparison), 13/13 on int8 and 13/13 on bf16:

  • alone → mixed → alone: a 384-token reply starts alone, two others join at its 1st, 8th or 22nd token and finish, it ends alone; equal to its solo and serial runs, greedy and sampled (6/6 each dtype).
  • hang-ups: two clients leaving 0.4 s into a ~20K-token prefill and two mid-reply, beside 4 live requests: live 4/4 equal to solo, then 8 at once 8/8 equal.
  • resumed second turns (23 cached tokens) equal to serial, 3/3.
  • response_format and guided_regex refused with HTTP 400 in 1-2 ms.

Neither rank logged an error, OutOfStep or NCCL warning in any run.

@jschmied

jschmied commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

see #180 (comment)

@ashhart

ashhart commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thank you, @BHCC2025. --parallel N on two ranks for Flash Next is in TensorFold 0.6.4, with your commit under your name: https://github.com/ashhart/TensorFold/releases/tag/v0.6.4

We adapted parts of the scheduler to fit main, and our follow-up commits coordinate prompt pieces, growing caches, fork plans and readiness across the two ranks. We tested it with #180 and #219 on two DGX Sparks: drafted replies matched one-token decoding in all 18 checked cells, 9 resumed conversations matched fresh ones, and 8 truly concurrent requests each matched its solo run. This also answers #123. Thanks for building it.

@BHCC2025

BHCC2025 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart, here are the Flash Next numbers on the released 0.6.4 that you asked for: two Sparks (TP2) and one Spark (TP1), --parallel 8 against the default, with every reply checked for equality.

TP4: Flash Next accepts --tp 1 or --tp 2 only (cli_args.py, choices=(1, 2) in v0.6.4 and v0.6.5), so there is no four-rank Flash Next run to report. Our four-Spark run is GLM-5.3 (#159).

Setup

  • TensorFold v0.6.4 (6ea5ade), run from the tag's source inside a container image (torch 2.13.0a0+nv26.07, CUDA 13.3, Triton 3.7.1), driver 580.178.04 on both Sparks.
  • Spark GB10, TP2 over a direct 200G RoCE link (NCCL over RoCE v2, one port per Spark); TP1 on one of the same Sparks.
  • Checkpoint Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP at snapshot dadefa80 on both ranks. The server notes it is not one of the tested checkpoints (TensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTP). We have not run that one, so if its weights differ, the speeds could too.
  • --context 65536 --kv-dtype int8 --mtp-drafts 6 --mtp-confidence 0.60 --ple-on-ssd, prompt pieces of 2,048 rows, MTP drafts on. Four configurations: --tp 2 --parallel 8, --tp 2, --parallel 8, and default (one Spark, no flags).
  • tools/bench_concurrent.py --levels 1,2,4,8 --alone --serial --reps 3 (256 tokens, ignore_eos), aggregate tok/s, median of 3.

Every reply is exact

On --tp 2 --parallel 8, with the serial ("draft": false) references recorded on this same build:

  • Resumed equals fresh: 6 second turns fresh, then resumed from the kept prompt end, then all 6 resumed at once. Every reply equals its serial reply by token ids.
  • 1 / 2 / 4 / 8 users each equal their serial and solo replies. Hang-ups in prefill and in decode beside 4 live requests, twice, with all 4 live replies equal. Structured output and images refused with HTTP 400 before any reply.
  • Our wide byte-exactness suite (16 cases alone, all at once, staggered, with hang-ups and invalid requests, all at once again, 4 multi-turn conversations at once): identical in every row, reasoning, content and finish reason.
  • bench_concurrent.py --alone --serial in all four configurations: 180 of 180 replies equal their alone run and 72 of 72 equal their "draft": false run, with no failed or unmeasured requests.

Aggregate tok/s

prompt temp users TP2 --parallel 8 TP2 default TP1 --parallel 8 TP1 default
code 0 1 96.6 105.8 67.7 67.8
code 0 2 172.4 105.5 122.0 67.5
code 0 4 280.4 104.7 209.4 67.0
code 0 8 406.1 103.6 319.4 67.0
code 1 1 102.9 113.4 88.1 87.6
code 1 2 134.6 106.4 106.8 82.0
code 1 4 174.1 100.9 138.6 77.9
code 1 8 241.6 102.3 177.1 77.5
chat 0 1 81.0 88.3 63.0 64.3
chat 0 2 144.2 87.2 114.0 63.9
chat 0 4 232.6 87.0 197.2 63.6
chat 0 8 352.0 87.0 304.9 63.5
chat 1 1 70.0 77.7 59.6 59.4
chat 1 2 104.6 81.1 85.0 61.5
chat 1 4 143.8 78.8 114.1 59.9
chat 1 8 196.6 77.1 151.3 59.0
  • At 8 users, --parallel 8 gives 2.4x to 4.0x the total throughput at TP2 and 2.3x to 4.8x at TP1 (the larger factors are greedy).
  • On our earlier two-Spark run of the 0.6.1 port with Flash Next CUDA (0.6.1 port): the lone stream's graph slot keeps its rows, so its graphs are captured once #180, 8 users gave 394.1 / 337.7 / 220.4 / 184.6 (code greedy / chat greedy / code sampled / chat sampled). On 0.6.4 they give 406.1 / 352.0 / 241.6 / 196.6. The default at TP2 is unchanged from 0.6.0 for one stream (code greedy 105.8 against 106.4, chat greedy 88.3 against 88.9).
  • Still open: a lone request on --tp 2 --parallel 8 runs 8 to 10% slower than on the default at TP2 (code greedy 96.6 against 105.8, code sampled 102.9 against 113.4, chat greedy 81.0 against 88.3, chat sampled 70.0 against 77.7). On one Spark --parallel 8 costs a lone request 2% or less (63.0 against 64.3 at most). On 0.6.1 this gap was about 11% at TP2.

Method

Same checkpoint, same settings and the same bench in every column; each configuration was started fresh and ran its three repetitions in one session. Raw bench JSONs, the pipeline and the logs are available if useful.

@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants