Skip to content

feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) - #631

Merged
ashhart merged 39 commits into
ashhart:mainfrom
BlivionIaG:qwen35-engine
Oct 16, 2026
Merged

ashhart merged 39 commits into
ashhart:mainfrom
BlivionIaG:qwen35-engine

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Slice 12 of #491: the Qwen3.5 / Qwen3.6 engine on HIP. RCCL (slice 13) is no longer in this PR: the engine reaches the other ranks through hip/collective.zig, and RCCL comes behind that interface in its own PR, prepared on our fork. The family's config and weights are refit once the family question is settled.

What this changes

  1. feat(hip): the runtime pieces an engine uses beyond #463's model-free set:
  2. feat(hip): the kernels a tensor-parallel rank and the MTP head add: ops/tp.hpp, device code only (a rank sum added once, local expert ids and masks, a token's softmax probability), with their launches and host-reference tests.
  3. feat(qwen3_5): the Qwen3.5 / Qwen3.6 engine on HIP, its native server and model checks:
  4. feat(hip): one rank source: a HIP serve refuses --speed-up, as asked on feat(server): serve flags a backend opts into: tensor parallelism, MTP, kept entries, policy #624.
  5. feat(qwen3_5): the HIP prompt cache serves serial requests too: a request with drafts off now resumes and keeps prompt states like a drafted one. The kept states are the target's alone.
  6. test(qwen3_5): chat with the prompt cache equals chat without it through regenerate, edit and delete rewinds: serve_rewind.py, the gate asked for on feat(core): a paged prompt cache, a radix tree over the backend's own KV pages #625.
  7. feat(qwen3_5): a prompt runs 512-row chunks while other streams decode (policy fill_rows): with 1024-row chunks a decoding stream waited about 500 ms for each one. The cut is a multiple of 64, and replies are the same however a prompt is cut (256 and 1024, 9B and 35B-A3B, prompts of 325 to 5025 tokens).
  8. feat(hip): RDNA4 runs on the dot2 tiles; matrix=on is refused where no matrix-core tile exists: gfx1200 and gfx1201 build every target. The matrix-core GEMM is gfx11's WMMA layout only, so an explicit matrix=on is refused on RDNA4 (not implemented yet) and on RDNA2 (no matrix cores).
  9. refactor(qwen3_5): the engine reaches the other ranks through hip/collective.zig: a Group (link, communicator, close) and a Comm (all-reduce, all-gather, broadcast).
    • The server and tf-qwen35-test join through one hip.joinGroup.
    • This PR has no collectives backend: more than one rank is refused, the server lists no --tp, and the rccl_lib key goes.
    • The engine's tensor-parallel paths and their kernels stay, with their tests.
  10. build(hip): the HIP server's CLI module takes EXLR8's import, as main's server does since 1.0.8.
  11. feat(hip): the graph cache by shape in the hip module, for every HIP family: the engine's graph cache moves to hip/graph_cache.zig.
  12. feat(hip): a step recorded as graphs cut at its collectives, the collectives issued between replays (hip/graph_split.zig).
  13. feat(hip): the graph cache over any replayable step, a caller's own kept with hold.
  14. feat(qwen3_5): HIP rounds record split graphs: the collectives run between a round's graphs, not inside one. At one rank a round is one graph, as before; under tensor parallelism (feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) #655) it becomes graphs cut at each collective.
  15. perf(qwen3_5): the HIP loader drops each part's mapped pages once it is uploaded: after the embedding, norm and head, each layer and the MTP head, their pages leave the loader's mapping (madvise DONTNEED); the page cache keeps them, and a later read faults them back.

The shared-code change the shortest-prompt-first fill needs is its own PR, #651.

Receipt

  • Environment: head 73e4989, on feat(qwen3_5): the GPU backends' checkpoint loader, on the host (slice 11) #626 at 02c1dd6, main 0efbd44 (1.0.8). Zig 0.17.0, HIP 7.14, Fedora Linux, on a Radeon PRO W7800 (gfx1100, 48 GB) and a Radeon PRO V620 (gfx1030, 32 GB).

  • Exactness:

  • Model checks (tf-qwen35-test check): all pass at tp 1 on both GPUs (9B, 35B-A3B, 27B), speeds within noise of 7f5fd5b. They include drafted == serial (greedy and sampled), solo == together, graph == eager, resumed == fresh, and the radix cache's page and sharing checks.

  • Rewind gate: a server with the cache and one with --prompt-cache-gib 0 give equal replies through three turns, a regenerate, an edit of the last message, a delete, and an edit of the first turn, drafts on and off.

  • Serving receipt with the repo's tools, Qwen3.6-35B-A3B MLX 4-bit MTP at revision f84b054c, one model process set at a time, built at feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) #655's head 10926cf (this PR's engine plus comm/), one GPU. Raw JSON, the exact token arrays, request settings and scripts: receipts-qwen35-hip/receipts/qwen35-hip.

    Cold prefill (bench_cache.py, exact token arrays, --prompt-cache-gib 0, three cold runs each, 0 cached tokens):

    Prompt tokens W7800 V620
    2,048 0.64 s, 3,190 tok/s 0.91 s, 2,258 tok/s
    8,192 2.81 s, 2,914 tok/s 3.92 s, 2,091 tok/s
    32,768 16.07 s, 2,039 tok/s 20.98 s, 1,562 tok/s
    65,536 45.04 s, 1,455 tok/s 56.03 s, 1,170 tok/s
    131,072 141.86 s, 924 tok/s 166.89 s, 785 tok/s
    261,888 (the native window) 489.29 s, 535 tok/s 551.12 s, 475 tok/s

    Decode and concurrency (bench_openai.py --tokens 256 --reps 3 --temperatures 0; bench_concurrent.py --levels 1,4 --alone --serial):

    W7800 V620
    decode, code / chat 176.5 / 140.8 tok/s 157.3 / 127.9 tok/s
    4 streams total, code / chat 283.7 / 252.0 tok/s 257.1 / 239.9 tok/s
    replies equal to solo / to "draft": false 30/30, 4/4 30/30, 4/4

    Memory of the server process only: device peak 26.2 GiB (native window, 1 stream) and 23.8 GiB (32K window, 4 streams) on either GPU; host RSS about 0.5 GiB while serving, and an RSS high-water mark of 19.5 GiB during the load, the mapped checkpoint.

  • Loading (perf(qwen3_5): the HIP loader drops each part's mapped pages once it is uploaded), Qwen3.6-35B-A3B 4-bit, warm page cache, two runs each before and after; PSS splits pages the ranks share:

    GPUs Load time Peak PSS during load, all ranks RSS high-water mark, all ranks
    W7800, tp 1 25.9 / 26.2 → 20.6 / 21.1 s 19.2 / 18.2 → 2.3 / 2.4 GiB 19.5 → 2.5 GiB
    2 × W7800, tp 2 (feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) #655) 34.8 / 33.6 → 28.1 / 27.7 s 20.6 / 20.4 → 4.5 / 4.5 GiB 39.1 → 5.1 GiB
    4 × V620, tp 4 (feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) #655) 26.9 / 27.6 → 25.0 / 25.1 s 21.0 / 21.4 → 6.5 / 6.6 GiB 76.4 → 8.7 GiB

    The weights on the device are the same bytes (tf-qwen35-test digest identical) and decode logits are byte-identical, on gfx1100 and gfx1030; serving memory is unchanged.

  • Break checks:

    • the kernel tests fail with tf_add_wide adding twice the sum;
    • the runtime test fails with raw.copy ignoring its offset;
    • the matrix=on test fails with the gfx12 refusal removed.
  • Tests run:

    • macOS zig build test test-golden -Dcpu=apple_m1: golden 0 unexpected; one inherited failure, core.checkpoint_metal's split-checkpoint test, which logs the same error on main;
    • Linux zig build test: 57/57 steps, 695/702 tests (7 skipped);
    • hip-kernel-test 66/66 on gfx1100 and on gfx1030;
    • zig fmt --check is clean;
    • lean_check.py: 539 problems, the same as main.
  • Not run, and why: RDNA3.5 and RDNA4 on a card (no such cards here; gfx1151 and gfx1201 runs were offered on Zig ROCM: RDNA2/3/3.5/4 and more integration #491); a standard-server comparison (vLLM on these GPUs) is not in this receipt.

Checklist

  • 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. (checked on both GPUs above)
  • No precision traded for speed.
  • Prompt processing is no slower than the last release. (no shared prompt path changed)
  • The description says which platforms I ran and which I could not.
  • 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. No AI attribution lines.

…, 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.
@BlivionIaG BlivionIaG changed the title feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP with RCCL tensor parallelism (draft, slices 12-13) feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (draft, slice 12) Oct 11, 2026
@ThinkOffApp

Copy link
Copy Markdown
Contributor

gfx1151 receipt (Strix Halo: Ryzen AI Max+ 395, Radeon 8060S, RDNA3.5), head ebda131, fresh Zig cache per step. This covers the RDNA3.5 row your receipt lists as not run.

  • Ubuntu 26.04.1, Linux 7.0.0, Zig 0.17.0, HIP 7.14.60850 (TheRock), -Dhip-arch=gfx1151
  • hip-kernel-test 59/59 and hip-gpu-test 32/32 (your 91), hip-affine-test 27/27, hip-host-test 48/48. Nothing skipped.
  • tf-qwen35-test check, Qwen3.8-27B MLX 4-bit (Vontra's conversion, which carries no MTP weights), tp 1:
    • invariants: 42 passed, 0 failed, 5 skipped. The skips are the four drafted == serial checks ("the model has no draft head") and the radix memory check ("too few ids"), as on yours.
    • speed: 7 passed. Prefill 298 tok/s at 2,048 tokens and 285 at 8,192. Decode 12.6 tok/s for 1 stream and 36.2 for 4 streams with drafts off; drafts on gives the same here, since there is no draft head. Graphs: 12 captured, 2,448 of 2,460 rounds replayed.
  • native-hip serve with --backend rocm --policy graphs=on --mtp-drafts 3: /health reports the policy (with fill_rows=512), and a greedy chat completion is coherent (my 32-token cap ended it inside the answer, "Helsinki").
  • Linux zig build test: 49/49 steps, 484/486 tests (2 skipped).
  • The same run at 7c3f1a2 earlier today gave the same counts and speeds within 1 tok/s (prefill 297 / 284).
  • Decode is in line with HIP: native Zig engine for Qwen3.5 MLX affine on RDNA2 / RDNA3 #490 on this box: HIP: native Zig engine for Qwen3.5 MLX affine on RDNA2 / RDNA3 #490's native-hip gave 12.7 to 13.0 tok/s on a Qwen3.8-27B MLX 4-bit checkpoint on 10 Oct, through a different harness (256-token greedy chat over HTTP).
  • Not run: drafted == serial on RDNA3.5 (needs a checkpoint with MTP weights; I can run the 35B-A3B or 9B MTP checkpoints if you name the ones you used), tp 2 (one GPU here).

…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.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

@ThinkOffApp thanks. Three public checkpoints, byte-identical to the ones I ran at baa1a981:

…, 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]>
@ashhart ashhart mentioned this pull request Oct 14, 2026
…refill kernel goes

gatedDelta sent 64 rows or any prefill to gdn_prefill.hip (fp16 products, __expf), so a prompt cut on either side
of 64 rows was a different sum. Every length now runs the fp32 recurrence. The new test cuts a 200-row prompt at
1, 63, 64, 65 and 136 rows and checks the rows and state equal one call's bits; it fails with the chunked kernel.
@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @BlivionIaG and @ThinkOffApp,

Thank you for the one-rank HIP engine, and for the gfx1151 drafted-equals-serial runs on the three public checkpoints.

We have no AMD card. This lands on your receipts plus our host checks. #617 lands first. This head already contains that fp32 recurrence, and Policy.gdn is gone with the chunked kernel. Those gfx1151 runs are on the previous head. This head still needs tf-qwen35-test check on gfx1100 and gfx1030. launches.zig still re-exports gdn_chunk. That line comes out with #617.

Thank you both.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

This head still needs tf-qwen35-test check on gfx1100 and gfx1030.

tf-qwen35-test check at 4aaeac0, one rank:

Checkpoint Radeon PRO W7800 (gfx1100) Radeon PRO V620 (gfx1030)
Qwen3.5-9B-MLX-4bit 42 passed, 0 failed, 5 skipped 42 passed, 0 failed, 5 skipped
Qwen3.6-35B-A3B-MLX-4bit-MTP 46 passed, 0 failed, 1 skipped 46 passed, 0 failed, 1 skipped
Qwen3.8-27B-MLX-4bit 42 passed, 0 failed, 5 skipped 42 passed, 0 failed, 5 skipped

@ashhart
ashhart merged commit 8b30db7 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's commit landed above with the same code (its policy commit is #631's change, already in); this keeps the PR's head in the history with no change to the tree.
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's three new commits landed above with the same lines; the others are #631's changes under other hashes, already in. This keeps the PR's head in the history with no change to the tree.
ashhart added a commit that referenced this pull request Oct 16, 2026
#626's three loader commits are in both histories as the same patches. The tree keeps the HIP series' qwen3_5/weights files and zig/build/hip.zig (one coreModule), drops qwen3_5/weights/experts.zig (core/quant stacks the experts now), and puts #626's CHANGELOG line before #631's.
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 the one-rank HIP engine and the rewind gate, and @ThinkOffApp for the gfx1151 drafted-equals-serial runs on three public checkpoints.

It ships in TensorFold 1.0.12 under your name, its seventeen commits from e307b0849 to bb44f8975, after #617, #621 and #626, all applied unchanged. Your head is merged after them with no change to the tree (8b30db731), and #626's head comes in with it, so both pull requests show as merged.

We have no AMD card, so this lands on your receipts plus our host checks: zig build test builds tf-qwen35-test and the HIP server against stub kernels and runs the engine's host tests on macOS and Linux, test-qwen35 passes, and the copy scan finds no shared window. The CUDA and Metal servers built with the series are byte for byte the ones built without it.

Your model checks at 4aaeac091, the head that landed, are in the CHANGELOG: 42, 46 and 42 passed with none failed on the W7800 and the V620, for the 9B, the 35B-A3B with its MTP head and the 27B. Still open: this head on gfx1151 and gfx1201.

Posted by Ash's AI Assistant Synthena

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
The contributor's commits landed above with the same code, after ashhart#626's three loader commits; this keeps the PR's head, ashhart#626's head with it, in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's commit landed above with the same code (its policy commit is ashhart#631's change, already in); this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's three new commits landed above with the same lines; the others are ashhart#631's changes under other hashes, already in. This keeps the PR's head in the history with no change to the tree.
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
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
 with the HIP series

ashhart#626's three loader commits are in both histories as the same patches. The tree keeps the HIP series' qwen3_5/weights files and zig/build/hip.zig (one coreModule), drops qwen3_5/weights/experts.zig (core/quant stacks the experts now), and puts ashhart#626's CHANGELOG line before ashhart#631's.
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.
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