Repository navigation
metal: one gemm_nax kernel macro for the vision towers' and Spark2.5's and Llama's prompt GEMMs (#2251) - #2787
Conversation
|
Thanks @jschmied. All 56 calls pass exactly the type,
|
fa4cadf to
9dbe8d1
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. |
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
|
Thanks @jschmied! This is in TensorFold 1.2.8, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.8
|
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
…with its q, k and v biases and YaRN at HF's rounding points The family admits model_type qwen2 for the checkpoints checked against Hugging Face: the q, k and v biases join the projections' fp32 sums before their one rounding (ll_matvec_bias_* beside the shared ll_matvec_*, which stay core/bf16_matvec.metal's; a prompt chunk's GEMM stores its sums through ll_gemm_f32_*, gemm_nax with fp32 output, and ll_bias_round adds the bias and rounds once), and the rope carries transformers' static YaRN table for 128-wide heads (rope_yarn.yarnOf; the 64-wide table unchanged), computed once at parse, with its attention factor on the bf16 cosines and sines. Config refuses a root rope_theta that disagrees with rope_parameters', a layer_types entry that is not full_attention, and reads a null rope_parameters as absent. Every changed and new kernel is under the contract with five more planted controls; the controls' source edits now name the shared matvec's loop and the GEMM macro lines (ashhart#2787 left gemm_untransposed's edit matching nothing). --drafter is refused by name for a checkpoint no drafter was checked with, Qualified.copy_drafts turns the lane core's copies off for Bimo-7B-CyberAgent, and the template's lack of a think block is declared to the server. tools/zig/llama_f64_reference.py takes the Qwen2 layout.
The next section-1 group of #2251: six copies of the same
tfp::gemm_naxkernel-wrapper macro become one.What changes
GLMV_GEMM(glm_vision),S5V_GEMM(step5/vision),G4V_GEMM(gemma4/vision),QWV_GEMM(core/qwen_vision),SP_GEMM(spark25/gemm) andLL_GEMM(llama/gemm) each defined the same kernel: buffers A, B, P, D, 256 threads,tfp::gemm_nax<T, TA, TB, AM, AN, false, 64, 128, 256, 2, 4>.QWV_GEMMfixed TA to false;SP_GEMM/LL_GEMMfixed T tobfloat16_t, TA false and TB true.TF_GEMM_NAX_KERNEL(NAME, T, TA, TB, AM, AN)in the newprefill/gemm_nax_kernel.metal; each family's lines call it with the arguments the old macros fixed spelled out. Kernel names and the 56 instantiations are unchanged.sources.zig: a privategemm_nax(prefill/gemm_nax.metal++prefill/gemm_nax_kernel.metal) heads the six sources that started withprefill/gemm_nax.metal.gemm_nax.metalitself is unchanged, socheck_prefill_ops.pyandprefill_launch.pysee the same file.Same code before and after (M3 Pro, main cd6060a against this branch)
Preprocessed sources: each of the six sources, assembled as
sources.zigembeds it withnax.hinlined, preprocesses (xcrun metal -std=metal4.1 -E -P) to byte-identical text on main and the branch.Compiled code: the LLVM IR of all six is identical (
-S -emit-llvm,-fmetal-math-mode=safe, with-fmetal-math-fp32-functions=fastand=precise; Gemma 4's with theG4V_OUTdefine its loader prepends), source path normalized.Not run here: these GEMMs run on the tensor units; this Mac has none, so no GPU run. The evidence is the preprocessor and IR identity above.
Tests: native build;
test-kernel-symbols-host,test-step5-host,compile-step5-host,test-spark25-host,test-gemma4-contract-host,compile-gemma4-contract-host,compile-gemma4-host,test-qwen-vision-weights-host,test-glm-image-cache-host,test-gemma4-tower-host,test-contract-images-host,test-vision-cli-host,test-qwen35-images-hostpass. Lean 386 vs 386, 0 new;zig fmt --checkandgit diff --checkclean.x86 CI (Linux build + host tests on fa4cadf): 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: of this PR's files, only
sources.zigis also edited by other open PRs (30 of them); whichever lands later may need a small rebase there.