Repository navigation
feat(qwen4exp): split Qwen3.8-Flash-Next across an R9700 and a Strix Halo - #827
Merged
Merged
Conversation
davide221
commented
Oct 8, 2026
davide221
left a comment
Contributor
Author
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and logic errors in the changed code.
Reviewed bf86eb8e · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again
This was referenced Oct 8, 2026
With an expert device, the routed expert stacks (71.7 GiB on UD-Q4_K_XL) load on it, while dense weights, the KV cache, the MTP drafter and every non-expert node stay on the target. One ggml_backend_sched drives both GPUs: graph inputs stay on the target, cross-device inputs split late, and a parallel scheduler with a single copy set waits on events rather than on the host. Prompt chunks pipeline over 2 to 4 streams of about 4096 rows, so one stream's experts run on the expert device while another's attention runs on the target; the routed sum crosses back as F16. The chunk planner measures the split scheduler and keeps chunks within the MoE id helper's 16384 rows (8192 with hot experts). Optionally the most-routed experts are also copied to the target. Verify steps of 2 to 8 rows send each pick to one device through per-layer lookup tables, so both GPUs run experts at once; single-token decode and prompt chunks keep every pick on the expert device. QSA runs on RDNA4 as well as gfx1151, and F16-input projections stay gfx1151-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PLE and GDN conv tails, the M-RoPE permute and the HC mix reduce have no gfx1151 kernels, but were gated on the current device being gfx1151, so the R9700 side of a split ran their unfused chains (the HC mix alone is seven ops, twice a layer). ggml_cuda_qwen4exp_graph() is the profile on any device; the WMMA paths (MMB, the HC gate GEMM fold) keep the gfx1151 test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Verify forwards keep one graph per width, with its own scheduler and allocation, and draft ranks keep one graph per catch-up width and per later rank, with bucketed K/V spans and runtime inputs. A step replays instead of rebuilding, re-splitting and re-allocating a graph of a few thousand nodes. A retained graph is never split again: the scheduler rewrites node sources to its input copies in place. The adaptive verify width keeps its cost model across requests and uses each width's measured cycle time, taken only from steps that replayed their graphs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decode and verify steps write the conv history and the recurrent state with two copies instead of a pair per row, hand the raw alpha and beta projections to the recurrence (dt_bias and A packed per layer at load), and normalize q and k together: about 15 fewer kernels per linear layer. Outputs are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Past 2K tokens each verify row ran its own QSA selection, about 17 kernels per row per full-attention layer. The rows now share one indexer projection, norm and RoPE, one tokenwise score (the one-token decode kernel for every row), one multi-row top-k and a loaded ones tensor for the head weights, and each row keeps the one-token path's arithmetic. On gfx1201 the QSA top-k takes the block-radix selection, as on gfx1151. R9700 + Strix Halo, split + MTP, fixed width 4 after a 16K prompt: 57.7 -> 53.7 ms per verify step, 41 -> 44.9 tok/s; greedy text unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…egime The backend carried one cost table across requests, so widths timed in a long-context request (about 2 ms more per verify row at 16K) made the next short request's narrow widths look about 10% dearer than they are, and that request never re-timed them. The width memory now keeps a cost per context regime (<2K, <8K, <32K, longer) and carries the per-depth acceptance across requests, scaled to at most 32 trials so a new request's text takes over quickly; with carried acceptance the k>=3 warmup floor lasts 4 cycles instead of 16. R9700 + Strix Halo, split + MTP, adaptive before / after / fixed width 4 (tok/s): first 16K request 37.3 / 40.7 / 41.0, short 74.0 / 73.9 / 71.6, thinking (greedy) 64.5 / 63.8 / 64.8; outputs identical. A unit case runs a bench-shaped request sequence through the memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sh-Next split mode Split mode was switched on by environment variables. It is now server configuration: - --expert-device backend:gpu puts the routed experts on a second GPU (the flag DeepSeek V4 already uses); dense work, KV cache and the MTP drafter stay on --target-device. - --hot-experts PATH (routing-stats CSV) and --hot-experts-gib N (default 8) copy the most-routed experts to the target, where verify steps run them while the expert device runs the other picks. - --profile qwen-next-r9700-strix sets up an R9700 + Strix Halo box. The routing recorder and the unused eager peer-copy scheduler hook are gone; the smoke binary takes --expert-gpu N. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A snapshot restore also clears the retained verify and MTP graphs, which were built at the pre-restore position. - In split mode the chunk planner reserves 8192 prompt rows (two 4096-row pipeline streams) before the prefix snapshot allowance, not 4096. - --max-concurrency > 1 with --expert-device is refused: the multi-slot decode graph has no split-mode placement yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… too Verify rows ran their hot picks on the target while single-token decode ran every pick on the expert device, so a token's numerics depended on whether it was verified in a batch or decoded alone, and greedy text in split mode with hot experts followed the adaptive verify widths, which are timing-driven. Single-token steps now take the verify route. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…end's snapshot allowance In split mode the qwen4exp backend sizes its snapshot allowance against the target GPU (3.2 GB on a 32 GB R9700 with hot experts), below the server's automatic resident limit (three full-context snapshots). Once the allowance filled, the backend refused every capture while the cache, still under its own limit, never evicted: a 16K prompt sent twice was prefilled twice. Backends now report the allowance they enforce, and the automatic limit takes the smaller of the two. Co-Authored-By: Claude Opus 5.5 <[email protected]>
How to run and build Flash-Next with the routed experts on a second GPU, what --hot-experts does, the measured speeds against the Strix Halo alone, and the split-mode rows of the support table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…veSpecWidth Qwen4ExpMtpWidth was a fork of the shared verify-width controller. The shared class now covers what the fork added, as options that leave its current users unchanged: - CostSeed::kShape: a seed is only the shape of the cost curve. A width is priced from its own trusted measurement (a running mean of its live samples, outliers clipped), otherwise from its seed scaled to the nearest trusted width. A measurement left unrefreshed for 64 timed steps is re-priced by the shape and restarts on its next sample. - AcceptanceModel::kReachedDepths: acceptance counted per depth only where a step reached it, bounded, with a probe one width wider every 17 steps. - measured_costs()/set_measured_costs() and SpecWidthCostMemory: measured costs carried across requests, one set per context range; a range never timed starts from the nearest timed one, lightly weighted. - carry_acceptance(): a bounded share of one request's evidence for the next. qwen4exp keeps one controller across requests in that configuration and deletes Qwen4ExpMtpCost/Evidence/Width/Memory. A unit test replays DS4's configuration over 400 steps and checks every decision against the controller before this change. The qwen4exp policy simulations keep their bars (0.98 of the best fixed width on stationary and noisy streams, 0.97 on the bench-shaped request sequence). Split mode with hot experts, adaptive MTP, greedy, same session, old vs new controller: identical text on all six prompts; short 72.5 -> 73.5, code 68.4 -> 70.4, thinking 63.3 -> 66.9, 16K 47.3 -> 47.9, 16K again 50.9 -> 54.1, short again 73.3 -> 70.4 tok/s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tier #827 gave Qwen3.8-Flash-Next split mode its own --hot-experts and --hot-experts-gib next to DeepSeek4's --ds4-expert-placement and the LUCE_EXPERT_BUDGET_MB budget that DeepSeek4 and Laguna already read. Now: - --expert-placement <FILE> is the one placement flag. DeepSeek4 takes its owner-map JSON, Qwen3.8-Flash-Next with --expert-device a routing-stats CSV. --ds4-expert-placement stays an alias, so DeepSeek4 launch commands and profiles are unchanged. The path travels in the plan's existing execution.expert_placement field. - LUCE_EXPERT_BUDGET_MB sizes the hot set on the target. One helper, expert_budget_bytes_from_env(), reads it for DeepSeek4, Laguna and Qwen3.8-Flash-Next; Qwen's default stays 8 GiB. - The feature gate admits --expert-placement for a local DeepSeek4 or for Qwen3.8-Flash-Next with --expert-device; the router bias and protected experts stay DeepSeek4-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… paths build_moe (one device) and build_moe_route (split mode) each built the router (softmax, top-k, renormalized weights) and the gated shared expert on their own. Both now call moe_router and moe_shared; the graph ops and their order are unchanged. The row thresholds that pick the split path's scheduler and link precision, and the decode/verify step width, are named (kSplitShortRows, QWEN4EXP_MTP_MAX_VERIFY) instead of 64 and 8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…layer builder The pipelined split prompt chunk repeated the main loop's layer body: PLE, the HC mix into attention, the attention dispatch, the last layer's output row selection, the HC combine into the FFN norm and the PLE-aware combine with the next layer's norm. Both now build each layer from attn_half, last_row, ffn_input and ffn_output; a stream passes its own positions, mask, span and pooled blocks. The graph is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n jump drops free, reset and snapshot restore each listed the retained workspaces, and disagreed: restore dropped the verify and MTP graphs, reset kept them. Both are keyed by their spans and upload every position-dependent input on each replay, so a position jump only drops the stable T=1 graph (clear_position_bound_graphs); free drops all of them (clear_retained_graphs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The split-mode chunk caps (16384 rows for the expert device's MoE id helper, 8192 with hot experts) were clamps applied after the planner chose a chunk; the planner now searches only up to them, and the pipeline's 4096-row stream size and the 8192-row split floor are named constants. Also: the hot-expert lookup tables' allocation is checked, the top-k GGML_DS4_TOPK_BLOCK_RADIX override is read once and its defaults use the RDNA3.5/RDNA4 arch checks, the qwen4exp profile comments sit on their own functions, the fusion pass drops a device check ggml_cuda_qwen4exp_enabled already makes, and a duplicate include is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r the memory free now park() frees the weights, the hot experts and their lookup tables, but unpark() reloaded only the weights and the cache, so a split model ran without its hot experts after a park, and it kept the prefill chunk and the prefix allowance measured at init. init and unpark now share one bring-up, load_target(): weights, the main cache, the hot experts, the chunk and allowance measured from the memory free now, then the slot engine. release_target() undoes it for park, shutdown and a failed unpark, so a failed unpark leaves nothing resident. The model lifecycle test takes an expert GPU and a placement and checks, in split mode, that the hot experts are resident after init and after park/unpark and that the greedy text after the unpark matches the text before the park. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne arena for derived constants - The server's --expert-device validation is the one check that the expert device differs from the target; the backend no longer repeats it. - The 8 GiB hot-expert default is kQwen4ExpHotExpertBudget, passed as the fallback of expert_budget_bytes_from_env(), which now takes one (DeepSeek4 and Laguna keep no fallback, so their budgets are unchanged). - The raw-gate parameters, QSA's head weights and the hot-expert lookup tables were three context and buffer pairs with three allocate and free paths. They now live in one Qwen4ExpDerived arena: each group opens a context, creates its tensors and commits them as one weights buffer, and free_qwen4exp_derived() releases them all and clears every pointer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The UD-Q4_K_XL shards and the MTP drafter are mirrored, byte-identical, in Lucebox/Qwen3.8-Flash-Next-GGUF, so installs fetch them from one place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
forward_impl had grown to 918 lines and 13 lambdas. It is now 335 lines that read as the forward's steps; the pieces are free functions and one struct: - Qwen4ExpLayerBuilder: the per-layer builders (attention half, FFN input and output, FFN half, last-row selection), shared by the single-stream layers and the pipeline's streams. - build_pipelined_layers / upload_pipeline_inputs: the split prompt chunk's streams and their R/S/C interleave. - Qwen4ExpStableInputs with upload_stable_inputs, upload_stable_qsa and run_stable_graph: a retained graph's per-call inputs and replay. - stable_qsa_supported, stable_workspace_stale, bootstrap_qsa_prefix, graph_context, split_scheduler, build_mtp_prefill, measure_split_graph, place_inputs_in_ring, allocate_graph and upload_graph_inputs. Code motion only: greedy text identical in split + hot and Strix-only (8/8 each), the split smoke's tokens, logits, draft chain and rollback identical, units and the split park/unpark lifecycle test pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rix Halo Adds Flash-Next to the supported-models table (UD-Q4_K_XL and the MTP drafter from the Lucebox repo, on the Strix Halo and split across an R9700 + Strix Halo) and to the heterogeneous results. Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221
force-pushed
the
feat/qwen4exp-split
branch
from
October 8, 2026 16:19
780eaf2 to
31b7c70
Compare
davide221
added a commit
that referenced
this pull request
Oct 9, 2026
Conflicts with #827 (Qwen3.8-Flash-Next split), resolved: - ggml-backend.cpp: a split input copy stays persistent for the parallel scheduler's copy events (main) and for dedicated copies (this branch). - ggml-cuda.cu: the DS4 fusions keep their place before main's qwen4exp fusions, which now run on every device of the graph. - adaptive_spec_width.h: main's shared controller replaces this branch's change, as planned: DS4 seeds it with CostSeed::kShape, and this branch's tests of the old change go with it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
davide221
added a commit
that referenced
this pull request
Oct 12, 2026
The :rocm image was the only build still on ROCm 6.4.1; the Lucebox boxes and the AMD CI runner build and test on 7.2.4, and the README lists ROCm 7.2 for both supported AMD GPUs. Every main push since 10-07 failed it: - mmid.cu calls __syncwarp() (#774), which ROCm 6 declares only on opt-in. - The DS4 indexer's tokenwise path (#827) called the WMMA decode kernel outside the rocWMMA 2.x guard, and ROCm 6.4 ships rocWMMA 1.x. The image now uses ROCm 7.2.4 on Ubuntu 24.04: ROCm 7.2's CMake package files need CMake 3.25 or newer, and 22.04 ships 3.22. 24.04 has a Python 3.12 of its own, so uv is told to keep its managed build under /opt/uv, as in the CUDA image. The tokenwise call moves inside the guard, so a source build without rocWMMA 2.x compiles again; every score then takes the scalar kernel, one token each. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
dusterbloom
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 14, 2026
…ate forces eager launches; upstream Luce-Org#827 retained verify graphs is the fix
dusterbloom
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 14, 2026
…tained graphs replay, k=4 77.4 vs 89.7 ms, per-row still ~10 ms
dusterbloom
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 15, 2026
…per-row stable QSA rows) -- the verify forward (T=k+1 rows) was rebuilt, re-allocated and run eagerly on every call (ggml_backend_cuda_graph_invalidate_range per call, VERIFY-PROFILE.md: ~18 ms idle at k=4). It now replays a retained graph per width like T=1 decode: cache.verify_workspace[T] (one Qwen4ExpDecodeWorkspace per width, keyed by the rows' dense K/V spans or the QSA bucket), T-wide kv_row set_rows, qsa_pooled_keys_stable chaining ceil(T/4) set_rows slots, and per-row stable QSA inputs (Qwen4ExpQsaRow: visibility F32[qsa_blocks], qsa_params I32[10] per row -> valid count / raw rows / destination / M-RoPE positions) so every row keeps the T=1 decode arithmetic (ggml_ds4_indexer_score_masked on a 1-D view, ggml_top_k_qsa with the row's valid count and min_valid=max(513,(kv_bucket-255-T)/4)); main's at_once path (tokenwise indexer score, multi-row top_k_qsa) is not ported, our ggml lacks those ops. upload_stable_inputs fills positions / kv_row / ple / dense masks or QSA positions per row and the QSA params; run_stable wraps the replay in ScopedCudaGraphOverrides(mmvq_batch_invariant=verify) as the build does. Exact-stack fusions stay in the verify graph (build_shared_overlap / elide_qsa_cont stay T=1 only). Kill switch LUCE_VERIFY_GRAPH_LEGACY=1 = the old per-call path. Decode copies (LUCE_DECODE_REQ) are T==1 only (dec()), so verify rows read the exact weights on every path, unchanged. lucebox4 gfx1151, build1151 (luce_server dda1dc0e, ggml-hip 60dcc204): test_qwen4exp_mtp 4236 cases, test_qwen4exp_mtp_dispatch 21 cases; smoke_qwen4exp_forward 2200 --draft MTP --mtp 128 --mtp-draft 4 --chunk 2048: PASS in both modes, tokens_identical=1 logits_identical=1, rollback 20/20, cancel-reset-reuse hash equal; retained builds=4 replays=47 (legacy builds=0). The smoke now fails when the retained path shows no replays; bench_verify_realtok prints builds/replays per width. bench_verify_realtok 8K ids, 20 reps, max_ctx 12000, same binary: legacy k1 41.4 / k2 59.9 / k3 72.5 / k4 80.4 / k8 127.5 ms; retained (two runs) k2 55.0/58.3, k3 65.8/70.7, k4 76.7/78.3, k8 122.7/126.6 (HEAD binary 938bea37: 44.0 / 64.2 / 77.3 / 81.1 / 128.3). mtp_ab.sh: MTP e2e A/B harness (arms NAME=ENV/FLAGS, --draft sidecar unless --no-draft, [qwen4exp-mtp] line kept per request, PREFILL=1 for p4096/p16384, greedy texts in round 0); mtp_absum.py summarises it (median / mean / min / max / round spread, acceptance, width histogram, greedy identity, prefix_len proof).
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.
Runs Qwen3.8-Flash-Next with the routed experts on a second GPU. On an R9700 + Strix Halo box, the R9700 holds the dense weights, the KV cache, the MTP drafter and the most-used experts, and the Strix Halo holds the rest of the experts. Both GPUs run under one scheduler.
Results
UD-Q4_K_XL, adaptive MTP, greedy, 131K context, 8 GiB of hot experts. Same harness for both columns.
Without
--expert-placement, the split decodes a short reply at 69 tok/s.How to run
--expert-device hip:1: the existing DeepSeek V4 flag now also places Flash-Next's routed experts. It must differ from the target device.--expert-placement PATH: one flag for every expert tier. DeepSeek V4 reads its owner-map JSON; Flash-Next with--expert-devicereads a routing-stats CSV and copies the most-routed experts to the target, where decode and verify steps run them.--ds4-expert-placementstays as an alias. The CSV is an operator input and is not part of this PR.LUCE_EXPERT_BUDGET_MB(default 8192 for Flash-Next): the same budget DeepSeek V4 and Laguna use, read through one helper.--profile qwen-next-r9700-strix: targethip:0, experts onhip:1,--max-ctx 131072.gfx1151;gfx1201).-DGGML_HIP_GRAPHS=ONadds about 3%.Split mode serves one sequence.
--max-concurrencyabove 1 is refused together with--expert-deviceuntil the multi-slot graph gets split placement (follow-up PR).Commits
feat(qwen4exp): split mode runs the routed experts on a second GPU. Prompt chunks pipeline over 2 to 4 streams, so one GPU works on one stream while the other works on the next. QSA runs on RDNA4.perf(cuda): qwen4exp's generic fusions on every device of the graph.perf(qwen4exp): MTP verify and draft steps replay retained graphs.perf(qwen4exp): linear-attention steps run fewer kernels.perf(qwen4exp): verify attends every sparse-attention row in one pass (block-radix top-k on gfx1201 too).fix(qwen4exp): the adaptive verify width keeps its cost per context range and its acceptance across requests.feat(server): the flags above replace the old environment variables.fix(qwen4exp): split mode with prefix snapshots. A restore also clears the retained verify and draft graphs, and split mode keeps an 8192-row prompt chunk ahead of the snapshot allowance.fix(qwen4exp): single-token steps run their hot experts on the target too, so greedy output does not depend on the verify width.fix(server): the prefix cache's automatic limit stays within the backend's snapshot allowance. Before this fix, a full allowance refused every new capture and evicted nothing.docs(qwen4exp): split mode section.Cleanup on top, so nothing runs in two parallel copies:
refactor(spec): Flash-Next's MTP verify width runs on the sharedAdaptiveSpecWidth. The Flash-Next controller classes are gone. The shared class gains opt-in pieces (shape seed, per-depth acceptance, cost per context range, carried acceptance). DeepSeek V4's defaults are unchanged: a replay test checks 800 of its width decisions against the previous controller.refactor(server): one--expert-placementand one budget for every expert tier, replacing the Flash-Next-only flags.refactor(qwen4exp): one router and shared-expert builder for both MoE paths.refactor(qwen4exp): single-stream and pipelined layers share one per-layer builder.refactor(qwen4exp): one place decides which retained graphs a position jump drops.refactor(qwen4exp): split chunk limits live in the chunk planner, plus a checked table allocation and named constants.fix(qwen4exp): unpark brings the hot experts back and sizes the chunk and snapshot allowance for the memory free at that moment. Init and unpark share oneload_target(); park, shutdown and a failed unpark sharerelease_target().refactor(qwen4exp): one expert-device check (in the server), a named hot-expert budget, and one arena for the small derived tensors.docs(qwen4exp): UD-Q4_K_XL downloads from the Lucebox repo (a byte-identical copy of the Unsloth files, with the MTP drafter).refactor(qwen4exp):forward_implbuilds from named pieces (918 to 335 lines): aQwen4ExpLayerBuildershared by single-stream layers and pipeline streams, the pipelined stage loop, and the stable-graph upload and replay as their own functions. Code motion only; greedy text identical.docs(readme): Qwen 3.8 Flash-Next in the supported-models table (Strix Halo, and R9700 + Strix Halo) and the heterogeneous results.Validation
--verify-width 4and MTP off (8/8 prompts). On one GPU the branch matches main (8/8). The cleanup commits keep greedy output identical to the commit before them, in split and on one GPU (8/8 each).test_qwen4exp_mtp,_mtp_dispatch,_chunk,_prefix_cache,test_server_unit(with the new split-placement plan test).test_qwen4exp_indexer_score,_qsa_idsand_qsa_attnpass on both gfx1201 and gfx1151.🤖 Generated with Claude Code