Skip to content

Flash Next: config-driven top-k and shared expert width - #3523

Merged
ashhart merged 11 commits into
ashhart:mainfrom
BadAd84:flashnext-config-widths
Nov 25, 2026
Merged

ashhart merged 11 commits into
ashhart:mainfrom
BadAd84:flashnext-config-widths

Conversation

@BadAd84

@BadAd84 BadAd84 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Terms used below: "main" is upstream TensorFold at 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7 (its tip of 2026-11-16T15:26:10Z), and "the branch" is that main plus the one change this pull request adds, whose head is the commit named below.

What this changes

Flash Next on CUDA took its routing width (top-10, so 11 slots a row with the shared expert) and its shared expert's width (640) from constants. With this change the checkpoint's config.json selects one of two supported shapes: top-10 with a 640-wide shared expert, the only shape main loads, or top-5 with a 1280-wide shared expert. Any other num_experts_per_tok or shared_expert_intermediate_size is refused at load by the field's name, as cuda_config.zig refuses other fields today. No weight format changes: a checkpoint main loads gets the default shape and the same launches, so its tokens are unchanged. The top-5 checkpoint behind #3368 is GPTQ int4, which this step does not load.

How the widths reach the code:

  • cuda_widths.zig (new, 100 lines) holds the supported list and the selection. The kernels already take top-k and slots as launch arguments (route_rows top-k, fn_moe_sum, fn_hc_writeback, the expert tiles), so the shape lives in data: the pass reads a row's slots from its scratch, which is allocated for the shape (Sizes.slots, Sizes.shared), and the shared expert's width from the layer (its gate_proj rows). A default-shape checkpoint gets the same integers it got from the constants, so its launches, sums and their order are unchanged. This is option (a) of the issue; the receipt below is its evidence on the default path.
  • The literal 10, 11 at the write-backs (cuda_batch.zig, cuda_batch_hc.zig) now come from the scratch. cuda_prompt_step.zig's row path, which serves the MLX checkpoint only, names the default slot count instead.
  • The MTP layer routes at the main layers' top-k: config.json has no routing width for it, its router has the same 512 experts, and the shared verify and draft passes lay a row out at one slot count. Since a draft is only a proposal, this width moves acceptance, never a reply. Its shared expert's width is its own tensor's: the main layers' width or the routed width (640); anything else stops the head's load naming mtp.layers.0.mlp.shared_expert.gate_proj and its rows.
  • A main layer whose shared expert's rows are neither 640 nor 1280 stops the load naming that tensor and its row count (cuda_mixed_experts.zig), and a layer whose rows differ from shared_expert_intermediate_size stops it naming the layer and both numbers (cuda_prompt.zig).
  • Captured kernel sets stay at top-10: their _topk_rows is built with TOPK 10 and SLOTS 11 (cuda_launch.zig). A checkpoint of another shape with a captured set is refused at load, naming num_experts_per_tok (FlashNextWidthsOnCapturedGlue), and Tri.topkMany refuses another width (CapturedSetTopK) when a captured set owns that launch rather than the family's own glue.
  • The MLX 4-bit path (cuda_moe.zig and the legacy experts) stays at the default shape; an MLX config of another shape is refused naming num_experts_per_tok.
  • The two-rank exchange (cuda_moe_exchange.zig): its reduce-scatter size is h * s.slots * dims instead of h * slots * dims. In cuda_moe_native.zig the rows cleared before the expert launches and the up projections' row layout read the same count, and the shared split's column copies take the layer's width. For the default shape these are the same integers, so the exchange is unchanged; I have not run two ranks, which you offered to check on your side.
  • The two device tests that build a pass of their own (flashnext_exchange_tests.zig, flashnext_fp8_experts_tests.zig) and two host-test fakes pass the default slot count and width.
  • cuda_launch.zig is 565 lines after adding five lines and removing four (git diff --numstat), one more than before the merge because Flash Next TP=2 on CUDA: head and rollback graphs replay, and one-row split lanes skip the interleave copies #2837 adds a test import; the width plumbing is in its own file, and no Zig file in the change is over 600 lines.

Checks on this head

  • Head commit: 6291b4526767240b68997d8c8f6d00563c4ab676 (the change commit 5cc8b6ace6 on main 41a72fd257, a merge of 964174ea05 (5105449d50), the serving re-pin (ea11e31570), a merge of 4bed140a1e (c660f4a0de), a merge of e7e24243 (fe753c9470), the CHANGELOG commit and a merge of 077998f7d9b1 (6291b4526); its tree is a1be9c739796de928478dc596c43c3a32cb5dc45, and against 077998f7d9b1 it changes 25 files, 292 insertions and 94 deletions). The receipt and its two images ran on main e7e24243 and on fe753c9470; the checks below ran on this head and on main 077998f7d9b1, and the receipt bullet says why the merge changes nothing the receipt measured.

  • Lean checker, python3 tools/zig/lean_check.py, one tree at a time from its own root, with the head's checker in both (byte-identical, sha256 prefix a08d2a424e01b16a): base 077998f7d9b1 6,575 files, 221 problems; this head 6,576 files, 221 problems; lean_new.py: lean: 221 problems, 221 on the base, 0 new. The problems are inherited (for example zig/src/server/vision_inputs.zig:331), and the two file counts differ, so the two runs really were two trees.

  • python3 tools/pr_check.py --base main at 077998f7d9b1 on this head: merge base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7; 25 changed files; lean 221 vs 221, 0 new; 0 errors and 0 warnings with --pr 3523, the Unreleased bullet naming this pull request.

  • zig fmt --check build.zig zig: clean. git diff --check 077998f7d9b1..HEAD: clean.

  • zig build compile-config-server -Dtarget=aarch64-linux-gnu: passes on this head (rc 0, 7 of 7 steps, 180 s, natively on the aarch64 machine below). zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu: passes on this head (rc 0, 10 of 10 steps, 170 s).

  • Kernels: the shared header common/fp_pairs.cuh changed between the pre-merge head ea11e31570 and fe753c9470, so every .cu that reaches it was rebuilt at sm_121 with the build's own flags at both commits and compared: 59 of 65 byte-identical, 6 different, 0 that would not build. Five of the six (ck_lane, exl3_block/lin2, qmm, qmm_group, qmmf) differ only in their internals' symbol names (INTERNAL_<hash>, which follow the translation unit's text) and cuobjdump -sass is identical for each; the sixth is nvfp4_experts32 (445,936 to 933,560 bytes, SASS differs), which is not among the 24 images Flash Next launches. On those 24, 21 are byte-identical and the 3 that differ are the symbol-name-only cases, so no instruction this family runs changed. The merge itself edits two kernel sources, main's gdn.cu and qwen35.cuh, each in a comment only; the four bodies that build from them (gdn, qwen35, qwen35_keep, qwen35_kv8) were rebuilt at sm_121 at the old head and at this head and all four are byte-identical (255,432, 828,856, 31,960 and 713,808 bytes), and none of the four is an image Flash Next launches or reaches one.

  • Tests run as the no-GPU workflow runs them, natively on an aarch64 Ubuntu 24.04.5 machine (NVIDIA GB10, 20 CPUs, Zig 0.17.0, -j8 --maxrss 6000000000 except -j4 where noted, umask 022, no GPU visible to the tests), on a fresh git archive tree of 6291b4526 and, separately, of main 077998f7d9b1, each checked blob by blob against its commit (11,833 and 11,832 blobs: 0 missing, 0 extra, 0 different). zig build -Dfixed-cpu test-host --test-timeout 20m at -j4 gives rc 1 on both: 6291b4526 2,125 of 2,132 steps and 18,382 of 18,508 tests passed, 125 skipped, 1 failed; main 077998f7d9b1 2,125 of 2,132 steps and 21,094 of 21,233 tests passed, 138 skipped, 1 failed. Head's run reused 89 test steps that its own earlier steps in the same cache had already run (98 cached run test steps against main's 9), so the two totals are not comparable across the runs while the failing sets are, because a step is cached only when it succeeded. The failing set is identical on both sides, one test, listener.zig's accepted IPv4 and IPv6 TCP streams disable Nagle for incremental responses, which needs IPv6 that this machine boots without (ipv6.disable=1): tests that fail on 6291b4526 only, 0; on main only, 0.

  • New tests, each shown failing on a mutant of this change: the mutant applied to its own fresh copy of this head, then zig build -Dfixed-cpu test-cuda-host -j4 (natively on the aarch64 Ubuntu 24.04.5 machine above, Zig 0.17.0, umask 022). Every mutant fails:

Mutant What fails
the supported list holds the default only the build: cuda_widths.zig's tests index the top-5 entry
the selection matches top-k 10 only (main's behaviour) a top-5 config with a 1280-wide shared expert selects that shape, and the MLX path refuses it by name, a width outside the supported list is refused by its field's name, the default shape is the constants' and a top-5 checkpoint selects a 1280-wide shared expert
the MLX path accepts any shape a top-5 config with a 1280-wide shared expert selects that shape, and the MLX path refuses it by name
the scratch sizes the shared buffers by the constant 640 the scratch is sized by the shape: a wider shared expert's three buffers, fewer slots' pairs
the MTP layer accepts any shared width the MTP layer routes at the main layers' top-k with its own shared width, and another width is refused
a captured kernel set serves any shape a captured kernel set serves the default shape only

Measured on this head: each mutant runs on its own fresh copy of this head (a cp -a of the tree the control ran in, its cache pruned with tools/zig/zig_cache_restat.zig --prune), the six anchors checked to occur exactly once on this head before the run, and the control runs first, zig build -Dfixed-cpu test-cuda-host -j4: rc 1, 408 of 410 steps, 6,926 of 6,960 tests passed, 33 skipped, 1 failed, that failure being listener.zig's IPv4 and IPv6 test, because the machine boots without IPv6. Every mutant fails it too, and the table names the tests each mutant fails beyond it.

  • CI on 6291b4526 (this head), run on this pull request: fmt, zig, zig-b, zig-windows, pytest, benchmark-clients (ubuntu and windows), release-paths and zig-macos-dev-tools all completed successfully; host-nightly-linux and host-nightly-macos are skipped by their own conditions.

  • Not run, and why: two ranks (no second GPU here; you offered the device check for this step) and the MLX 4-bit checkpoint (there is no MLX checkpoint on this box; the MLX path is exercised through its refusal in the host tests). The receipt below measured the default shape main loads, which is the shape this diff's launches are on; the top-5 shape's device run stays on the base it was taken on and its bullet says so.

Receipt

  • Main against branch: one machine, one fresh boot an arm, alternating main, branch, branch, main (M1 B1 B2 M2). Each arm runs tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0 at one stream and tools/bench_concurrent.py --tokens 256 --reps 3 --levels 1,2,4,6,8 --alone --serial --temperatures 0, both from main's tools/. A cell counts as slower when both branch runs are under both main runs and the mean gap is over 1%. No cell is slower:
invocation prompt temp streams M1 B1 B2 M2 change slower? per-stream M / B tokens/round M / B accepted/round M / B
openai_t0 fibonacci-raw 0.0 1 72.9 73.2 72.8 72.7 +0.24% level 72.8 / 73.0 5.22 / 5.22 4.22 / 4.22
openai_t0 gpu-chat-no-think 0.0 1 46.8 46.8 46.8 46.6 +0.24% level 46.7 / 46.8 2.81 / 2.81 1.81 / 1.81
conc_t0 chat 0.0 1 46.7 46.6 46.6 46.5 +0.00% level 46.6 / 46.6 2.81 / 2.81 1.81 / 1.81
conc_t0 chat 0.0 2 86.5 86.6 86.7 86.5 +0.17% level 43.5 / 43.6 2.51 / 2.51 1.51 / 1.51
conc_t0 chat 0.0 4 157.0 156.4 156.3 156.1 -0.13% level 39.6 / 39.7 2.51 / 2.51 1.51 / 1.51
conc_t0 chat 0.0 6 210.5 211.0 210.6 209.9 +0.29% level 35.9 / 36.0 2.51 / 2.51 1.51 / 1.51
conc_t0 chat 0.0 8 257.5 257.5 258.1 257.2 +0.17% level 33.2 / 33.2 2.51 / 2.51 1.51 / 1.51
conc_t0 code 0.0 1 72.7 72.8 72.7 72.6 +0.14% level 72.7 / 72.8 5.22 / 5.22 4.22 / 4.22
conc_t0 code 0.0 2 138.5 138.5 138.0 137.5 +0.18% level 69.7 / 69.9 4.83 / 4.83 3.83 / 3.83
conc_t0 code 0.0 4 244.1 244.1 243.5 242.3 +0.25% level 62.4 / 62.6 4.83 / 4.83 3.83 / 3.83
conc_t0 code 0.0 6 308.0 307.5 308.6 306.9 +0.20% level 53.1 / 53.3 4.49 / 4.49 3.49 / 3.49
conc_t0 code 0.0 8 375.3 373.0 373.3 372.3 -0.17% level 49.0 / 49.0 4.49 / 4.49 3.49 / 3.49
Verdicts: 0 faster, 12 level, 0 slower, 0 unmeasured
Mean change per concurrency level (the concurrent cells, both prompts):
streams cells mean change faster level slower
1 2 +0.07% 0 2 0
2 2 +0.18% 0 2 0
4 2 +0.06% 0 2 0
6 2 +0.24% 0 2 0
8 2 +0.00% 0 2 0
  • Rerun: No cell was slower in the first pair, so no rerun was taken.
  • Accepted drafts a round and the server's own acceptance, from /metrics before and after each probe:
arm invocation accepted drafted acceptance alone equal/unequal serial equal/unequal
M1 openai_t0 1488 2384 0.6242 - -
M1 conc_t0 22760 33060 0.6884 24/0 1/0
B1 openai_t0 1488 2384 0.6242 - -
B1 conc_t0 22760 33060 0.6884 24/0 1/0
B2 openai_t0 1488 2384 0.6242 - -
B2 conc_t0 22760 33060 0.6884 24/0 1/0
M2 openai_t0 1488 2384 0.6242 - -
M2 conc_t0 22760 33060 0.6884 24/0 1/0
  • Boot time, the window and the pool line of every arm:
arm pass image ctx/par wall s server answered
M1 1 tensorfold-qwen38:wr-m-e7e24243 32768/8 37.2 37
B1 1 tensorfold-qwen38:wr-b-fe753c94 32768/8 34.0 34
B2 1 tensorfold-qwen38:wr-b-fe753c94 32768/8 34.0 33
M2 1 tensorfold-qwen38:wr-m-e7e24243 32768/8 34.0 34
M1 2 tensorfold-qwen38:wr-m-e7e24243 131072/4 34.0 34
B1 2 tensorfold-qwen38:wr-b-fe753c94 131072/4 34.0 33
B2 2 tensorfold-qwen38:wr-b-fe753c94 131072/4 34.0 34
M2 2 tensorfold-qwen38:wr-m-e7e24243 131072/4 34.0 34
M1 3 on tensorfold-qwen38:wr-m-e7e24243 32768/8 34.0 33
M1 3 off tensorfold-qwen38:wr-m-e7e24243 32768/8 34.0 33
B1 3 on tensorfold-qwen38:wr-b-fe753c94 32768/8 34.0 33
B1 3 off tensorfold-qwen38:wr-b-fe753c94 32768/8 34.0 33
M1: model 72.71 GiB; 8 streams at once, 1.29 GiB each at a 32768-token window, of 27.8 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 16.0 GiB prompt cache; own glue kernels
B1: model 72.71 GiB; 8 streams at once, 1.29 GiB each at a 32768-token window, of 27.9 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 16.0 GiB prompt cache; own glue kernels
B2: model 72.71 GiB; 8 streams at once, 1.29 GiB each at a 32768-token window, of 27.9 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 16.0 GiB prompt cache; own glue kernels
M2: model 72.71 GiB; 8 streams at once, 1.29 GiB each at a 32768-token window, of 27.9 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 16.0 GiB prompt cache; own glue kernels
  • Exactness, from bench_concurrent --alone --serial and served_exactness.py against "draft": false:
    M1 cache on concurrent: concurrent equals solo 156 equal / 0 unequal; drafted equals "draft": false 56 equal / 0 unequal
    M1 cache on golden: concurrent equals solo 13 equal / 0 unequal; drafted equals "draft": false 24 equal / 0 unequal
    M1 cache on drafts: 8 of 8 equal to "draft": false (basis ['token_ids'])
    B1 cache on concurrent: concurrent equals solo 156 equal / 0 unequal; drafted equals "draft": false 56 equal / 0 unequal
    B1 cache on golden: concurrent equals solo 13 equal / 0 unequal; drafted equals "draft": false 24 equal / 0 unequal
    B1 cache on drafts: 8 of 8 equal to "draft": false (basis ['token_ids'])
    M1 cache off drafts: 8 of 8 equal to "draft": false (basis ['token_ids'])
    M1 cache off fresh: 7 of 7 resumed replies equal the fresh ones
    B1 cache off drafts: 8 of 8 equal to "draft": false (basis ['token_ids'])
    B1 cache off fresh: 7 of 7 resumed replies equal the fresh ones
    Branch replies equal main's (pass A greedy token_sha, every stream and rep): 528 equal, 0 unequal
  • Prompt speed before and after: the same images and machine, M1 B1 B2 M2 again, each a fresh boot with --prompt-cache-gib 0 at a 131,072-token window with 4 slots; cold prompts of 2k, 8k, 32k and 64k tokens (a fresh salt first, thinking off, median of 3), then tools/bench_cache.py --require-cold. Same noise rule, with slower meaning longer. No cell is slower:
prompt M1 B1 B2 M2 change slower?
cold2k-off 1.063 1.082 1.091 1.082 +1.31% level
cold8k-off 3.994 4.009 4.021 4.016 +0.25% level
cold32k-off 16.080 16.080 16.050 16.064 -0.04% level
cold64k-off 33.016 33.074 33.074 33.118 +0.02% level
bench_cache --require-cold, first ttft_s 1.223 1.225 1.227 1.225 +0.12% level
cached tokens on each cold first request: M1 0 B1 0 B2 0 M2 0; qualified M1 True B1 True B2 True M2 True
Flagged cold samples (NOTCOLD or NOLOAD, excluded from the medians): 0
M1 cold 64k: summary cold64k-off idle n 3 ttft med 33.016 p90 33.126 admit 0.035 queue - prefill 32.981 other 0.000 server 33.007 excluded 0
B1 cold 64k: summary cold64k-off idle n 3 ttft med 33.074 p90 33.090 admit 0.035 queue - prefill 33.052 other 0.000 server 33.072 excluded 0
B2 cold 64k: summary cold64k-off idle n 3 ttft med 33.074 p90 33.091 admit 0.023 queue - prefill 33.050 other -0.000 server 33.072 excluded 0
M2 cold 64k: summary cold64k-off idle n 3 ttft med 33.118 p90 33.159 admit 0.035 queue - prefill 33.083 other -0.000 server 33.116 excluded 0
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: TensorFold main e7e24243 as tensorfold-qwen38:wr-m-e7e24243 and the branch fe753c94 as tensorfold-qwen38:wr-b-fe753c94, each built by build.sh from a verified git archive tree of its own commit (e7e24243d63e232b05d4892df4fa01c9a2d6c70b, fe753c9470fb04c2c4a1bb09ac0d6e08b7c00775; image ids and labels sha256:94ef45cd6a1c432e0e39a8a6468ac15741e1857a041d013de3edcb17b893e888 created=2026-11-16T07:25:56.999388196Z kernels=embedded and sha256:43be8280bdcf3d21c5829969400675947d07a3dda30852266f2a38097eb0f176 created=2026-11-16T07:16:54.426273349Z kernels=embedded), nothing of ours patched into either; 7.0.0-1019-nvidia-64k; Ubuntu 24.04.5 LTS; NVIDIA GB10, 580.178.04, [N/A]; RAM 123 GiB; NVCC Cuda compilation tools, release 13.3, V13.3.73 Build cuda_13.3.r13.3/compiler.38244171_0; ZIG 0.17.0 (GB10's unified memory: nvidia-smi reports the memory total as [N/A] and the box reports its RAM); checkpoint nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300; bf16 KV, decode and exactness at a 32,768-token window with 8 slots, the cold pass at 131,072 with 4 slots.
  • Boxes it reaches: Flash Next on CUDA (one GPU and two ranks); the MLX path only through its refusal.
  • New switch? None. The config decides.
  • Paths and platforms the change reaches, which I ran and which I could not: one GPU on GB10 run at 1, 2, 4, 6 and 8 streams; two ranks not run.
  • Why the receipt describes this head: every number in it was measured on main e7e24243 and on the branch of it (fe753c94), the Environment bullet's two images, so the comparison is this change and nothing else, and the merge of 077998f7d9b1 adds no work to the cells it measured. Flash Next TP=2 on CUDA: head and rollback graphs replay, and one-row split lanes skip the interleave copies #2837's runtime change runs only at two ranks: its two statements in cuda_shared_split.zig sit inside if (native.split_shared), its one in cuda_split_lane.zig after lw.dense_cut orelse return self.lane(...), and cuda_dense_split.applies returns false unless world == 2, so on the one GPU every row was taken on neither executes; its cuda_launch.zig change is a test import. At the default shape this change's integers are main's, cuda_widths.zig's default being wt.slots - 1 slots and wt.moe_w rows (11 and 640) and Sizes defaulting to the same two, so main-at-T and branch-at-T issue the same launches with the same arguments and run the same kernel files, and no cell of the receipt can differ. What does not transfer is the absolute figures, which are what those two images produced; main's own commits between e7e24243 and 077998f7d9b1 are on both arms. As context only, and not part of this receipt: main cf4555373 against e7e24243 is level in all 22 cells it was measured in, -0.77% to +0.07%, on the same machine and checkpoint.
  • The top-5 shape on the device, measured on 964174ea05 and not retaken here (this window served the default shape only): from the FP4-Local snapshot I built a top-5 checkpoint whose 48 main layers' shared expert carries 640 zero-padded rows (they contribute exactly zero), with the MTP layer's shared expert left at 640, which the MTP rule allows. The branch loaded and served it (model 72.88 GiB, 4 streams at 4.11 GiB each, 27.9 GiB left after the 9.0 GiB reserve): bench_concurrent --alone --serial 1, 2 and 4 streams at 68.5, 58.8 and 52.7 tok/s a stream on code and 55.7, 52.9 and 47.9 on chat; drafts 8 of 8 equal to "draft": false with 173 to 234 accepted a reply; bench_openai 67.98 and 55.71 tok/s; 2,805 accepted of 4,593 drafted over 1,824 rounds in the concurrent bench; and a plain question answered coherently. Main refused the same checkpoint by name: config.json's num_experts_per_tok differs from the supported Flash Next CUDA layout.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title, the stack and the checks describe the head commit, and the receipt's rows are measured on main e7e24243 and on the branch of it (fe753c94) in one window.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo, measured on fe753c9470 in this window; the receipt bullet says why the merge adds no work to those paths.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted, and no cell of the decode or cold tables is slower.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. The design is clean: the kernels already take top-k and slots as launch arguments, so the shape is plain data. cuda_widths.zig holds the two supported shapes (cuda_widths.zig:24), and the default shape gets the same integers main's constants gave it. Your receipt backs that up: 528 of 528 greedy replies equal main's, drafted output equal to "draft": false, concurrent equal to solo, resumed equal to fresh, and all 12 decode cells and 5 prompt cells level. Unsupported shapes are refused by field name, and so are a captured kernel set or the MLX path asked to run top-5 (cuda_lanes_load.zig:27, cuda_launch.zig:428). The lean count stays at 221, no file goes over 600 lines (cuda_batch_state.zig is the largest at 597), and the changelog line is under Unreleased.

On main the three commits conflict in one source file, cuda_shared_split.zig. Main's #2837 added the one-row path at cuda_shared_split.zig:20. Your merge commit already settles this the way the description says (both kept, with the width taken from native.shared_width), so you don't need to rebase for it. The pin file conflicts in the same place, and the cuda_launch.zig row now carries both notes.

We added one small commit on top, with no change in behaviour. It drops Scratch.shared_w, which Scratch.alloc and the split-lane test set but nothing reads, and re-pins cuda_batch_state.zig in gradient-serving.tsv.

Must fix: none in the code.

Requested before landing: numbers for the top-5 shape at the current head. The top-5 run in the description was taken on 964174ea05, before the merges of e7e24243 and 077998f7d9b1. It reports drafts equal to "draft": false (8 of 8) but gives no equal/unequal counts for concurrent against solo or for resumed against fresh. Main refuses this shape, so there is no main reply to compare against. For that reason the exactness contract on the top-5 path is the evidence that matters here. Could you post, on this head with your zero-padded top-5 checkpoint:

  1. bench_concurrent --alone --serial equal/unequal counts at 1, 2 and 4 streams;
  2. drafted against "draft": false, and resumed against fresh, as in your default-shape receipt.

Optional:

Device checks, which we will run on our side:

  • GB10 (CUDA), one GPU, the top-5 shape at the current head: tokens equal across concurrent/solo, drafted/"draft": false and resumed/fresh.

  • GB10 (CUDA), two ranks (--tp 2), default shape: tokens equal to main's, and the same three equalities. The reduce-scatter size and the shared split's column copies now read s.slots and native.shared_width, and the description says two ranks were not run.

  • Synthena

@BadAd84

BadAd84 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the extra commit. I fetched it and built on it, so the code below is your commit plus one small one (c0eb2126d), and the head now on the branch, 10da73f54, is that commit merged with main af9777b49, which conflicted only in CHANGELOG.md. Nothing in c0eb2126d changes behaviour.

The two optional fixes:

  • The split path's comment now names the width that path reads, shared_width, rather than a per-rank constant.
  • The head load takes the engine's widths. Head.init receives e.widths from the lanes load, from the drafted check
    and from the device parity test, and the MTP rule reads that value instead of parsing config.json a second time, so
    the two cannot drift. The rule itself is unchanged: the head's shared expert may be the main layers' width or the
    routed 640, and any other row count still stops the load naming mtp.layers.0.mlp.shared_expert.gate_proj. A host
    test fails if the head reads the config again or a caller stops passing the widths; three mutants of the new path each
    fail it.

Numbers for the top-5 shape on c0eb2126d, one GB10, one GPU, one image built from that commit, with the same zero-padded checkpoint as before (48 main layers' shared expert at 1,280 rows, the added 640 rows zero; the MTP layer's shared expert left at 640), and the default FP4-Local checkpoint on the same image as the control. A fresh server an arm, --parallel 4 --context 131072, bf16 KV, drafts on:

measurement top-5 default shape
concurrent equal to solo, 1, 2 and 4 streams, greedy 14 equal, 0 unequal, 0 failed 14 equal, 0 unequal, 0 failed
concurrent equal to solo, 1, 2 and 4 streams, temperature 1.0, seed 1234 14 equal, 0 unequal, 0 failed 14 equal, 0 unequal, 0 failed
alone equal to "draft": false, greedy 6 equal, 0 unequal 6 equal, 0 unequal
alone equal to "draft": false, temperature 1.0 24 equal, 0 unequal 24 equal, 0 unequal
drafted equal to "draft": false, eight prompts 8 of 8 8 of 8
resumed equal to fresh, seven turns, plain and drafted 7 of 7, no problems 7 of 7, no problems

The top-5 boot's own lines:

  • model 72.88 GiB; 4 streams at once, 4.11 GiB each at a 131072-token window, of 27.7 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 11.2 GiB prompt cache, loaded in 31.6 s, serving as Qwen3.8-Flash-Next with drafts: MTP + copies.
  • The default shape's: model 72.73 GiB; 4 streams at once, 4.11 GiB each ... of 27.8 GiB left; ... a 11.4 GiB prompt cache, loaded in 30.8 s.
  • Drafting was live on the top-5 shape: 14,434 drafted and 9,056 accepted over the arm (the default shape's arm: 14,089 drafted and 9,082 accepted).

Main still refuses this checkpoint by name, so there is no main reply for the top-5 shape. The two-rank check is yours as offered; this head has not run --tp 2.

On the CPU side, on a clean host of its own: whole-tree fmt clean on both sides; lean 221 problems on the base and 221 on
this head, 0 new by (path, reason); test-gradient-serving and test-qwen-serving-host pass; both aarch64 compile steps
pass; and pr_check --pr 3523 reports 0 errors and 0 warnings. test-cuda-host is green on this head (410 of 410 steps),
and each of the three mutants of the new path kills exactly one test, the new one: the parent's head load re-reading
config.json, a head that ignores the widths it is given, and a caller that passes the default shape instead.

A first run of that suite on this head failed two timing tests the base did not (the GLM warm-peer bounds and the server's
benchmark receipt). Both are in modules this change does not touch, and the warm-peer step passes on its own on both
trees (11 of 11 tests); the base had failed one of the same pair in the same run. That box was also carrying another
lane's Rust build, at a load average of 26 to 33 on 16 cores.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @BadAd84. The top-5 numbers you posted cover every equality we asked for: concurrent against solo at one, two and four streams, drafted against plain, and resumed against fresh, all equal with no failures. The mutants and host suite are noted too.

We will run our GB10 device check on our side and post the result here. Nothing else is needed from you.

  • Synthena

@ashhart
ashhart force-pushed the flashnext-config-widths branch from 10da73f to b350eff Compare November 20, 2026 08:16
@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I reran the host checks on b350eff3a with Zig 0.17.0 on an M5 Max. zig build test-flashnext-compose-host test-gradient-serving -j4 --summary all passed all 43 tests. A local test filter over the existing checkpoint-width cases also passed, covering top-5 with a 1280-wide shared expert, unsupported widths, and the MTP head's use of the resolved widths. The full zig build test-cuda-host test-gradient-serving -j5 --summary all run also finished with 440/440 steps, 7,642 tests passed and 49 skipped.

One landing detail for when you pick this up after the GB10 check. git merge-tree --write-tree 1ece6e6db b350eff3a reports conflicts in CHANGELOG.md and zig/tests/fixtures/gradient-serving.tsv. In a scratch merge against that exact main, I recalculated the conflicted fixture rows from the merged sources. The combined hashes for cuda_batch.zig and cuda_launch.zig differ from both sides' pins. With the refreshed rows, zig build test-gradient-serving -j4 --summary all passed. Recomputing the hashes after the rebase will keep both the existing fused readout and this PR's width changes covered.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I rechecked e84fdf78b against main 2ce240cf0. All source files merge cleanly. The only conflict is zig/tests/fixtures/gradient-serving.tsv, covering six Flash Next rows.

In scratch I kept main's notes and the PR's width notes for those rows and recomputed their hashes from the merged source bytes. No source edits were needed. On M5 Max with Zig 0.17.0, zig build test-flashnext-compose-host test-gradient-serving -Dcpu=apple_m1 -j4 --summary all then passed 10/10 steps and all 44 tests. git diff --cached --check passed.

That isolates the textual merge blocker to the fixture refresh. This was a host check. The GB10 device gate remains separate.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the flashnext-config-widths branch from e84fdf7 to 37d99a8 Compare November 22, 2026 00:55
@AIFlowML

Copy link
Copy Markdown
Contributor

The refreshed head 37d99a8aeb now applies cleanly to main 2ce240cf0. On M5 Max with Zig 0.17.0, the compose and serving-pin targets passed all 44 tests. The refreshed #3218 head 20003e9670 also applies cleanly by itself, with 76 host tests passing.

I also tested the order #3512 (8976552196) → #3218 → #3523 on the same base. In that order, the overlaps are confined to docs/environment.md, environment_flashnext_test.zig and gradient-serving.tsv. I kept the setting descriptions, used the combined inventory of 52 settings (29 switches, 13 integers, 4 reals and 6 structured) and repinned the conflicted rows from the merged sources. Both MTP and prompt handler pins pass with that resolution. The code files merged automatically.

zig build test-environment-host test-gradient-serving test-flashnext-compose-host \
  test-flashnext-mtp-plan-host test-flashnext-loader-host check-native-cuda-host \
  -Dcpu=apple_m1 -j4 --summary all

All 27 build steps passed, with 118 fresh tests and four reused results, including the serving-pin check. The Linux ARM64 CUDA native build check passed. The GB10 device gate is still separate.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the flashnext-config-widths branch from 37d99a8 to bbb526c Compare November 23, 2026 11:53
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. One small tidy-up, not a blocker: the MTP head's byte estimate still sizes its shared expert at 640 wide, so a 1280-wide one is undercounted by about 3 MB. Placement for these checkpoints already adds a 1 GiB allowance, so this should not change what gets admitted. If you touch this code again, reading the width from the loaded tensor would keep the estimate exact.

  • Synthena

BadAd84 added a commit to BadAd84/TensorFold that referenced this pull request Nov 23, 2026
ashhart#3523 was rebased onto main's ce02643 and re-pins the serving sources main
moved under it, so this branch's five commits keep their content and only the
stack's base moves.

Two files conflicted. The scratch keeps this change's tail bytes beside the
base's own terms. In the serving pins the base's rows and notes are kept, this
change's six note sentences and its new cuda_projection_tail_test.zig row are
applied, and every row's hash is recomputed from the merged bytes.
@BadAd84

BadAd84 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, taken: the MTP head's byte estimate now reads its shared expert's width from the loaded tensor.

The old headBytes priced the shared expert at the 640-wide constant, so a 1280-wide one was undercounted by its three projections' 3,072,000 bytes. cuda_mtp.zig:344 now reads:

const experts = wt.experts_n * routed + 3 * shared * dims / 2 * 5 / 4;

and headBytes takes that width as its second argument (cuda_mtp.zig:340). The routed experts' own arithmetic is unchanged, so the delta is still 3,072,000 at either routed format.

headSharedWidth (cuda_lanes_bytes.zig:37) reads the width from the head's own gate_proj rows and returns what the loader keeps on the device, not what the tensor says:

  • whole routed experts next to the shared expert are the modelopt load, which keeps every row, so a 1280-wide expert is priced at 1280;
  • the legacy path keeps the first 640 rows of a taught folder's wider expert, so it is priced at 640;
  • a checkpoint with no MTP tensors is priced at the 640 constants, as before.

deviceWeightBytes degrades as it did: 0 for the checkpoint if the routed-experts probe fails, and the 640 width if only the width probe fails. Placement still turns either probe's error into a refused admission. The 1 GiB allowance is unchanged, so what gets admitted does not change, and for the top-5 checkpoint in your receipt, whose MTP layer's shared expert is 640, the byte total is identical.

The test is at cuda_fp8_experts_load_test.zig:269. It writes four one-shard checkpoints with the repo's own safetensors fixture and asserts, for each, the width the reader returns and the price the estimate gives at that width:

  • no MTP tensors;
  • a 1280-wide shared expert with whole experts;
  • a 768-row legacy head;
  • a 640-wide shared expert with whole experts.

The 1280 case must price exactly the 640 estimate plus 3,072,000.

On this head zig build test-flashnext-loader-host passes with it, 41 of 41. Restoring the parent's behaviour in the reader, a one-line mutant that returns the 640 constant, makes the same test fail with expected 1280, found 640. Pricing the shared term at the constant instead of the width makes it fail with expected 1743537312, found 1740465312, a difference of 3,072,000. A third mutant, expect(false) planted in the sibling test in cuda_mtp.zig, fails test-cuda-host and names that test, so both tests are reached by the steps I ran.

Checks on this head, on paperclip, under the host lock:

  • zig fmt --check build.zig zig: clean.
  • Lean, one tree at a time with the head's checker in both: the merge-base tree 7,689 files and 165 problems, this head 7,690 files and 165 problems, lean: 165 problems, 165 on the base, 0 new.
  • zig build test-gradient-serving: 1 test passed, the re-pinned cuda_mtp.zig row included.
  • zig build test-flashnext-batch-host: 17 tests passed.
  • zig build test-environment-host: 32 tests passed.
  • zig build test-flashnext-loader-host: 41 tests passed.
  • zig build check-native-cuda-host and zig build compile-flashnext-mtp-parity-host: both compile.
  • zig build test-cuda-host: 474 of 474 steps, 8,649 of 8,691 tests passed, 42 skipped.

All host steps, no GPU used.

The head is 09fb979b9368f529cabc567f44829c88071a1534 on flashnext-config-widths, one commit on top of your re-pin.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for the thorough follow-up. The one-row comment now names the width it uses, the MTP head takes the engine’s widths, and the byte estimate reads the shared expert’s loaded rows. The default path also keeps the same routing values and launch order in the source I reviewed.

One small loader edge still needs a fix. cuda_widths.zig adds the learned-neuron count to the supported shared width without checking for overflow. The full server config reader checks that count first, but widthsIn does not, and standalone engine initialization calls widthsIn directly. A learned count near the signed integer maximum can therefore panic instead of refusing the checkpoint by field name.

Please apply the learned-neuron bounds rule on every width-selection path, or use checked addition and refuse that field on overflow. A direct test with an extreme learned count would cover the standalone path.

There is also one remaining byte-accounting issue. cuda_mtp.zig prices the shared expert at 0.625 byte per weight for every format. That is right for the legacy packed form, but whole heads can keep BF16 or MXFP8 shared projections. For a 1280-wide BF16 shared expert, the new correction still leaves the estimate 6,758,400 bytes short; MXFP8 leaves it 1,996,800 bytes short. Please price the shared projections from their actual loaded format and add BF16 and MXFP8 cases beside the legacy test.

The two current merge conflicts are mechanical: the MTP byte estimate needs both the existing split-scratch accounting and your shared-width term, and the serving rows then need fresh hashes. We can handle that integration here; no rebase is requested from you.

The source defaults look unchanged. The remaining runtime checks should cover the default and top-5 shapes on one GPU, six-slot FP8 routing, and two-rank default and top-5 paths.

  • Synthena

@BadAd84

BadAd84 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Both are fixed, in two commits on the branch: 81afc64161 for the learned-neuron count and 9b77fbe585 for the shared expert's bytes. Nothing is rebased; the merge base is ce0264367e against upstream main at 9a38b1f7b, and the changelog overlap is yours as you said.

The learned-neuron count. The rule was already stated in the full config reader (cuda_config.zig:106: a whole number of 32-neuron groups, 128 at most). It has one owner now, widths.learnedOk, and select applies it before the shared width is summed, so widthsIn (the standalone path) and widthsOf refuse tensorfold_learned_neurons by field name rather than adding it. The test reads a taught folder's config.json (64 neurons, 704 shared rows) through widthsIn, then passes the same fields with 9223372036854775807 to the selection and gets the field name back.

The shared expert's bytes. headBytes now takes each projection's stored form (5/8 of a byte a weight affine, two bytes BF16, a code and a scale byte a 32 MXFP8), and headShared reads each form from the tensor the checkpoint holds. On a 1280-wide expert, the 640 rows past the 640 constants cost 9,830,400 bytes BF16 and 5,068,800 MXFP8 where the width correction priced 3,072,000, so they are 6,758,400 and 1,996,800 short, matching your numbers. The whole expert is 6,144,000 affine, 19,660,800 BF16 and 10,137,600 MXFP8, and the test asserts each figure. The loader test covers affine, BF16 and MXFP8 checkpoints through headShared.

Receipts: on linux x86-64 with Zig 0.17.0, the filtered host run over the touched tests passes 51/51 and test-flashnext-loader-host passes 41/41. With each fix reverted the matching test fails: an integer overflow at the sum for the count (both the standalone read and the selection), expected 19660800, found 6144000 for the bytes, and expected .bf16, found .affine for the reader. pr_check --base up/main --pr 3523 is rc 0, lean 165 against 165 with 0 new, and zig fmt --check and git diff --check are clean.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. Both fixes are present: every width selection checks the learned count before addition, and shared-head pricing reads each projection's stored form. The new tests cover the extreme count and affine, BF16 and MXFP8 costs. The earlier top-5 equality results are credited too.

No further source fix is requested. We can handle the MTP merge and final serving-pin refresh; two raw pins still describe the earlier source. Current integrated default/top-5, six-slot FP8 and two-rank qualification remain open, with exact checkpoint identities recorded for each.

  • Synthena

@ashhart
ashhart force-pushed the flashnext-config-widths branch from 9b77fbe to 20829c3 Compare November 24, 2026 20:53
@ashhart
ashhart force-pushed the flashnext-config-widths branch from 20829c3 to 779b959 Compare November 25, 2026 00:51
ashhart added a commit to BadAd84/TensorFold that referenced this pull request Nov 25, 2026
…a_mtp.zig keeps to 600 lines

Main's cuda_mtp.zig grew since ashhart#3523 was last rebased, and the merged file came to 649 lines. The head's byte
pricing moves whole to cuda_mtp_bytes.zig with its three tests: split_bytes, the shared projection's Format,
Shared, sharedBytes and headBytes. cuda_mtp.zig re-exports split_bytes, Format, Shared and headBytes, so
every caller is unchanged. No behaviour change. Re-pins cuda_mtp.zig.
BadAd84 and others added 5 commits November 25, 2026 02:51
The CUDA path took the routing width (top-10, 11 slots) and the shared expert's width (640) from
constants. config.json now selects one of two supported shapes, top-10 with a 640-wide shared
expert or top-5 with a 1280-wide one, and refuses any other value by the field's name. The
pass reads the slots from its scratch, which is sized by the shape; the shared expert's width
is its gate_proj's rows. The MTP layer routes at the main layers' top-k. A captured kernel set
serves the default shape only. The default shape's launches take the same integers as before.

Refs ashhart#3368
…ment names the width it reads

Head.init read config.json a second time through widthsIn, after Engine.init had already
selected the same shape into e.widths, so a change to one read could leave the other stale.
It now takes the engine's widths as an argument, and the MTP rule is unchanged: the head's
shared expert may be the main layers' width or the routed width (640), and any other row
count stops the load naming mtp.layers.0.mlp.shared_expert.gate_proj. The lanes load, the
drafted check and the device parity test pass e.widths.

The one-row split path gathers [2, 1, width] blocks into the row the down projection reads,
and that row's width is native.shared_width, not the halved per-rank width; the comment now
names it.

A host test pins the single reader: cuda_mtp.zig holds no widthsIn, its init takes the
engine's widths, and both callers pass them.

Re-pins cuda_mtp.zig, cuda_lanes_load.zig and cuda_mtp_check.zig in the serving fixture.
BadAd84 and others added 6 commits November 25, 2026 02:51
headBytes priced the shared expert at the 640-wide constant, so a 1280-wide
one was undercounted by its three projections' 3,072,000 bytes: gate, up and
down at 5/8 of a byte a weight over 640 rows.

The estimate now takes the width as an argument. headSharedWidth reads it from
the head's own gate_proj rows: whole routed experts beside it are the modelopt
load, which holds every row, while the legacy path keeps the first 640 rows of
a taught folder's wider expert, and a checkpoint with no head prices the 640
constants. deviceWeightBytes degrades as before, pricing the 640 width when
only the width probe fails; placement propagates the error and refuses
admission.

A host test pins the 1280 case: the head's bytes grow by exactly 3,072,000 at
either routed format, and a fixture checkpoint with a 1280-wide shared expert
prices that tensor's rows, while 640-wide, 768-row legacy and head-less
checkpoints price the default.

Re-pins cuda_mtp.zig in gradient-serving.tsv.
…umming it

config.json's tensorfold_learned_neurons went straight into the supported shared width's sum, so the
standalone engine's read (cuda_config.zig's widthsIn, which cuda_prompt.zig's initialization takes) overflowed
on a count near the signed maximum instead of refusing the checkpoint by field name; the server's read
checked the count before its selection, so the two paths disagreed.

cuda_widths.zig now owns the rule (whole 32-neuron groups, 128 at most) as learnedOk, and select applies it
before the sum. cuda_config.zig's geometry calls the same rule, and the field name comes from cuda_widths.zig
rather than being spelled again there.

Tests: select on the signed maximum, the signed minimum, 129 and 40, and the taught 704-row shape; the
standalone widthsIn on a 64-neuron folder's config.json plus the same fields with the signed maximum, which
the selection refuses by field.
…ed in

headBytes priced every shared projection at 5/8 of a byte a weight, the affine pair's cost, so a whole head
whose shared expert is kept BF16 or MXFP8 was estimated short. For a 1280-wide expert the 640 rows past the
640 constants cost 9,830,400 bytes BF16 and 5,068,800 MXFP8, against the 3,072,000 the width correction
priced: 6,758,400 and 1,996,800 short.

headBytes now takes a Shared: the intermediate width and each of the gate, up and down projections' stored
form, priced 5/8 a weight affine, two bytes BF16, a code and a scale byte a 32 MXFP8. headShared reads each
form from the tensor the checkpoint holds: F8_E4M3 codes are MXFP8, BF16 is kept, anything else is the
affine pair.

Tests: the whole 1280-wide expert against no shared rows, 6,144,000 affine, 19,660,800 BF16 and 10,137,600
MXFP8; the 640-row correction's 6,758,400 and 1,996,800 shortfalls; one projection at another form;
headShared's forms over affine, BF16 and MXFP8 checkpoints.
…a_mtp.zig keeps to 600 lines

Main's cuda_mtp.zig grew since ashhart#3523 was last rebased, and the merged file came to 649 lines. The head's byte
pricing moves whole to cuda_mtp_bytes.zig with its three tests: split_bytes, the shared projection's Format,
Shared, sharedBytes and headBytes. cuda_mtp.zig re-exports split_bytes, Format, Shared and headBytes, so
every caller is unchanged. No behaviour change. Re-pins cuda_mtp.zig.
@ashhart
ashhart force-pushed the flashnext-config-widths branch from 58a036f to 4dbfaa3 Compare November 25, 2026 02:51
@ashhart
ashhart merged commit 6811c37 into ashhart:main Nov 25, 2026
1 check failed
ashhart added a commit that referenced this pull request Nov 25, 2026
…a_mtp.zig keeps to 600 lines

Main's cuda_mtp.zig grew since #3523 was last rebased, and the merged file came to 649 lines. The head's byte
pricing moves whole to cuda_mtp_bytes.zig with its three tests: split_bytes, the shared projection's Format,
Shared, sharedBytes and headBytes. cuda_mtp.zig re-exports split_bytes, Format, Shared and headBytes, so
every caller is unchanged. No behaviour change. Re-pins cuda_mtp.zig.
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @BadAd84. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants