Repository navigation
lfm2: d1-3B on CUDA, text and pictures, answering System One and decisions - #844
Conversation
…engine decide hook
Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (#617, #621, #626, #631, #697, #655, #811-#818), bracket classes in the tokenizer (#842), System One requests (#843), the shared norm's loads (#796) and d1-3B on CUDA (#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's tf_rms_rows_bf16 record takes #796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from #846) takes the 32 static bytes #796 leaves, with the 79 registers sm_80 had.
The CUDA LFM2-VL family (d1-3B, #844) lives at zig/src/families/lfm2/ and zig/src/native/lfm2.zig, the paths this Metal family used. The Metal LFM2-MoE family moves to zig/src/families/lfm2_moe/ (its root file lfm2_moe.zig) and zig/src/native/lfm2_moe.zig, and tensorfold.zig exports it as lfm2_moe. A pure move: every file keeps its bytes but the import lines that name the new paths.
|
Thank you, @plotarmordev. d1-3B on CUDA arrived with host references for every kernel, the attention bound and the parity receipts. It ships in TensorFold 1.0.12 under your name ( One change is ours, not a flaw in your work. The project loads outside libraries at run time rather than carrying code rewritten from them, so d1's pictures now decode through the shared decoder in On a GB10, Posted by Ash's AI Assistant Synthena |
…date The contributor's commit landed above with the same code; the two fixture scripts that recorded its JSON goldens through the Python engine stay out of the tree, and the JSON stays. This keeps the PR's head in the history with no change to the tree.
with the HIP series ashhart#626's three loader commits are in both histories as the same patches. The tree keeps the HIP series' qwen3_5/weights files and zig/build/hip.zig (one coreModule), drops qwen3_5/weights/experts.zig (core/quant stacks the experts now), and puts ashhart#626's CHANGELOG line before ashhart#631's.
…rt#844 onto the candidate Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (ashhart#617, ashhart#621, ashhart#626, ashhart#631, ashhart#697, ashhart#655, ashhart#811-ashhart#818), bracket classes in the tokenizer (ashhart#842), System One requests (ashhart#843), the shared norm's loads (ashhart#796) and d1-3B on CUDA (ashhart#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's tf_rms_rows_bf16 record takes ashhart#796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from ashhart#846) takes the 32 static bytes ashhart#796 leaves, with the 79 registers sm_80 had.
The CUDA LFM2-VL family (d1-3B, ashhart#844) lives at zig/src/families/lfm2/ and zig/src/native/lfm2.zig, the paths this Metal family used. The Metal LFM2-MoE family moves to zig/src/families/lfm2_moe/ (its root file lfm2_moe.zig) and zig/src/native/lfm2_moe.zig, and tensorfold.zig exports it as lfm2_moe. A pure move: every file keeps its bytes but the import lines that name the new paths.
What this changes
d1-3B (Liquid AI's LFM2-VL decision model) on CUDA in the native engine, answering
POST /v1/systemoneand/v1/decisions. On top of #842 (tokenizer) and #843 (System One and thedecidehook); their commits come first here.The recipe this ports, with its container build, checkpoint checksums and benchmarks, is github.com/plotarmordev/d1-tensorfold. That repository goes public within the next 24 hours; until then the link does not resolve.
native/lfm2.zig,families/lfm2/model.zig): a decision engine, not a lane engine. Each request is one prompt pass over the shared state (the trunk) and a branch a question, packed on one row axis; each branch's labels are read at its last row (labelLogits), so the vocabulary head is not computed for System One. Branches are packed into passes within the context, 256 branches and 4,096 labels. Chat and completions are refused (Info.decides).lfm2.cu,kernels.zig,config.zig,weights.zig): LFM2's gated short convolution with each row's taps in its own sequence (branch, then trunk), QK RMS norm and rotary, add-norm and SiLU gate in bf16 with f32 sums, the projections as cuBLASLt GEMMs (w1|w3 and q|k|v stacked at load).prefill_attention.cu, newprefill_attention_rows.cuh,attention.zig): the existing prompt-attention kernel's body moves to a header included by each kernel, and gains three compile-time switches: a key range a block (a branch sees the whole trunk, then its own rows causally), no mask (the vision tower), and a head dim padded inside the kernel (72 to 80). New instantiations:tree_kernel<64,8,4,8>(LFM2's GQA, 32 by 8 heads) andfull_kernel<72,8,8>(SigLIP2). Nemotron'spattn_kernel<128,8,8,8>compiles to byte-identical SASS (cuobjdump -sassagainst main's build).image.zig,png.zig,jpeg.zig,resample.zig): data URL to RGB as Pillow decodes it (PNG all bit depths and colour types, baseline and progressive JPEG, EXIF orientation), the 1024×1024 pixel cap, thenLfm2VlImageProcessor's resize, 512-pixel tiling and thumbnail, normalization and 16-pixel patches, and the placeholder ids. Malformed files are refused, never trapped. The decoders port libjpeg-turbo and Pillow's arithmetic so pixels are byte-equal; credits and licenses are inTHIRD_PARTY_NOTICES.mdandLICENSES/.vision.zig,lfm2_vision.cu): SigLIP2's NaFlex tower (position grid resized with antialiasing per tile, 27 pre-LN layers, tanh GELU) andLfm2VlMultiModalProjector(pixel unshuffle, exact GELU), a tile at a time; features replace the placeholder rows' embeddings. Linear biases run in cuBLASLt's epilogue where the plain GEMM's algorithm takes it (Linear.initEpilogue,runBias;Linear.initand every existing caller unchanged), else in a bias kernel with the same single rounding.Receipt
Environment: this branch (main
2962468f+ tokenizer: an ASCII class inside (?i:) folds to its case variants #842 + server: /v1/systemone, llama-server's System One request, through an engine decide hook #843), Zig 0.17.0, CUDA 13, DGX Spark (GB10, sm_121),LiquidAI/d1-3BBF16 (model_type: lfm2_vl),--context 32768. Reference: Transformers' bf16 answers and the recipe's TensorFold Python 0.6 engine (containerd1-tensorfold), both on the recipe's parity set (48 text requests and one picture, 99 questions).Exactness (this head's build):
The picture question ("how many cats": one / two / more) gives "two" at 0.98388, Transformers 0.98412.
tf-cuda-test lfm2-kernels: 41 of 41 comparisons byte-equal to host references that round as torch's bf16 modules do.lfm2-attention: causal, tree (trunks 0 to 3,400, 1 to 64 branches) and full attention within an f64 bound; every branch bit-equal to causal attention over trunk ++ branch.lfm2-vision: the tower's kernels byte-equal to host references, cuBLASLt's bias epilogue byte-equal to the f32 GEMM plus bias on exact inputs, and three pictures' features (1 to 7 tiles) against Transformers' CPU bf16 tower (cosine ≥ 0.998).glue(Nemotron): 1,242 of 1,242 byte-equal.Decode speed: n/a, a decision writes no tokens.
Prompt speed, the recipe's bench (
bench/systemone_bench.py, 3 rounds of 50, two alternating starts of each engine), p50:The Grill's
systemoneA/B/A2 on the recipe's audited plan (100 bursts a cell): the 3,446-token state PASS (272.6 → 259.1 ms) and 64 packed states PASS (40.4 → 42.1 a second); one question, three questions and the picture INCONCLUSIVE (means within 1%: 24.6 → 24.4, 27.7 → 27.5, 43.0 → 43.0 ms; single-request spread wider than the plan's ±5% gate). No failures in any arm.Tests run:
zig build test48/48 steps, 760/765 passed (5 skipped); server tests 210/210 and 110/110;zig build test-golden309/319 equal, 0 unexpected differences;tf-cuda-testlfm2-kernels, lfm2-attention, lfm2-vision and glue PASS on GB10;zig fmt --check;lean_checkas on main.Not run, and why: Metal (the family is CUDA only; a Mac server has no
lfm2_vlbackend and refuses the checkpoint as before). Other CUDA GPUs than GB10 (not available). The NVFP4/quantized d1 variants (the checkpoint is BF16 only).Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (A request's answers do not depend on what else is packed with it beyond bf16 GEMM sums: every branch's attention is bit-equal to its solo causal pass.)tf-cuda-test; the CPU tests, including the picture goldens and a seeded set of truncated and altered files, run inzig build test.)