Skip to content

feat(hip): tensor parallelism over RCCL, behind hip/collective.zig (slice 13) - #655

Merged
ashhart merged 42 commits into
ashhart:mainfrom
BlivionIaG:qwen35-rccl
Oct 16, 2026
Merged

ashhart merged 42 commits into
ashhart:mainfrom
BlivionIaG:qwen35-rccl

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Slice 13 of #491: tensor parallelism over RCCL, behind the hip/collective.zig interface #631 introduced. Stacks on #631 and #696 (the server's std options); review three commits: feat(hip): tensor parallelism over RCCL, graphs at any world size, and the window fix. The graph and loader commits before them are #631's.

What this changes

  • 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: the ranks' TCP link. Rank 0 listens and sends the communicator's id and its policy, and a rank whose GPU differs from rank 0's is refused. The link then carries rank 0's steps.
  • comm/group.zig: joins the two into a collective.Group, and hip.joinGroup becomes its join (feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's was noGroup). The server and tf-qwen35-test go through it.
  • Serving: the server lists --tp again (1, 2, 4 or 8 ranks, --rank, --master, --master-port). A rank above 0 serves no HTTP and runs rank 0's steps.
  • Graphs at any world size (feat(qwen3_5): HIP rounds replay split graphs at any world size, RCCL outside them): a round under tensor parallelism replays the graphs feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631 cuts at each collective, the collectives issued between them. Rounds no longer run eager under tp unless graphs=on; graphs=off still turns them off.
  • One window for every rank (fix(qwen3_5): every rank sizes its streams for rank 0's window): a follower started without --context sized its streams for the 32,768-token default while rank 0 served a longer window, and the first prompt past it stopped rank 1 (Invalid, a page table larger than its own). Engine.first gives every rank rank 0's values over the same all-gather as least.
  • No signal stack: RCCL's and HIP's threads fail pthread_create under Zig's per-thread alternate signal stack, so the HIP build's native module declares std_options without it. The server takes it through feat(server): a backend's std options reach the server binary #696, split out because it touches the shared server.

Receipt

  • Environment: head d47b0f8, on feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631 at 73e4989 and feat(server): a backend's std options reach the server binary #696, main 0efbd44 (1.0.8). Zig 0.17.0, HIP 7.14, RCCL from the same ROCm, Fedora Linux, on Radeon PRO W7800 (gfx1100) and Radeon PRO V620 (gfx1030).

  • Model checks on Qwen3.6-35B-A3B MLX 4-bit with its MTP head, at 66d8a19:

    GPUs tp result
    2 × W7800 2 19 passed, 0 failed
    2 × V620 2 19 passed, 0 failed
    4 × V620 4 19 passed, 0 failed

    The rounds under tensor parallelism are compared to one rank: drafted == serial, solo == together, resumed == fresh, and graph == eager (split graphs; 19 checks pass where 14 did before).

  • Graphs at any world size: decode logits byte-identical graphs on and off; served serve_check 15/15 (drafted == serial, solo == together) and the rewind gate 16/16 at tp 2 and tp 4.
    Decode tok/s, before (eager under tp) and after (split graphs), serve_bench.py:

    GPUs Model 1 stream 1 stream, drafts 4 streams 4 streams, drafts
    4 × V620, tp 4 Qwen3.5-9B 94.5 → 97.6 300.1 → 306.9
    4 × V620, tp 4 Qwen3.6-35B-A3B 75.6 → 79.4 108.1 → 113.1 221.3 → 228.0 272.9 → 278.5
    4 × V620, tp 4 Qwen3.8-27B 38.3 → 40.3 121.1 → 123.6
    2 × W7800, tp 2 Qwen3.5-9B 108.8 → 102.8 338.1 → 311.4
    2 × W7800, tp 2 Qwen3.6-35B-A3B 97.4 → 101.1 136.9 → 139.7 254.9 → 259.2
    2 × W7800, tp 2 Qwen3.8-27B 38.9 → 39.0 112.1 → 112.1

    One loss: Qwen3.5-9B at tp 2 on the W7800s (-5.5% at one stream, -8% at four). At tp 1 graphs are unchanged.

  • The window fix, failing before: at 10926cf, a tp 2 server whose rank 1 had no --context stopped rank 1 on the first 65,536-token prompt, on the W7800s and on the V620s, every time; at 66d8a19 the same run serves 65,536 and 131,072 cold (27.2 s and 79.1 s on the W7800s).

  • Loading with feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's page release, at tp 2 and tp 4: see feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's receipt (2 × W7800 28 s and 4.5 GiB peak PSS, 4 × V620 25 s and 6.5 GiB, against 34 s / 20.5 GiB and 27 s / 21 GiB before); model checks at d47b0f8 pass 19/0 at tp 2 and tp 4.

  • 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; raw JSON, the exact token arrays, request settings and scripts: receipts-qwen35-hip/receipts/qwen35-hip. One GPU is feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's head (10926cf build).

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

    Prompt tokens W7800 tp 1 2 × W7800 tp 2 V620 tp 1 2 × V620 tp 2 4 × V620 tp 4
    2,048 0.64 s 0.44 s 0.91 s 0.58 s 0.50 s
    8,192 2.81 s 1.88 s 3.92 s 2.46 s 2.08 s
    32,768 16.07 s 10.09 s 20.98 s 12.50 s 9.60 s
    65,536 45.04 s 26.85 s 56.03 s 32.14 s 22.67 s
    131,072 141.86 s 79.73 s 166.89 s 91.79 s 59.04 s
    261,888 (native window) 489.29 s 266.79 s 551.12 s 292.93 s 172.75 s

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

    W7800 tp 1 2 × W7800 tp 2 V620 tp 1 2 × V620 tp 2 4 × V620 tp 4
    decode, code / chat 176.5 / 140.8 181.8 / 143.6 157.3 / 127.9 149.1 / 127.0 153.8 / 129.5
    4 streams total, code / chat 283.7 / 252.0 372.6 / 310.5 257.1 / 239.9 341.3 / 285.3 406.8 / 333.4

    Every reply equals its solo run and its "draft": false run in every column (30/30 and 4/4).

    Memory of the server processes only (all ranks): device peak 26.2 / 27.9 / 26.1 / 27.7 / 35.6 GiB at the native window with one stream; host RSS while serving 0.5 GiB at tp 1 and about 1 GiB a rank under tp. During the load the RSS high-water mark is about 19.5 GiB a rank: each rank maps the whole checkpoint, and the mappings share one page cache.

  • One rank: the tp 1 columns are feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631's head; the window fix only runs when there is more than one rank.

  • 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, 693/700 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 groups (no such cards here), and a standard-server comparison (vLLM on these GPUs).

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 under tp 2 and 4)
  • No precision traded for speed.
  • Prompt processing is no slower than the last release. (one rank unchanged)
  • 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]>
…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.
…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,

Thank you for the tensor-parallel HIP engine, and for the tp 4 table on four V620s (gfx1030).

We have no AMD card. This lands on your receipts plus our host checks, after #617 and after #631. It meets #631 in zig/src/hip/root.zig. This head contains the fp32 recurrence, so that V620 table does not cover it. The receipt still needed is tp 2 on gfx1100 and gfx1030, and tp 4 on gfx1030, for the 35B-A3B, on this head.

Thank you.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

The receipt still needed is tp 2 on gfx1100 and gfx1030, and tp 4 on gfx1030, for the 35B-A3B, on this head.

tf-qwen35-test check on Qwen3.6-35B-A3B-MLX-4bit-MTP at 1bdd859:

Ranks Result
tp 2, 2 × Radeon PRO W7800 (gfx1100) 19 passed, 0 failed, 4 skipped
tp 2, 2 × Radeon PRO V620 (gfx1030) 19 passed, 0 failed, 4 skipped
tp 4, 4 × Radeon PRO V620 (gfx1030) 19 passed, 0 failed, 4 skipped

@ashhart
ashhart merged commit afb2740 into ashhart:main Oct 16, 2026
4 checks passed
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 added a commit that referenced this pull request Oct 16, 2026
ashhart added a commit that referenced this pull request Oct 16, 2026
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG, for tensor parallelism on HIP, and for the tp 4 comparison with vLLM on the V620s.

Your commits ship in TensorFold 1.0.12 under your name: 9457d35e3, ea3032bcf and 7da06d1cb, after #631 and #697. Five of the pull request's commits are #631's under other hashes, and 1bdd859a7 is #631's policy change, so those were in already. Your head is merged, so this pull request shows as merged.

Our ec2c2077b follows. With at least as many KV heads as ranks, kvSpan split the rows evenly when the heads do not divide: six KV heads on four ranks gave each rank a head and a half while localSpec counted one. That split is now refused with KvHeads, as the fewer-heads case already was, and a test checks both. Every model in your receipts divides, so nothing you ran changes.

We have no AMD card, so this lands on your receipts plus our host checks: the policy, link, rccl and slicing tests pass on macOS and Linux. Your runs at the landed head, 19 passed on two W7800s, two V620s and four V620s, are in the CHANGELOG. Still open: tp 8, RDNA3.5 and RDNA4.

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 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 added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG added 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
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
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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