Skip to content

feat(volta): Qwen3.8-27B NVFP4 checkpoints on two ranks (--tp 2) on sm_70 - #376

Closed
gilby wants to merge 9 commits into
ashhart:mainfrom
gilby:volta-tp2
Closed

gilby wants to merge 9 commits into
ashhart:mainfrom
gilby:volta-tp2

Conversation

@gilby

@gilby gilby commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Part of #313. Stacked on #264 and #374, with #354, #355, #356, #357 (--device, NVFP4 at
--tp 2, shard-as-load, host-memory rank sums). The earlier commits on this branch are #264's three commits replayed onto v0.6.5 (see our note on #264), #374's commit, and copies of #354's, #355's, #356's and #357's commits. The copies are the same patches except #356's (80ccd20), which adds and not volta() to its startup_copies= line. This pull request is the last commit. VoltaLinear now shards like the sm_80+ linears, every stored word
kept, so an NVFP4 27B runs on two V100s:

  • outputs(rows): any output columns (a rank's GDN gate rows too), re-tiled from only the 32-output tiles they
    touch, a chunk at a time; equal to the projection built from the checkpoint's rows.
  • inputs(rank): whole 64-input groups, an NVFP4 group's block scales with it; 16-bit rows keep their powers of
    two.
  • partial(x): the fp32 product, unrounded and row-count invariant, for the rank-ordered sum.
  • copy(): the two-rank DFlash2 drafter owns its head rows instead of views of the unsplit head.
  • The rank-sum extension builds on sm_70, so V100s without P2P sum through shared page-locked host memory (perf(cuda): two-rank sums through shared page-locked host memory where the GPUs cannot map each other #357).

Bits: each rank's partial is the same fp16-activation, fp32-sum arithmetic as one GPU's sm_70 kernel on its half of
K, and the rank sum adds them in rank order; so two-rank replies equal two-rank serial decoding, and may differ from
one GPU's (as on sm_80+).

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: two Tesla
    V100-PCIE-32GB (sm_70, no P2P) in a VM; local branch on 0.6.2 + Qwen3.8-27B on Tesla V100 (sm_70): Volta kernels #264's commits + the equivalent of this stack;
    PyTorch 2.10.0+cu128. RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead with z-lab/Qwen3.8-27B-DFlash2.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: ours (own A/B
    script) not recorded for this change at the server level; the two-rank tests below check windows == serial steps
    on the real layouts. Not yet run with upstream's tool (no --tp 2 serve).
  • Decode speed before and after, from tools/bench_openai.py: before is a refusal (NVFP4 at --tp 2 refused on
    sm_70). Not yet run with upstream's tool (no --tp 2 serve); the one-V100 reference is feat(volta): Qwen3.8-27B NVFP4 checkpoints on sm_70 (W4A16 / W8A16, fp16 activations) #374's receipt.
  • Prompt speed before and after, from tools/prefill_cold.py: not run on sm_70; GB10 in the v0.6.5 check.
  • On v0.6.5 (this branch as 51e2351, on Qwen3.8-27B on Tesla V100 (sm_70): Volta kernels #264 replayed onto v0.6.5): Mac host suite (M5 Ultra): 5003 passed, 1 failed, 596 skipped. Tesla V100s: 416 passed, 50 skipped, plus Qwen3.8-27B on Tesla V100 (sm_70): Volta kernels #264's 61 failures on v0.6.5 (see feat(volta): Qwen3.8-27B NVFP4 checkpoints on sm_70 (W4A16 / W8A16, fp16 activations) #374); the two-rank NCCL and host-memory-sum process tests ran (the four-rank ones come with feat(qwen3.8 cuda): --tp 4 for Qwen3.8-27B; rank sums of two to eight ranks #377); the P2P test skipped (no peer mapping on these cards). Port: 0.6.5 removed dflash2.py's early return in the NVFP4 head branch, so VoltaLinear.copy() stays without it; test_qwen27_nvfp4_tp.py (sm_80) skips on sm_70, which runs test_qwen27_nvfp4_tp_volta. No --tp 2 serve receipt.
  • Tests run, with pass, fail and skip counts: Mac host suite on the earlier 0.6.3 version of this branch (M5 Ultra, tests minus tests/cuda and tests/control): 4461 passed, 1 failed, 566 skipped (on v0.6.5: see the line above); the failure is test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, which fails on the release too. New
    tests/cuda/test_qwen27_nvfp4_tp_volta.py (shards == sliced checkpoint, synthetic and real with
    TENSORFOLD_QWEN27_NVFP4=<dir>; partials; the two-rank forward in two threads on one GPU: windows == serial
    steps, runs repeat, prompts ignore chunking); module-level skip off sm_70. Not yet run with upstream's tool.
  • Checked on v0.6.5 (2026-10-04): two Tesla V100s (no P2P), --tp 2 --parallel 4 --context 54065 (startup 27.29 GiB of 27.29), rank sums through shared page-locked host memory: fresh == resumed (2,296 of 2,301 tokens from the prompt cache) == "draft": false, token_sha db7ba9d1c2bf; 19 × 23 drafted == "draft": false 7773d573571d; tools/bench_concurrent.py --levels 2,4 --alone --serial: 0 failed, 0 unequal in all 8 cells; tools/bench_openai.py fibonacci-raw / gpu-chat 105.8 / 51.7 tok/s (T=1), 81.1 / 53.0 (T=0). New tests on Tesla V100s, this branch's test files copied into the parent's tree, then here: tests/cuda/test_qwen27_nvfp4.py, test_qwen27_nvfp4_tp.py and test_qwen27_nvfp4_tp_volta.py: 28 failed, 4 errors; here 39 passed, 8 skipped. Prompt speed on a checkpoint v0.6.5 serves, RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead + z-lab/Qwen3.8-27B-DFlash2 on one DGX Spark (GB10), tools/prefill_cold.py (2k / 8k / 16k, 3 reps, median tok/s; runs v0.6.5, this, this, v0.6.5, each side the mean of its two), v0.6.5 → the top of this stack (feat(volta): Qwen3.8-Flash-Next NVFP4 checkpoints on sm_70, one GPU or four ranks #380's tree): 2,591 → 2,606 / 2,840 → 2,855 / 2,731 → 2,751 (the sm_70 code is gated on build.volta(), so GB10 does not run it).
  • Not run, and why: tools/prefill_cold.py at --tp 2 on V100s; GB10 / A40 paths unchanged except the shared
    split_output / admission lines (to show with pytest tests/cuda -k "qwen27 or nvfp4 or distributed" on GB10).

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. (Two V100s with upstream's tools: see the v0.6.5 check.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. (No before on sm_70: v0.6.5 refuses NVFP4 there. On a checkpoint v0.6.5 serves, RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead on one DGX Spark (GB10), the top of this stack is within noise of v0.6.5 (+0.5 to +0.7%); see the v0.6.5 check.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (On V100s: 28 failed and 4 errors on the parent's tree, 39 passed and 8 skipped here; test_qwen27_nvfp4_tp_volta.py skips off sm_70 at module level.)
  • 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.

The three #264 commits carried here are RoscoeTT's as replayed onto v0.6.5; their Co-Authored-By trailers are his.

RoscoeTT and others added 9 commits October 4, 2026 09:23
Triton's tl.dot has no tensor-core path on Volta (0.2 TFLOPS) and the shared FP8 and bf16 extensions need sm_80, so the
Qwen3.8-27B MLX 4-bit weights get their own kernels, with the row-invariance contract kept:

- Decode: mma.m8n8k4 from registers, one weight column a thread, weights repacked once at load (Tiled), rows scaled by
  a power of two so every bf16 value is an exact fp16, fp32 sums; the K split is a function of the weight's shape and
  its slices add in order, so a row never depends on the row count. Rows reach the kernel in its fragment order.
- Prompts: a dense fp16 copy of each weight and one cuBLASLt algorithm pinned per weight shape (split-K off), so a row's
  chain over K is the same at every row count and any chunking.
- Extensions declare Volta with need=VOLTA; the FP8 and sm_80 builds keep their clear refusal.
- The Volta-only tests skip elsewhere; sm_80-only modules skip on Volta with their reasons.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- Tree attention (attention_volta.cu): attention.py's chunk partials on mma.m8n8k4, one per-warp routine under two
  kernels (chunks wholly below the committed keys with every window row in one block; the rest per row with its path
  keys). A row's partial never depends on its warp mates and a key on a path gives the same bits as the same key
  committed, so drafted rows equal serial ones.
- Prompt attention: PyTorch's memory-efficient (CUTLASS) attention in fp16, one key head at a time with its query heads
  on the batch axis and its keys and values broadcast without a copy; query rows pad back to a 128-aligned position so
  a row's tile never moves with chunking.
- DFlash2's block attention (draft_attention_volta.cu), with its shape and shared-memory limits checked.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The Qwen3.8 engine states its own capability floor at admission (the MLX checkpoint runs on sm_70; EXL3 and NVFP4
packs are refused by name there), and both planners count the fp16 key and value staging of the prompt attention.
README, the recipe's V100 section with measurements, the family's kernel map and a changelog entry.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…p16 activations)

An NVFP4 checkpoint's three kinds of projection (NVFP4, FP8, bf16) get an sm_70 linear, VoltaLinear, on the
mma.m8n8k4 skeleton of the 4-bit Volta decode kernel. Weights expand in registers to exact fp16 values (e2m1 code
times e4m3 block scale, e4m3, or bf16 scaled by a power of two a column) and one fp32 factor a column is applied
last; rows are prep884's power-of-two-scaled fp16 rows. One kernel and one K split, chosen from the weight's shape,
serve every row count, and the last K slice adds the slices in slice order, so a row never depends on how many rows
share the launch. Prompt rows take a dense fp16 copy of the same values through the pinned cuBLASLt GEMM (chunk
invariant); the bf16 head prompts on the decode kernel.

The bf16 embedding stays in page-locked host memory and the GPU gathers its rows through the mapped address
(HostRows), so admission counts it as no device bytes. nvfp4_load builds these linears on sm_70; the engine admits
NVFP4 there (EXL3 is still refused) with two staging copies instead of three. test_qwen27_nvfp4's synthetic model runs
on sm_70 with the new linears; tests/cuda/test_qmmf_volta.py checks row-count invariance, the stored values and chunk
invariance.
--device N (TF_CUDA_DEVICE) makes device N the current CUDA device before an engine loads, in every CUDA engine,
and the unified-memory check reads the current device. Two ranks on one machine can then both see both GPUs and
each run on its own, so their transfers can map the peer GPU. Without the flag nothing changes: device 0.
An NVFP4 checkpoint (NVFP4 MLP, FP8 attention and DeltaNet, bf16 gates and head) now shards as the MLX checkpoint
does, every stored byte unchanged. Fp4Linear and Fp8Linear gain outputs() (whole 64-output tiles of the loaded
tiling, a zero tile padding an odd count) and inputs() (whole 64-input groups, four e4m3-scaled 16-input blocks
each, the per-tensor scale kept), and partial(), the lane matmul with an unrounded fp32 epilogue for the
rank-ordered sum. Plain and Plain8 split their rows or columns as stored. split_weights keeps the checkpoint's
precision settings, and the two-rank DFlash2 drafter takes its half of the draft vocabulary from the bf16 head.
The engine no longer refuses --tp 2 for NVFP4; EXL3 packs and checkpoint math still run on one GPU.
…ms over a peer mapping

load_nvfp4 takes a per-layer hook, and two ranks split each layer to their shard as it loads, so a rank holds one
full layer at most; admission counts layer tensors halved and no startup copy, where before a rank needed twice
the full checkpoint at startup.

tensorfold.cuda.p2p: when both ranks' GPUs can map each other, a row-parallel sum is one kernel. Each rank stages
its fp32 partial in a cudaIpc buffer the peer has mapped, blocks meet their peer blocks on flags that only grow,
and both ranks add rank 0 + rank 1 in fp32 and round once to bf16: the bits of the gathered rank-ordered sum.
Sums larger than the staging buffer (prompt chunks) keep NCCL; TF_TP_P2P=0 turns the kernel off. Two ranks on
one machine reach it with --device 0 and --device 1.
…e the GPUs cannot map each other

GPUs without a peer mapping (PCIe cards in a VM, where cudaIpcOpenMemHandle fails with
cudaErrorPeerAccessUnsupported) never installed the P2P sum, so every row-parallel sum went through NCCL.
HostSum puts both ranks' staging and flags in one /dev/shm buffer, page-locked and mapped by each GPU
(cudaHostRegister + cudaHostGetDevicePointer); the same kernel writes and reads the partials over PCIe, rank 0 +
rank 1 in fp32, rounded once, so the bits equal the NCCL gather. Waiting blocks poll the host flags with a short
__nanosleep (TF_TP_HOST_SPIN_NS).

install() picks P2P, else host memory when both ranks run on one machine (hostname and boot id), else NCCL;
TF_TP_HOST_SUM=0 keeps NCCL. Startup names the transport.
…m_70

VoltaLinear shards like the sm_80+ linears, every stored word kept:
- outputs(rows): any output columns (a rank's GDN gate rows too), re-tiled from only the 32-output tiles they
  touch, a chunk at a time; equal to the projection built from the checkpoint's rows (codes, e4m3 block scales,
  column factors).
- inputs(rank): whole 64-input groups, an NVFP4 group's block scales with it; 16-bit rows keep their powers of two.
- partial(x): the fp32 product, unrounded, row-count invariant (its bf16 output is it rounded once).
- copy(): the two-rank DFlash2 drafter owns its head rows instead of views of the unsplit head.

The rank-sum extension builds on sm_70, so two V100s without P2P sum through shared page-locked host memory.

Tests: tests/cuda/test_qwen27_nvfp4_tp_volta.py (shards equal the sliced checkpoint, synthetic and real; partials;
the two-rank forward in two threads: windows equal serial steps, runs repeat, prompts ignore chunking);
test_qwen27_nvfp4's two-rank start covers sm_70 too.
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. Sharding VoltaLinear on whole 64-input groups and 32-output tiles, so every stored word is kept, and leaving each rank's fp32 partial unrounded for one rank-ordered sum, gives two-rank replies that equal two-rank serial decoding, even on V100s that can't map each other.

The Python engine is frozen (#286), so this won't merge. Zig CUDA runs on one GPU, GB10 only, so two V100 ranks wait for ranks and an sm_70 target there. When they come, VoltaLinear's outputs, inputs and partial are where that work starts, with your credit.

@ashhart ashhart closed this Oct 6, 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.

3 participants