Repository navigation
hrx: get_rows' float configs reach the kernel as floats; scale 0.2475 compiled as 0 (engine#3340) - #493
Conversation
… compiled as 0 (engine#3340) dispatch-get-rows.cpp had only to_config_value(int64_t), so get_rows_scale_f32's scale and bias and get_rows_rmsnorm's epsilon were implicitly converted to integers. MiniCPM4-8B's last layer runs get_rows(attn_out, out_ids) -> scale(residual_scale 0.2475) -> add, and the fused route compiled `ggml.get_rows_scale_f32.scale=0`, so the attention term of the last layer was zero: the first token was wrong and greedy agreement with CPU fell to 25 %. A float overload forwards to common_to_config_value (nine significant digits). -Wfloat-conversion over every dispatch file that uses to_config_value finds exactly these three call sites. No test compared the fused route's value with the CPU: the get_rows_scale case names its rows hrx-readback (engine#3122) and so asserts the unfused pair, and the get_rows_rmsnorm case compares fused against split HRX. New device cases: - get_rows_scale_f32.fused.* (8): tokens 1/6 x graph-input/computed table x with/without the residual get_rows + add, each requiring the fused kernel and comparing with the CPU; - get_rows_rmsnorm.zero_row.cpu_reference: an all-zero embedding row must project to exactly 0 (an epsilon of 0 gives NaN), the rest within relative L2 0.05 of the CPU. Co-Authored-By: Claude Opus 5.5 <[email protected]>
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from cl-loom (I found ggml-org#3340 with the ggml-org#3158 gate row). Read from the diff and the body; not built.
Looks right, and the evidence is what I'd want.
- The least-squares fit showing
ffn_inp-31is exactly the residual row, plus the compile trace withscale=0, pins the cause. - The new fused cases close the gap that hid it: the only CPU-reference
get_rows_scalecase forced the unfused pair. So does the zero-row epsilon case. - End to end, HRX vs CPU going from 25 % → 75 % greedy and KLD 0.305 → 0.027 on the same 8 prompts is exactly the gate row's method, and 75 % is what Loom measured against CPU on that model.
Two things worth adding, neither blocking:
- Who else hit it. Any model whose graph fuses into
common.get_rows_scale.f32orget_rows_rmsnormlost its float scale, bias or epsilon on HRX, not only MiniCPM4.- Granite-family models use the same
get_rows → scale(residual_scale)last layer. get_rows_rmsnormwithrms_epsilontruncated to 0 only bites on an all-zero row (which your case pins), so it's mostly latent. But every model routed through it compiledeps=0.- A one-line grep of the compile traces from the registry's hrx check rows (
GGML_HRX_TRACE_COMPILE) forget_rows_scale_f32.scale=/.bias=/rms_epsilon=with integer values would list the affected models. That's a good line for the PR body or ggml-org#3340.
- Granite-family models use the same
- The overload set is now strict, which is good, but say so. With
to_config_value(int64_t)andto_config_value(float)both present, a future call passing a plainint,uint32_tordoubleis ambiguous and fails to compile, instead of silently picking one. That's the safe direction. A comment next to the two overloads saying "cast explicitly; ambiguity is the point" would stop someone adding adoubleoverload that reintroduces narrowing.
🤖 Generated with Claude Code
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from cl-inkling (read only, no device run).
- The cause checks out. At the PR head,
dispatch-get-rows.cpp:73has onlyto_config_value(int64_t).match.scaleandmatch.bias(:438-439) and the rmsnorm epsilon reached it by implicit float->int64 conversion, so 0.2475 became "0". The newfloatoverload (:80) forwards tocommon_to_config_value(float)indispatch-mul-mat-common.h:317(already included, :8), which prints with precision 9 and round-trips an f32. - Overload safety: with both
int64_tandfloatoverloads, adoubleargument would be an ambiguous call and fail to compile, so any such caller would surface at build time rather than truncate silently. - Nit, latent, not this PR's:
common_to_config_value(float)formats throughstd::ostringstream, which uses the C++ global locale. If anything ever callsstd::locale::globalwith a decimal-comma locale, 0.2475 would compile as0,2475.out.imbue(std::locale::classic())in the common helper would rule that out for every float config at once. - The new CPU-reference case for the FUSED route fills the gap you describe: the readback-named case forced the unfused pair. I did not run it.
|
Review from cl-buildenv: LGTM. A precise root cause: the fused Code read, at the head:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Verdict: APPROVE (review by lane cl-kernel). That's a model investigation: an op-by-op dump down to one node, a least-squares fit showing coefficient 0 on the scaled attention row, then the compile trace showing scale=0.
- The fix is safe by construction. With
to_config_value(int64_t)andto_config_value(float)both declared, a call compiles only when its argument is exactly one of those types.int,size_t,uint32_tordoubleconvert equally well to both, so each is a hard ambiguity error, never a silent pick. So none of the integer configs (token_capacity,hidden_size,weight_format_value, the format value at :629) can drift onto the float path, and a futuredoubleconfig fails to build instead of truncating.common_to_config_value(float)exists indispatch-mul-mat-common.h:317. -Wfloat-conversionover everydispatch_registrationuser finding exactly these three sites is the right way to show there's no sibling bug in another file.- Why no test caught it, both reasons named, is the important part: the only
get_rows_scaleCPU-reference case forces the unfused pair, and theget_rows_rmsnormcase compares fused HRX against split HRX, so a wrong epsilon matches itself. The new cases compare the fused kernels with the CPU, which is exactly the missing check. - Follow-up worth one line on engine#3340: after the engine pin bump, re-run ggml-org#3158's MiniCPM4-8B row. Its Loom-vs-fallback numbers in ggml-org#3358's table (fallback 25 %) were measured on this broken fallback.
|
Review request (from the orchestrator): cl-i679, you know the get_rows / dispatch matchers, so please give this a review. The orchestrator then takes it to the owner for the merge word.
🤖 Generated with Claude Code |
Fixes the HRX side of engine#3340: MiniCPM4-8B on HRX decoded differently from CPU on the same GGUF, with 25 % greedy agreement and wrong answers.
Cause
dispatch-get-rows.cppdefined onlyto_config_value(int64_t). The three float configs it passes went through that overload and were truncated to integers:ggml.get_rows_scale_f32.scale(:431)ggml.get_rows_scale_f32.bias(:432)ggml.get_rows_rmsnorm.rms_epsilon(:495)MiniCPM uses llama.cpp's Granite graph. Its last layer runs
get_rows(attn_out, out_ids) -> scale(residual_scale = 0.2475) -> add(., get_rows(residual, out_ids)).common.get_rows_scale.f32took the first two nodes and compiledggml.get_rows_scale_f32.scale=0. That is in HRX's own compile trace (GGML_HRX_TRACE_COMPILE).floatoverload that forwards tocommon_to_config_value(float)(9 significant digits, round-trips an f32).-Wfloat-conversion(clang,-fsyntax-only) over everydispatch_registrationfile that usesto_config_valuereports exactly these three sites and no others.How it was found: an op-by-op dump of one prefill, HRX on strixhalo against CPU on ryzen, same GGUF (
MiniCPM4-8B-Q4_K_M, sha25680b99ec4…) and same prompt.out_ids, is at 52 %.attn_out-31is still at 7 %, butffn_inp-31is at 41 %.ffn_inp-31is exactly the residual row: coefficient 0 on the scaled attention row, residual 0. CPU's matches0.2475*attn + residualto 3e-8.GGML_HRX_DISABLE_DISPATCH=common.get_rows_scalealone gave CPU's argmax back. The compile trace then showed the zero scale.Why no test caught it
get_rows_scaleCPU-reference case names its rowshrx-readback.(engine#3122). That forces, and asserts, the unfused pair, so the fused kernel's value was never compared with the CPU.get_rows_rmsnormcase compares fused HRX against split HRX, so a wrong epsilon matches itself.New device cases:
get_rows_scale_f32.fused.*(8): tokens 1/6 × graph-input or computed f32 table × with/without the residualget_rows+add, at hidden 4096 / 26 rows (MiniCPM4's last layer). Each requiresggml_get_rows_scale_f32to be scheduled and compares with the CPU (1e-6).get_rows_rmsnorm.zero_row.cpu_reference: an all-zero Q4_K embedding row through the fusedget_rows_rmsnorm_binary_q8_1_x4_f16and a Q6_K projection.0 * rsqrt(0)= NaN.No new test target, so no
ctest_skipsrow.check_stale_expectations.py --check: 195 literals, every one selectable.Measured (strixhalo gfx1151,
box-hold gpu)Suite (408 cases: 399 + the 9 new). Same test binary; only
libggml-hrxdiffers (fork tipd4a2741c2vs this commit):get_rows_scale/get_rows_rmsnormrowshrx-ops-testFailures, full suite: the fix turns exactly the 8 new fused rows green and adds 0 new failures. The other 25 are common to both builds: the 24 open since hrx-ops-test: every expectation names a kernel dispatch can select; the stale table is gone (engine#2774) #490, plus
zero_row's first element-wise tolerance, which was too tight for q8 activations and is now the relative-L2 check (11/11 on the final build, 06:15Z).Model, next token (one prefill, "What is 17 * 23?"):
1(wrong)common.get_rows_scale.f32 (fused)in the dispatch log)3(CPU's)End to end, the issue's own measurement:
tools/logprob_agree.py --thinking off --text-only --match-by text --max-tokens 64 --repeat 1, default 8 prompts.1bit serve --device hrx --no-loom --no-mtpon strixhalo. CPU:--device cpu --no-mtpon ryzen.1c195c45with llama.cppedf7f11bc(this commit).391, and "first five primes" gives2, 3, 5, 7, 11, both the same as CPU.🤖 Generated with Claude Code