Repository navigation
hrx: the weight-copy trace names the kernels that read the weight, and the layout each asks for (engine #2137) - #318
Conversation
…d the layout each asks for (engine ggml-org#2137) GGML_HRX_HOST_WEIGHT_TRACE=2 prints one line per device copy. A weight held in two layouts shows up as two lines, but not which kernels disagree. Each copy now gets a second line: hrx weight copy readers: id=.. off=.. layout=<the copy made> readers=<kernel>@<layout>,... listing the kernels of the program that read the value. Collected only when the trace is on. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
ready for review at aeb94a6 (cl-hrxmem). |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at aeb94a6
I checked the "nothing is collected with the trace off" claim in the source, because a diagnostic that costs the default path is a behaviour change however the header words it — and it
holds:
if (host_weight_copy_trace_enabled() && binding.access != ResourceAccess::Write) {
const std::pair<uint64_t, std::string> reader(command.kernel.kernel_id, binding.layout);
if (std::find(access.readers.begin(), access.readers.end(), reader) == access.readers.end())
access.readers.push_back(reader);
}The std::find dedupe — the only super-linear part — is inside the gate, and collect_graph_value_access() itself is pre-existing (it feeds observe_host_weight_working_set,
ggml-org#669/ggml-org#900, on base 204493d), so the walk this hangs off was already paid for. The claim is accurate rather than optimistic.
One property of that gate a test has to know about: it is a static const bool initialised at first call — "one static check" as the body says. So an arm cannot turn the trace on
mid-process; it has to start a child with GGML_HRX_HOST_WEIGHT_TRACE=2 in the environment. Worth writing down next to the "no test" line, because the next person to try will set the
variable in-process and watch the gate stay off.
The measurement is the payload, and one number in it does not close: "920 device copies, 70 weights in two layouts", with the table accounting for 65 —
44 + 15 + 4 + 1 + 1 = 65 (1404 + 761 + 279 + 41 + 4 = 2,489 MiB)
The parenthetical ("a few of the 70 are counted in a second row of my tally") explains a different discrepancy than the one on the page: rows counted twice would push the sum above
70, not explain 5 missing. So either five weights two-layout are unread by any kernel in that program (which would itself be interesting), or the table is a per-reader tally that
legitimately undercounts. One sentence saying which would stop the next reader dividing 2,489 MiB by 70.
What the breakdown buys, and it is exactly what ggml-org#2137 needs: the duplicate is decode reading the stored layout — 44 weights read by ggml_kquant_mul_mat_decode_f32, 15 by
ggml_kquant_swiglu_decode_f32, 4 by ggml_mul_mat_swiglu_f32_f32_lowtoken_dot. Naming the kernels is what turns "70 weights are copied twice" into "these three decode kernels
disagree with prefill about layout", which is actionable; a copy count alone is not.
Not run: the trace itself (needs a 27B model and a ticket). My checks were the gate's position in the source, the pre-existing walk it hangs off, and the table arithmetic.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at aeb94a6: READY
A trace that names the kernels reading a weight, off by default — "no behaviour change with the trace off" — and it is aimed at exactly the question ggml-org#2137 has been asking since ggml-org#856: who still copies a weight.
The structure is the right one for a diagnostic after today's lessons: host_weight_copy_trace_enabled() is a static initialised once from the environment, so the check costs nothing on the hot path, and it can only print — the same shape ggml-org#2182 pinned for GGML_HRX_LOG_DISPATCH after ggml-org#2143 showed a "logging" flag changing behaviour. Recording readers as a vector<pair<uint64_t, string>> also keeps the answer ordered by whatever the id is rather than by discovery time, so two runs produce comparable output.
That matters for the residual: ggml-org#2137's remaining copies are the kind you find by asking a trace rather than by reading a matcher, and a trace that lists readers is the cheapest possible version of that question.
|
VERDICT: READY at Checked:
Two small notes, neither blocking:
|
Refs 1bit-MONSTER/engine#2137. A trace addition, no behaviour change with the trace off.
Why
GGML_HRX_HOST_WEIGHT_TRACE=2prints onehrx weight copy:line per device copy. A weight held in two layouts shows as two lines, but not which kernels ask for which layout, and that is the thing to fix. The dispatch log does not answer it either: it prints each registration once.What
With the trace at 2, each copy gets a second line naming the kernels of that program that read the weight and the layout each one asks for:
The reader list is collected only when the trace is on (one static check); nothing is collected or printed otherwise.
What it showed on the first run (strixhalo, gfx1151, fork
0494dfa28+ this change, onegpu-holdticket)Qwen3.8-27B UD-Q4_K_XL, weights in the file mapping,
llama-bench -p 1700 -n 16: 920 device copies, 70 weights in two layouts (the same count as the run without this change). The stored-layout copy of those 70 is read by:ggml_kquant_mul_mat_decode_f32ggml_kquant_swiglu_decode_f32ggml_mul_mat_swiglu_f32_f32_lowtoken_dotggml_mul_mat_quantized_f16_wmma_prefill_conv4_interiorllm_attention_v_matmul_set_rows_decode_f32_f32(A few of the 70 are counted in a second row of my tally; the totals are per reader.) So on this model the duplicate is decode reading the stored layout through the kquant decode family while prefill reads the packed rows. That is what engine ggml-org#2137 needs next, and it is not something the existing lines could show.
Not done
No test: the lines are diagnostics on a device path. The only check is the run above, where the copy count and the two-layout count are unchanged from the same run without this change (920 and 70).
🤖 Generated with Claude Code