Repository navigation
metal: MiniMax-M3's, Spark2.5's and Llama's NaN-aware bf16 argmax from one source (#2251) - #2949
Conversation
|
Thanks @jschmied. We checked the claim independently: each library built from
|
9188f37 to
1716a73
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 section-1 group 7 of #2251, the NaN-aware argmax. It follows #2792 (the bf16 matvec, merged), whose
sources.ziglines it extends. Head 9188f37, one commit on main a0e2665.What changes
minimax_m3/glue.metal,spark25/glue.metalandllama/glue.metaleach had the same comparator (mm_better/sp_better/ll_better: NaN first, the lower id among NaNs, then the larger value, ties to the lower id). Each also had the same 1024-thread*_argmaxkernel over one bf16 logits row intoids[0].core/bf16_argmax.metalholds them once:tf_bf16_argmax_betterandTF_BF16_ARGMAX(NAME).sources.zigputs it ahead of the three glue files. Each file makes its kernel withTF_BF16_ARGMAX(mm_argmax)/(sp_argmax)/(ll_argmax)where the kernel was, so names and the module's order are kept.tf_argmax_bf16is a different kernel (many rows, an optional id map). Its glue source also feeds Nemotron's kernel identity hash.tf_dsv41_betterhas other rules (out-of-range ids, a control switch).stream_rinv: ten of its eleven copies, and two oftf_rotary_scalar's six, are Flash Next's recorded kernel texts (flashnext/*_<hash>.metal), whichtools/zig/flashnext_checked.pywrites verbatim. They stay.tf_rotary_scalarcopies (prefill/fn_select,fn_pool_pos,fn_mrope) are the textrotary_cache.zigfinds and patches in each source. It refuses one that differs fromfn_rotary_scalar.metal(RotarySourceMismatch), so they are already held to one text.Same code before and after (M3 Pro, main a0e2665 against this branch)
Compiled code: the LLVM IR of
minimax_m3_glue,spark25_glueandllama_glue(with theLL_DHdefine its loader prepends) is identical, with the comparator's name mapped back. This holds for-fmetal-math-mode=safewith both-fmetal-math-fp32-functions=fastand=precise.Kernel contract (
tf-kernel-contract --rotary-accuracy rotary.json; main a0e2665 against this branch):--only minimax: both runs giveSUMMARY 50 kernels: 50 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems.--only llama: both runs giveSUMMARY 22 kernels: 22 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems.mm_argmaxandll_argmaxand their NaN rule; Llama's control "a NaN logit never wins" goes red as planted.Tests: native build;
test-spark25-host,test-lfm2-dspark,test-minimax-info-host,test-minimax-cuda-hostandtest-kernel-symbols-hostpass. Lean 386 vs 386, 0 new;zig fmt --checkandgit diff --checkclean.x86 CI (Linux build + host tests on 9188f37): green, 700/700 steps;
check-native-cuda-host compile-cuda-testsgreen; pr_check 0 errors; fmt, diff --check clean; lean 386 vs 386, 0 new.Rebased onto a0e2665 after #2792 merged:
git range-diffshows the patch unchanged, onlysources.zigcontext lines moved; all checks above were rerun on the rebased head.Not run: seeded, resume and concurrency reply checks against main, because the compiled IR is identical, so no served output can change.
Proposed CHANGELOG line (for you to place):