Repository navigation
Conversation
|
The checkpoint-precision version of this library is now #958, stacked on this one.
If you prefer, #947 and #958 can be squashed into one bf16-only change, with int8 kept on our fork. 🤖 Generated with Claude Code |
…for a host pipeline A video model's denoising transformer: no lane round, and int8 products and attention on mma.sync m16n8k32. It is a library (zig build tf-h3) beside the engine for a host that owns the rest of the pipeline and shares its CUDA context; the lane core and the server are untouched. docs/recipes/minimax-h3-cuda.md holds the receipt.
A host that merges a LoRA into the checkpoint's weights hands the merged projection over and the library quantizes it as at load; the int8 copy saved beside the checkpoint is left as it was.
A rank runs the rows of its own routing tiles; every block it hands the other ranks its tiles' int8 keys, values, scales and pooled means and takes theirs, then attends as on one GPU. The kernels and their arithmetic are unchanged row for row, so a pass on N ranks gives the bits of a pass on one. - h3_xchg.c: the exchange over libibverbs. One registered region a rank, one reliable queue pair a peer and rail; a rank RDMA-writes its share into the same offsets of every peer's region, the last write carrying a sequence number. A rail is one RDMA device; two rails split each span. - The region is pinned host memory; the buffers stay on the device and h3_spans packs a rank's tiles into the region and unpacks the others' out of it. Two halves of the region by block parity: a rank one block ahead never writes what another is unpacking. - Inputs.tile0/tile1/cuts: a rank's tile range and every rank's. Routing, top-k and attention run for the rank's own query tiles; kernels take their tile range by where their buffers start. - tf_h3_open on a .tf-int8 path opens the saved int8 copy alone (a rank holds no checkpoint). - tf_h3_forward_host, tf_h3_host_alloc / _free: inputs in host memory, for a rank without a framework. - tf_h3_tp_init / _close / _info / _connect / _stats. The connection records travel over the host's own channel. - The sequence's buffers move to cuda_geometry.zig and the world to cuda_tp.zig, keeping each file under 600 lines.
…e recipe's receipt contract_h3.zig registers h3_gemm, h3_gemm_n256, h3_gemm_swiglu and h3_gemm_wide (exact int32 sums, fp32 scales, bf16 out) and h3_spans (a move) for gates 1 to 4, with their launches and per-SM records for gate 5. The H3 kernel image is built once for the library and the contract's runner, and kernel-contract-fatbins installs it.
b570b8f to
7a66f00
Compare
|
Rebased on main |
|
Thanks, @drowzeys, for the original H3 CUDA work and its receipts. #958 supersedes this proposal with the stored-bf16 H3 component and carries your work and credit; its remaining integration and qualification checks are tracked there. Please reopen if any part of this proposal is left uncovered. Posted by Ash's AI Assistant Synthena |
beneath it #958's transformer blocks, kernels and contracts as a C library for a host pipeline (zig build tf-h3, libtf_h3.so) on one device; its sequence-parallel exchange over RoCE waits for a follow-up of its own. With our repairs: checkpoint and projection bounds before any allocation, the host's primary context through Context.shared, complete blocks only, partial loads keeping their destinations and parent objects until their copies are proven complete, and one recovery walker for each failed-load registry. The H3 kernels join the CUDA kernel contract. The host steps (test-h3-ownership, -metadata, -arithmetic, -blocks and -boundaries, compile-h3-library) sit beside the Metal family's in zig/build/h3_host.zig, and the tests are named for what they check.
… with ashhart#947 beneath it ashhart#958's transformer blocks, kernels and contracts as a C library for a host pipeline (zig build tf-h3, libtf_h3.so) on one device; its sequence-parallel exchange over RoCE waits for a follow-up of its own. With our repairs: checkpoint and projection bounds before any allocation, the host's primary context through Context.shared, complete blocks only, partial loads keeping their destinations and parent objects until their copies are proven complete, and one recovery walker for each failed-load registry. The H3 kernels join the CUDA kernel contract. The host steps (test-h3-ownership, -metadata, -arithmetic, -blocks and -boundaries, compile-h3-library) sit beside the Metal family's in zig/build/h3_host.zig, and the tests are named for what they check.
Thank you, Ash, for the invitation to send this for review, and for the CUDA runtime it builds on.
This is the first video generation model on TensorFold's CUDA runtime, and its first sequence-parallel split of one pass across machines. MiniMax H3 / FastH3 is a joint video and audio diffusion transformer: 50 blocks with hidden size 5376, run over one packed sequence of text, audio and video rows. Its 50 blocks now run on TensorFold's CUDA runtime as a library,
libtf_h3.so. There is no PyTorch inside it, and a host pipeline calls it once per denoising pass. One pass can also be split across several DGX Sparks. Each rank trades int8 keys and values with the others every block over RDMA (RoCE), and the result is the same bits as one GPU.This is the case for TensorFold beyond text: the same runtime, kernel contract and lean code carry a model whose step is a denoising pass over 15,000 rows, and they scale it across nodes.
The receipts are for a 5 s clip (864x480, 124 frames, 15,433 rows, 8 passes) on DGX Spark (GB10), each measured on the same machine. The reference is ComfyUI's own bf16 blocks.
main, 517 here). The host suites pass.Precision is int8, and that is the first thing to change. The weights are int8 with a scale per channel; the activations are int8 with a scale per row. Sums are int32, and scales and softmax are fp32. The error above includes all of it.
What comes next, for the gate we agree on:
Linear, plus a bf16 version of the tile-routed attention. The int8 kernels would stay a choice the user makes.Context.sharedandStream.borrowed, is on its own branch as a separate pull request. This change does not depend on it.I did not open an issue first, since this came by invitation. Happy to move the gate discussion into one if you prefer.
What it adds
These are new files, plus the minimal wiring: the
tf-h3step inzig/build/cuda.zig, the H3 image inzig/build/kernel_contract.zig, 20 lines in the contract runner, and 5 records inregistry.zig. Four commits plus a recipe update:tf_h3_set_weight, for LoRA weights merged by the host;zig/src/families/h3/:cuda.zigholds the forward.cuda_geometry.zigholds the buffers that depend on the sequence.cuda_weights.zigquantizes on the GPU, keeps the saved.tf-int8copy, and doesset_weight.checkpoint.zigmaps the safetensors file by name, with 2 host tests.cuda_tp.zigandh3_xchg.care the ranks and the RDMA exchange over libibverbs. There is one reliable queue pair per peer and rail, and the region has a half for each block parity.cuda_lib.zigholds the C entry points.zig/kernels/cuda/h3.cuandh3_products.cuh:mma.sync m16n8k32;h3_spans.zig/tests/cuda/contract_h3.zig: the registrations.docs/recipes/minimax-h3-cuda.md: the API, the arithmetic and the receipt.Rank orchestration stays with the host. Moving each pass's rows to the ranks and back, starting ranks, and the app's distribution of whole clips across Sparks will come in a later Studio pull request.
Receipts
Environment:
b570b8f0onmain46a08c18.a4b5a045(0.39.0).FastVideo/FastVideo-FastH3-Comfyfastvideo_fasth3_8step_v2_pruned_bf16.safetensors.cefc3568(same kernels), same seedThe last row compares two different attentions at sigma 1, where tile routing among pure-noise tiles flips on tiny differences. The dense rows are the arithmetic check.
Memory, the library alone:
tf_h3_openon the int8 copy, then three passes over the same 15,433-row geometry, sampled every 0.5 s.Commands:
The clip timings and parity came from the Studio's ComfyUI node; parity used its
TF_H3_CHECK=1mode. The ranks ran the Studio'srank.py, and the memory figures came from itsbench.py. These are app-side harnesses and are not part of this change.Kernel contract
h3_gemm,h3_gemm_n256,h3_gemm_swigluandh3_gemm_widedeclare exact int32 sums followed by fp32 scales. Against them, fp16 sums would miss by 1347x to inf and bf16 sums by 256x to 13541x.h3_spansis a move.Gate 3 runs at the engine's widths with 16 rows plus the row-tile edges. A float64 host reference cannot follow 15k rows.
kernel-contract-limitsreports:PASS ... every registered launch fits sm_80, sm_86, sm_89, sm_120 and sm_121, every control red. Gates 1–4 ran on GB10 only.Checks
main46a08c1python3 tools/zig/lean_check.pyzig build test(fresh cache)zig build test-cuda-host(fresh cache)zig build test-kernel-contractzig fmt --check, changed Zig fileszig build tf-h3at each commit; full CUDA build at the lastNot yet tested
Licenses
The code is Apache-2.0. MiniMax H3 / FastH3 weights are under the MiniMax H3 Community License, which limits territories. No weights are included.
The runtime hook this library uses to share a host's CUDA context is #946; the Studio that drives it is #941.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PfjmufXm4L7qsVNFyRw9ZK