Repository navigation
metal: Spark2.5's and Llama's bf16 decode matvec from one source (#2251) - #2792
Conversation
|
Thanks @jschmied. The template in
|
b010d38 to
227b296
Compare
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thanks @jschmied! This is in TensorFold 1.2.8, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.8
|
The next section-1 group of #2251:
sp_matvec_tandll_matvec_twere the same function under two prefixes.What changes
spark25/glue.metalandllama/glue.metaleach carried the same{rows, n, k, ldy}args struct, the same*_matvec_t<ROWS>template (bf16 W [n, k], fp32 sums, a simdgroup an output row) and the same kernel macro for 1, 2, 4, 8, 16 and 32 rows. They differed only in thesp_/ll_prefix.core/bf16_matvec.metalholds them once:tf_bf16_mv_args,tf_bf16_matvec_t<ROWS>, andTF_BF16_MATVECS(P), which makes the kernelsP_matvec_1toP_matvec_32.sources.zigputs it ahead of each glue file. Each glue file instantiates its six kernels with oneTF_BF16_MATVECS(sp)/TF_BF16_MATVECS(ll)where the block was, so the kernels keep their names, and the module keeps its order.ll_q4_dequantread the samell_mv_argsand now readstf_bf16_mv_args, which has the same layout. Four host and contract comments name the new struct. The host code is unchanged._Pragma("clang loop unroll(full)"), which is whatTF_UNROLL_4expands to), so the shared file does not depend on either glue file's macro.Same code before and after (M3 Pro, main cd6060a against this branch)
Compiled code: the LLVM IR of
spark25_glueand ofllama_glue(with theLL_DHdefine its loader prepends) is identical once the struct and template names are mapped back. This holds for-fmetal-math-mode=safewith both-fmetal-math-fp32-functions=fastand=precise. The renamed struct and template, and their mangled names, are the only differences.Kernel contract (
tf-kernel-contract --only llama --rotary-accuracy rotary.json): main and branch bothSUMMARY 22 kernels: 22 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems. The outputs are identical apart from the SUMMARY's timings. Among the 22 arell_matvec_1.._32andll_q4_dequant, and the matvec control goes red as planted. Spark2.5's glue has no contract entries; its evidence is the IR identity.Tests: native build;
test-spark25-host,test-lfm2-dspark,test-kernel-symbols-hostpass. Lean 386 vs 386, 0 new;zig fmt --checkandgit diff --checkclean.x86 CI (Linux build + host tests on b010d38): green.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
With the other metal: unify duplicated kernels (attention partials, norms, gemm_nax wrappers, glue, RoPE) #2251 group: gemm-nax-macro (fa4cadf) and bf16-matvec-unify (b010d38) both edit
sources.zigon different lines;git merge-treemerges them cleanly in either order.Overlap:
sources.zigis also edited by 26 other open PRs, andzig/tests/contract/metal_llama_dense.zigby ricursive: speed up Ripple-65B on two GB10s #2523, ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522, ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514, ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475, ricursive: Ripple-65B-Preview on native CUDA (NVFP4) #2302, ricursive: the publisher's DFlash2 drafter for Ripple-65B (stacked on #2231) #2260 and ricursive: Ripple-65B-Preview on native Metal (NVFP4 and bf16 releases) #2231; whichever lands later may need a small rebase there. It merges cleanly with today's main.