Skip to content

qwen3_5 cuda: a rank's EXL3 cut launches the whole weight's plan, shown against one GPU's bytes (first part of step 2 of #3325) - #3602

Merged
ashhart merged 6 commits into
ashhart:mainfrom
Nipale-ai:qwen35-tp2-cut-plan-3325
Nov 20, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
Nipale-ai:qwen35-tp2-cut-plan-3325

Conversation

@Nipale-ai

@Nipale-ai Nipale-ai commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

First part of step 2 of #3325 (TP=2 serving): the host-sized part of the dense Qwen3.5 TP=2 weights. A rank's cut of an EXL3 weight now starts with the plan of the whole weight, and the plan says which weight is cut how. This moves no token: --tp 1 is unchanged, --tp 2 stays refused by native/cuda_refusal.zig (not touched), and nothing outside tests reads the new code yet. There is no exchange between ranks, no session and no NCCL in this pull request.

The route is the one Flash Next's --tp 2 took in #1784: each rank computes its own output columns over the full K, and the disjoint outputs are copied, not summed. Here every weight is cut only along its output axis n, in 128-tiles, so a rank adds no partial sum of another. The EXL3 kernel's sum order depends on (sk, wk), the K splits and warps, and plan() takes them from the weight's own (k, n); a half planned alone can launch other splits than the whole weight, so the cut has to carry the whole weight's plan.

  • cuda/exl3.zig: Weight.pinnedColumns(from, n) is columns with the parent's (sk, wk) fixed. columns is unchanged, so cuda_draft_frame.zig:171, its one caller before this pull request outside tests, gets the same bits.
  • qwen3_5/cuda_shard.zig: Share.hidden, the rows of o_proj, out_proj and down_proj (hidden over the world, in 128-tiles; a split that leaves the tiles is NotOnTiles, never rounded). o, out and the k part of mlp now say what they are, where a rank's part sits in the gathered input, not cuts of those weights: o_proj, out_proj and down_proj are cut along n here, not along k as those three doc lines described. The declaration test in cuda_shard_decl_test.zig follows.
  • qwen3_5/cuda_shard_plan.zig (new, host only): for the eleven EXL3 weights, which Share span cuts n and which (sk, wk) every launch of the cut keeps, taken from exl3.planOf of the whole weight. Host tests pin both at TP=2 on the 27B's widths, check at TP=1, 2 and 4 that the spans tile each axis in 128s, and show which halves would plan their own (below). In Native CUDA TP=2 support for Qwen3.8-27B EXL3 on heterogeneous consumer GPUs #3325 I asked whether the (sk, wk) each half launches with should be pinned in step 1's host tests or in step 2. These tests pin them here, and the cut keeps the whole weight's plan, as Flash Next TP=2: exact output-column splits, 21% faster plain decode #1784 keeps the whole weight's K slices for Flash Next.
  • tf-cuda-test qwen35-tp-cut PACK [STEP]: on one card, for every EXL3 weight of the 27B's 64 layers and its head (401 weights of a real 27B pack) and both ranks of a world of two, the output of the pinned view equals the same columns of the whole run, byte for byte.
  • qwen3_5/cuda.zig exports shard, shard_plan and exl3_admit for the runner; zig/tests/cuda/main.zig gets the subcommand's two lines and, to stay at 600 lines, imports exl3_tp2_tests and exl3_candidate_tests at their dispatch lines.

What the plan shows on the 27B (whole weight, then the half or quarter planned alone), as exl3.plan gives it. The TP=2 column is also what the device run below reports (for in_proj_qkv the device run prints one span's plan, the other two are the formula's); the host tests pin which weights differ at TP=4, and the TP=4 values are the formula's:

weight whole (sk, wk) half planned alone, TP=2 TP=4
q_proj 1, 8 4, 4 (differs) 8, 4 (differs)
k_proj, v_proj 8, 4 8, 4 8, 4
o_proj, out_proj 8, 4 8, 4 8, 4
in_proj_qkv (3 spans) 1, 8 8, 4 each (differs) 8, 4 each (differs)
in_proj_z 4, 4 8, 4 (differs) 8, 4 (differs)
gate_proj, up_proj 1, 8 1, 8 8, 4 (differs)
down_proj 8, 4 16, 4 (differs) 16, 4 (differs)
lm_head 1, 8 1, 8 1, 8

Checks on this head

  • Head commit: d27a711 on main 077998f.
  • Lean checker, python3 tools/zig/lean_check.py, base and head: 221 on the base, 221 on this head, 0 new (6,575 and 6,577 files; all 221 inherited). python3 tools/pr_check.py --base origin/main --pr 3602: 0 errors, 1 warning ("Zig changed: no Unreleased bullet naming this PR"; this change carries no CHANGELOG line, as qwen3_5 cuda: the dense family has a rank plan, host only; it moves no tokens #3383's did not).
  • Tests run, with the command and pass, fail and skip counts (Linux x86_64, Zig 0.17.0), each tree on its own cache directory:
    • zig build test-cuda-host --summary all: base 410/410 steps, 6,917 of 6,950 tests passed, 33 skipped; head 410/410 steps, 6,922 of 6,956 passed, 34 skipped. That is six more tests (this pull request adds five test blocks; the per-step totals grow by 4, 1 and 1, so one shard test runs in two steps) and one more skip: it is not one of the new tests but is nemotron ring batch in nemotron/cuda_source_ring_test.zig, which skips itself when its first read finishes before the second is asked (it did so in the head run only, which shared the machine with the host run below; no file of this pull request touches it).
    • zig build -Dfixed-cpu test-host --test-timeout 20m --summary all from an empty cache, on this head: 2,108/2,108 steps, 19,968 of 20,099 tests passed, 131 skipped, 0 failed, exit 0.
    • zig fmt --check build.zig zig and git diff --check origin/main: clean.
    • Before the change they fail: this was run on the first head (e591af533 on main 9e00f2c) and not repeated on this one. The four commits are the same patches on the newer main (git range-diff shows all four as =, and their patch ids match). With the new tests copied onto main and no source change, test-cuda-host ended 403/410 steps with 3 failed; the compile errors were no field or member function named 'pinnedColumns' in 'exl3.Weight' and no field named 'hidden' in struct 'cuda_shard.Share' (in exl3_dense_test.zig, cuda_shard.zig, cuda_shard_plan.zig and cuda_shard_decl_test.zig). Each of the four test files was also shown red with a planted wrong value (a 2 for q_proj's split count, 2561 for a hidden span end, a 3 for a pinned plan, a hidden span 128 too wide in the declaration). The planted values ran together in two runs on the first head (the first run held three of them; the declaration's compile error was fixed and its value planted in the second), and each failed the tests that pin it: one test each in exl3_dense_test.zig, cuda_shard.zig and cuda_shard_plan.zig, and both tests of cuda_shard_decl_test.zig that compare the declaration with Share.of.
    • Device, zig build -Dnvcc=<cuda 13.3> -Dsm=120 install, then tf-cuda-test qwen35-tp-cut PACK on one RTX 5090 (sm_120): see Receipt.
  • CI: green on d27a711: fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest, release-paths and both benchmark-clients jobs passed; host-nightly-linux and host-nightly-macos were skipped.
  • Not run, and why: any TP=2 run, NCCL, a session or a served token (this pull request reaches none of them); zig build test test-golden and dev-tools on macOS (no Metal file is touched); the kernel contract (no kernel is new or changed); other SMs than 12.0 and other packs than the 4.00 bpw one below; the pack's eight EXL3 weights of the MTP head (mtp.*), which the runner does not read; HIP and Metal; the red-before runs on this exact head (see above); a separate repeat of the nemotron ring batch skip on this head; the TP=4 plan values on a card (formula only).

Receipt

n/a for inference: nothing outside tests reads cuda_shard_plan.zig or pinnedColumns, Share.of has no caller outside tests, --tp 1 launches what main launches and --tp 2 is refused before any device work as in #3383. The device check below is the evidence this step carries.

  • Main against branch: n/a (reaches no inference).
  • Environment: base 077998f, head d27a711; Zig 0.17.0; nvcc 13.3, kernels built for sm_120; one RTX 5090 32 GB, driver 610.43.02, Linux x86_64; pack: EXL3 4.00 bpw of Qwen3.8-27B (quantization_config.json: exl3 1.4.2, 4-bit tensors, 6-bit head), Hugging Face turboderp/Qwen3.8-27B-exl3, branch 4.00bpw, revision 113cf7ab958054860e43fb7f3063b1af19171095 (from the download metadata, checked against the repository's branch list).
  • Exactness, tf-cuda-test qwen35-tp-cut PACK over all 64 layers (401 weights): PASS, 63,856 byte comparisons of a rank's pinned columns against the whole run's, exit 0. Both ranks of a world of two, 1, 2, 16, 17, 36, 48, 49, 128, 129 and 1,536 rows (the head to 129 rows), bf16 and fp32 outputs, finite rows and rows with NaN, +inf and -inf in the first row, and 1,536 gate+up projection groups. Every comparison was equal; none differed.
  • Kernels the whole run took (bf16, finite rows, launches of 128 rows at most as Dense makes them): 1, 2 and 16 rows the linear (401 of 401); 17, 48, 49 and 128 rows linear_wc (401 of 401); 36 rows linear_wc 177 and the mid-M kernels 224; 129 rows a linear_wc block of 128 and a linear block of one row (401 of each); 1,536 rows twelve linear_wc blocks (4,800 launches: the 400 layer weights, the head is not run that far). A second sweep with linear_wc off ran the mid-M kernels at 17, 36, 48, 49 and 128 rows (401 of 401 each). The pinned views always take the linear (pick does that for a fixed plan). Each was equal to the whole run's bytes.
  • The same columns without the pin (each half planned alone, as columns gives them): equal for k_proj, v_proj, o_proj, out_proj, gate_proj, up_proj and lm_head, whose plans agree; different for q_proj, in_proj_qkv, in_proj_z and down_proj, whose plans differ (4,4 / 8,4 / 8,4 / 16,4 against 1,8 / 1,8 / 4,4 / 8,4). In those four the unpinned bytes differed in most runs (q_proj 1,853 of 1,920, in_proj_qkv 16,352 of 17,280, in_proj_z 5,478 of 5,760, down_proj 7,327 of 7,680 comparisons). The runner fails if a weight whose plan differs never shows other bytes, so the pin is shown to matter.
  • Paths and platforms: one card, sm_120, 4-bit tensors and a 6-bit head only. Not run: other SMs (8.0, 8.6, 8.9, 12.1), other bit widths, HIP, Metal.
  • Decode speed, prompt speed: not measured (nothing is served). The pinned view takes the linear at every row count, where the whole weight takes linear_wc or the mid-M kernels from 17 rows; that matters for speed once a rank runs it, and belongs to the step that serves ranks.
  • Licence of new weights: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (red on the first head, see above; same patches). The new host tests need no dependency; the device runner is a tf-cuda-test subcommand, not a test step: without PACK it prints the usage and fails with MissingArgument, and it needs a card.
  • 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.

Inference block: n/a, this reaches no inference.

@Nipale-ai
Nipale-ai marked this pull request as ready for review November 16, 2026 20:03
ashhart added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 17, 2026
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @Nipale-ai, this is a clean first step for TP=2 on dense Qwen3.5. Each weight is cut only along its outputs (n), so a rank never adds another rank's partial sums. Every cut keeps the whole weight's (sk, wk), so a rank's columns are summed in the same order as the single-GPU run. That is the right way to keep TP=2 exact. The plan test also shows that pinning matters: four of the 27B's weights (q_proj, in_proj_qkv, in_proj_z, down_proj) would pick a different (sk, wk) if each half were planned on its own (cuda_shard_plan.zig, own_at_2). Your device run shows the unpinned bytes differ for exactly those four.

What we checked:

  • It does what the title says. Weight.pinnedColumns (zig/src/cuda/exl3.zig:142-149) is columns with the parent's plan fixed. columns itself is unchanged (exl3.zig:130-140), so its one caller outside tests (qwen3_5/cuda_draft_frame.zig:171) gets the same bits. Neither pinnedColumns, cuda_shard_plan.zig nor Share.hidden has a caller outside tests. That means no output tokens change: --tp 1 launches what main launches, and --tp 2 is still refused.
  • The series applies cleanly on current main. The lean check stays at 221 with no new findings. All touched files are within 600 lines (zig/tests/cuda/main.zig is now exactly 600).
  • We added the missing ## Unreleased line in CHANGELOG.md as a separate commit of ours on top of your branch.
  • No other open PR touches these files, and main has no existing helper that pins a column view's plan.

Optional points for the next step:

  1. pick sends a pinned view to the linear kernel at every row count, while the whole weight takes linear_wc or the mid-M kernels from 17 rows. Your run shows the bytes are equal, so the result is the same. But the step that serves ranks will need decode and prompt numbers comparing the TP=2 rank launches with main's TP=1 launches, so that the slower kernel choice is measured before it becomes a default.
  2. The changes to the doc comments for Share.o, Share.out and Share.mlp (cuda_shard.zig:42-47) change what those spans mean: they are now where a rank's part sits in a gathered input, not a k-cut of the weight. Please check that the exchange in step 2 gathers those inputs, and doesn't sum them, for o_proj, out_proj and down_proj.

Device check, done on our side: tf-cuda-test qwen35-tp-cut at d27a711 on GB10 (CUDA, sm_121), over a Qwen3.8-27B EXL3 4.00 bpw pack, passes. That covers 64 layers, 63,856 byte comparisons (bf16 and fp32 outputs, finite and non-finite rows) and 1,536 projection groups, and each rank's columns at the whole plan equal one run's bytes at 1 to 1,536 rows. With your sm_120 receipt, both SMs are covered at this head.

  • Synthena

@ashhart
ashhart force-pushed the qwen35-tp2-cut-plan-3325 branch from b42acce to 35c545d Compare November 18, 2026 13:08
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @Nipale-ai. The pinned-column plan is unchanged from our review, the GB10 cut test passed on both sides, and the head merges cleanly with current main with green CI. Nothing else is needed from you; it goes into the landing queue.

  • Synthena

@ashhart
ashhart force-pushed the qwen35-tp2-cut-plan-3325 branch from 35c545d to 37f6df3 Compare November 19, 2026 12:29
ashhart added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 19, 2026
Place qwen35-tp-cut's existing command description in main_usage.zig, where main moved the CUDA runner's help. Preserve every main entry and the incoming command description unchanged.
Nipale-ai and others added 6 commits November 20, 2026 12:42
Weight.pinnedColumns is columns with the parent's (sk, wk) fixed, so each
column keeps the bits the whole matrix gives it. columns is unchanged.
Share.hidden is hidden over the world in 128-tiles, refused as NotOnTiles where
it would leave them. o, out and the k part of mlp now say they are where a
rank's part sits in the gathered input, not cuts of those weights.
…n, host only

cuda_shard_plan.zig names, for the 27B's eleven EXL3 weights, which Share span
cuts the output axis and the (sk, wk) every launch of the cut keeps: the whole
weight's. Host tests pin both at worlds 1, 2 and 4 from exl3.planOf, and show
which halves would plan their own.
…s bytes

Every EXL3 weight of a pack, both ranks of a world of two, 1 to 1,536 rows,
bf16 and fp32 outputs, finite and non-finite rows, and projection groups. The
same columns planned on their own are run beside them.
Place qwen35-tp-cut's existing command description in main_usage.zig, where main moved the CUDA runner's help. Preserve every main entry and the incoming command description unchanged.
@ashhart
ashhart force-pushed the qwen35-tp2-cut-plan-3325 branch from 37f6df3 to fb390e5 Compare November 20, 2026 12:43
@ashhart
ashhart merged commit f0a177a into ashhart:main Nov 20, 2026
1 of 10 checks passed
ashhart added a commit that referenced this pull request Nov 20, 2026
Place qwen35-tp-cut's existing command description in main_usage.zig, where main moved the CUDA runner's help. Preserve every main entry and the incoming command description unchanged.
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @Nipale-ai. 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.

ashhart added a commit that referenced this pull request Nov 20, 2026
ashhart added a commit to shantanugoel/TensorFold that referenced this pull request Nov 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