From 5d225a2f20c4231847b718f7190d851c45d3c265 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 12:03:14 -0400 Subject: [PATCH 1/3] ci: the f16 narrowing ratchet matches the vector form, so it lists all 52 bodies (engine#2219) The ratchet matched "f32 to f16" or "truncf" as substrings. That misses `vector.fptrunc %x : vector<4xf32> to vector<4xf16>`, which is 132 of the 233 narrowing lines at llama.cpp 2b7960bae. The baseline listed 25 of the 52 bodies that narrow. The match is now a regex that also takes vector to vector (not bf16). The baseline is regenerated at 2b7960bae, with 27 lines added and none removed. The self-test gains a vector-form arm and a bf16 control. The header's stray engine#1595 line and its stale pin are corrected. Co-Authored-By: Claude Opus 5.5 --- tools/ci/hrx_f16_narrowing.py | 18 +++++++++++++++--- tools/ci/hrx_f16_narrowing.txt | 31 ++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/ci/hrx_f16_narrowing.py b/tools/ci/hrx_f16_narrowing.py index 4d4034a0f..e163fe92f 100755 --- a/tools/ci/hrx_f16_narrowing.py +++ b/tools/ci/hrx_f16_narrowing.py @@ -24,7 +24,8 @@ This is the ratchet: - * every .loom body that narrows f32 to f16 (`f32 to f16` or `truncf`) is listed in + * every .loom body that narrows f32 to f16 (scalar `f32 to f16`, vector `vector to vector`, + or `truncf`) is listed in tools/ci/hrx_f16_narrowing.txt, and a body that appears without a line, or a line whose body is gone, fails the check -- the two arms a ratchet needs (a list that can only grow cannot see a rename, engine#1728's lesson); @@ -41,11 +42,15 @@ """ import argparse import pathlib +import re import sys CORPUS = pathlib.Path("third_party/llama.cpp/ggml/src/ggml-hrx/kernel-corpus/kernels") BASELINE = pathlib.Path("tools/ci/hrx_f16_narrowing.txt") -NARROW = ("f32 to f16", "truncf") +# The vector form is most of the corpus: `vector.fptrunc %x : vector<4xf32> to vector<4xf16>` contains neither +# "f32 to f16" nor "truncf", and at llama.cpp 2b7960bae 132 of the 233 narrowing lines are written that way. +# Matching the scalar spelling alone listed 25 bodies; the corpus has 51 (engine#2204's review). +NARROW = re.compile(r"f32 to f16|vector<[0-9x]*f32>\s+to\s+vector<[0-9x]*f16>|truncf") GUARD = ("scale_log2", "prescale") @@ -59,7 +64,7 @@ def narrowing_bodies(corpus): found = set() for path in corpus.rglob("*.loom"): body = path.read_text(encoding="utf-8", errors="replace") - if any(marker in body for marker in NARROW): + if NARROW.search(body): found.add(path.relative_to(corpus).as_posix()) return found @@ -139,6 +144,13 @@ def check_that(ok, what): (corpus / "c.loom").write_text(" %z = scalar.fptrunc %w : f32 to f16\n") new, stale = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) check_that(new == ["c.loom"] and not stale, "a new narrowing body is drift, and only it") + (corpus / "v.loom").write_text(" %h = vector.fptrunc %v : vector<4xf32> to vector<4xf16>\n") + (corpus / "w.loom").write_text(" %h = vector.fptrunc %v : vector<4xf32> to vector<4xbf16>\n") + new, _ = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) + check_that(new == ["c.loom", "v.loom"], + "a vector<4xf32> to vector<4xf16> narrowing is found, and a bf16 one is not") + (corpus / "v.loom").unlink() + (corpus / "w.loom").unlink() (corpus / "c.loom").write_text(" %z = scalar.constant 0.0 : f32\n") (corpus / "a.loom").rename(corpus / "renamed.loom") new, stale = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) diff --git a/tools/ci/hrx_f16_narrowing.txt b/tools/ci/hrx_f16_narrowing.txt index b7e67e613..3926874c8 100644 --- a/tools/ci/hrx_f16_narrowing.txt +++ b/tools/ci/hrx_f16_narrowing.txt @@ -13,29 +13,53 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Targets whose add_test() names them and which CI never builds (engine#1595). -# -# engine#1962: the .loom bodies that narrow an f32 value to f16, at llama.cpp pin 7a1f2b81c. +# engine#1962: the .loom bodies that narrow an f32 value to f16 (scalar or vector form), at llama.cpp pin 2b7960bae. # Paths are relative to third_party/llama.cpp/ggml/src/ggml-hrx/kernel-corpus/kernels. This is a # RATCHET, not a list of bugs: a body here may narrow a bounded value (a scale, a weight) and be # perfectly correct. What the list buys is that a NEW narrowing body cannot appear without someone # writing it down and saying what feeds it -- and that is the open question on engine#1962: which of # these are protected by a producer-side prescale cannot be answered by reading them. +loom-libs/motifs/bf16_f16.loom +loom-libs/motifs/dequant.loom +loom-libs/motifs/dequant_1bit.loom +loom-libs/motifs/dequant_prism.loom +loom-libs/motifs/f32_f16.loom +loom-libs/motifs/llm_attention_qkv_matmul_postops.loom +loom-libs/motifs/mul_mat_f32_f32_wmma_core.loom loom-libs/motifs/mul_mat_id_f16_f16_wmma_core.loom +loom-libs/motifs/mul_mat_id_f32_f32_wmma_core.loom loom-libs/motifs/mul_mat_id_q4k_f16_wmma_projection.loom loom-libs/motifs/mul_mat_id_q5k_f16_wmma_projection.loom +loom-libs/motifs/mul_mat_id_q6k_f16_wmma_projection.loom +loom-libs/motifs/mul_mat_id_swiglu_f16_f16_accumulate.loom +loom-libs/motifs/mul_mat_id_swiglu_f16_f16_wmma_body.loom +loom-libs/motifs/mul_mat_quantized_f16_prefill.loom +loom-libs/motifs/publish_f32.loom loom-libs/motifs/q4_k_f16.loom +loom-libs/motifs/q6_k_f16.loom +loom-libs/motifs/q8_0_f16.loom +loom-libs/motifs/q8_1_f16.loom loom-libs/motifs/quantize_q8_1_x4.loom loom-libs/motifs/unary_f32_apply.loom +loom-libs/ops/copy_f32.loom loom-libs/ops/flash_attention_decode_split_f32_f16_wmma.loom loom-libs/ops/flash_attention_f32_f16_wmma.loom loom-libs/ops/gated_delta_net_f32_wmma.loom +loom-libs/ops/llm_attention_k_matmul_rope_set_rows_decode_f32_f32.loom loom-libs/ops/llm_attention_v_matmul_set_rows_decode_f32_f32.loom +loom-libs/ops/mul_mat_id_swiglu_f32_f32_wmma.loom +loom-libs/ops/mul_mat_q6_k_packed_f16_wmma.loom +loom-libs/ops/mul_mat_swiglu_f32_f32_wmma.loom loom-libs/ops/mul_mat_swiglu_symmetric_i4_wmma.loom +loom-libs/ops/mul_mat_symmetric_i4_wmma.loom loom-libs/ops/mul_mat_symmetric_i8_wmma.loom +loom-libs/ops/rmsnorm_binary_f32.loom +loom-libs/ops/rope_set_rows_f32.loom loom-libs/ops/set_rows.loom loom-libs/ops/small_rows_f32.loom +qwen_moe/ggml/linear_q6k_q8_1_x4.loom qwen_moe/ggml/quantize_q8_1_x4.loom +qwen_moe/qwen3_moe/attention_postprocess_f32_f16.loom qwen_moe/qwen3_moe/attention_prepare_quantized.loom qwen_moe/qwen3_moe/dense_linear_quantized_f16_wmma.loom qwen_moe/qwen3_moe/flash_attention_decode_f32_f16_wmma.loom @@ -43,6 +67,7 @@ qwen_moe/qwen3_moe/flash_attention_decode_q128_f32_f16_wmma.loom qwen_moe/qwen3_moe/flash_attention_decode_split_f32_f16_wmma.loom qwen_moe/qwen3_moe/flash_attention_decode_split_next_q8_test.loom qwen_moe/qwen3_moe/flash_attention_f32_f16_wmma.loom +qwen_moe/qwen3_moe/routed_down_quantized_f16_wmma.loom qwen_moe/qwen3_moe/routed_down_weighted_reduce_next_rmsnorm_q8_1_x4.loom qwen_moe/qwen3_moe/routed_gate_up_swiglu_q4k.loom qwen_moe/qwen3_moe/routed_linear_q4k_f16_wmma.loom From 86141663a652bd3a7a4ab8fbaff3497a66e88e3c Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 13:01:08 -0400 Subject: [PATCH 2/3] ci: a bare truncf is not a narrowing to f16, so unary_f32_apply leaves the ratchet (engine#2219) `scalar.truncf %v : f32` and `vector.truncf %w : vector<4xf32>` in unary_f32_apply.loom round within f32; the file never mentions f16. The bare `truncf` alternative listed it anyway, a false positive carried over from #2114. Every truncf that narrows names its f16 type, which the scalar and vector patterns already match. Dropping the alternative leaves 51 bodies, none new and none stale, at llama.cpp 2b7960bae and at 0494dfa28. The self-test gains an f32-only truncf control (9 arms). Co-Authored-By: Claude Opus 5.5 --- tools/ci/hrx_f16_narrowing.py | 14 ++++++++++---- tools/ci/hrx_f16_narrowing.txt | 1 - 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/ci/hrx_f16_narrowing.py b/tools/ci/hrx_f16_narrowing.py index e163fe92f..21b0cea80 100755 --- a/tools/ci/hrx_f16_narrowing.py +++ b/tools/ci/hrx_f16_narrowing.py @@ -24,8 +24,8 @@ This is the ratchet: - * every .loom body that narrows f32 to f16 (scalar `f32 to f16`, vector `vector to vector`, - or `truncf`) is listed in + * every .loom body that narrows f32 to f16 (scalar `f32 to f16` or vector `vector to vector`) + is listed in tools/ci/hrx_f16_narrowing.txt, and a body that appears without a line, or a line whose body is gone, fails the check -- the two arms a ratchet needs (a list that can only grow cannot see a rename, engine#1728's lesson); @@ -49,8 +49,10 @@ BASELINE = pathlib.Path("tools/ci/hrx_f16_narrowing.txt") # The vector form is most of the corpus: `vector.fptrunc %x : vector<4xf32> to vector<4xf16>` contains neither # "f32 to f16" nor "truncf", and at llama.cpp 2b7960bae 132 of the 233 narrowing lines are written that way. -# Matching the scalar spelling alone listed 25 bodies; the corpus has 51 (engine#2204's review). -NARROW = re.compile(r"f32 to f16|vector<[0-9x]*f32>\s+to\s+vector<[0-9x]*f16>|truncf") +# Matching the scalar spelling alone listed 25 bodies; the corpus has 51 (engine#2204's review). A bare `truncf` is +# not a narrowing to f16: `scalar.truncf %v : f32` rounds within f32 (unary_f32_apply.loom), and every truncf that +# does narrow names its f16 type, which the two patterns below already match (engine#2220's review). +NARROW = re.compile(r"f32 to f16|vector<[0-9x]*f32>\s+to\s+vector<[0-9x]*f16>") GUARD = ("scale_log2", "prescale") @@ -149,8 +151,12 @@ def check_that(ok, what): new, _ = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) check_that(new == ["c.loom", "v.loom"], "a vector<4xf32> to vector<4xf16> narrowing is found, and a bf16 one is not") + (corpus / "t.loom").write_text(" %t = scalar.truncf %v : f32\n %u = vector.truncf %w : vector<4xf32>\n") + new, _ = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) + check_that("t.loom" not in new, "a truncf that stays in f32 is not a narrowing") (corpus / "v.loom").unlink() (corpus / "w.loom").unlink() + (corpus / "t.loom").unlink() (corpus / "c.loom").write_text(" %z = scalar.constant 0.0 : f32\n") (corpus / "a.loom").rename(corpus / "renamed.loom") new, stale = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) diff --git a/tools/ci/hrx_f16_narrowing.txt b/tools/ci/hrx_f16_narrowing.txt index 3926874c8..2c6eba434 100644 --- a/tools/ci/hrx_f16_narrowing.txt +++ b/tools/ci/hrx_f16_narrowing.txt @@ -40,7 +40,6 @@ loom-libs/motifs/q6_k_f16.loom loom-libs/motifs/q8_0_f16.loom loom-libs/motifs/q8_1_f16.loom loom-libs/motifs/quantize_q8_1_x4.loom -loom-libs/motifs/unary_f32_apply.loom loom-libs/ops/copy_f32.loom loom-libs/ops/flash_attention_decode_split_f32_f16_wmma.loom loom-libs/ops/flash_attention_f32_f16_wmma.loom From 951af924d56debadde3a75f1a8ce8040f7974bd1 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Wed, 11 Nov 2026 16:06:18 -0400 Subject: [PATCH 3/3] ci: an fptrunc the narrowing ratchet cannot classify fails the check (engine#2219) The review of 8614166 asked for a matcher that covers every spelling by construction rather than by type pattern. Matching the bare op would count f32 -> bf16 truncations, which cannot reach inf. Instead, every `fptrunc` line must now match the f16 patterns or a known non-f16 target (bf16). Anything else is reported as UNCLASSIFIED and fails the check, so the next unknown spelling cannot pass the way the vector form did. At 2b7960bae and 0494dfa28: 51 bodies, none new, none stale, 0 unclassified. Mutation (vector pattern removed): FAIL with 132 unclassified, the corpus's vector-form count. Self-test: 11 arms. Co-Authored-By: Claude Opus 5.5 --- tools/ci/hrx_f16_narrowing.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/ci/hrx_f16_narrowing.py b/tools/ci/hrx_f16_narrowing.py index 21b0cea80..5f7ad5185 100755 --- a/tools/ci/hrx_f16_narrowing.py +++ b/tools/ci/hrx_f16_narrowing.py @@ -71,6 +71,24 @@ def narrowing_bodies(corpus): return found +# Every `fptrunc` narrows to something, so one whose type pair neither NARROW nor KNOWN_NON_F16 recognises is a +# spelling this tool does not know yet. It fails rather than passing silently, the way the vector form did +# (engine#2219): a new spelling is classified by extending one of the two patterns, never by omission. +FPTRUNC = re.compile(r"\bfptrunc\b") +KNOWN_NON_F16 = re.compile(r"\bbf16\b|xbf16>") + + +def unclassified_truncations(corpus): + """`fptrunc` lines that are neither an f32 -> f16 narrowing nor a known non-f16 target, as (path:line, text).""" + out = [] + for path in sorted(corpus.rglob("*.loom")): + text = path.read_text(encoding="utf-8", errors="replace") + for number, line in enumerate(text.splitlines(), 1): + if FPTRUNC.search(line) and not NARROW.search(line) and not KNOWN_NON_F16.search(line): + out.append((f"{path.relative_to(corpus).as_posix()}:{number}", line.strip())) + return out + + def guarded(bodies, corpus): """Bodies that also carry a producer-side guard marker -- reported, never asserted.""" out = set() @@ -95,14 +113,19 @@ def check(root): found = narrowing_bodies(corpus) new, stale = drift(baseline, found) guard = guarded(found, corpus) + unknown = unclassified_truncations(corpus) + for where, text in unknown: + print(f"hrx_f16_narrowing: UNCLASSIFIED fptrunc at {where}: {text} -- its type pair matches neither the f16 " + f"patterns nor a known non-f16 target; extend NARROW or KNOWN_NON_F16 (engine#2219)") for rel in new: print(f"hrx_f16_narrowing: NEW narrowing body {rel} -- it narrows an f32 value to f16 and the " f"baseline does not name it; add the line and say what feeds it (engine#1962)") for rel in stale: print(f"hrx_f16_narrowing: {rel} is in the baseline but no longer narrows -- drop the line, the " f"list should shrink") - if new or stale: - print(f"hrx_f16_narrowing: FAIL ({len(new)} new, {len(stale)} stale of {len(baseline)})") + if new or stale or unknown: + print(f"hrx_f16_narrowing: FAIL ({len(new)} new, {len(stale)} stale of {len(baseline)}, " + f"{len(unknown)} unclassified fptrunc)") return 1 print(f"hrx_f16_narrowing: {len(baseline)} narrowing body(ies), none new, none stale; " f"{len(guard)} of them carry a guard marker" + @@ -154,6 +177,12 @@ def check_that(ok, what): (corpus / "t.loom").write_text(" %t = scalar.truncf %v : f32\n %u = vector.truncf %w : vector<4xf32>\n") new, _ = drift(baseline_paths((root / BASELINE).read_text()), narrowing_bodies(corpus)) check_that("t.loom" not in new, "a truncf that stays in f32 is not a narrowing") + check_that(unclassified_truncations(corpus) == [], + "an f16 and a bf16 fptrunc are both classified") + (corpus / "x.loom").write_text(" %h = vector.fptrunc %v : vector<[4]xf32> to vector<[4]xf16>\n") + check_that([w for w, _ in unclassified_truncations(corpus)] == ["x.loom:1"], + "an fptrunc spelling the patterns do not know fails as unclassified, not silently") + (corpus / "x.loom").unlink() (corpus / "v.loom").unlink() (corpus / "w.loom").unlink() (corpus / "t.loom").unlink()