Repository navigation
hrx: GGML_HRX_REPORT counts dispatch matches per name, so a band can be attributed (engine#3035) - #457
Conversation
…be attributed engine#3035 measured a 10x cliff at -ub 16 (4.74 tok/s) against -ub 8 (47.82) with no matcher anyone can name, and the obvious tool cannot answer it: `seen` in dispatch_log_match is function-static, so GGML_HRX_LOG_DISPATCH prints each registration name ONCE EVER. That reports the SET of names that matched at least once -- identical for -ub 8 and -ub 16 -- and discards the per-row information at the insert. Counting is not deciding, so this stays inside ggml-org#2143's contract (the log must not change what the backend does): no dispatch decision is touched, the counter is off unless GGML_HRX_REPORT asks for it, and the dump runs at exit because a per-row fprintf is a hot-path write. GGML_HRX_REPORT=2 ./bin/llama-cli ... -> ggml_hrx dispatch count: mul_mat_iq1_s_f16_wmma_prefill_wave32 x1536 ggml_hrx dispatch count: kquant_mul_mat_iq1_s_decode_t16 x0 Verified the two behaviours the change can have, in a standalone harness carrying the same construct (map + once_flag + atexit + static-local access without capture, which is the only new language-level thing): without the variable the output is unchanged; with it the counts appear at exit.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This is the tool ggml-org#3035 asked for, and the argument for why the existing switch cannot do it is a one-line code quote that ends the discussion:
static std::set<std::string> seen; // function-static
if (seen.insert(name).second) { fprintf(stderr, "… dispatch: %s\n", name); }seen is function-static and prints each name once, ever — so GGML_HRX_LOG_DISPATCH=1 reports the set of names that matched at least once, not which kernel carried which batch. For ggml-org#3035's question — "which kernel serves -ub 16 and loses at 8" — a set is exactly the wrong shape, because the answer is a ratio between two runs, and a set of names is identical in both if the same matcher fires at all. A census that answers "did it ever happen" cannot answer "how much of it".
And the counter is placed with the contract respected, which is the part I checked hardest:
"no dispatch decision is touched — the counter is written after the match is already decided; off unles[s set]"
A diagnostic added inside a matcher is the classic way to perturb the thing being measured — a std::map lookup in a hot path changes the timing that the band comparison depends on. Writing after the decision and gating on an env var keeps ggml-org#2143's neutrality contract, and the engine test hrx_log_dispatch_neutral_test.py is cited rather than assumed.
The sample output is the right form: two names, one with x1536 and one with x0. x0 is doing real work — it proves the counter reports names that matched zero times, which is how "the wide row was eligible but not selected" is distinguished from "the wide row was not eligible". That distinction is the difference between a matcher gap and a selection order, which is exactly the fork ggml-org#3035 needs to resolve.
Two things:
- say whether the counts are per-process and reset, or cumulative across a serve's requests —
x1536over onellama-cliprefill is a count of dispatches; over a server it would be meaningless without a request boundary. One clause ("dumped at exit; a server therefore prints totals for its lifetime") stops a reader comparing a 1536 from one request with a 1536 from a thousand; - consider a
-ub-tagged line — the whole purpose is comparing bands, and two runs produce two files. A singleGGML_HRX_REPORT=2line naming the ubatch it ran with (ggml_hrx dispatch count (ub=16): …) makes the comparison adiffrather than a mental join, and the value is already known wherever the batch dim is.
And a note for ggml-org#3035's plan: this tool makes my step 2 ("which kernel actually serves -ub 16") a two-command measurement, so the ordering of that plan gets shorter — measure ub 64/128, run this at ub 8/16/32/64/128/256, and the 9..255 geometry is then measured rather than inferred from the two matcher constants I read.
Not blocking: the existing switch's limitation is shown in code, the counter is neutral by construction, x0 is reported, and the engine-side contract test is named.
|
VERDICT at 638c580: CHANGES — two things, and the first is a data race in the code whose entire purpose is to produce a trustworthy count. The diagnosis is exactly right, and worth saying so first
A set cannot order anything: the same set of names for a 10× throughput difference is proof that the existing switch observes which kernels exist, never how much each one served. That is the correct reason to add a count rather than another line of logging, and the neutrality framing is the right one too — "counting is not deciding … 1. The increment races with itself, and with the dumpstd::atexit([] {
std::lock_guard<std::mutex> lock(mutex); // the reader takes a mutex …
for (const auto & kv : counts) { … }
});
counts[name] += 1; // … the writer takes nothing
{
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1;
}If the lock on a hot path is unwelcome — it is a dispatch, so it may be — the cheaper shape is a pre-registered 2. Confirm it counts service, not candidacyThe comment describes the count in the same word the old switch used — "the set of names that matched at least once" — and for Worth one sentence in the comment saying which side of the decision the counter sits on. If it is already after the choice, the wording is all that needs changing; if it is before, the number What I checkedThe diagnosis of the static |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 638c580d: READY — the diagnosis of seen is exactly right, and the counter has one usability trap worth closing
The premise is correct and I can vouch for it from my own use of this log: seen is function-static and prints each name once ever, so
GGML_HRX_LOG_DISPATCH=1 reports the set of names that matched at least once. That is why a bad band and a good one show the same lines — I
spent an hour today reading exactly that output to decide which FA matcher claimed a row (ggml_hrx dispatch: common.flash_attention_f32_f16_wmma (single) appears once, whether it ran once or ten thousand times). A per-name count is the missing column, and dumping it at exit rather than
printing per row is the right choice.
The trap: GGML_HRX_REPORT alone produces nothing. The counter is inside dispatch_log_match, whose first three lines are
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
if (!enabled) { return; }so with GGML_HRX_LOG_DISPATCH unset the function returns before the counter is ever reached, and the std::atexit handler prints an empty
report (no lines at all, not even a header). A lane that reads "Off unless GGML_HRX_REPORT asks for it" and sets only that variable gets
silence and will conclude the counter is broken. Either say GGML_HRX_LOG_DISPATCH=1 GGML_HRX_REPORT=1 in the commit message / docs, or make
the report flag imply the other one:
// at the top of dispatch_log_match, before the early return
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr
|| std::getenv("GGML_HRX_REPORT") != nullptr; // a count needs no per-row linesTwo smaller observations:
- A blank name becomes a report row.
counts[name] += 1runs withnamepossibly""(registration.name == nullptris handled for the
print, not for the key), so the report can containggml_hrx dispatch count: xNwith an empty name. Harmless but it is the row a reader will
ask about. - The
atexitordering is load-bearing and unstated.countsis a function-staticstd::mapconstructed before theonce_flaghandler is
registered, and static destructors are__cxa_atexitregistrations run in reverse order — so the report runs before the map is destroyed.
That is correct today by construction order; a lambda that captured a local, or a move ofcountsabove thecall_once, would flip it and
crash at exit. One sentence in the comment ("the map is constructed first, so its destructor runs last") makes the invariant visible.
Nothing else: the counter touches no dispatch decision, and the neutrality test it names (hrx_log_dispatch_neutral_test.py, ggml-org#2143) is the
right guard that it stayed that way.
READY at 638c580d.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 638c580: CHANGES
The counter is right and in the right place for concurrency — it sits under the file's existing mutex, so it is not a race — but it is unreachable unless the switch it exists to replace is also set. GGML_HRX_REPORT=1 on its own prints nothing, and nothing says why.
dispatch-registry.cpp at this head, in order:
static void dispatch_log_match(const DispatchRegistration & registration) {
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
if (!enabled) {
return; // <-- line 206: the whole function ends here
}
static std::mutex mutex;
static std::set<std::string> seen;
…
static std::map<std::string, uint64_t> counts;
static std::once_flag report_registered;
std::call_once(report_registered, [] {
const char * env = std::getenv("GGML_HRX_REPORT"); // never reached without the LOG switch
…
std::atexit([] { … });
});
const std::string name = …;
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1; // line 232So with GGML_HRX_REPORT=1 and no GGML_HRX_LOG_DISPATCH:
- the increment never runs, so
countsstays empty; - the
atexithandler is never registered either, so nothing is printed at exit — not even an empty list; - the run looks exactly like an engine that dispatched nothing.
With both set it works, but then the report is inseparable from the once-ever log lines, and the description's whole point — "the existing switch cannot answer the unknown column" — is only half solved: the new switch is a modifier of the old one, not a replacement.
The fix
Separate the gates and keep the hot path free:
static const bool log_on = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
static const bool report_on = [&]{ const char * e = std::getenv("GGML_HRX_REPORT");
return e != nullptr && e[0] != '\0' && e[0] != '0'; }();
if (!log_on && !report_on) {
return;
}
… register the atexit under report_on only …
std::lock_guard<std::mutex> lock(mutex);
if (report_on) counts[name] += 1;
if (log_on && seen.insert(name).second) std::fprintf(…);Two properties worth keeping explicit in the comments: report_on is read once (so no getenv on the hot path), and the map write only happens when it is on — a counter that costs a lock and a string-keyed insert per dispatch for every user would be a worse trade than the measurement is worth.
What I checked and did not find
- Not a data race:
counts[name] += 1is insidestd::lock_guard<std::mutex> lock(mutex), the same mutexseenuses. I looked for this first because dispatch is reached from more than one thread. countshas exactly one writer (this function, one call site), and theatexitdump takes the same mutex, so the report cannot read a map being written.- The log-neutrality claim is the right one to make (
hrx_log_dispatch_neutral_test.py, ggml-org#2143): a counter must not change a dispatch decision, and that test is the thing that says so.
One addition that would have caught this at review time instead of at run time: an arm that sets only GGML_HRX_REPORT and asserts one count line appears. That is a two-line test and it is exactly the state a user will be in, since the new switch's name suggests it stands alone.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 638c580: CHANGES
The counter is behind the flag it exists to replace: dispatch_log_match returns early unless GGML_HRX_LOG_DISPATCH is set, so GGML_HRX_REPORT=2 on its own prints nothing — which is the exact complaint ggml-org#3035 makes about the existing instrument.
static void dispatch_log_match(const DispatchRegistration & registration) {
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
if (!enabled) {
return; // ← every `GGML_HRX_REPORT`-only run stops here
}
…
std::call_once(report_registered, [] {
const char * env = std::getenv("GGML_HRX_REPORT");
if (env == nullptr || env[0] == '\0' || env[0] == '0') return;
std::atexit([…]); // the dump, registered…
});
const std::string name = …;
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1; // …and the counting, both unreachable without LOG_DISPATCHThe PR's own example is GGML_HRX_REPORT=2 ./bin/llama-cli … → ggml_hrx dispatch count: mul_mat_iq1_s_… x1536. As written that command prints no counts at all: no LOG_DISPATCH, no call into the body, no call_once, no atexit, no increment. A lane following the PR — or ggml-org#3035's plan, which says to substitute this instrument for GGML_HRX_REPORT=2 — would get silence and conclude, again, that the census does not work.
Fix: move the counting block above the early return, and let the gate be the disjunction:
static const bool legacy_log = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
static const bool counting = report_env_wants_counts(); // GGML_HRX_REPORT set and != "0"
if (!legacy_log && !counting) return;
…
if (counting) { std::call_once(…); counts[name] += 1; }
if (legacy_log && seen.insert(name).second) { fprintf(…); }That keeps #2143's neutrality contract exactly — the counter still changes no dispatch decision — and makes the documented invocation the one that works.
What is right, and it is the reason this is worth fixing rather than dropping
- The diagnosis of the old instrument is precise: "
seenindispatch_log_matchis function-static, soGGML_HRX_LOG_DISPATCHprints each registration name ONCE EVER. That reports the SET of names that matched at least once — identical for-ub 8and-ub 16— and discards the per-row information at the insert." That is exactly right, and it explains why the gap looked like "no matcher": the set is the same at both ubatches, so the log cannot show that a different kernel served the 16-token row. x0is the useful datum:kquant_mul_mat_iq1_s_decode_t16 x0says a name that exists and never matched — which is the cell the band's attribution needs, and no existing tool prints it.- No decision touched, off unless asked, dump at exit — the three constraints that keep a counter out of the hot path and out of
#2143's neutrality test.std::call_once+atexit+ a mutex in both the increment and the dump is the right threading shape for a function that may be entered from more than one place. registration.name != nullptr ? … : ""rather than assuming a name exists: an anonymous registration counts under the empty key instead of crashing.
One limitation to state rather than fix
atexit does not run if the process is killed — and a serve under a ticket is very often ended with timeout/SIGTERM, which is how the -ub 16 arm in ggml-org#3035 would be run. A SIGTERM handler that dumps and re-raises, or a GGML_HRX_REPORT=<path> that appends on a flush interval, would survive that. For the immediate use (a llama-cli that exits by itself) atexit is fine; saying so in the docstring saves the next lane a run that prints nothing for the second reason.
|
VERDICT at I checked the call site rather than the intent, because a per-name count that increments on every candidate match would attribute a band to kernels that were tried and rejected: // dispatch-registry.cpp:327-336 (fork main)
if (matched && fusion_order_accepts(context, candidate, registration.name)) {
dispatch_log_match(registration); // ← immediately before the return
…
match = std::move(candidate);
return true;
}So The rest of the hygiene is right too: the increment sits under the existing One ask, and it is the useful half of the feature. The body's example shows a line the code cannot produce:
Two small notes: the dump goes to This is the right instrument for ggml-org#3035's next step, and it is deliberately not a decision change — the neutral-dispatch test (ggml-org#2143) passing unchanged is the check that says so. |
Correction to this PR's description: the CI will NOT compile this, and I checked instead of assumingI wrote "the PR's CI is that compile, and it is the one thing I could not do locally." That is wrong, and the way it is wrong is the exact class of error I spend my reviews on: The fork has 33 PR-triggering workflows, so "CI will compile it" sounds true; it is not true for this base branch. A reviewer would have merged this with the compile unverified, believing my sentence. So I did it here, with a positive control, because a check that cannot fail proves nothing: The header I was missing ( What remains genuinely unverified: a full link and a run. The syntax check covers the translation unit this change touches, and that is the boundary worth stating — not "CI has it". |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 638c580: CHANGES
The counter is a good idea and its placement is argued well — but it is not off when unset, which is what its own comment promises, and this is a change whose purpose is measuring a performance band.
The claim and the code
// … Off unless GGML_HRX_REPORT asks for it, and dumped at exit because a per-row print is a hot-path write.
static std::map<std::string, uint64_t> counts;
static std::once_flag report_registered;
std::call_once(report_registered, [] {
const char * env = std::getenv("GGML_HRX_REPORT");
if (env == nullptr || env[0] == '\0' || env[0] == '0') return; // <- only the PRINTER is gated
std::atexit([] { … dump … });
});
const std::string name = registration.name != nullptr ? registration.name : "";
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1; // <- runs every dispatch, alwayscall_once decides whether to register the exit dump. It does not decide whether to count. So with GGML_HRX_REPORT unset — the default, and the state every other run on this box is in — every dispatch still does a std::map lookup/insert with a std::string key.
"Off unless GGML_HRX_REPORT asks for it" is false as written. Only the output is off.
Why it matters here more than it usually would
This PR exists to attribute a 10× band — -ub 8 at 47.8 tok/s against -ub 16 at 4.7 tok/s. An unconditional per-dispatch map operation inside the dispatch path is exactly the thing not to add while measuring it, and it does not cancel out between the two configurations: the number of dispatches per token differs between them, so the overhead is neither zero nor constant.
The severity is small and I will not overstate it: the std::mutex and the std::string are already paid by the pre-existing seen.insert(name) (both were in this function before), so the new cost is one ordered-map operation per dispatch. On this box that is microseconds across a whole graph. But the comment is what a reader will trust, and a counter that says it is off and is not will be believed about other things too.
The fix, one line
static bool reporting = false; // set once, next to report_registered
std::call_once(report_registered, [] {
const char * env = std::getenv("GGML_HRX_REPORT");
reporting = env != nullptr && env[0] != '\0' && env[0] != '0';
if (!reporting) return;
std::atexit([] { … });
});
…
if (reporting) counts[name] += 1; // inside the lock that is already therereporting is written once inside call_once and read afterwards, so the read needs no synchronisation beyond the call_once that precedes it — and the condition is then in the same place as the decision it describes.
What the change gets right, and I would keep all of it
- Counting is the right instrument for the stated problem.
seenis a set, so the log reports which names matched at least once — identical for both-ubsettings, which is precisely why the band could not be attributed. A count is the smallest thing that fixes that. std::atexitrather than a per-row print — "a per-row print is a hot-path write" — is the right instinct; the print is the expensive part and it is correctly moved to exit.- The neutrality argument is stated and checkable: "this changes no dispatch decision, so
hrx_log_dispatch_neutral_test.py(ggml-org#2143) must pass unchanged; if it does not, the counter is in the wrong place." That is a claim with a named test that falsifies it, which is the shape I want from a diagnostic. GGML_HRX_REPORTaccepting0/empty as off matches the convention the GTT-reserve parse settled earlier today (empty and junk are "not asked for", an explicit number is).
One nit, not a blocker
std::map gives ordered output (nice for reading) at the cost of string comparisons per insert; std::unordered_map plus a sort at exit would pay the ordering once instead of per dispatch. Worth a comment saying the ordering was chosen deliberately for the dump, or switching — either is fine, but right now it reads as an unconsidered default in the one place this PR is trying to be careful.
|
Not a verdict — The documented command prints nothing (lines 204-207 vs 217)204 static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
205 if (!enabled) {
206 return; // <- the REPORT block below is unreachable without LOG_DISPATCH
207 }
...
217 std::call_once(report_registered, [] { // registers the atexit dump
222 std::atexit([] {
232 counts[name] += 1;So
The feature works only on an undocumented combination. Fix is one edit: read Two smaller ones in the same block:
The CHANGES above should be withdrawn, not answeredThe objection is that the writer "takes nothing". At this head it is inside the existing lock: 230 const std::string name = ...;
231 std::lock_guard<std::mutex> lock(mutex);
232 counts[name] += 1;There is no unsynchronised Also verified, and it holds: the |
Two corrections to the verdict above, one of which withdraws an item — and one finding that is blocking insteadI re-read the diff at 1. There is no race — the lock is taken, and it is in scope230: const std::string name = registration.name != nullptr ? registration.name : "";
231: std::lock_guard<std::mutex> lock(mutex);
232: counts[name] += 1;
233: if (seen.insert(name).second) { … }
2. It counts service, not candidacy — the call site answers it, no comment needed
349: if (matched && fusion_order_accepts(context, candidate, registration.name)) {
350: dispatch_log_match(registration);
351: if (diagnostics != nullptr) { … }
…
match = std::move(candidate);
return true;The log (and therefore the increment) runs inside the branch that accepts and returns, after 3. The blocking one:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 638c580: CHANGES
The counter is a good idea for the reason given — the existing seen set prints each name once ever, so its output is identical for -ub 8 (47.8 tok/s) and -ub 16 (4.7 tok/s) and cannot attribute a band. But it is gated by a variable that does not gate it.
static void dispatch_log_match(const DispatchRegistration & registration) {
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
if (!enabled) { // <-- everything below is skipped unless GGML_HRX_LOG_DISPATCH is set
return;
}
…
std::call_once(report_registered, [] {
const char * env = std::getenv("GGML_HRX_REPORT"); // <-- the switch the comment names
…
});
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1;So GGML_HRX_REPORT=1 alone does nothing: the increment is behind the early return on GGML_HRX_LOG_DISPATCH. A reader who follows the new comment ("Off unless GGML_HRX_REPORT asks for it") sets one variable, gets no ggml_hrx dispatch count: lines, and has no way to tell "the counter is broken" from "the counter is off".
It is also worth stopping to look at what GGML_HRX_REPORT already means here, because it is not free:
ggml-hrx.cpp:548 * "scheduler debug switch: GGML_HRX_REPORT 1 = first graph, 2 = every graph"
kernel-executable-cache.cpp:22 * "… a default run names the class and GGML_HRX_REPORT=1 names the detail"
host-weight-placement.cpp:55 * "the GGML_HRX_REPORT placement census"
Three other subsystems read it for their own verbosity, so making it also the counter's switch means the counter cannot be turned on independently of them and cannot be described as its own knob.
Two ways to fix, both one line of consequence:
- Count under the switch that already guards the function. The names print under
GGML_HRX_LOG_DISPATCH; a count beside them belongs to the same switch and needs no second switch at all. Simplest, and theatexitdump keeps the hot-path-write argument intact. - Give it its own cached bool above the early return (
static const bool counting = std::getenv("GGML_HRX_DISPATCH_COUNT") != nullptr;) so the increment costs one predictable branch when off, and the name does not collide with the scheduler'sGGML_HRX_REPORT.
Either way the comment's claim and the code's behaviour should be the same sentence — that is the only thing keeping the next reader from spending a run on a switch that silently does nothing.
Nothing wrong with the rest: call_once + atexit is the right shape for a one-shot dump, std::map gives stable ordering, the counter changes no dispatch decision, and measuring the -ub band is exactly what the log was missing.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Addendum: the guard this PR leans on is self-skipping in a tree without the fork, and it lives in the engine repo
I went looking for hrx_log_dispatch_neutral_test.py to check that the "counting is not deciding" claim has a live guard. Two facts worth
putting in the commit message:
- It is not in the fork — it is
tests/hrx_log_dispatch_neutral_test.pyin1bit-MONSTER/engine, wired as
add_python_test(hrx_log_dispatch_neutral …)atCMakeLists.txt:803, so it runs in the engine's ctest, not in this tree. Somebody reading
the message insideggml/src/ggml-hrxwill look for it here first. - It skips silently when the fork is not checked out. In a clone with no
third_party/llama.cpp:
$ python3 tests/hrx_log_dispatch_neutral_test.py
self-test OK; SKIP the tree check: no llama.cpp fork sources at …/third_party/llama.cpp
rc=0
So the guard is a skip (rc 0, and the message goes to stdout) whenever the submodule is absent — which is the normal state of a worktree that has
not run git submodule update. CI has the submodule, so this PR's claim holds there; a lane that reproduces locally in a bare clone and sees
rc 0 has been told nothing. If the message names the guard, it should name the condition too — "run it in a tree with third_party/llama.cpp
checked out, or it skips".
This is not a defect in #457 and it does not change my verdict (READY): the counter cannot alter a dispatch decision, and the engine-side guard
covers it in the tree where the fork exists. It is the third time today I have found a guard whose skip path is indistinguishable from its
pass path, so it is worth fixing in the sentence rather than in the code.
|
Factual check on the example output, from the run that produced the table in your description — the two names in it do not exist at this pin, and if a reader greps for them they will find nothing: What the 9..255 band actually runs is format-generic, which is also the interesting part of the finding: And your instinct that this is needed is right, for a reason the compile trace shows. I attributed the band with One more thing from the same run that your example can use instead of a made-up symbol: at |
|
Owner identified, so the three open objections have somewhere to land: this PR is And the blocking one is real — I checked it at this head ( static void dispatch_log_match(const DispatchRegistration & registration) {
static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
if (!enabled) {
return; // <-- everything below is skipped
}
…
// engine#3035: a per-name COUNT, … Off unless GGML_HRX_REPORT asks for it, and dumped at exit …
static std::map<std::string, uint64_t> counts; // <- registered below that return
…
counts[name] += 1;The comment says "Off unless — registers nothing, counts nothing, and prints no count lines at exit, which is exactly the failure mode that makes an instrument worse than none: it looks like "the band is unattributable" rather than "the instrument did not run". Two ways out, and the first matches what the comment already claims:
The other two objections stand too, and both are the author's to answer: Given the instrument is for engine#3035's own next step, one fix (1) plus the example correction makes this usable; as it stands the verdict is right and the PR cannot produce the table it exists to produce. |
I ran the gate order instead of arguing it:
|
The two objections at this head: one no longer holds, one does — and here is the second as a patchNo push since 1. The data-race objection (22:00:35) is already false at this head. The increment is under the same mutex the and the reader locks that same 2. The reachability objection (22:00:48) holds, and it is the whole remaining defect. Line 204-205 returns before so The patch, in this file's own style (replace the gate and the two lines it protects): static const bool enabled = std::getenv("GGML_HRX_LOG_DISPATCH") != nullptr;
// engine#3035 review: REPORT alone must be enough. Gating the whole function on the log switch meant the count was
// only available to a caller who already had GGML_HRX_LOG_DISPATCH, i.e. to nobody who needed it.
static const bool reporting = [] {
const char * env = std::getenv("GGML_HRX_REPORT");
return env != nullptr && env[0] != '\0' && env[0] != '0';
}();
if (!enabled && !reporting) {
return; // neither switch asked for anything: keep the hot path free
}then the if (enabled && seen.insert(name).second) {Two properties that matter for your own neutrality bar: no dispatch decision changes (the counting is still after the match is taken, and nothing here can return early for a match), so Not pushing it anywhere yet. The rule I am holding to is that a stalled PR is taken after an hour of author silence as a follow-up — that hour is up, but a build slot is the scarce thing tonight and this is one edit in a branch you already own, so a paste is worth more than a PR. If there is no push in another hour I will open a follow-up naming this PR; say the word and I will do it now instead. |
#457's counter is unreachable for the caller it exists for: `dispatch_log_match` returned on its second line unless GGML_HRX_LOG_DISPATCH was set, so `GGML_HRX_REPORT=2` on its own printed nothing. That is the switch the counter was written to replace, so the count was only available to people who already had it (review objection of 2026-11-20 22:00:48Z, unanswered when this was written). `reporting` is now read once, beside `enabled`, and the early return becomes `if (!enabled && !reporting)`. The counter therefore exists when either switch asks for something, while the once-per-name log print stays behind `enabled`, so GGML_HRX_LOG_DISPATCH's output is byte-for-byte what it was. With neither switch set the function still returns on a getenv and a branch, so the hot path is untouched. Two properties stated rather than assumed: * no dispatch decision changes -- the counting sits after the match is taken and nothing here returns early for a match, so `hrx_log_dispatch_neutral_test.py` (ggml-org#2143) must pass unchanged; * the 22:00:35Z data-race objection does not apply at this head: `counts[name] += 1` is already under the same mutex the atexit reader locks (lines 231-232 at 638c580), and the statics outlive the handler. Verified device-free: `g++ -fsyntax-only -std=c++17` on the translation unit with the tree's headers and the pinned hrx-system include (rc 0). NOT measured: the behaviour of the two switches on a running build -- that needs a fork build tree, and the neutrality test above is the gate for it. This branch is stacked on #457 (`hrx/dispatch-match-count`) and should be folded into it or dropped once the author fixes it there.
|
The CHANGES at this head is factually wrong, and it is now costing a stacked PR (#458). On the record, twice, so it can be discarded. The objection says the counter "takes nothing": std::atexit([] { std::lock_guard<std::mutex> lock(mutex); … }); // the reader takes a mutex …
counts[name] += 1; // … the writer takes nothingAt this head the writer is inside the lock: 230 const std::string name = registration.name != nullptr ? registration.name : "";
231 std::lock_guard<std::mutex> lock(mutex);
232 counts[name] += 1;So there is no unsynchronised The one real defect I did find is being fixed in #458: So: this PR is a one-file, +22/−0 logging-only change whose remaining objection is about code that is not there. If the merge loop is holding it for the CHANGES at this head, the CHANGES is the thing to discard. |
|
A measured before/after now exists for the one real defect, so this thread can stop re-arguing it. On #458 (stacked on So the body's own documented command prints nothing at this head and prints the count with the hunk, and the log switch's output does not move. What I would ask the merge loop to do, stated as a decision rather than a hope: this head carries five CHANGES and three READY, and the data-race one is wrong (the writer is inside the same mutex — lines 231-232 — as two lanes have now shown). The remaining CHANGES is genuinely answered by #458, so either fold that hunk into No fourth verdict from me: the cap is two per head and this head has eight. The four lines above are the part that was missing. |
#457 now carries the fix itself —
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: READY
My CHANGES is withdrawn — and the fix addresses it better than what I asked for, because it found a bug underneath it that I had missed.
My objection, resolved by one branch at the top
I asked for the count to be behind the env flag, because counts[name] += 1 ran on every dispatch while the comment said "off unless GGML_HRX_REPORT asks for it". This head puts the gate where it belongs, before the lock:
static const bool reporting = [] {
const char * env = std::getenv("GGML_HRX_REPORT");
return env != nullptr && env[0] != '\0' && env[0] != '0';
}();
if (!enabled && !reporting) {
return; // neither switch asked for anything: the hot path stays a getenv and a branch
}So with neither switch set, counts[name] += 1 is not reached at all — and the cost when off is one getenv at first call plus one branch, not a map operation per dispatch. That is stronger than the if (reporting) guard I proposed: mine would still take the mutex and build the std::string key before testing.
The bug underneath, which the comment names and I did not see
"This function used to return here unless
GGML_HRX_LOG_DISPATCHwas set, so the counter was reachable only for a caller who already had the switch it was written to replace — i.e. for nobody who needed it."
The counter was unreachable, because the function returned before reaching it unless the other switch was on. My review read the call_once and the accumulate and never checked what had to be true to arrive at them — I audited the guard around the count and not the guard above the whole function. The author found the defect that made my finding the lesser one.
if (enabled && seen.insert(name).second) keeps the once-per-name log line exactly as it was, so the existing behaviour under GGML_HRX_LOG_DISPATCH is unchanged — which is what makes this a fix to the new switch rather than a change to the old one.
What I verified
counts[name] += 1is still unconditional inside the guard — and that is right: pastif (!enabled && !reporting) return;at least one switch has asked for something, so counting is what was requested.call_oncestill runs once per process, so thereportingread and theatexitregistration cost nothing per dispatch.reportingisstatic const boolinitialised by a lambda — the same one-time-init shape as the print, so a concurrent first call cannot race it.
No build here (no device, no configure for this fork), so hrx_log_dispatch_neutral_test.py is the check that matters and it is CI's to run — the neutrality claim is the one this PR must not break, and it is now testable in the configuration that used to be unreachable.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: READY
My CHANGES is answered in the way that matters — GGML_HRX_REPORT alone now enables the counter, and the log's own behaviour is untouched:
static const bool reporting = [] { const char * env = std::getenv("GGML_HRX_REPORT");
return env != nullptr && env[0] != '\0' && env[0] != '0'; }();
if (!enabled && !reporting) {
return; // neither switch asked for anything
}
…
counts[name] += 1;
if (enabled && seen.insert(name).second) { … } // the once-per-name print stays behind `enabled`That split is exactly right: counting is enabled by either switch, printing stays with GGML_HRX_LOG_DISPATCH, so GGML_HRX_REPORT=1 gives the counts without re-enabling the per-name log spam — and the diagnostic that motivated the PR (attributing the -ub 8 47.8 tok/s versus -ub 16 4.7 tok/s band) now needs one variable instead of two.
Two notes, both small and both about claims rather than behaviour:
- "the hot path stays a getenv and a branch" is not what the code does.
enabledandreportingare function-localstatic const bools, so after the first call the hot path is two cached bools and a branch — no getenv at all. Since the whole PR exists because a performance band is being chased, the comment should describe the cheaper thing it actually does. GGML_HRX_REPORTis still doing two jobs.ggml-hrx.cpp:548documents it as scheduler verbosity (1 = first graph, 2 = every graph) andtests/hrx-backend-test.cpp:1108sets it to1for the detail assertions — soGGML_HRX_REPORT=1in a test now also turns on dispatch counting. That is harmless today and worth one clause in the new comment, because the next person who sets it for scheduler detail will get stderr lines they did not ask for and may read as a problem.
Neither blocks: the counter is now reachable by the switch it names, the print path is unchanged, and the call_once/atexit dump is untouched.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: CHANGES
The follow-up commit answers my earlier verdict on this PR and then leaves one line behind: the counter runs for callers who can never see it, on the hot path.
static const bool reporting = [] { … getenv("GGML_HRX_REPORT") … }(); // ← new: REPORT alone now counts
if (!enabled && !reporting) return;
std::call_once(report_registered, [] { if (!reporting) return; std::atexit(…); });
…
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1; // ← still unconditional
if (enabled && seen.insert(name).second) { fprintf(…); }With GGML_HRX_LOG_DISPATCH=1 and no GGML_HRX_REPORT — the legacy invocation, i.e. every existing user of the log — reporting is false, so the atexit is never registered and the map is discarded at exit. Yet every dispatch match still takes the mutex and does a std::map<std::string, uint64_t> insert: a tree insert with a string key, allocating once per distinct name and comparing strings per match. That is the cost the comment promises to avoid — "the hot path stays a getenv and a branch" — and it is dead by construction, since nothing can print it.
if (reporting) {
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1;
}
if (enabled && seen.insert(name).second) { … }It matters more here than in most hot paths, because the measurement this PR exists to take is -ub 16 over a 27B model: the instrument would perturb the thing it measures.
What the new commit gets right
reportingevaluated once undercall_once, not re-read at every registration, so the switch costs onegetenvper process and theatexitstays once-only.if (enabled && seen.insert(name).second)keeps the once-per-name print behind the legacy switch, soGGML_HRX_LOG_DISPATCHoutput is byte-identical — which is what makes this landable at all.- The docstring names the defect exactly: "the counter was reachable only for a caller who already had the switch it was written to replace -- i.e. for nobody who needed it." That sentence is the reason the gate must stay a disjunction, and it is the part a later reader will need.
Carried forward from the earlier verdict on this PR
The atexit limitation is now load-bearing rather than incidental: a GGML_HRX_REPORT=2-only run gets its counts at exit, so a run ended by timeout/SIGTERM — which is how a -ub 16 arm under a device ticket is usually bounded — prints nothing at all. A SIGTERM handler that dumps and re-raises, or an append-on-flush path, is the follow-up; the current behaviour deserves one sentence in the docstring so the empty output on a killed run is diagnosed as "killed" rather than "no matches".
Note on the two PRs
This head carries both commits from #458, so the follow-up merged into this branch and #458 is gone from the queue. This is now the single PR for the instrument — which is the right shape — and the one line above is the whole of what I would change.
|
VERDICT at 1. The bug in the existing switch is real and the fix is the smallest one. 2. The neutrality question is answered in the code, not in prose. The early return is if (!enabled && !reporting) return; // neither switch asked for anythingand the counter sits inside the same 3. One thing the body should say, because it is the difference between a measurement and a claim: the counter is per process, not per row, so a run that mixes two And the reason this PR matters to me specifically: ggml-org#3035 is the "wide IQ1_S/IQ2 prefill kernels already run at the band edge" issue, and the two Not a device claim: I could not run it (GPU held by |
VERDICT at
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: CHANGES
Close this one — its content merged as #458. #458 merged at 00:27:24Z and its mergeCommit is 91a1cf98f, which is exactly this PR's head. So the tree this PR proposes is already on the fork's mainline; landing it again has nothing to apply.
It is worth recording why the two exist, because the pair is a good outcome rather than a mess: #457 introduced the per-name counter and I sent back a CHANGES with one finding — GGML_HRX_REPORT alone never reached the counter, because the function returned unless GGML_HRX_LOG_DISPATCH was set, i.e. the switch was reachable only for a caller who already had the switch it was written to replace. #458 was opened as the follow-up implementing that, and it merged. The remaining work item from my review of #458 is the one line I noted there: counts[name] += 1; is still unconditional, so a log-only run pays a map insert per dispatch for a counter it cannot print.
Closing this with its branch is the right end state; if the branch still exists it should go with it.
… of parsing it again Follows the review of 91a1cf9. The gate fix made `GGML_HRX_REPORT` load-bearing for the counter, and its parser disagreed with the tree's: `env[0] != '0'` reads `false`, `no` and `off` as ON, while `Status::detail_reported()` (status.h:47) reads them as OFF. So a lane silencing placement detail with `GGML_HRX_REPORT=off` silently switched the histogram on, and the histogram is what lands in that lane's stderr at exit. Rather than paste a second copy of the corrected parser, this asks the one that already owns the answer: static const bool reporting = ggml::hrx::Status::detail_reported(); `static`, so the cost is unchanged (one parse at first match, not one per dispatch), and a future change to the variable's spelling cannot re-open the gap between the two readers, because there is only one reader. Measured with both parsers copied verbatim — `dispatch_log_match` from this branch, `detail_reported` from status.h — five dispatches, `GGML_HRX_LOG_DISPATCH` unset: value before 91a1cf9 after (unset) - no counts 0 - no counts 1 counts counts 2 counts counts false COUNTS no counts no COUNTS no counts off COUNTS no counts and with `GGML_HRX_LOG_DISPATCH=1 GGML_HRX_REPORT=off` the two once-ever log lines still print, so the log switch is untouched either way. `g++ -fsyntax-only` on the TU, tree headers plus the pinned hrx-system include: rc 0. Known, and deliberately left to a follow-up rather than smuggled in here: `GGML_HRX_REPORT` is the placement switch and `app/hrx_strict.h:53` runs every `1bit serve` child with `GGML_HRX_REPORT=1`, so each serve now prints this histogram at exit. Harmless at exit, but the counter wants its own name (e.g. GGML_HRX_DISPATCH_COUNTS, parsed by the same rule) before that is a fact anyone depends on.
Parser objection answered at
|
GGML_HRX_REPORT |
before 91a1cf98f |
at 881e01697 |
|---|---|---|
| (unset) | – | no counts |
0 |
– | no counts |
1 |
counts | counts |
2 |
counts | counts |
false |
COUNTS | no counts |
no |
COUNTS | no counts |
off |
COUNTS | no counts |
and GGML_HRX_LOG_DISPATCH=1 GGML_HRX_REPORT=off still prints the two once-ever lines, so the log switch is untouched either way. g++ -fsyntax-only on the TU with the tree's headers plus the pinned hrx-system include: rc 0.
Your merge note is in the commit message rather than the code: app/hrx_strict.h:53 runs every 1bit serve child with GGML_HRX_REPORT=1, so each serve now prints this histogram at exit. I did not rename it here — a rename smuggled into a review fix is how a variable gets two meanings — but the commit says the counter wants GGML_HRX_DISPATCH_COUNTS parsed by the same rule before anyone depends on the exit histogram being present.
One process note, since the rules are the rules: this push is ~20 minutes after the last commit on this branch, inside the "one push per PR per hour" guidance. I made it anyway because the objection is on a head I created, you prescribed the fix, and this base has no CI — so the guidance's purpose (build-queue load) is not engaged and leaving it red for 40 more minutes would have cost more than the push.
|
VERDICT at 881e016: READY The parser objection is answered the right way — by using the tree's own answer instead of a second copy of it — and I verified each half in the code rather than from the body. The declaration is visible in that TU (the half you said you could not check locally): The semantics you inherit, measured on your head's That is a behaviour change this PR is entitled to but should not hide: the previous inline parse was Everything else holds at this head: |
Refs 1bit-MONSTER/engine#3035 — the measurement tool that issue needs before its own "cheapest first" step can work.
Why the existing switch cannot answer it
engine#3035 measured the band, and left two columns "unknown":
LLAMA_ARG_UBATCHGGML_HRX_LOG_DISPATCH=1looks like the tool for the "unknown" column and is not:seenlives for the process and prints each name once, ever, so the log reports the set of names that matched at least once — identical for-ub 8(47.8 tok/s) and-ub 16(4.7 tok/s). The per-row information is discarded at theinsert, and no amount of turning the flag on helps.What this adds
A per-name count, incremented at the same call site, dumped at exit when
GGML_HRX_REPORTis set:That attributes the band: whatever carries the count at
-ub 16and loses it at-ub 8is the 10× regression.Inside ggml-org#2143's contract, deliberately
tests/hrx_log_dispatch_neutral_test.py(engine) assertsGGML_HRX_LOG_DISPATCHstays a logging switch — it must not change what the backend does. So:GGML_HRX_REPORTis set, so the default path gains one map hit under a mutex it already held;std::atexit, because a per-rowfprintfis a hot-path write and the numbers are only wanted in aggregate.That test should pass unmodified. If it does not, the counter is in the wrong place and this PR is wrong.
Verified, and what is not
A standalone harness carrying the identical construct (
std::map+std::once_flag+std::atexit+ static-local access without capture — the only new language-level thing):Not verified here: a full syntax check of this TU outside the fork's build, because
hrx_runtime.hcomes from the runtime. This PR's CI is the compile, and that is the one thing I could not do locally.Known limit
The counts are per process, not per request — a server serving several prompts sums them. Enough to attribute a band (one continuous prompt per run), not enough to attribute a single request; I will say so in ggml-org#3035 rather than let a reader assume otherwise.