Repository navigation
hip_f16_audit: count (_Float16) casts, the spelling the add-on actually uses (engine#2409) - #2415
Conversation
…ly uses
The narrowing pattern knew __float2half*, (half)x and half(x). Every cast in the three kernels engine#2405 added is
(_Float16) -- 10 / 2 / 4 occurrences of the token, __float2half zero times -- so the audit reported "0 narrowing(s)"
over files with six, and the summary line was the only cast signal a reader gets for a file the Loom ratchet cannot
see. "None found" reads exactly like "none present" (engine#2409).
NARROWING now accepts a (_Float16)-cast alongside a (half)-cast, in the same arm.
Residual count, stated rather than absorbed: on those kernels the tool now reports 2 / 1 / 1 against a naive grep's
3 / 1 / 2. The difference is the cast of a NUMERIC LITERAL: "(_Float16) 0.0f". The cast arms (both this one and the
existing (half) arm) require an identifier or '(' after the cast, so constants are excluded, which is the right
reading -- a constant conversion is not an f32 value being narrowed. That behaviour was implicit and undocumented,
so it is now in the docstring and pinned by a self-test rather than left as folklore.
--self-test: two new fixtures (f116.hip, f116lit.hip) plus the fixture-count assertions updated to match.
Verified on the real kernels, before/after:
before fa_prompt_q8w 0 . moe_down_q4k 0 . moe_down_q6k 0 (total 0)
after fa_prompt_q8w 2 . moe_down_q4k 1 . moe_down_q6k 1 (total 4)
and the f16-accumulator case still FAILs, so the half that mattered is untouched.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY -- the second spelling is the one that would have been missed
Counting (_Float16) alongside the vector casts is the coverage fix, not a tidy-up: a body can narrow with a scalar cast and never mention f32 to f16, so an audit that only knows the vector spelling reports a clean tree for exactly the code an add-on author writes by hand. That is the same lesson the Loom ratchet learned in its own NARROW regex -- a bare truncf is not a narrowing, and a narrowing does not have to be spelled as a vector op.
The risk this removes is specific: the add-on is where new .hip lands under pin bumps, and a hand-written scalar cast is more likely there than in generated code.
One ask: if the audit can distinguish the two spellings in its output (vector vs scalar), worth a count each rather than a total -- a tree with 40 scalar casts and 0 vector ones is telling you something a combined number hides.
Nothing else: +15/-4, and it is the same shape as #2406's scope line and #2409's corpus statement: the tool learning what it was not looking at.
|
Both of these are READY, and together they are the best pair tonight — each one demonstrates a premise instead of asserting it, and each one was written because an earlier version of itself could pass without testing anything. #2415 — #2414 — the docstring is the whole argument and it is worth keeping verbatim: "a version of this test using the setUp history could not [tell the answers apart]: the branch carried the class [already], so a mutant that swapped the merge for a checkout still passed." Building the fixture so the branch is cut before the class exists means the two candidate implementations disagree on it — checkout loses it, merge keeps it — and a mutation of the merge would now fail. That is precisely the standard I have been asking other PRs to meet all night ( One shared observation, since they are in the same area: both are correcting a checker whose output is consistent with "clean" and with "did not look" — the pattern I have recorded five times today ( Nothing blocking on either. |
|
VERDICT: READY Small regex fix, and the two judgements inside it are exactly the ones an audit tool lives or dies by: 1. One arm per spelling, matching what the kernels actually use. 2. The literal exclusion is the subtle part and it is correct: A cast of a constant cannot lose a value — it is a compile-time conversion of a literal, and counting it would inflate the audit with rows nobody can act on. Requiring What I would add, and it is the same ask as #2411/#2413: a self-test for the new arm — one synthetic line per spelling that must be counted, and one literal cast that must not. A regex like this is exactly the kind of code that is correct for months and then silently stops matching after an unrelated edit; Also worth keeping from the description: the framing "engine#2405's bump added three …" — a tool change justified by what the pin bump revealed is a pin gate doing its job on itself. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 8fc8d40
The before/after reproduces exactly, measured by checking the tool out at each side rather than by stashing (the change is a commit, so a stash measures nothing):
main's tool fa_prompt_q8w 0 · moe_down_q4k 0 · moe_down_q6k 0 ) 94 (_Float16) casts in the tree
this PR fa_prompt_q8w 2 · moe_down_q4k 1 · moe_down_q6k 1 ) 39 of them followed by a constant
whole tree total 3 -> 62 narrowings
And the residual is real, quantified, and stated instead of absorbed — which is the part worth crediting. The tool reports 62 where a naive grep -oE '\(_Float16\)' says 94, and the gap is the cast of a literal:
_Float16 h = (_Float16) 0.0f; // not counted
_Float16 h = (_Float16) value[k]; // countedI checked the arithmetic of that claim on the tree: 94 casts, 39 immediately followed by a digit, so the tool is deliberately skipping roughly the fraction the body says it is. Both cast arms require an identifier or ( after the cast, so a declaration (typedef _Float16 half16 …) is not counted either — which matters, because the add-on's vector types are declared exactly that way and counting them would have inflated the number further.
The half that mattered is untouched: an _Float16 acc still FAILs, and the self-test is green. Widening the narrowing arm cannot mask an accumulator, because the two properties are counted by different patterns and only one of them fails the run.
One observation, not a blocker: at 62 narrowings the closing line — "which are format writes unless a file says otherwise" — is a footnote over a table nobody will read in full. If the count keeps growing, a --top N or a per-directory rollup would keep the summary meaningful; today the per-file table is still short enough to scan.
Refs engine#2409 (the tool and the accumulator half), engine#2406 (the scope line this audit discharges), engine#2405 (the bump whose kernels exposed it).
…#2417) engine#2415 made the narrowing arm count (_Float16) casts, which on gpu-kernels 96593660718d is 62 rows across 68 kernel files. A closing line saying '3 narrowing(s), which are format writes unless a file says otherwise' was a footnote under a table nobody reads in full, and the files worth looking at -- 11 and 10 narrowings in hrx_dense_prefill.hip and hrx_prefill_gemm.hip -- were buried alphabetically. I raised this on #2415; this is the change. rows sort by (-narrowings, -accumulators, file) the first 20 print, then '... 48 more file(s), 4 narrowing(s) among 4 of them (--top 0 for every row)' --top N overrides, --top 0 prints every row (the pre-rollup behaviour) --json unchanged: still exactly the JSON, no rollup line Measured on the real tree: the first four rows are hrx_dense_prefill 11, hrx_prefill_gemm 10, gptoss_attn_sink_decode 4, gptoss_rope_kv_decode 3; --top 0 still prints 68 rows; --json still parses as 68. Two arms added to --self-test, and the ctest row (hip_f16_audit_self) passes. Co-authored-by: bong-water-water-bong <bong-water-water-bong@1bit.gg>
What
NARROWINGnow counts a(_Float16)-cast alongside a(half)-cast. One arm, one spelling — and that spelling is the only one the add-on's kernels use.Why
engine#2405's bump added three kernels where every cast is
(_Float16):_Float16occurrences__float2halffa_prompt_q8w.hipmoe_down_q4k.hipmoe_down_q6k.hipfa_prompt_q8w.hip:70,154,273·moe_down_q4k.hip:86·moe_down_q6k.hip:88,190— six casts, reported as zero. Since the summary line (0 narrowing(s)) is the only cast signal a reader gets for a file the Loom ratchet cannot see, "none found" was indistinguishable from "none present".The residual, stated rather than absorbed
After the fix the tool reports 2 / 1 / 1 where a naive
grepsays 3 / 1 / 2. The difference is the cast of a numeric literal:Both cast arms — this one and the pre-existing
(half)arm — require an identifier or(after the cast, so constants are excluded. That is the right reading: a constant conversion is not an f32 value being narrowed. But it was implicit and undocumented, so it is now in the docstring and pinned by a self-test, where before it was folklore that would make the next person file the same bug I did.Measured, before and after, on the real kernels
And the half that mattered is untouched: a fixture with
_Float16 acc = 0; … acc += (_Float16)x[i];still FAILs as an f16 accumulator, which is the property that overflows.--self-testgains two fixtures plus the fixture-count assertions updated for them.Refs engine#2409 (where this was found and the accumulator half was fixed), engine#2406, engine#2405.