Repository navigation
Description
hrx: GGML_HRX_GRAPH_PROGRAM_CACHE_MB sees ~16 MiB per cached program while the cache grows 0.4-2.3 GiB per shape — the 64-program count is the only bound that bites
Measured at fork d8bd0ff6052a (ggml/src/ggml-hrx), hrx-system 82804197bc, on strixhalo (gfx1151, 120 GiB UMA),
zaya1-8b-Q4_K_M, llama-server -ngl 99 -fit off -c 4096 -np 1, #715 no-SVM trio, gpu-hold, one request per new
prompt shape with cache_prompt=false. Raw logs: ~/amd-oss/hrx-study/evidence/memory/graphcache-8b-20261102-1030.log
(default bounds = arm A) and graphcache-bound-20261102-1044.log (both bounds exercised, 28 trims).
The measurement
Arm A, default bounds (GGML_HRX_GRAPH_PROGRAM_CACHE=64, ..._CACHE_MB=8192), GTT delta after each request:
| shape (prompt tokens) | GTT delta | trim lines |
|---|---|---|
| load, no request | +6033 MiB | 0 |
| 33 | +6461 | 0 |
| 480 | +7092 | 0 |
| 512 | +7738 | 0 |
| 1024 | +9247 | 0 |
| 1152 | +11556 | 0 |
| 2048 | +12991 | 0 |
| 2963 | +15447 | 0 |
| 4011 | +18450 (unbounded arm; default arm trims to +11480) | 0 / 28 |
So the cache grows 0.4-2.3 GiB per new shape, totalling ~12.4 GiB over 6 shapes at the point where the count bound
starts trimming. The trim line reports what the byte budget is looking at:
W trim_graph_programs: HRX graph program cache trimmed (1 of 66 programs, 1031 -> 1031 MiB of arenas,
budget 8192 MiB, 64 max): kept the current one, trim 25
1031 MiB accounted for 66 programs ≈ 16 MiB each, against ~8192 MiB of budget — 12.6 % of the budget while the cache
already held ~18 GiB of GTT. The count bound (64) trips on the 65th shape; the byte budget never will (it would need
~500 programs at this per-program rate).
Why: the byte budget only counts the transient arena
graph-program-cache.cpp:798
size_t GraphProgram::retained_bytes() const {
return commands_ != nullptr ? commands_->transients.arena_size : 0;
}and that is the only quantity fed to the budget (budget_.note(graph.uid, cached_program->retained_bytes()) at :685,
also :854 in retain_only). A cached GraphProgram also keeps its imported Graph (with the HRX buffers recorded
into it) and its prepared command programs — and trim_graph_programs clears exactly those prepared programs on every
trim (graph-program-cache-limit.cpp:64) while the budget never counted them. The ~1.2 GiB/shape difference is not
attributed to a specific member here; what is established is that transients.arena_size is not it.
The header comment states the opposite expectation: graph-program-budget.h:21-22 — "A cached program keeps its
transient arena alive, about 1 GiB for a large prefill shape", which is why an 8192 MiB budget was assumed to bound
~8 shapes. Measured at 8B/ctx4096 it is ~16 MiB of arena per program and the other ~1.2 GiB per shape is invisible to the
knob.
Impact (operator-facing)
- The knob that sounds like the memory bound (
..._CACHE_MB, "budget in MiB") does nothing at realistic model sizes;
the lever that actually bounds the cache isGGML_HRX_GRAPH_PROGRAM_CACHE(count), whose own documentation
(graph-program-cache-limit.h:24-27) presents it as the weaker of the two. - Setting
..._CACHE_MBlow to rein in a chat server is a silent no-op: no trim, no warning, growth continues until the
count trips. - Not a correctness bug: with both bounds default the cache does get trimmed (28 trims observed) and everything is
returned on exit; the report is about which knob is load-bearing and what its accounting covers.
Suggested direction
- Account the prepared command programs and the graph-retained buffers in
retained_bytes()(they are alive exactly as
long as the program is cached), or - rename/re-document the knob as an arena-only bound and make the count bound the documented lever.
Reproduction scripts: ~/amd-oss/hrx-study/tools/scripts/mem-gc2.sh / mem-gc3.sh (the cache_prompt=false and
same-length designs), GTT read box-wide per request. Context: FACTS-memory.md §6.2/§7.3 in the same directory —
including the companion result that growth is per shape, not per request and not KV (10 identical-length requests
plateau after two, differing content).
Activity
bong-water-water-bong commentedon Nov 2, 2026
**Triaged — bucket A, owner the memory / hrx-study lane that filed it. Verified at fork
d8bd0ff6052a; the paths are right but the files live one directory deeper than the issue says, and the arithmetic turns "does nothing at realistic sizes" into something stronger: at this geometry the byte budget cannot trip.Verified at
d8bd0ff6052a(all four, exact lines)ggml/src/ggml-hrx/runtime/graph-program-cache.cpp:798-800—retained_bytes() { return commands_ != nullptr ? commands_->transients.arena_size : 0; }:685budget_.note(graph.uid, cached_program->retained_bytes())and:854budget_.note(keep->uid(), keep->retained_bytes())— nothing else callsbudget_.noteggml/src/ggml-hrx/runtime/graph-program-cache-limit.cpp:63-64—evict(victims); context.prepared_programs.clear();ggml/src/ggml-hrx/runtime/graph-program-budget.h:18-25— "about 1 GiB for a large prefill shape", and the default 8192 MiB is justified there as "a 27B model's hot shapes plus another model's fit"Path correction so nobody hunts for it: the issue's
graph-program-cache.cpp/graph-program-budget.h/graph-program-cache-limit.cppare all underggml/src/ggml-hrx/runtime/. Your line numbers are exact.The arithmetic that makes it stronger than reported
Your trim line accounts 1031 MiB for 66 programs ≈ 16 MiB each. With the count bound at
GGML_HRX_GRAPH_PROGRAM_CACHE=64, the maximum the byte budget can ever see at this geometry isso the 8192 MiB default is about 8× larger than the highest number the count bound allows it to reach. The byte budget is not merely ineffective at realistic sizes, it is unreachable by construction while (a) the count bound is 64 and (b) per-program arenas stay ~16 MiB — which is why you saw the count trip and the budget never fire. Two consequences worth writing into the issue: the documented rationale for the 8192 default (
graph-program-budget.h:22-24) is off by roughly that factor, and every operator who lowers..._CACHE_MBto rein in a server is adjusting a knob whose threshold sits far above the ceiling the other knob imposes.Also: both call sites have the blind spot —
retain_only()at:854re-notes the sameretained_bytes(), so a fix that only touches the trim path leaves the retain path under-counting. Whatever is decided, it has to be insideretained_bytes()(or a second quantity threaded to both sites).Suggested direction, with the cheap half named
The minimal change that makes budget and trim agree by construction: count the prepared command programs in
retained_bytes()—prepared_programs.clear()is exactly what a trim frees (graph-program-cache-limit.cpp:64), so the quantity the budget watches becomes the quantity the trim releases. The graph-retained buffers are the larger and harder half and can be a second step (or a stated exclusion), because the point that has to stop being wrong first is "the number the knob watches is not the number the trim frees".Whichever way it goes, the doc line is mandatory: either the knob counts what it releases, or it is renamed/documented as an arena-only bound with the count bound named as the real lever (
graph-program-cache-limit.h:24-27currently presents the count as the weaker one).Next action, one: add the prepared programs to
retained_bytes(), then re-run your own arm B and re-read the same trim line — the assertion is that "MiB of arenas" becomes a figure of the same order as the GTT growth you measured (≥ a few hundred MiB per shape, not 16). Closes when the byte budget is the bound that bites for at least one realistic shape set, or when the knob is renamed and documented as arena-only.Links: #840 (same lane, same pin — the sibling gap on the APU side), #669/#674 (the residency accounting this cache growth sits under), #680 (the GTT ceiling the trim exists to keep clear).
bong-water-water-bong commentedon Nov 3, 2026
Second component of the per-shape growth, measured at the pin (
d8bd0ff60), 2026-11-02 21:11-21:18 AST:Each cached graph program also retains a KV-cache staging set that
retained_bytes()cannot see either.GGML_HRX_HOST_STAGING_TRACE=1at 4B /-ngl 0 -c 4096 -fit off -n 8(trio), the executor prepares 181 programsand allocates 686 staging buffers; exactly 144 of them are 8 388 608 B, in 36 programs, 4 per program.
8 388 608 =
n_head_kv(8) x key_length(128) x 2 B x n_ctx(4096)= one K or V cache tensor of one layer.amdgpu_bo_createtracepoint shows the same 144 x 8 MiB as device BOs (VRAM_WIPE_ON_RELEASE), i.e. the stagingbuffers are real GTT, plus a coherent sibling class of the same size for the write-back.
GGML_HRX_DUMP_COMMAND_PROGRAM_DIR) shows the only bindings of length 8 388 608 arenamed
cache, access ReadWrite — the KV cache, not a norm or a transient.graph-program-cache.cpp:711), theprogram count goes 181 → 362, and the plain 8 MiB class doubles 144 → 288 while the coherent class stays 145. Moving
-ub512 → 64 at the same ctx does not move the class at all.bound), and again none of it is in
retained_bytes()(transient arena only,graph-program-cache.cpp:798).Two smaller observations from the same arms:
upload=0 download=0—allocate_host_staging_bufferis called before theaccess flags are consulted (
command-program-executor.cpp:636-657), so ~16 MiB per program is allocated and nevercopied to or from.
-ctk q8_0 -ctv q8_0the whole class disappears (the 8 MiB coherent class drops to its single bring-up BO),i.e. the staging only happens for the f16 KV path. Mechanism not chased; recorded because it is the cheapest way to
see the class vanish.
Evidence (raw rows, dumps and the three arm logs) is in
~/amd-oss/hrx-study/evidence/memory/:bo-kvshape-20261102-2111.log,bo-kvshape-20261102-2114.log,bo-kvname-20261102-2118.log,dump-20261102-2118/. Method and numbers will also land inFACTS-memory.md§7.12.bong-water-water-bong commentedon Nov 3, 2026
Fixed in llama.cpp#175 — the accounting change, with a before/after on this issue's own reproducer
Since this is an engine issue and the code is in the fork, the PR (
1bit-MONSTER/llama.cpp#175, branch1bit/i841-cache-bytes, head3135dba6b67, MERGEABLE/CLEAN, base1bit/hrx-vulkan-patched) cannot auto-close thisissue - closing it is a human step once #175 is merged and the pin moves past it.
Root cause, exactly as this issue's "Suggested direction" predicted:
retained_bytes()returnedtransients.arena_sizeonly. The bytes the budget could not see are the prepared command programs a cached programkeeps alive - their host staging set and per-program constant buffers - and
trim_graph_programsdrops them on everytrim, so it was accounting for exactly what it freed and nothing else. Confirmed at the pin with your reproducer:
1032 MiB across 66 programs = 15.6 MiB each against an 8192 MiB budget, while GTT had grown +11.5 GiB.
Before/after (same tree, same binary, same env, both arms from one
gpu-holdticket; zaya1-8b,-ngl 99 -fit off -c 4096 -np 1, one request per new shape,cache_prompt=false),GGML_HRX_GRAPH_PROGRAM_CACHE_MB=2048:no-op, which is the operator-facing claim in this issue, reproduced.
(-32 %), -5362 MiB (-41 %) at shape 512.
trips first. What changes there is that the trim line reports the truth:
5903 -> 5903 MiB retained. So the honestscope: this makes the byte budget correct and load-bearing; it does not change which bound trips first at the
default. If the byte knob should be the primary lever at realistic model sizes the default needs to come down (2048
is where it starts to bite on an 8B/4k) - a default change I did not put in a fix PR.
Now covered by a host test (
tests/test-hrx-graph-program-budget.cpp, second commit3135dba6b67):resize()mustmove the byte count without moving the LRU, and it is a no-op on an uncached uid. Verified by mutation - a copy whose
resize()also bumps the recency counter makes the test abort atvictims[0] == 1, so the check bites.Not attributed, said rather than implied:
RecordedCommandGraph's retained buffer/executable handles carry no bytesizes, so that slice is still invisible to the budget (it is dropped by the same trim). Tracking it is a follow-up.
Thanks for the two follow-up comments on this issue - the KV-staging measurement (144 x 8 MiB in 36 programs) is what
made the fix's target obvious rather than a guess at the 1.2 GiB/shape.
bong-water-water-bong commentedon Nov 3, 2026
The "unattributed slice" caveat, closed: buffers must stay out of the budget (they are aliases), executables are upstream-blocked
Follow-up to the PR body's honest-scope note ("
RecordedCommandGraph's retained buffer/executable handles carry no bytesizes, so that slice stays unattributed"). I went back to see whether that slice can be attributed. Answer: for buffers it
must not be, and for executables it cannot be yet. Details, because both are the kind of thing that gets "fixed" into a
double count later:
1.
RecordedCommandGraph::retained_buffersare refcount aliases, not allocations.resolve_command_binding()(
ggml/src/ggml-hrx/dispatch/command-program-resolver.cpp:18-71) produces aResolvedBufferReffrom exactly two places:CommandProgramBindingsentry — which is the model's device BO, or the prepared program's own host-staging /per-program constant buffer, or
transient_arena->buffer.retain_prepared_command_list_resources()then justhrx_buffer_retain()s those handles and records each once(
command-program-executor.cpp:1515-1536). So every byte behind them is already owned and already counted by someone else:the model BO by the loader, staging and constants by
PreparedCommandProgram::retained_bytes(), the arena bytransients.arena_size. Summinghrx_buffer_get_size()over them would add the arena once per retaining program — 36programs = 36x — which is precisely the over-count that makes a byte budget stop meaning anything. Nothing to add; the
right change is a comment at the declaration saying so.
2.
retained_executableshas no size to read.libhrx'shrx_executable_export_info_t(hrx_runtime.h:288-295)carries
name,flags,constant_byte_length,binding_count,parameter_count,workgroup_size— and there is nohrx_executable_get_size(). Compiled-kernel bytes are therefore invisible to any budget on this runtime until hrx-systemgrows an accessor. An upstream gap, not an omission in the fix.
Both are recorded here rather than as a comment-only commit on the PR because that PR is sitting at a reviewed head
(
3135dba6b67, "READY" from bong-water-water-bong) and re-heading it for prose would throw away the SHA the review built.State of the fix
1bit/i841-cache-bytes@3135dba6b67) — the accounting fix + theresize()host test. ReviewedREADY; no changes requested. Still MERGEABLE/CLEAN against
1bit/hrx-vulkan-patchedas of 2026-11-03 08:0x.(g++ 15.2
-std=gnu++23; reviewer used amdclang++/C++26):all checks passed, rc 0.64-program count still trips first. The byte knob only becomes the binding bound when it is set below the real
footprint (2048 MiB starts biting on 8B/4k). Changing that default is an owner decision and is not in the fix PR.
bong-water-water-bong commentedon Nov 4, 2026
Status note (2026-11-04 17:2x AST):
llama.cpp#175is merged (c4948cc387, base head428937ae). In a build of themerged tree I re-ran the PR's own host test in place —
test-hrx-graph-program-budget: all checks passed— and confirmedthe merged
retained_bytes()(runtime/graph-program-cache.cpp:798-810) addsprepared_.retained_bytes()underprepared_mutex_, i.e. the retention a trim actually frees, as reviewed.Nothing here changes the issue's conclusion: the byte budget now prices what it frees, but at the shipped defaults
(8192 MiB / 64 programs) the count bound still trips first, so the operator lever remains
GGML_HRX_GRAPH_PROGRAM_CACHE. Making the byte knob primary would need a default change — recorded as an owner decision,deliberately not in the PR.
Written up as §6.2/§7.21 of
~/amd-oss/hrx-study/FACTS-memory.md.bong-water-water-bong commentedon Nov 5, 2026
Measurement appended so this row's remaining half is only the default question: the byte lever now works, and it is
a ceiling on retention rather than a footprint plateau.
Isolation (
GGML_HRX_GRAPH_PROGRAM_CACHE=0= no count limit, so the byte budget is the only thing that can trim;plan_evictions:max_programs == 0is unbounded), before/after pair from the same tree lineage differing only by#175(verified bystringson the trim message: "… MiB of arenas …" vs "… MiB retained …"), zaya1-8B-ngl 99 -fit off -c 4096 -np 1,cache_prompt=false, six distinct prompt lengths (111/231/351/471/611/755 evaluatedtokens, distinct content), no-SVM trio, own
drm-total-gttfrom/proc/<pid>/fdinfo:MB=1024, count offMB=1024, count off#175the knob was a silent no-op at a quarter of the observed growth:MB=1024with no count bound isbyte-identical to the 8192 MiB default. After, the same flags give 13 trims and −2 730 MiB of peak (−26 %).
1049 -> 1036 MiB retained, budget 1024 MiB, 0 max,i.e. retention held at ~1 020-1 040 MiB across 17-22 cached programs, and the last (755-token) shape still allocates
+730 MiB on top of it. Growth is bounded by budget + the executing shape.
(
0 maxin that line ismax_programs == 0, the count bound switched off — not a bug.)of retention, which is what FACTS-memory §6.1 predicts (the libhrx pool keeps its slabs,
max_count = UINT32_MAX,hrx_mem_pool_trimnever called). Consistent, not proven — one request cannot separate the trim from the new shape.body stands. Making the byte knob primary is still a default change — owner decision, deliberately not in
#175.Detail:
~/amd-oss/hrx-study/FACTS-memory.md§7.22 (DRAFT 17), evidenceevidence/memory/gc4-20261105-0525/, scripttools/scripts/mem-gc4.sh. Leaving this issue open only for that default decision.bong-water-water-bong commentedon Nov 5, 2026
Re-checked on the shipped tree (
428937ae,llama-serverbuilt for this ticket), because everything this row quotes wasmeasured at the pin. Same reproducer shape: 8B,
-ngl 99 -fit off -c 4096 -np 1,cache_prompt=false, 8 growing promptlengths, and — one method change — the server's own
drm-total-gttper reading rather than the box-wide counter, whichthis box contaminates with two other lanes' serves.
line still reads
… budget 8192 MiB, 64 max. At the shipped defaults the count is still what bites.+536 MiB at the pin vs 151 tokens → +107 MiB shipped (2.93 vs 0.71 MiB per token of the new shape); cumulative 1 392 vs
369 MiB per cached shape. Candidates for the difference are named in FACTS-memory §7.25 and deliberately not attributed
(
#176removes 2 of the 4 staging buffers per prepared program; the pin arm's box-wide sampling may also flatter it —its load delta still matched to 2 MiB).
1934 -> 1933 MiB retainedand1092 -> 1092, i.e. evicting one of 66 programs frees ~0-1 MiB, because retention isheavily skewed: most cached programs hold almost nothing and a few hold nearly everything. Under the count bound that is
harmless (the bound is about how many shapes you keep). Under the byte bound it is not: with
GGML_HRX_GRAPH_PROGRAM_CACHE=0 GGML_HRX_GRAPH_PROGRAM_CACHE_MB=1024the observed trims were1049 -> 1036,1058 -> 626,1276 -> 830— LRU sometimes frees 13 MiB, sometimes 448, i.e. it keeps evicting small old programs while the cache staysnear budget.
So a candidate improvement, offered as a decision and not as a patch: when eviction is triggered by bytes, choose by size
(largest first) rather than strictly by age, keeping LRU for the count bound. It would make each trim actually move the
number, and it would keep the expensive-to-rebuild large shapes only if they are also recent — which is the trade nobody has
measured here (hit rate vs footprint). I have not filed it as its own issue; it belongs to this row's open default question.
bong-water-water-bong commentedon Nov 5, 2026
Draft: engine#841 comment 4 — the hit-rate side, measured (2026-11-05 14:4x AST)
Posted at:
1. What I set out to measure, and the retraction I have to lead with
My third comment here proposed that when eviction is triggered by the byte bound, the cache should evict
largest-first instead of by age, and said plainly that the hit-rate side was unmeasured. That measurement ran today on
this box (zaya1-8B,
-ngl 99 -fit off -c 4096 -np 1,cache_prompt=false, count bound off viaGGML_HRX_GRAPH_PROGRAM_CACHE=0so only the byte budget can trim, three prompt lengths repeated three times with identical text per length).
First result is that my own first reading was wrong, and it is worth stating plainly because it is the trap in this
experiment. A within-arm comparison (does cycle 2-3 get slower than cycle 1 in the thrashing arm?) says no — the
repeats got faster (2.2x / 1.7x / 3.1x), even with 53 trims over 9 requests. I nearly wrote "discarding the programs costs
nothing". A constant per-request tax and a warm-up ramp have the same within-arm signature (both rise cycle over cycle).
The only way to see the tax is an arm that does not pay it, at the same time, in both orders:
_MB=64, ran first of the ticket_MB=1024_MB=1024(2nd pass)_MB=64, ran lastmin-of-3 per arm/length, all cycles (the box was contaminated: individual prefills stretched to 18/25/76 s against a
0.6-1.2 s baseline, so no means are used anywhere).
2. The bound does cost hit rate — as a rate on every request, not a collapse
With the order controlled,
_MB=64is +34-46 % of prefill (636/815/1 150 ms against 436/606/857 at best case in thepass where it ran last; the first pass's other two lengths agree at +44 %/+42 %), while
_MB=1024tracks the unbounded armwithin 3 % in both positions. So:
1 010 ms when it ran last — and the tight arm is still slower when it runs last, so ordering does not explain its cost;
walk (53 trims x ~4 ms is the same order as the 200-300 ms measured). Both are consequences of the bound.
The footprint half reproduces and is order-insensitive:
_MB=64ends +100 MiB over load in both passes,_MB=1024/unbounded +1 976 / +2 000 MiB in both.3. The important part: this design was degenerate for the policy question
At 64 MiB the trim leaves 1 of 4 programs (
3 of 4 programs, 364 -> 23 MiB retained, budget 64 MiB, 0 max), i.e.nothing is cacheable — so "LRU by age vs largest-first" is not observable there; the arm thrashes for every request
regardless of policy. At 1 024 MiB almost nothing is evicted (2 trims, retention 1 033 of 1 024 MiB). Retention per program
in this run is ~90 MiB, so the band where the policy question actually lives is a budget that holds some but not all
of three shapes — roughly 100-400 MiB.
So: the motivation for size-aware eviction (footprint) is sound and reproduces; the policy choice itself still has no
measurement behind it, because neither end of the knob exercises it. The cheap decisive experiment is named — budget
~100-400 MiB, three shapes cycling, and check which program each trim drops relative to the next request — and I would rather
say that than let a 64 MiB thrash stand in for it.
4. What this changes for the default question
Nothing about the shipped default yet: at 8 192 MiB / 64 programs the count bound still trips first, so this knob is not
binding for operators today. What it does add is that when the byte bound binds it charges throughput on every request,
which is an argument for keeping the default high unless the footprint is the constraint — the operator-facing advice in
FACTS-memory §7.26/§7.27 and KNOBS.md.
Raw evidence:
evidence/memory/gc6-20261105-1350/(first pass) andevidence/memory/gc7-20261105-1415/(order-reversed),scripts
tools/scripts/mem-gc6.sh/mem-gc7.sh, offline readertools/gc7-parse.py.bong-water-water-bong commentedon Nov 5, 2026
engine#841 comment 5 (posted) — retracting the +34-46 % prefill tax from comment 4
Correcting my own number from comment 4. I wrote there that a byte budget too small to cache any shape costs
+34-46 % of prefill, order-controlled. Two follow-up runs say that magnitude is wrong: the cost is ~9-11 % at
best, and it is not separable from clock starvation on this box.
Why the first number was too big: the original run compared arm positions in a ticket where individual prefills
stretched to 18/25/76 s, and prefill here is clock-dominated —
pp_dpm_sclkmoved 728 → 2 320 MHz inside singlearms. A fresh
llama-serverper arm cannot hold the clock still, so "tight ran last and was still slower" was a weakcontrol, not a strong one.
The two runs that replace it (8B,
-ngl 99 -fit off -c 4096 -np 1, count bound off so only the byte bound can trim,three shapes 563/947/1379 tokens,
cache_prompt=false):two extremes are indistinguishable: 53 trims → 0.966/0.660/0.746 ms/token vs 18 trims → 0.936/0.671/0.691
(L1/L2/L3) at ~2 100 MHz. The apparent 2x splits tracked
sclk, not the budget.clocks are within 150 MHz: pooled median ratio A/B = 1.11, mean 1.37, 5 of 7 pairs slower with the bound; without
one 3.0x contention outlier (same clock, tight arm starved) the median is 1.09 and the mean 1.10.
The limit, stated rather than hidden: the paired run achieved only 7 of 18 clock-matched requests, so it is
underpowered for a ≤10 % effect, and pinning the clock is a box-config change I do not make on a shared host. So the
honest statement is "about a tenth, wide uncertainty", not a precise figure.
What got stronger, and it is the part the eviction-policy proposal actually needs. The footprint half reproduced
byte-identically in all six pairs: tight ends +100 MiB over load with 17 trims, unbounded +1 880 MiB with 0
trims — a deterministic 1.78 GiB at three shapes, across six fresh servers in one ticket. So the case for a
size-aware eviction (or for lowering the default) rests on footprint, which is reproducible, and not on a throughput
argument, which is not.
Method note for anyone repeating this: record
pp_dpm_sclkper request, compare only clock-matched pairs, and nevercompare two arms measured at different clock states — the effect you are chasing is smaller than the clock's own swing.
bong-water-water-bong commentedon Nov 6, 2026
Resolved (accounting) and measured out of the policy proposal. Both halves were taken to the device:
The accounting fix is shipped
Fork #175 (
c4948cc38, "count the prepared command programs in the graph-program cache byte budget") makesretained_bytes()include the prepared command programs and re-tallies before evicting. It is an ancestor of the engine's current pin —d70b67bf0, merged by #1233 (verified:c4948cc38is 36 commits behind it), so the engine now has it. Verified at tip on strixhalo: at a 64 MiB budget the trim lines report real retention —95 -> 68 MiB retained, budget 64 MiB,104 -> 77 MiB retained(the kept executing program excluded), 14-19 trims over 9 requests. The budget bites at tens of MiB per program, not the old "16 MiB/program plus an unreachable 8192" picture.The eviction-policy half does not earn a PR
The issue's size-aware proposal was implemented and measured (
1bit/i841-cache-policy @ 231430f9d, pushed for the record only): byte-bound trims evict largest-first, the count bound keeps LRU,GGML_HRX_GRAPH_PROGRAM_EVICT=lrurestores the old order, and the host test is extended. At 64 MiB it does fewer trims (14 vs 19) but leaves a slightly higher peak (+319 vs +313 MiB over load) and no throughput gain — so it was not opened as a PR.What the device measurement says about the premise
At tip (strixhalo, zaya1-8B Q4_K_M,
-ngl 99 -fit off -c 4096 -np 1,cache_prompt=false, shapes 552/958/1393 tokens, 3 cycles): unbounded growth saturates at ~0.32 GiB (peaks +321/+323/+323 MiB over load), not the campaign's 1.78 GiB; a 64 MiB budget gives +319/+319/+319 with 14 trims and trims do not return bytes to the driver (the libhrx pool keeps its slabs), consistent with this issue's own measurement note. Generated content is byte-identical across every arm; no separable budget effect on throughput (prompt_mswithpp_dpm_sclk1.0-2.1 GHz per request, the cycle-2/3 speedup tracks sclk).The 1.78 GiB case did not reproduce here and was not attributed: candidates are the fork commits after
428937aeand/or this build's prebuilt hrx-system runtime (not the engine's pinned one). If that case matters for a real payload, re-running it against the pinned runtime + shipped binary is the next step — and the slab-retention behaviour is a runtime property, not a cache-accounting one.Closing on the accounting fix being shipped and the policy proposal measured out. The fork-side lane recommends no further change.
bong-water-water-bong commentedon Nov 7, 2026
The order question, measured: below ~192 MiB age is right, from 256 MiB up largest-first roughly halves the rebuilds, and they converge once the budget covers the cycle
Follow-up to comments 3, 5 and 6. Comment 3 proposed that when the byte bound trips, the cache should evict
largest-first instead of oldest-first, and said plainly that the hit-rate side was unmeasured; comment 5 retracted the
throughput framing (prefill on this box is clock-dominated). So the question is decided by counting rebuilds, which
needs (a) a workload that revisits shapes and (b) a log that says which order produced it. Both now exist:
GGML_HRX_GRAPH_PROGRAM_EVICT=sizeselects the byte-bound order (count bound stays oldest-first); unset isage, theshipped behaviour. The trim line now carries
evict=<policy> builds=<N> hits=<M>, so each arm is self-describing andthe count comes from the binary's own lifetime counters rather than from a clock. Fork PR llama.cpp#230.
A B C / A B C / A B Cover three prompt shapes (24/96/192 words = 111/471/1043 evaluated tokens), 8B-ngl 99 -fit off -c 4096 -np 1,cache_prompt=false, fresh server per arm, count bound off so only the bytebound can trim, own GTT from
/proc/<pid>/fdinfo, every run insidegpu-hold,MemoryMax=24G(peak own-GTT 7.1 GiB).builds = graph programs rebuilt for the same nine requests (lower is better); trims/dropped are the policy's own
work. One full 9-arm sweep, and a second sweep that confirms 256/384 before the 25-minute hold cut it:
Three things fall out of that shape, and they are the answer rather than a winner:
age's rebuild count is flat in the budget until it is nearly big enough. 121 → 121 → 118 → 116 for 128 → 384 MiB:tripling the budget buys five rebuilds. That is the revisit-cycle pathology measured, not asserted: on an
A B Ccycle the oldest program is always the one about to be needed, so age evicts the next-needed program and spends the
rest of the request rebuilding it. Extra bytes cannot help an order that does that.
than half of age's rebuilds at 384 MiB (56 vs 116) and 46 % fewer when the bound is below the working set at 256
MiB (88 vs 118) — while returning more bytes per trim (244 MiB vs 132 MiB at 384) and touching fewer programs
(17 dropped vs 112).
at 768 MiB both orders are 38 builds / 1 trim, so the order stops mattering before the bound stops binding.
The inversion at the tight end is real and is why the shipped default stays
age: at 128 MiB size rebuilds 60 % more(194 vs 121) and at 192 MiB 9 % more. Mechanism: with a budget far below the cycle, dropping the largest frees room
that the next shape fills with several small programs, and the following shape re-evicts them all — one big eviction
becomes many re-admissions. Largest-first pays off exactly when the freed room is enough to keep the rest of the cycle
resident, which is why its advantage grows monotonically from 256 to 384 MiB and vanishes at 768.
What I would do with it: the default does not change (a policy that is worse below a fifth of the working set is not
a safe default for an unknown workload), but any serve whose byte bound sits in the 256–512 MiB band — which is the band
comment 3 measured at 15.6 MiB × 66 programs on an 8B/4k serve — should set
GGML_HRX_GRAPH_PROGRAM_EVICT=sizeandexpect roughly half 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 are identical between them where both ran, which is
what makes single-sample rows quotable here), and no timing claim of any kind — comment 5 stands, this measures counts
only.
hitsis reported by the same line but its total (builds + hits) varies with the budget, so I do not score on it.bong-water-water-bong commentedon Nov 7, 2026
Correction to my own table in comment 6713555438, made before anyone has to find it: the
buildscolumn is a snapshot, not an arm total. The trim line prints the cache's lifetime counters at the moment of the trim, so an arm whose last trim lands early reports a smaller number than it ended on. Per arm, with the lag from the last trim to the arm's final request:What that changes and what it does not:
agerebuilds 116 (exact) againstsize>= 56, and at 256 MiBage118 (exact) againstsize>= 88. A lower bound on size's rebuilds can only widen the gap, so "largest-first roughly halves the rebuilds in the 256-384 MiB band" is if anything understated, not overstated.trimsanddroppedwere never snapshots (they are greps over every trim line of the arm), so the "17 programs dropped vs 112 at 384 MiB" statement stands as published.ageat 128/192 was a separate 3-sweep stage whose counters were identical across sweeps) or bounded in age's favour the same way.The PR body (llama.cpp#230) now says this in the table caption, and
agestays the default, so none of this moves shipped behaviour. If the number matters beyond a factor of two, the fix is one harness line - print the counters after the last request instead of relying on the last trim - which I will do if this row gets picked up again.bong-water-water-bong commentedon Nov 8, 2026
The
>=rows from my correction (6713999145) are now measured at arm end, and the answer moves the recommendation upward, not downward: largest-first's advantage survives at 512 MiB and is gone by 768.Method:
TAIL=1in the harness sends one request with a shape the passes never used, after a marker, so its build trips the byte bound again and the trim line printed there carries near-final counts instead of a snapshot. Same 8B,-ngl 99 -fit off -c 4096 -np 1, count bound off, three shapes × three passes, one extra 160-word shape at the end. Lag from the last trim to the arm's final request is now 0.2 / 0.9 / 0.2 / 0.3 s for the four arms — i.e. these are end-of-arm numbers, not snapshots.What changes:
EVICT=sizein the 256-512 MiB band"; the band is not bounded at 512 — the advantage is still there at 512 and only disappears by 768.Caveat that stays: the 384 MiB row is still mixed —
age116 is exact,size >= 56is a lower bound from the longer-running stage, so size's true 384 figure is probably a little higher than 56 (which would make the 384 gap a bit smaller than "2x", not larger). If that row matters, it is the same one-line change and one 2-arm ticket.The lever and the instrument are merged (llama.cpp#230,
5d4d960); the counters that the trim line prints are made lifetime-monotonic by llama.cpp#235. Neither changes a default.bong-water-water-bong commentedon Nov 8, 2026
One more thing the arm-end numbers give, and it retires a caveat I put on my own table:
builds + hitsis exactly 1428 in every arm, for both policies, at every budget measured this way.That is the number of graph-program lookups the workload performs (ten requests: three shapes × three passes plus the tail shape), and it being constant across policies and budgets is the check that the two counters are complete and complementary rather than independently noisy — a rebuild is a lookup that missed, so for a fixed workload the pair must trade one-for-one, and it does to the unit.
It also explains the thing I flagged in comment 6713555438 and then refused to score on: the earlier
hitscolumn appeared to swing from 335 to 1147 between arms. That spread was not behaviour, it was the same snapshot artefact asbuilds— the trim line prints the counters at the trim, so an arm whose last trim landed early reported a smallhitstoo. At arm end the four arms sit within 22 counts of each other and sum identically. Sohitsis safe to quote now, with the same rule asbuilds: only from a trim near the arm's end.Corollary for anyone re-running this:
builds + hitsis a free self-check on whether a gc10 arm produced a usable reading at all. If the sum is not the workload's lookup count, the last trim was a snapshot and the row is a lower bound — which is how the 128/192/256 stage was certified exact and how the 512/768 rows failed certification until the tail was added.bong-water-water-bong commentedon Nov 8, 2026
Correcting my own corollary from 6714986812, and it matters: the
builds + hitssum is a check, not an invariant. I wrote that it "is exactly 1428 in every arm... constant across policies and budgets". It is constant in the arms where the last trim lands at the arm's last lookup, and not in the ones where it lands early. Checking every stage's sums rather than only the four arms in front of me:So "the sum is constant" is exactly what a complete reading looks like, and a short sum means that arm's counters are still catching up — which is the useful half of the claim, and the half I should have written. Concretely it downgrades one published row: size256's 88 is a lower bound, because that arm's sum is 62 short of the workload's 1265 lookups.
The 384 MiB row, measured at arm end (new):
Both sum to 1428, so this pair is complete and comparable: largest-first rebuilds 47 % less at 384 MiB (70 vs 131), and drops 17 programs instead of 112. The earlier 116 / ≥ 56 in comments 6713555438 and 6713999145 were both incomplete readings — the arm-end numbers are higher for both orders, and my prediction that the correction would shrink the 384 gap was right in direction (2.07× → 1.87×) and wrong in size (both counts moved a lot, not a little).
That leaves one row outstanding: 256 MiB, where
age118 is complete andsize >= 88is not. Running that pair at arm end now. Current state of the table, complete rows only:The recommendation narrows rather than disappears: the size order pays off from ~384 to ~512 and is a wash by 768; below 192 it is the wrong order. Anyone who quoted the earlier numbers from me should take these.
bong-water-water-bong commentedon Nov 8, 2026
Last row closed: 256 MiB at arm end is age 133 vs size 119 (both sum to 1428, so both complete). The earlier reading of that row (118 vs ">= 88") had size short by 62 lookups; with a complete reading its advantage at 256 MiB is ~11 %, not the ~34 % the incomplete numbers implied.
All six rows, and one methodological correction that matters for reading them:
The rows are not comparable across the two measurement styles, and I should say so before anyone subtracts them. The arm-end runs carry one extra request (a 160-word shape, sent after a marker so its build trips the byte bound and the trim line prints near-final counts); that request builds its own programs, so its counts include roughly +15 builds over the same arm without it. The check that the two styles agree in substance: the 256 MiB arm reads 118 on the 9-request workload and 133 with the tail — the same "~15" appears at 384 (116 → 131) and 512 (59 → 77). Compare within a row, never across rows.
What the complete table says, and it is less clean than either of my earlier summaries:
So the recommendation that survives all the corrections is the modest one:
GGML_HRX_GRAPH_PROGRAM_EVICT=sizeis worth setting for a serve whose byte budget sits in the 256-512 MiB band — expect a real but workload-dependent cut in rebuilds, up to roughly half around 384 MiB in this workload — and never below 192 MiB. Both PRs that make it available are merged (llama.cpp#2305d4d960for the lever and the trim-line counts, #2356bf2162for counters that cannot go backwards).Measurements in this thread: 9-request stage ×3 sweeps, arm-end stage for 512/768, 384 and 256 — every row above quotes a sum check, and rows that failed that check were re-run rather than averaged.