Skip to content

feat(qwen3_5): the GPU backends' checkpoint loader, on the host (slice 11) - #626

Merged
ashhart merged 19 commits into
ashhart:mainfrom
BlivionIaG:qwen35-family
Oct 16, 2026
Merged

ashhart merged 19 commits into
ashhart:mainfrom
BlivionIaG:qwen35-family

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Slice 11 of #491: the HIP engine's checkpoint loader. Its config reader now applies qwen27/config.zig's checks and adds the fields qwen27 refuses (MoE, tied heads, MTP layers). The proposal on #491 to share one reader across the family stays open.

Stacks on #621 (with main merged in, since #612, #613, #623, #624 and #625 have landed); review the last three commits (the loader, the MTP head's zero-centered norms, and the config checks).

What this changes

The Qwen3.5 / Qwen3.6 checkpoint loader the HIP engine reads, host side only (zig/src/families/qwen3_5/weights/, loader.zig):

  • the geometry from config.json: dense and MoE, MTP layer count, rotary, layer types (config.zig's Spec, beside the Metal 2B admission, which is unchanged);
  • the MLX affine quantization table per module, 2- to 8-bit;
  • one tensor index over the safetensors shards, the projections, and the routed experts stacked;
  • the tensor-parallel cuts on core/quant (feat(core): weight formats behind one interface, MLX affine 2- to 8-bit and dense, with tensor-parallel cuts #612);
  • the config checks qwen27 makes, in config_checks.zig (ashhart's rules, credited in the commit): the activation (silu), the attention gate (swish, no bias), the recurrent state type (fp32, under mamba_ssm_dtype or linear_attn_state_dtype), each layer's kind from layer_types in any order, the mrope sections (three, filling half the rotary width), max_position_embeddings, sizes that fit the kernels' 32-bit counts, and the end ids of config.json and generation_config.json (the 27B names <|im_end|> only in the latter);
  • an MTP head shipped zero-centered gets its 1 + w back. mlx-serve's Qwen3.8-27B conversions bake the +1 into the trunk's norms but not the head's, so the head drafted nothing (0 accepted). A head whose norms average under 0.5 is un-centered; the baked heads (9B, 35B, 27B-3bit-mtp) average 1.2 and above and are kept.

zig build test runs its tests. TF_QWEN_DIR indexes a real checkpoint (zig build test-qwen35).

Receipt

  • Environment: head 4c231bf, on main e7c523e. Zig 0.17.0, on macOS (Apple silicon) and Linux 7.1.7.
  • Exactness:
    • On 20 MLX affine checkpoints, every tensor resolves with consistent shapes: Qwen3.5 0.8B/4B/9B, Qwen3.6-35B-A3B (2-bit, and 4-bit with MTP), and Qwen3.8-27B at 2-, 3-, 4-, 6- and 8-bit, with and without MTP heads.
    • Refused as designed: the exl3, GPTQ and AutoRound exports, a qwen3_5_mtp export, and one raw 0.8B 2-bit export with an unexpected tensor (its requantized copy loads).
    • The cut functions compile in the tests (refAllDecls): with a shape of the old rank 4, the test build fails.
    • With the tied-head default flipped, "a top-level config, the partial rotary default and the MoE fields" fails.
    • Each config check has a test that fails with the check taken out (activation, sizes, layer kinds, mrope sections, max_position_embeddings, generation_config.json's end ids). The same 20 MLX checkpoints load, and the same six exports are refused.
    • feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's logits at this loader are byte-identical to before on the 9B, the 35B-A3B and the 27B, on both GPUs.
    • The MTP fix: Qwen3.8-27B-MLX-Serve-4bit goes from 0 to 82 of 128 drafts accepted on a V620 (21 to 42 tok/s at one stream), and drafted == serial holds on both GPUs at tp 1 and 2. Its test fails with the un-centering switched off.
  • Decode and prompt speed: not applicable (host loader only).
  • Tests run:
    • macOS zig build test test-golden -Dcpu=apple_m1: 146/146 steps, 529/530 tests (1 skipped); golden 0 unexpected.
    • Linux zig build test: 42/42 steps, 483/484 tests (1 skipped).
    • zig fmt --check is clean.
    • lean_check.py: 534 problems, the same as main.
  • Not run, and why: device runs (nothing here touches the GPU).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No engine path touched.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (No engine path touched.)
  • No precision traded for speed.
  • Prompt processing is no slower than the last release. (No prompt path touched.)
  • 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.
…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]>
@BlivionIaG BlivionIaG changed the title feat(qwen3_5): the GPU backends' checkpoint loader, on the host (draft, slice 11) feat(qwen3_5): the GPU backends' checkpoint loader, on the host (slice 11) Oct 12, 2026
@grantoverton grantoverton mentioned this pull request Oct 13, 2026
8 tasks done
…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 merged commit 205b800 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's commits landed above with the same code, after #626's three loader commits; this keeps the PR's head, #626's head with it, 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. The loader reads cleanly, and the config checks are the refusals the HIP kernels need.

Your three commits ship in TensorFold 1.0.12 under your name: 17df3ef25 (the loader), e33b2646d (the MTP head's zero-centered norms) and 62505e4ab (the config checks). Our da2f1f35d adds the coreModule helper the loader's test step calls, your five lines unchanged with you as co-author, and ec2c2077b refuses KV heads that do not split into whole heads a rank, so six KV heads on four ranks stop at load with error.KvHeads. Your head is merged with #631's, so this pull request shows as merged.

zig build test-qwen35 passes on macOS and Linux, and with TF_QWEN_DIR it read five MLX 4-bit checkpoints on a GB10 (Qwen3.5 0.8B, 2B, 4B and 9B, and Qwen3.6-35B-A3B) with every tensor resolved.

Posted by Ash's AI Assistant Synthena

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
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.

2 participants