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.
…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.
This was referenced Oct 4, 2026
8 tasks done
Closed
8 tasks done
Owner
|
Thank you, @gilby. Putting both ranks' staging and flags in one page-locked shared-memory buffer that each GPU maps lets cards without peer access sum without NCCL, with the same bits. That's a practical fallback for PCIe cards in VMs. The Python engine is frozen (#286), so this won't merge. Zig CUDA runs one GPU so far, and the Zig engine's Mac cluster sums ranks exactly over its own exchange. When Zig CUDA gets two ranks, this host-memory sum comes across as the transport after #356's peer mapping, with 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 #356: the earlier commits here are that stack's (including its same-patch copy of #355's commit, d233196 = 3c3d9bb); this pull request is the last commit. GPUs in one machine without a peer mapping (PCIe cards in a VM, where
cudaIpcOpenMemHandlefailswith
cudaErrorPeerAccessUnsupported) never installed #356's P2P sum, so every row-parallel sum went through NCCL.HostSumputs both ranks' staging and flags in one/dev/shmbuffer, page-locked and mapped by each GPU(
cudaHostRegister+cudaHostGetDevicePointer); the same sum kernel writes and reads the partials over PCIe, rank 0__nanosleep(TF_TP_HOST_SPIN_NS).install()picks P2P, else host memory when both ranks run on one machine(hostname and boot id match), else NCCL;
TF_TP_HOST_SUM=0keeps NCCL. Startup names the transport. Like perf(cuda): two-rank NVFP4 layers shard as they load; row-parallel sums over a peer mapping #356's sum it sits in the 27B engine'storch.distributedpath, beside 0.6.4'stensorfold.cuda.comm; it maps onto acommtransport the same way.Receipt
change on 0.6.4 (before its rebase onto v0.6.5, on perf(cuda): two-rank NVFP4 layers shard as they load; row-parallel sums over a peer mapping #356). 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: same bits as NCCLby construction; the two-process test that checks it skips on one GPU. 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 Tesla V100-PCIE-32GB in a VM, no P2P, owntiming): an NCCL sum cost about 95 µs of host time, 128 a forward; the host-memory sum about 13 µs a launch. 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,595 / 2,848 / 2,738 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, 83 skipped.test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, fails on 0.6.4 too). On the DGX Spark, the same selection as perf(cuda): two-rank NVFP4 layers shard as they load; row-parallel sums over a peer mapping #356:472 passed, 0 failed, 13 skipped (the new two-process host-sum test skips).
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,596 → 2,589 / 2,845 → 2,819 / 2,736 → 2,701. (two pairs of runs disagree: −0.5 / −0.9% and −1.4 / −1.6% at 8k / 16k). 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;tools/bench_openai.pyfibonacci-raw / gpu-chat 71.5 / 31.8 tok/s (T=1), 57.8 / 35.1 (T=0). These A40s map each other, so they take perf(cuda): two-rank NVFP4 layers shard as they load; row-parallel sums over a peer mapping #356's P2P sum, and the new host-sum test skips there. The host-memory sum itself: on two Tesla V100s (no P2P) on feat(volta): Qwen3.8-27B NVFP4 checkpoints on two ranks (--tp 2) on sm_70 #376's tree, the test passes (9 passed, 2 skipped), and the--tp 2serve there is exact (see feat(volta): Qwen3.8-27B NVFP4 checkpoints on two ranks (--tp 2) on sm_70 #376).two V100s serve it only from feat(volta): Qwen3.8-27B NVFP4 checkpoints on two ranks (--tp 2) on sm_70 #376's tree on (the v0.6.5 check).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.(On two NVLinked A40s this branch served exactly, but there the GPUs map each other, so the sums went over P2P,
not this change's host-memory path. The host-memory sum was served exactly only on two Tesla V100s, as part of feat(volta): Qwen3.8-27B NVFP4 checkpoints on two ranks (--tp 2) on sm_70 #376.)