Repository navigation
Conversation
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.
… ranks
--tp {1,2,4} and --rank 0..3; ranks past 0 follow rank 0. The 27B engine, its shards (distributed.split_layer and
split_weights, every inputs() shard: NVFP4/FP8 lane, bf16 Plain, VoltaLinear, MLX affine), decode_tp (candidates
merged in rank order), the --parallel decoder and admission (layers split by the rank count) take two or four
ranks. The DFlash2 drafter splits over two ranks only; at four, rank 0 drafts alone with the whole drafter.
p2p: PeerSum and HostSum add every rank's partial in rank order (fp32, one rounding), two to eight ranks; each
block keeps its round in device memory, so a captured sum replays with the next round.
Tests: four-process host-memory sum equals the gathered rank-ordered sum; four-rank shards equal checkpoint slices
(synthetic and the real checkpoint); four-rank windows equal serial steps, repeated runs and chunked prompts are
bit-identical; the CLI takes --tp 4 and --rank 0..3.
…tials by copies through shared host memory - p2p: the sums install over torch.distributed's group or an engine's own communicator (all_gather, barrier, world), with a stage size the caller picks; the sum kernel stages into two buffers by round parity and meets its peers once. Partials too large for one launch (prompt chunks) go by DMA copies through the shared page-locked buffer (HostSum.gather) and are added in rank order in fp32, the bits of the NCCL gather and rank-ordered sum. - The 27B engine sizes the stage for a 4,096-row prompt chunk, so prompt sums take the copies instead of NCCL. - comm: the library found in the pip nvidia-nccl wheel torch depends on. Tests: the multi-process host-memory test gathers prompt-sized partials by copies and checks them, and every round's sum, against the NCCL gather plus the rank-ordered add.
…sums over the shared rank-sum transports - weights: heads split by the rank count (refused by name where they do not divide); key/value heads past the rank count are shared, each rank keeping the one its query heads read; expert and shared-expert widths split on whole quantization groups (ranks.share: the lower ranks one block more where they do not divide); the MTP layer's bf16 experts keep each rank's gate rows and its up rows. - engine: --tp 1, 2 or 4; rank 0 posts each request to every following rank, settings are gathered from every rank, and the rank sums install over the engine's communicator. NVFP4 checkpoints still run on one GPU here; --parallel stays on one GPU or two ranks. - forward: row-parallel branches sum through the installed transport (one launch, or copies for prompt-sized partials), NVFP4 bf16 faces return fp32 partials, and prompt partials of an NVFP4 checkpoint are bf16. - gdn / gdn_io: a rank's share of four (4 key and 12 value heads). - geometry: admission counts a rank's expert share, shared key/value heads, and bf16 MTP experts as NVFP4. - n-gram tables are locked only as far as the host's available memory allows on a discrete GPU; read-ahead pins host pages on the caller's device. tests/test_flashnext_ranks_host.py: the shares are whole groups, lower ranks first, and a width that leaves a rank no group is refused.
|
@gilby, a small thing in the MLX loader for |
…read With 2 key/value heads over 4 ranks, the MLX loader's attention sliced kv_heads // world = 0 heads a rank, so every rank's k and v projections were empty. It now takes the same shared head as the NVFP4 loader: one head a rank where the heads do not divide, head rank * kv_heads // world. tests/test_flashnext_ranks_host.py: load() of a one-layer checkpoint as each rank of 2 and of 4 keeps whole k/v rows of the right head.
|
@BHCC2025, thanks, good catch. Fixed in 40a79ab: the MLX loader's |
|
Thank you, @gilby. Splitting Flash Next's heads by the rank count while each rank keeps the key and value heads its queries read, and splitting expert widths on whole quantization groups, is the hard part of four ranks, and it's laid out clearly here. The Python engine is frozen (#286), so this won't merge. Flash Next is on the Zig engine, but on Metal. Zig CUDA runs only Nemotron, on one GPU, so four CUDA ranks for Flash Next wait for Zig CUDA to take the family and ranks. When it does, your head and expert sharing rules are where it starts, with your credit. |
What this changes
Part of #313. Stacked on #378. The earlier commits on this branch are #378's (see #376 for what they carry). This pull request is the last two commits: the four-rank change and a fix from review (MLX key/value heads, below). Qwen3.8-Flash-Next runs on one GPU, two ranks or four:
shared, each rank keeping the one its query heads read. Expert and shared-expert widths split on whole
quantization groups (
ranks.share: the lower ranks one block more where they do not divide). The MTP layer's bf16experts keep each rank's gate rows and its up rows.
over the engine's communicator, and row-parallel branches sum through them (one launch, or copies for
prompt-sized partials). NVFP4 bf16 faces return fp32 partials; an NVFP4 checkpoint's prompt partials are bf16.
NVFP4 checkpoints still run on one GPU here.
gdn/gdn_iotake a rank's share of four (4 key and 12 value heads).kv_local/kv_first);before, 2 key/value heads over 4 ranks gave every rank empty k and v projections.
host pages on the caller's device.
Receipt
this split yet.
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: to run, fourGPUs,
TensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTP,--tp 4(four ranks with--rank 0..3and--master).tools/bench_openai.py: before is a refusal (--tp 4); to run.tools/prefill_cold.py: to run.open_comm, upstream's two-rank--paralleldecoder kept,--parallelrefused at--tp 4only;p2p.installalso runs at--tp 2(separate DGX Sparks should fall back to the NCCL gather; not run on GB10). Not served on its own: its code ran in feat(volta): Qwen3.8-Flash-Next NVFP4 checkpoints on sm_70, one GPU or four ranks #380's four-rank receipt on V100.test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, fails on the release too).tests/test_flashnext_ranks_host.pyfails before (module absent) and passes here (2 passed).
tests/test_flashnext_ranks_host.pyon the V100 machine: import error on the parent's tree, 2 passed here. Served: this code is in feat(volta): Qwen3.8-Flash-Next NVFP4 checkpoints on sm_70, one GPU or four ranks #380's tree, whose four-rank Flash Next serve is exact (see feat(volta): Qwen3.8-Flash-Next NVFP4 checkpoints on sm_70, one GPU or four ranks #380). Prompt speed on a checkpoint v0.6.5 serves,RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead+z-lab/Qwen3.8-27B-DFlash2on 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 onbuild.volta(), so GB10 does not run it).tests/test_flashnext_ranks_host.py::test_mlx_ranks_keep_the_key_value_head_their_queries_readcalls
load()as each rank of 2 and of 4 on a one-layer checkpoint (2 key/value heads) and checks every rank'sk/v rows. Linux host (no GPU used): before the fix the four-rank case fails (empty rows), two ranks pass; after,
4 passed. M5 Ultra (no torch): 2 passed, 2 skipped.
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not served on its own; feat(volta): Qwen3.8-Flash-Next NVFP4 checkpoints on sm_70, one GPU or four ranks #380's four-rank Flash Next serve on V100s carries this code and is exact there (resumed == fresh, drafted =="draft": false, concurrent == solo).)RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHeadon 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.)tests/test_flashnext_ranks_host.pyfails before with the module absent and passes here; the review fix'sload()test fails before it at four ranks and skips without torch or Triton.)The three #264 commits carried here are RoscoeTT's as replayed onto v0.6.5; their Co-Authored-By trailers are his.