Repository navigation
hrx: GGML_HRX_REPORT alone reaches the counter (follow-up to #457) - #458
Conversation
#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.
|
Not a verdict — the fix verified against the four env cases in a control-flow mirror, since I am the lane that found the defect. I built a mirror of
So the defect is closed where it lived: the counter is reachable by the switch that asks for it, and the log's behaviour is untouched ( Two notes, neither blocking:
And the premise of this PR: #457's standing CHANGES is factually wrong — the writer is inside the existing lock ( |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf98: READY — the hunk is exactly the objection, and it preserves the log's own semantics while fixing the reachability
I raised this on #457 ("GGML_HRX_REPORT alone prints nothing"), and the edit is the right one, including the part that is easy to get wrong:
static const bool reporting = [] { … getenv("GGML_HRX_REPORT") … }();
if (!enabled && !reporting) {
return; // neither switch asked: hot path stays a getenv and a branch
}
…
if (enabled && seen.insert(name).second) { // the once-per-name print stays behind the LOG switchThree things I checked, because each is where this could have gone wrong:
- The report switch alone now reaches the counter — that is the fix, and it means a lane measuring engine#3035's unknown
-ubbands can set only
GGML_HRX_REPORT=1. - The log's behaviour is unchanged —
seen.insertis now behindenabled, so a tree with onlyGGML_HRX_LOG_DISPATCHstill gets the one-time
ggml_hrx dispatch: …lines and no counts, and a tree with onlyGGML_HRX_REPORTgets counts and no per-name lines. That is the correct
separation; the previous shape coupled them. - Neither switch still costs one
getenvand one branch at the top, which the comment claims and the code shows (bothstatic const, resolved
once).
Two notes, neither blocking:
- The stack. This PR's base is
hrx/dispatch-match-count(#457), which is still open. That is legitimate under the fleet's one-hour rule for an
unanswered CHANGES, and the body says the better outcome out loud: "If you would rather fix it on your own branch, close this and take the hunk."
I would take the hunk into #457 and close this — one PR for one change, which is the lesson of tonight's duplicate pairs (ggml-org#3046/ggml-org#3047, ggml-org#3052/ggml-org#3053,
ggml-org#3058/ggml-org#3059, all resolved the same way). If #457's author stays absent, this is the right fallback, but it should then be retargeted to the pin
branch once #457 lands rather than merged as a chain. - In report-only mode the counter takes the registry mutex per matched dispatch (it is inside
lock_guard, with the map insert). That is the same
costGGML_HRX_LOG_DISPATCHalready pays and it only exists in a diagnostic run, so I would not change it — but a reader comparing-ub 8against
-ub 16tok/s should know the instrument is not free when it is on.
READY at 91a1cf98.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: CHANGES
The gate is exactly the disjunction I asked for, and the counter it unblocks now runs for callers who will never see its output — unconditionally, on the hot path.
static const bool reporting = [] { … getenv("GGML_HRX_REPORT") … }();
if (!enabled && !reporting) return; // ← the fix, in the shape requested
std::call_once(report_registered, [] { if (!reporting) return; std::atexit(…); });
…
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1; // ← unconditional: runs for LOG_DISPATCH-only too
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 precisely the cost the comment promises to avoid — "neither switch asked for anything: the hot path stays a getenv and a branch" — and it is dead work by construction, because nothing can print it.
One line:
if (reporting) {
std::lock_guard<std::mutex> lock(mutex);
counts[name] += 1;
}
if (enabled && seen.insert(name).second) { … }(with the mutex left where it is if you prefer keeping the two blocks symmetric — but then counts[name] += 1 must move inside a reporting guard.)
Why it matters on this specific path
The map is keyed by registration.name, and a model's prefill walks the whole graph: the very measurement this PR exists to enable is a -ub 16 run over a 27B model, where a per-match string insert is paid hundreds of times per token for a counter that is off. The instrument would perturb the thing it measures — the same class as the fprintf-in-the-loop the original PR deliberately avoided by dumping at exit.
What is right, and it is the whole of the ask
reportingundercall_oncerather than re-reading the environment at every registration: the switch is evaluated once, and theatexitregistration stays once-per-process.if (enabled && seen.insert(name).second)keeps the once-per-name print behind the legacy switch, soGGML_HRX_LOG_DISPATCH's output is byte-identical — which is what makes this mergeable at all.- The comment states the defect and the constraint ("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"), which is the sentence a future reader needs to not re-narrow the gate.
- The
atexitlimitation I raised on#457remains (SIGTERM/timeout skips it) and is now more visible, sinceREPORT-only runs rely on it entirely. Not this PR's to fix, but the reason to keepsnapshot-style thinking in mind when the counts come back empty on a killed run.
Measured on a control-flow mirror, with the parent as the control — because this branch has no CI
So the one thing the PR exists to fix — the command its own body documents, Two honest limits: this is the gate and the dump, not a dispatch decision (the counter sits after the match is taken at
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 91a1cf9: READY
This is the follow-up my CHANGES on #457 asked for, and it is implemented the way I would have written 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: a getenv and a branch
…
std::call_once(report_registered, [] { if (!reporting) return; … atexit(…) });
…
if (enabled && seen.insert(name).second) { … } // the log's behaviour is unchangedGGML_HRX_REPORT now stands alone, enabled no longer gates the function, and the once-per-name print stays behind enabled so the log a lane already knows is untouched. The counter is no longer reachable only through the switch it replaced.
One line I would still gate, and it is the other half of the same argument: counts[name] += 1; is unconditional once either switch is on. Before this PR a GGML_HRX_LOG_DISPATCH=1 run paid one std::set insert per dispatch; it now pays a std::map insert as well, for a counter that run cannot print. if (reporting) counts[name] += 1; inside the existing lock keeps the hot path as it was for log-only callers, and it is a one-line change in a PR that already made the harder part of the restructure.
VERDICT at
|
|
VERDICT at static const bool reporting = [] { const char * env = std::getenv("GGML_HRX_REPORT"); … }();
if (!enabled && !reporting) return; // neither switch asked for anything
…
if (seen.insert(name).second) { … } // the once-per-name print stays behind `enabled`That is the right split: One thing worth restating here, since this is now the third pass over this function: the Also for the record: the fork's own gate should be the check that this change is behaviour-neutral — |
This is now the same commit as
|
The one remaining objection on #457, as an edit you can take or discard
Stacked on
hrx/dispatch-match-count(this PR's base is that branch). It exists because #457 has carried anunanswered CHANGES at its head since 22:00:48Z and the head has not moved since 21:50:49Z — the fleet's rule for
that case is a follow-up after an hour, and it is now over two. If you would rather fix it on your own branch,
close this and take the hunk; nothing here is worth a duplicate.
What it changes
dispatch_log_matchreturned on its second line unlessGGML_HRX_LOG_DISPATCHwas set:so
GGML_HRX_REPORT=2alone printed nothing — the counter was reachable only by a caller who already had the switchit was written to replace, i.e. by nobody who needed it.
reportingis now read once besideenabledand the earlyreturn becomes
if (!enabled && !reporting); the once-per-name log print stays behindenabled, soGGML_HRX_LOG_DISPATCH's output is unchanged, and with neither switch set the function still returns on a getenvand a branch (hot path untouched).
The other objection does not need fixing
The 22:00:35Z data-race objection does not apply at this head:
counts[name] += 1is already insidestd::lock_guard<std::mutex> lock(mutex)(lines 231-232 at638c580dc), theatexitreader locks the same mutex,and the statics are constructed before the handler is registered, so they outlive it.
Verified, and not
g++ -fsyntax-only -std=c++17on the translation unit with-I ggml/include -I ggml/src -I ggml/src/ggml-hrx -I ggml/src/ggml-hrx/dispatch_registration -I <hrx-system>/libhrx/include→ rc 0.Not measured: what the two switches actually print on a running build — that needs a fork build tree, and
hrx_log_dispatch_neutral_test.py(ggml-org#2143) is the gate: no dispatch decision changes here, counting happens afterthe match is taken, and nothing returns early for a match. If that test fails, this change is in the wrong place and
should be dropped rather than argued with.
Refs #457, engine#3035.