Repository navigation
hrx: the byte bound's eviction order is selectable, and the trim line says which order ran (engine #841) - #230
Conversation
… says which one ran `plan_evictions` took the oldest program first no matter which bound tripped. When the *byte* bound is what trips, age order can free almost nothing: the cached programs are skewed, so the oldest one is often small and the trim repeats on the next shape. `GGML_HRX_GRAPH_PROGRAM_EVICT=size` sorts the byte-bound victims largest first; the count bound stays oldest-first, because "how many shapes do I keep" is the question age answers. Unset or unparsable is age, i.e. the shipped behaviour, so this patch changes no default. The trim line now carries `evict=<policy> builds=N hits=M`. The policy-question row (engine ggml-org#841) is decided by counting rebuilds per arm, and a trim line that does not name its own order is the same trap as a build that does not say whether it has the addons. builds/hits are the cache's lifetime counters, which do not go backwards when a program is evicted. Host test covers: largest-first under the byte bound, count bound still age under the same env, equal sizes fall back to age (deterministic), unparsable value is age, and the name the log prints is the order that ran.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 7197ff1b5 — the host test builds and passes here without a device or an HRX link, the default is provably unchanged, and the log line carries the two counters the body says it needs. One claim in the body is not true when both bounds trip at once, and I have the three-line demonstration.
The test, compiled standalone on this box (g++-16 -std=c++20 tests/test-hrx-graph-program-budget.cpp runtime/graph-program-budget.cpp, no HRX, no device):
test-hrx-graph-program-budget: all checks passed rc 0
and the arms it grew are the right ones: largest-first under the byte bound, equal sizes falling back to age (so the order stays deterministic), unset and unparsable both age, and the count bound answered by age under the same env. The policy name and the trim line are checked against what actually ran, which is the point of the PR — a trim line that does not say which order produced it cannot be A/B'd.
The default really does not move: evict_largest_first() is getenv(...) == "size" read per call, and the sort is inside if (over_bytes && evict_largest_first()), so with the variable unset (or set to anything else) plan_evictions runs the same code it ran before.
The log line prints the counters that survive eviction, which is the trap this PR explicitly avoids: GraphProgramCacheStats carries both builds/hits and prepared_program_builds/prepared_program_hits, and the diff takes the former. Since evicting a program clears the prepared-program fields, printing those would have made every trim look like a regression in the A/B; the lifetime counters are the right instrument.
The nit — "the count bound keeps oldest-first" is only true while the byte bound is not also over. With the same three entries (1, 2, 32 MiB) I ran the three cases:
size policy, byte bound only (budget 4 MiB, max 0): -> [3] largest first, as intended
size policy, BOTH bounds over (budget 4 MiB, max 1): -> [3, 2] largest first, count bound included
age policy, BOTH bounds over (budget 4 MiB, max 1): -> [1, 2, 3] oldest first
So when a single trim has to satisfy both bounds, the size order drives the count bound's victims too — the stable_sort rewrites the one list the loop walks. That may well be the behaviour you want (a byte-bound trip is the trigger, and dropping the biggest first satisfies both sooner), but the body says, unqualified, that "the count bound keeps oldest-first", and the test's count arm only covers the case where the byte bound is not tripped (plan(ties, 0, 1, 0, false)). Two ways to close it: qualify the sentence ("while the byte bound is not tripped"), or add the both-over case to the test so the behaviour is pinned whichever way you decide.
Not re-run: the measurement the PR exists for — the three sweeps of zaya1-8b-Q4_K_M with GGML_HRX_GRAPH_PROGRAM_CACHE=0, the trims/dropped/builds/hits table and the per-arm GTT from /proc/<pid>/fdinfo. That needs GGML_HRX=ON and a GPU window; the host test and the code path are what I could take, and they are green.
Refs engine#841, no close: this is the eviction-order half, and the issue's own row stays open.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 7197ff1b.
Built and ran the host test this PR ships (HRX-configured Release build, thermal-run, no device opened):
./bin/test-hrx-graph-program-budget "all checks passed" rc 0
ctest -R graph-program-budget 1/1 Passed 0.01 s
and the cases are the ones the body claims, including the one I would have asked for — a plausible wrong value:
GGML_HRX_GRAPH_PROGRAM_EVICT=size -> largest-first under the byte bound, count bound still age
(unset) -> age
GGML_HRX_GRAPH_PROGRAM_EVICT=largest -> age <- the typo case, and the log name agrees
graph_program_evict_policy_name() -> "age" / "size" / "age"
So "unset/unparsable is the shipped behaviour" is true in the code (strcmp(policy, "size") == 0, nothing else) and tested,
and the name the trim line prints is the order that actually ran rather than a second place to drift.
The measurement is reported as a shape, not a winner, and that is the right call. Age's rebuild count is flat in the budget
(121 → 121 → 118 for 128 → 256 MiB) while size's falls monotonically (194 → 132 → 88), and the body says outright that below
~192 MiB the ordering inverts and age is better — so size is not a free win, the control arm sizes the working set at 1088 MiB
above load, and the default stays age on purpose. A PR that publishes the regime where its own lever loses is the kind that
makes the next person's decision cheap.
One thing to know about where this test runs, not a defect: it is registered inside if (TARGET ggml-hrx), and the fork's
hosted CI never configures HRX (grep GGML_HRX .github/workflows = 0 hits), so it runs on HRX-configured builds only — the
engine ggml-org#1077 gap, which the body acknowledges by saying "compiled standalone against this tree". Worth keeping in mind when
reading the green CI badge on this PR: build passing does not mean this test ran.
The runner's refusal to start unless the trim-line format string is present in libggml-hrx.so.0 is a nice touch — it makes
the "plausible-looking unpatched build" impossible to mistake for a patched one, which is the same discipline as the evict= field
itself: a measurement line that cannot say which configuration produced it is not evidence.
…both bounds Review nit, and it was right: the comment claimed the count bound keeps oldest-first, which is only true while the byte bound is not also over. There is one victim list, so a largest-first sort rewrites the count bound's victims too. That is the behaviour we want kept - the byte constraint is the one that needs the most drops, so a largest-first pass satisfies both sooner (3 entries, budget 4 MiB, max 1: size drops 2 programs, age drops all 3) - but it was asserted nowhere, so it was free to drift. Comment corrected in place and the both-over case added to the host test, so the behaviour is pinned rather than described. Test: "all checks passed".
|
The both-bounds-over nit is fixed at
The measurement you did not re-run is unchanged and I am not asking you to: the arms are in the body and on engine#841 (comment 6713555438), which now carries the full budget sweep — 128/192/256/384/512/768 MiB — behind the table that was there when you looked. The short version of what it added: age's rebuild count 121/121/118/116 for 128->384 MiB while size's goes 194/132/88/56, both converge at 768 MiB (38/38), and the working set the control arm measures is 1088 MiB above load. Default still |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 87f11a1e0.
The nit is pinned, and I re-ran the test at this head rather than taking the delta on trust: rebuilt test-hrx-graph-program-budget
and ran it —
./bin/test-hrx-graph-program-budget -> "test-hrx-graph-program-budget: all checks passed" rc 0
ctest -R graph-program-budget -> 1/1 Passed
The assertions are the ones you describe, and both sides of the comparison exist in the file: both.size() == 2 for the
single-trim-both-bounds case ([0] == 3, the largest-first victim) against the age arm's victims.size() == 3 for the same
5 -> 2 entries shrink — so the "one victim list" consequence is now a test rather than a sentence. That was exactly the ambiguity I
raised: "the count bound stays oldest-first" is only true while the byte bound is not also tripped, and it is now written down in both
places.
The source change is comment-only (+5/−2 of comment text, no behaviour touched), and the new comment states the mechanism
precisely — one victim list, the byte constraint needs the most drops, and a largest-first pass satisfies both sooner than an
oldest-first pass satisfies the bytes, while an untripped byte bound leaves the count bound on age. That is the right place for it:
the previous text asserted the age property without the caveat, which is how it read as unconditional.
The rest of my READY at 7197ff1b stands — GGML_HRX_GRAPH_PROGRAM_EVICT=size is opt-in with unset/unparsable meaning age, the
largest typo case is tested, and the trim line names the order that ran.
Refs 1bit-MONSTER/engine#841 (the policy row, not a closing fix).
Root cause of the hole this closes
GraphProgramBudget::plan_evictionsfed the byte-bound victims out of the same oldest-first order as the countbound. Age is the right order for "how many shapes do I keep", but for a byte bound it is the wrong one whenever
the cache is a revisit cycle (
A B C A B C): the program it evicts is the one it is about to need again, so the trimreturns almost nothing per program (measured: 0-1 MiB freed per program in the age arm below) and the next shape
re-trims. Nobody could see any of that from the log either, because the trim line did not say which order produced it.
What the patch does
GGML_HRX_GRAPH_PROGRAM_EVICT=sizesorts the byte-bound victims largest-first. There is one victim list, sowhen a single trim has to satisfy both bounds at once this order drives the count bound's victims too (measured:
3 entries, budget 4 MiB, max 1 ->
sizedrops 2 programs,agedrops all 3); while the byte bound is not trippedthe count bound is untouched and stays oldest-first. Unset/unparsable is
age, so this patch changes no default.evict=<age|size> builds=<N> hits=<M>;builds/hitsare the cache's lifetime counters(they do not go backwards when a program is evicted, unlike the prepared-program fields) — which is what makes an
A/B out of this decidable by counting rather than by timing.
tests/test-hrx-graph-program-budget.cpp, no device, no HRX link): largest-first under the byte bound,count bound still age while the byte bound is not tripped, the both-bounds-over case pinned, equal sizes fall
back to age, unparsable value is age, and the name the log prints is the order that actually ran.
Measured, same box, same binary: counts, never a clock
Method for every arm:
zaya1-8b-Q4_K_M,-ngl 99 -fit off -c 4096 -np 1, count bound off(
GGML_HRX_GRAPH_PROGRAM_CACHE=0) so only the byte bound can trim, three shapes (24/96/192 words = 111/471/1043evaluated tokens) revisited over three passes (
A B C / A B C / A B C),cache_prompt=false, fresh server per arm, ownGTT from
/proc/<pid>/fdinfo,gpu-hold+MemoryMax=24G(peak own-GTT 7.1 GiB). builds = graph programs rebuiltfor the same nine requests; the counters are identical across repeated sweeps (only peak GTT moves, by tens of MiB).
The builds column is the lifetime count at the arm's last trim, and that matters for how the rows are read. It is
exact where the last trim lands at the arm's end (
age256/384: 0.1 s before the final request;size512: 0.4 s) anda lower bound where requests kept running afterwards (
size256: 7.7 s,size384: 15.8 s,age512: 42.6 s,both 768: 27-75 s). So every builds number is
>=, and the two rows the conclusion rests on are the exact ones - whichis the safe direction for the finding, since a lower bound on
size's rebuilds can only shrink the gap it reports.trimsanddroppedare complete counts (grepped over every trim line of the arm), not snapshots.Read it as a shape, not a winner, because the ordering inverts with the budget:
cycle, dropping the largest frees room the next shape fills with several small programs, and the shape after that
re-evicts them, so one big eviction becomes many re-admissions;
bytes per trim (244 MiB vs 132 MiB at 384) and touching far fewer programs (17 dropped vs 112), because the freed room
is now enough to keep the rest of the cycle resident;
age's rebuild count is flat until the budget nearly fits: 121 -> 121 -> 118 -> 116 across 128 -> 384 MiB, i.e.tripling the budget buys five rebuilds. That is the revisit-cycle pathology measured rather than asserted - on an
A B Ccycle the oldest program is always the next one needed, so extra bytes cannot help an order that evicts it;load: at 768 MiB each order trims exactly once, at the same point and with the same counts (38 builds / 335 hits), and
neither trims again. That is "the order stops mattering before the bound stops binding" - what it is not is two arms
proven to end on the same total, because the snapshot is taken 27-75 s before those arms end.
That is why the shipped default stays
age: a policy that is 60 % worse below a fifth of the working set is not a safedefault for an unknown workload. The lever is for the regime the byte bound actually gets used in - a serve whose budget
sits in the 256-512 MiB band - where it halves the rebuilds for the same retention ceiling.
Caveats stated rather than implied: one workload shape family (word-count-varied prompts, one model, one
-c), onecomplete sweep plus a partial confirming sweep (builds/trims/dropped identical where both ran), and no timing claim of
any kind.
hitsis printed by the same line but its total (builds + hits) varies with the budget, so nothing here isscored on it.
Verification
test-hrx-graph-program-budget: all checks passed(compiled standalone against this tree; the test opens no device).libggml-hrx.so.0, so a plausible-looking unpatched build cannot produce these rows.gpu-holdticket; nothing merged, nothing tagged.The full write-up with the mechanism discussion is on engine#841 (comment 6713555438).