Repository navigation
Conversation
--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.
This was referenced Oct 4, 2026
Owner
|
Thank you, @gilby. Sharding NVFP4 layers as they load, so a rank never holds more than one full layer, and summing row-parallel partials through a peer mapping, rank 0 plus rank 1 in fp32 and rounded once, keeps NCCL's bits at a fraction of the host cost. The Python engine is frozen (#286), so this won't merge. Zig CUDA runs one GPU so far. The Zig engine's Mac cluster already sums ranks exactly the same way, in rank order over one-sided writes and flag words. When Zig CUDA gets two ranks, your peer-mapped sum is the first transport to try, ahead of #357's host-memory sum and NCCL, and it carries your credit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Stacked on #355 and #354: the earlier commits here are #354's commit and a same-patch copy of #355's (d233196, the same patch as 3c3d9bb); this pull request is the last commit. Two things for NVFP4 at
--tp 2:load_nvfp4takes a per-layer hook, and two ranks split each layer to their shard as itloads, so a rank holds one full layer at most. Admission counts layer tensors halved and no startup copy; before, a
rank needed twice the full checkpoint at startup and the 27B was refused on 48 GB cards.
tensorfold.cuda.p2p). When both ranks' GPUs can map each other, arow-parallel sum is one kernel: each rank stages its fp32 partial in a
cudaIpcbuffer the peer has mapped, blocksmeet 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 (two fp32 values add the same in either order). Sums larger than the
staging buffer (prompt chunks) keep NCCL;
TF_TP_P2P=0turns the kernel off. Two ranks on one machine reach it with--device 0and--device 1.On #219's interface: the 27B engine's two ranks still run on a
torch.distributedprocess group, so these sums sitbeside
tensorfold.cuda.commrather than inside it. If you'd like them ascommtransports, the smallest step we seeis an optional
rank_sumonComm(falling back to all_gather + rank-ordered add) and the 27B engine opening itscommunicator with
open_comm; we're happy to restructure this PR that way.Receipt
change on 0.6.4 (before its rebase onto v0.6.5, on feat(cuda): --device picks the GPU a rank runs on #354 and feat(qwen3.8 cuda): NVFP4 checkpoints on two ranks (--tp 2) #355). PyTorch 2.13.0a0 (NGC 26.07 container, CUDA 13.3), Triton 3.7.1; one DGX Spark (GB10, sm_121); real checkpoint
RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead@ 009632f withz-lab/Qwen3.8-27B-DFlash2@ 50307d4.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: the P2P sum givesthe NCCL gather's bits by construction; the two-GPU test that checks it skips on one GPU (below). Resumed == fresh, on v0.6.5 (one DGX Spark): the same 2,682-token prompt three times on one server at temperature 0: fresh, resumed (2,677 tokens from the prompt cache) and resumed with
"draft": false(one rank), alltoken_sha03c531b17784.tools/bench_openai.py: ours (two NVLinked NVIDIA A40s in a VM, 0.6.2 + theparent changes + this,
RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead, own timing): a 27B NVFP4 forward went from 75 to52 ms (NCCL all_gather + add + cast cost about 250 µs of host time each, 128 a forward; the P2P launch about 10 µs);
13.6 GiB resident a GPU at
--tp 2. Not yet measured with upstream's tools.tools/prefill_cold.py: prompt-sized sums keep NCCL. One rank only, measured later on v0.6.5: 2,602 / 2,840 / 2,731 tok/s at 2k / 8k / 16k against v0.6.5's 2,610 / 2,848 / 2,713.--tp 2: not run.test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, fails on v0.6.5 too. CUDA on v0.6.5 (one DGX Spark, GB10):pytest tests/cuda tests/test_cuda_build.py -k "qwen27 or qwen36 or nvfp4 or b16 or qmm or moe or build or distributed or dflash or dspark or exl3 or graph": 692 passed, 0 failed, 82 skipped.test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, fails on 0.6.4 too). On the DGX Spark,pytest tests/cuda tests/test_cuda_build.py -k "qwen27 or nvfp4 or b16 or qmm or build or distributed"plustests/test_cuda_device.py:472 passed, 0 failed, 12 skipped. The new two-process P2P test needs two GPUs in one machine and skips here.
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) onRadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead+z-lab/Qwen3.8-27B-DFlash2at--context 131072 --parallel 1, a checkpoint v0.6.5 serves: v0.6.5 → this 2,604 → 2,595 / 2,852 → 2,846 / 2,738 → 2,733. Two NVLinked NVIDIA A40s, this branch plus feat(cuda): Ampere (sm_80/86) runs the bf16 kernels; FP8 prompts stay at 8.9 and NVFP4 runs W4A16 below it #363's Ampere commit,--tp 2 --parallel 4 --context 65536with--device 0/--device 1, rank sums over P2P: fresh == resumed (2,296 of 2,301 tokens from the prompt cache) =="draft": false,token_shadb7ba9d1c2bf; 19 × 23 drafted =="draft": false7773d573571d;tools/bench_concurrent.py --levels 2,4 --alone --serial: 0 failed, 0 unequal in all 8 cells; code aggregate N=2 / N=4 80.6 / 161.1 tok/s (T=1).tests/cuda/test_qwen27_distributed.pyon the two A40s: copied into the parent's tree 1 failed, 8 passed, 1 skipped; here 9 passed, 1 skipped.two-rank receipt is on two A40s (the v0.6.5 check).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Two ranks on two A40s, with feat(cuda): Ampere (sm_80/86) runs the bf16 kernels; FP8 prompts stay at 8.9 and NVFP4 runs W4A16 below it #363's Ampere commit: see the v0.6.5 check.)tests/cuda/test_qwen27_distributed.pyon two A40s: 1 failed on the parent's tree, 9 passed and 1 skipped here; the two-GPU cases skip on one GPU.)