Skip to content

perf(flashnext): Flash Next HIP rounds replay split graphs - #818

Merged
ashhart merged 103 commits into
ashhart:mainfrom
BlivionIaG:fn3/i-flashnext-graphs
Oct 16, 2026
Merged

ashhart merged 103 commits into
ashhart:mainfrom
BlivionIaG:fn3/i-flashnext-graphs

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Slice I. Stacks on #817.

What this changes

  • HIP rounds replay graphs split at the collectives, by shape; host inputs staged in one upload; streams in kept cache slots.

Tests

  • Graphs (this PR against feat(flashnext): tensor parallelism for the Flash Next HIP engine #817, two alternating runs, the same tokens): decode code / chat 97.0 / 82.2 and 96.6 / 82.0 against 92.5 / 78.5 and 92.6 / 78.5 tok/s on 4 × V620, 105.9 / 90.1 and 102.3 / 86.8 against 100.8 / 85.6 and 99.9 / 84.7 tok/s on 2 × W7800; four streams (169.1 and 170.1 against 171.1 and 171.2 on V620) and an 8K prefill unchanged.
  • Flash Next on 4 × V620 (Qwen3.8-Flash-Next-MLX-4bit-MTP, tp 4) and 2 × W7800 (Qwen3.8-Flash-Next-MLX-3bit-MTP, tp 2):
    • serve_check 15 passed, 0 failed on both; the rewind gate against --prompt-cache-gib 0: 0 differing replies; graphs on and off (TF_POLICY=graphs=off): the same tokens.

    • Cold prefill (bench_cache.py --require-cold, exact token arrays, --prompt-cache-gib 0, 0 cached tokens in every row, no memory sampling), first run / the two after:

      Prompt tokens 4 × V620, --context 0 2 × W7800, --context 0
      2,048 12.84 / 1.74, 1.74 s 13.00 / 1.89, 1.90 s
      8,192 21.28 / 7.90, 7.93 s 23.13 / 9.21, 9.28 s
      32,768 50.26 / 34.79, 34.91 s 54.37 / 41.54, 41.95 s
      65,536 76.42 / 74.71, 74.76 s 89.82 / 90.41, 91.00 s
      131,072 168.46 / 168.43, 168.59 s 201.38 / 201.15, 201.90 s
      261,888 412.16 / 411.87, 411.61 s 474.05 / 475.14, 474.72 s
    • Decode (bench_openai.py --tokens 256 --reps 3 --temperatures 0), code / chat: 96.7 / 82.2 tok/s (V620), 105.7 / 89.9 tok/s (W7800).

    • Concurrency (bench_concurrent.py --levels 1,4 --alone --serial), total tok/s, code / chat: 1 stream 96.5 / 82.0 and 4 streams 164.2 / 140.8 (V620); 104.1 / 88.4 and 149.6 / 133.6 (W7800). Every reply equals its solo run and its "draft": false run.

    • Memory of the server processes (all ranks): at the 262,144-token window with one stream, device 104.4 GiB and PSS 113.6 GiB (V620), 75.6 GiB and 83.1 GiB (W7800); serving four 16K streams, device 94 GiB and PSS 79 GiB (V620), 71 GiB and 63 GiB (W7800). RSS counts the n-gram tables every rank maps (peaks of 388 GiB and 162 GiB at the 262,144-token window, 299 GiB and 122 GiB serving four streams); PSS counts them once.

  • Qwen3.5: model checks on the 35B-A3B at this head b473b7c: 46/0 at tp 1 on gfx1100 and gfx1030, 19/0 at tp 2 on 2 × W7800 and on 2 × V620, and at tp 4 on 4 × V620; decode logits byte-identical to feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) #655's head 1bdd859, at this head b473b7c (9B, 35B-A3B, 27B; gfx1100 and gfx1030).
  • macOS zig build test -Dcpu=apple_m1: one failure, core.checkpoint_metal's split-checkpoint test, which logs the same error on main;
  • Linux zig build test passes;
  • zig fmt --check is clean; lean_check.py 538, the same as main (1.0.9).
  • Not run: a standard-server comparison (vLLM) for Flash Next.

BlivionIaG and others added 30 commits October 10, 2026 18:24
…, DeltaNet, norms, RoPE, MoE routing and decode plans

The kernels a model engine composes, built by hipcc for -Dhip-arch with the caps table's instruction switches and
embedded as one code object a source group, launched from Zig: elementwise ops and casts, norms and the merged
decode tails, RoPE, the attention walks (flat, planned over a page table with the query heads of a KV head read
together, the 64-row prompt tile flat and paged), the DeltaNet recurrence token-serial and chunked, the
linear attention's conv and gates, the MoE router, pick and route, argmax and top-k, and a lane round's plan
kernels. A typed Ops layer checks shapes; an arena hands out a forward's scratch, and a counting stream measures
it without launching. hip-kernel-test checks each against a host or float64 reference, and the merged and paged
forms against the forms they replace, bit for bit where they promise it; -Dhip-device-lib names ROCm's bitcode.
The sources hold device code only: plain kernels by C name, templates instantiated for the types the launches use.
…it and dense, with tensor-parallel cuts

core/quant reads a checkpoint's MLX affine projections (bits 2, 3, 4, 5, 6 and 8, any group) or dense ones,
detects the format from the tensors, cuts a projection by output rows, by a rank's whole input groups or into
its two K halves, splits an expert stack across ranks, and hands a backend the upload. Every cut keeps the
codes and group tables byte for byte: a test quantizes with affine4_host and checks each cut dequantizes to the
same bits as the rows and columns it covers, and it fails when a cut is off by one group.
…st, one family of bits at every row count

core/registry selects, for a format, op (product, group, routed plan, routed with activation) and path (decode
or prompt), the cheapest entry the GPU, the run's switches and the shape allow, by a per-GPU tuning table read
at build time (core/tuning), so every rank picks alike. Its family rule checks that one (op, path) keeps one
family of entries at every row count from 1 to 256 for each width and group: a row's bits never depend on how
many rows share its launch. The rule's test fails when a tuning table lets another family take some rows.
… GEMM tile, stream and K-parallel tiles

The MLX affine 2- to 8-bit products a model's projections run, chosen per product by the kernel registry over a
per-GPU tuning table (gfx1030's for RDNA2, gfx1100's for RDNA3 to RDNA4): the decode row, column, stream and
split tiles, the RDNA2 wide tile, the prefill dot2 GEMM and K-parallel tiles, the gfx11 matrix-core GEMM tile
(compiler WMMA builtins, no rocWMMA), routed plans and products sharing x, with the routed gate and up's
activation as an epilogue. The tile sources hold device code only; each kernel the Zig launches resolve is
instantiated explicitly. hip-kernel-test checks every entry on the served models' shapes and a ragged sweep of
every width and group against float64, the entries the registry picks between by rows for equal bytes, and a
row's bytes alone and in a round of 2 to 32 rows.
…A header needed

From ThinkOffApp's gfx1151 runs on this PR and ashhart#621: Ubuntu's HIP 7.1 keeps its device bitcode in LLVM's clang
resource directory, and the kernels build there with -Dhip-device-lib set to it, without rocWMMA's header.
…e fork's hand ports

The kernel was written for TensorFold after FLA's chunk_gated_delta_rule; no
code came from vLLM or FLA, and the header only came along from the
opengfx1030/vllm-rdna ports.
Qwen3.5 / Qwen3.6 text checkpoints for the HIP engine, host side only: the geometry (dense and MoE, MTP layer
count, rotary, layer types) from config.json, the MLX affine quantization table per module, one tensor index
over the safetensors shards, the projections, the routed experts stacked, and the tensor-parallel cuts on
core/quant. `zig build test` runs its tests; TF_QWEN_DIR indexes a real checkpoint.

Draft: the geometry is a third Qwen text parser beside qwen27/config.zig and the Metal 2B's admission. ashhart#491
proposes one shared config and weight path instead; this is refit to that once agreed.
mlx-serve's conversions (Qwen3.8-27B-MLX-Serve-4/6/8bit) bake the trunk's
`1 + w` into its norms but ship the MTP head's norms zero-centered. Read as
gains, the head drafted nothing: 0 of 127 drafts accepted on the 27B.
Norms averaging under 0.5 now get the 1 added; the baked heads (9B, 35B,
27B-3bit-mtp) average 1.2 and above and are kept.
…, and reads layers, mrope and end ids

config_checks.zig takes qwen27/config.zig's rules to the HIP geometry: the
activation (silu), the attention gate (the swish gate, att * sigmoid(gate), and
no bias), the recurrent state type (fp32, under either key), the sizes the
kernels index with 32-bit counts, each layer's kind from layer_types in any
order, the mrope sections (three, filling half the rotary width,
interleaved), max_position_embeddings, and the end ids of config.json and
generation_config.json. The Qwen3.8-27B names <|im_end|> only in
generation_config.json. 0 and 1 count as false and true, as the 0.8B 2-bit
conversion writes them.

Co-authored-by: ashhart <[email protected]>
…el-free set

The device count, a context's free and total memory (hipMemGetInfo, looked up on its own so the admission set
is unchanged), a buffer's base address, a pinned host buffer's sub-range and typed view, and raw.zig: device
copies, fills and pinned transfers on a forward's raw stream handle, none of them on the counting stream.
hip-gpu-test checks each on the GPU.
ops/tp.hpp in the ops group, device code only: an activation plus an fp32 rank sum rounded once, a rank's local
expert ids and the masks of the experts another rank answers, and a token's softmax probability (MTP's
confidence). Zig launches in launches/tp.zig, `Ops.addWide`, `moeLocalize`, `moeForeignItems`,
`moeZeroForeign` and `tokenProb`. hip-kernel-test checks each against a host reference.
… and model checks

The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
…anks come from --tp

The two-Mac engines take their ranks from --speed-up's settings file; the HIP engine takes them from --tp and
the flags beside it. A HIP serve given --speed-up is refused, with or without --tp, so the two never mean
different things for one model.
A request with drafts off resumed nothing and kept nothing; it now resumes from the deepest shared snapshot and
keeps its marks as a drafted one does. The kept states are the target's alone (pages, DeltaNet states), so a
serial pass keeps what a drafted one reads and the other way round.
…ugh regenerate, edit and delete rewinds

serve_rewind.py runs one conversation against a server with the cache and one with --prompt-cache-gib 0,
drafts on and off: three turns, a regenerate, an edit of the last user message, a delete and a new turn, an
edit of the first turn. Every reply must be equal; it prints the prompt tokens each step took from kept states.
A prompt pass ran 1024-row chunks whatever else was running, so a decoding stream waited about 500 ms (gfx1100,
9B 4-bit) for each one. While another stream decodes, chunks are now policy fill_rows rows (512 by default, a
multiple of 64 dividing 1024); alone, 1024. A prompt cut on 64 rows gives the same tokens however it is cut:
with 256- and 1024-row chunks the 9B 4-bit and the 35B-A3B 2-bit reply the same to prompts of 325 to 5025
tokens. The policy carries fill_rows to every rank.
…o matrix-core tile exists

gfx1200 and gfx1201 build every target (the server, the model checks, the kernel and runtime tests, the bench)
and run their products on the dot2 and stream tiles: the matrix-core GEMM is gfx11's WMMA layout only. matrix=on
asked for matrix cores and silently got dot2 there; a serve now refuses it, naming the gfx12 tiles as not
implemented yet (RDNA2: no matrix cores). matrix=auto, the default, runs on every GPU in the caps table.
…lective.zig; RCCL becomes its own PR

The engine called RCCL and the ranks' TCP link directly. It now takes a collective.Group (the rank's link, its
communicator opened once the GPU is current, its close) and a collective.Comm (all-reduce, all-gather,
broadcast); tf-qwen35-test's group joins through the same hip.joinGroup as the server. This PR builds with no
collectives backend: joinGroup refuses more than one rank, the server lists no --tp, and the rccl_lib policy key
goes. RCCL (comm/: the library, the link, the group) returns behind the interface in the next PR, as ashhart#491's
order has it; the engine's tensor-parallel paths and their kernels stay here, with their tests.
…s each draw

The engine now declares structures, so response_format and the guided_*
fields reach it. The lane core's grammar (xgrammar) makes the masks; the
backend only applies them: each verify row's allowed bits, and the first
token through first_masked from the prompt's last row, kept for structured
replies. A masked row is drawn on the host from the whole row with the
disallowed tokens at -inf, by the same greedy and keyed draws. held() gives
the grammar the MTP drafts as host tokens.
comm/rccl.zig opens RCCL at run time (librccl.so.1, or the policy's rccl_lib first) and runs all-reduce,
all-gather and broadcast on the engine's streams; comm/link.zig is the ranks' TCP link (rank 0 listens, sends
the communicator's id and its policy; a rank whose GPU differs is refused) and carries rank 0's steps;
comm/group.zig joins the two into a collective.Group, and hip.joinGroup is its join. The server lists --tp
again (1, 2, 4 or 8 ranks, --rank, --master, --master-port), and tf-qwen35-test's --tp checks run.

RCCL's and HIP's threads do not start under Zig's per-thread alternate signal stack: the HIP build's native
module sets std_options without it, which the server root takes through the backend's std options (its own
commit, server/std_options.zig).
@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @BlivionIaG,

Thank you for replaying split graphs by shape, with graphs=off left eager.

We have no AMD card. This lands on your receipts plus our host checks, after #617. It contains #815, #816, and #817. We wrap forward.zig:170 and the other new lines past 120. A replay was not run, so that receipt is still the gate. This head takes #617's fp32 recurrence.

Thank you.

…quantization looks a module's width up

1.0.11's widths reached core/quant from config.zig and index.zig, which the HIP module imports with core as a module:
the HIP build stopped at an import outside its module path. Config.quantization becomes widths.quantization(config,
path): the reader's table when Config.widths (now an opaque pointer) is set, else Config.declared(path, canonical),
the config's own entries under the key spelling passed in. index.zig's walk takes the table's type as a parameter
(void when only names are checked), with its own Width for the refusal.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

A replay was not run, so that receipt is still the gate.

tf-flashnext-hip-test generate <checkpoint> --tp N --hash --repeat 2 at b473b7c, graphs on (the default) and --policy graphs=off, the same prompt and 32 greedy tokens as #817's receipt:

2 × Radeon PRO W7800 (gfx1100), tp 2, 3-bit 4 × Radeon PRO V620 (gfx1030), tp 4, 4-bit
Logits hash, graphs on, runs 1 and 2 6fbb0a3f895f7fa1, 6fbb0a3f895f7fa1 349d29968cc98589, 349d29968cc98589
Logits hash, graphs off, runs 1 and 2 6fbb0a3f895f7fa1, 6fbb0a3f895f7fa1 349d29968cc98589, 349d29968cc98589
Decode, second run, on / off 61.28 / 59.30 tok/s 49.74 / 47.71 tok/s

Every run's hash equals #817's at d4f9757 on the same GPUs.

@ashhart
ashhart merged commit 9d7a507 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
The lines #818 added past 120 columns (forward.zig:170 on its head among them), laid out by zig fmt one item a line. The same code: only layout and closing commas.
ashhart added a commit that referenced this pull request Oct 16, 2026
Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (#617, #621, #626, #631, #697, #655,
#811-#818), bracket classes in the tokenizer (#842), System One requests (#843), the shared norm's loads (#796) and
d1-3B on CUDA (#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's
tf_rms_rows_bf16 record takes #796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from #846) takes the 32
static bytes #796 leaves, with the 79 registers sm_80 had.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG, for replaying split graphs by shape with graphs=off left eager, and for the replay runs at b473b7ca7.

It ships in TensorFold 1.0.12 under your name as 1143d21cb, after #817, with our acaf2c458 for the wraps we named. Two more commits of ours follow, each with a host test: 9e0c2075a makes the graph vote impossible to skip, so running out of device memory while recording is a vote every rank sees and one failure stops every rank before another collective, and 0303df722 keeps a slot's caches when a lease's synchronize or reset fails, where the old lease freed buffers its replayed graphs still named. Your head is merged, so this pull request shows as merged.

We have no AMD card, so this lands on your receipts plus our host checks. At this head graphs on and off gave the same logits hash twice each at tp 2 and at tp 4, equal to #817's. The served checks in the description come from an earlier version, so at this head they are still open, with tp 8, RDNA3.5 and RDNA4.

Posted by Ash's AI Assistant Synthena

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

A correction to the replay receipt above: it is not valid as written.

That run loaded the system RCCL. With the RDNA RCCL build, the same #818 binary gives 349d29968cc98589 then 52fe0f9b8efaf508 on the second --repeat with graphs on (4 × V620, tp 4, 4-bit). The cause is in tf-flashnext-hip-test and keyOf: each repeat made its own caches outside the pool, and they replayed slot 0's graph over freed buffers. Served streams use pool slots and are not affected. #963 fixes it, with a host test that fails on main.

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The lines ashhart#818 added past 120 columns (forward.zig:170 on its head among them), laid out by zig fmt one item a line. The same code: only layout and closing commas.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…rt#844 onto the candidate

Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (ashhart#617, ashhart#621, ashhart#626, ashhart#631, ashhart#697, ashhart#655,
ashhart#811-ashhart#818), bracket classes in the tokenizer (ashhart#842), System One requests (ashhart#843), the shared norm's loads (ashhart#796) and
d1-3B on CUDA (ashhart#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's
tf_rms_rows_bf16 record takes ashhart#796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from ashhart#846) takes the 32
static bytes ashhart#796 leaves, with the 79 registers sm_80 had.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…nded in this release

Every file the head changes is in the candidate with the head's content, or differs only by commits documented at landing (our wraps and fixes, and later landed changes). This keeps the PR's head in the history and changes no file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants