[GH-ISSUE #1923] Engine-side expert-cache eviction policy (LRU / LFU-decay), opt-in; measured headroom on gfx906 #761

Closed
opened 2026-11-04 01:45:39 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @phoenixclyde on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1923

Context

ExpertCache::admit never evicts. include/strata/core/expert_cache.hpp:143 says: "it never evicts,
because eviction policy is a measured question (R4.1's LFU-decay vs LRU sweep)". tools/bench_eviction.py
is the harness for that measurement, and the policies it defines (fill-only, lru, lfu-decay, oracle) are
exactly the candidates.

Measurement

On a gfx906 / Radeon Instinct MI50 32GB, UD-IQ4_XS pack, engine 0.1.42, we replayed a --dump-routing
trace (3,838 positions x 48 layers x k=10 = 1,842,240 (layer,expert) lookups) through
tools/bench_eviction.py, prefilled with the production expert-profile.bin:

slots fill-only (today) lru lfu-decay oracle
9,761 (production) 0.7086 0.9751 0.9767 0.9890
64 0.0105 0.3931 0.0481 0.4221

At the production slot count the current policy leaves about 24-28 points of hit rate on the table, and
two policies that already exist in your own tool recover about 95% of the oracle bound. At small slot
counts the gap is far larger (slots=64: 0.0105 vs 0.4221), i.e. today's behaviour is mostly a function of
"are the slots big enough", not of any policy.

Caveat: these are hit-rate figures from offline replay, not wall-clock; the speed benefit depends on the
miss cost (PCIe / CPU pool share), which we have not measured live yet. The trace is one text-continuation
workload, not the full production distribution. Oracle reads the future and is not implementable; it is
only the upper bound.

Note on answers: an eviction policy changes WHICH experts are computed on the GPU (vs read from
RAM/files and computed on the CPU). The engine already documents that the GPU and the CPU round
differently and that a reply "can differ slightly" (bench/results/2026-09-27-cache-parity). So this
is NOT answer-neutral by construction; adoption would need a quality gate, the same way the other
answers-can-differ switches are handled.

Ask

Would an opt-in eviction policy for the VRAM expert cache be in scope? Concretely, a
STRATA_EXPERT_EVICT=lru|lfu-decay environment switch (default off = today's fill-only), with the policy
implemented to match tools/bench_eviction.py exactly so the offline prediction and the live engine stay
comparable. We are happy to prepare the patch if that helps.

Originally created by @phoenixclyde on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1923 Context ------- `ExpertCache::admit` never evicts. `include/strata/core/expert_cache.hpp:143` says: "it never evicts, because eviction policy is a measured question (R4.1's LFU-decay vs LRU sweep)". `tools/bench_eviction.py` is the harness for that measurement, and the policies it defines (fill-only, lru, lfu-decay, oracle) are exactly the candidates. Measurement ----------- On a gfx906 / Radeon Instinct MI50 32GB, UD-IQ4_XS pack, engine 0.1.42, we replayed a `--dump-routing` trace (3,838 positions x 48 layers x k=10 = 1,842,240 (layer,expert) lookups) through `tools/bench_eviction.py`, prefilled with the production `expert-profile.bin`: slots fill-only (today) lru lfu-decay oracle 9,761 (production) 0.7086 0.9751 0.9767 0.9890 64 0.0105 0.3931 0.0481 0.4221 At the production slot count the current policy leaves about 24-28 points of hit rate on the table, and two policies that already exist in your own tool recover about 95% of the oracle bound. At small slot counts the gap is far larger (slots=64: 0.0105 vs 0.4221), i.e. today's behaviour is mostly a function of "are the slots big enough", not of any policy. Caveat: these are hit-rate figures from offline replay, not wall-clock; the speed benefit depends on the miss cost (PCIe / CPU pool share), which we have not measured live yet. The trace is one text-continuation workload, not the full production distribution. Oracle reads the future and is not implementable; it is only the upper bound. Note on answers: an eviction policy changes WHICH experts are computed on the GPU (vs read from RAM/files and computed on the CPU). The engine already documents that the GPU and the CPU round differently and that a reply "can differ slightly" (bench/results/2026-09-27-cache-parity). So this is NOT answer-neutral by construction; adoption would need a quality gate, the same way the other answers-can-differ switches are handled. Ask --- Would an opt-in eviction policy for the VRAM expert cache be in scope? Concretely, a `STRATA_EXPERT_EVICT=lru|lfu-decay` environment switch (default off = today's fill-only), with the policy implemented to match `tools/bench_eviction.py` exactly so the offline prediction and the live engine stay comparable. We are happy to prepare the patch if that helps.
Author
Owner

@phoenixclyde commented on GitHub (Oct 11, 2026):

A clarification on our own numbers (they are trace-scoped, not workload-scoped)

In the measurement above the 0.7086 fill-only figure comes from replaying a --dump-routing trace
(3,838 positions, one text-continuation prompt) through tools/bench_eviction.py. That is NOT the
hit rate our production workload sees. On the same card, same slots (9,761), our live engine reports
decode expert cache hit rate of 95.4-98.0% on long runs (2.8-3.1M lookups) and 88-90% on short ones.

So the "+24-28 points left on the table" applies to a trace-like, cold-cache workload. We do not know
yet how much of it survives on a workload that a learned expert profile already covers at ~96%. The
part that plausibly survives is whatever the engine's adaptive swaps bring back today (its cache has no
eviction to fall back on), and we have not measured that split.

We therefore do not claim a production gain here; the proposal stands as "an opt-in policy is missing
and the offline headroom is real for trace-like traffic". If you want a number for a specific
workload shape, we can measure the fill-only vs lru delta on that shape and post it.

<!-- gh-comment-id:6106275361 --> @phoenixclyde commented on GitHub (Oct 11, 2026): A clarification on our own numbers (they are trace-scoped, not workload-scoped) ------------------------------------------------------------------------------ In the measurement above the 0.7086 fill-only figure comes from replaying a `--dump-routing` trace (3,838 positions, one text-continuation prompt) through `tools/bench_eviction.py`. That is NOT the hit rate our production workload sees. On the same card, same slots (9,761), our live engine reports `decode expert cache hit rate` of 95.4-98.0% on long runs (2.8-3.1M lookups) and 88-90% on short ones. So the "+24-28 points left on the table" applies to a trace-like, cold-cache workload. We do not know yet how much of it survives on a workload that a learned expert profile already covers at ~96%. The part that plausibly survives is whatever the engine's adaptive swaps bring back today (its cache has no eviction to fall back on), and we have not measured that split. We therefore do not claim a production gain here; the proposal stands as "an opt-in policy is missing and the offline headroom is real for trace-like traffic". If you want a number for a specific workload shape, we can measure the fill-only vs lru delta on that shape and post it. <!-- albus-checkin -->
Author
Owner

@phoenixclyde commented on GitHub (Oct 11, 2026):

Correction to our own report above.

We measured fill-only 0.7086 with tools/bench_eviction.py and read it as "the engine's
current admission, so this is today's hit rate". That was the wrong baseline. ExpertCache::admit
never evicts, but the same startup path also builds the resident-RAM mode's adaptive tier, which
does move residents in and out. On our box the production log says:

strata generate: pre-filled 9761 of 9761 slots from the profile in 8.2 s (2881 MB/s); slot 0 verified
strata generate: resident RAM mode: 33.44 GiB of experts in RAM (page-locked), 9761 in the GPU cache;
                 adaptive swaps exchange them with the GPU cache (no file reads)

Your own tools/replay_cache_policy.py is the model of that tier ("The simulated adaptive tier is
generate.cpp's adapt()"). Replaying the SAME --dump-routing trace, from the SAME shipped
expert-profile.bin, at the same 9,761 slots:

profile only, no adaptation                            0.7086
policy every 4, swaps 96, decay 0.70 (the engine's defaults)   0.9564   (11601 swaps)
static oracle (top-9761 by this trace's own counts)     0.9669

so the tier already recovers about 99% of what that trace allows, and 0.9564 sits right on the
95.4-98.0% decode hit rate our production engine reports. The five knobs match the engine's
defaults one for one: adapt_every = 4 (generate.cpp:577), adapt_decay = 0.7f (:578),
adapt_swaps = 96 (:607), adapt_min_gain = 1.5f (:581, compared at :8174), and the
candidate gate u[e] >= 2.0f (:8165).

So we withdraw the motivation "add an eviction policy to recover the 24-28 points". What is left
is narrower, and we are not asking for it here:

(a) machines that do NOT run the resident-RAM mode (there adapt() does not run at all) may
still sit at the fill-only rate - that is a question about the tier's reach, not about
adding a second eviction policy;
(b) the adapt_* knobs themselves: making them busier did not help on our trace
(--every 1 -> 0.9556, a looser gate -> 0.9590, both within a point of 0.9564).

Two small observations while we were in there:

  1. generate.cpp:5008 prints "expert cache %lld slots, %.2f GiB of VRAM; policy is\n" - the
    policy text is missing an argument, so the log line just ends with "policy is".
  2. bench_eviction.py describes fill-only as "the engine's current admission: ... the baseline
    a policy has to beat". On a --resident-* engine that reads as "the engine's current hit
    rate", which is what led us here. A word about adapt() in that docstring would have saved
    us the round.

Reproduce (no GPU needed):

python tools/replay_cache_policy.py TRACE.bin data/expert-profile.bin 9761
python tools/replay_cache_policy.py TRACE.bin data/expert-profile.bin 9761 --swaps 0
python tools/bench_eviction.py TRACE.bin --slots 9761 --prefill data/expert-profile.bin \
       --policies fill-only,lru,lfu-decay,oracle

Trace: 16,211,712 B, md5 6b5f1e44788fc13fa598d4261d5cbcde (0.1.42, 48 layers x 512 experts,
3,838 positions x k=10). Profile: 196,632 B, md5 ff1bc6544d3f2f0013e3e376632d33a8 - byte-identical
to the image's /src/data/expert-profile.bin.

<!-- gh-comment-id:6106666399 --> @phoenixclyde commented on GitHub (Oct 11, 2026): Correction to our own report above. We measured `fill-only 0.7086` with `tools/bench_eviction.py` and read it as "the engine's current admission, so this is today's hit rate". That was the wrong baseline. `ExpertCache::admit` never evicts, but the same startup path also builds the resident-RAM mode's **adaptive tier**, which does move residents in and out. On our box the production log says: strata generate: pre-filled 9761 of 9761 slots from the profile in 8.2 s (2881 MB/s); slot 0 verified strata generate: resident RAM mode: 33.44 GiB of experts in RAM (page-locked), 9761 in the GPU cache; adaptive swaps exchange them with the GPU cache (no file reads) Your own `tools/replay_cache_policy.py` is the model of that tier ("The simulated adaptive tier is generate.cpp's adapt()"). Replaying the SAME `--dump-routing` trace, from the SAME shipped `expert-profile.bin`, at the same 9,761 slots: profile only, no adaptation 0.7086 policy every 4, swaps 96, decay 0.70 (the engine's defaults) 0.9564 (11601 swaps) static oracle (top-9761 by this trace's own counts) 0.9669 so the tier already recovers about 99% of what that trace allows, and 0.9564 sits right on the 95.4-98.0% decode hit rate our production engine reports. The five knobs match the engine's defaults one for one: `adapt_every = 4` (`generate.cpp:577`), `adapt_decay = 0.7f` (`:578`), `adapt_swaps = 96` (`:607`), `adapt_min_gain = 1.5f` (`:581`, compared at `:8174`), and the candidate gate `u[e] >= 2.0f` (`:8165`). So we withdraw the motivation "add an eviction policy to recover the 24-28 points". What is left is narrower, and we are not asking for it here: (a) machines that do NOT run the resident-RAM mode (there `adapt()` does not run at all) may still sit at the fill-only rate - that is a question about the tier's reach, not about adding a second eviction policy; (b) the `adapt_*` knobs themselves: making them busier did not help on our trace (`--every 1` -> 0.9556, a looser gate -> 0.9590, both within a point of 0.9564). Two small observations while we were in there: 1. `generate.cpp:5008` prints "expert cache %lld slots, %.2f GiB of VRAM; policy is\n" - the policy text is missing an argument, so the log line just ends with "policy is". 2. `bench_eviction.py` describes `fill-only` as "the engine's current admission: ... the baseline a policy has to beat". On a `--resident-*` engine that reads as "the engine's current hit rate", which is what led us here. A word about `adapt()` in that docstring would have saved us the round. Reproduce (no GPU needed): python tools/replay_cache_policy.py TRACE.bin data/expert-profile.bin 9761 python tools/replay_cache_policy.py TRACE.bin data/expert-profile.bin 9761 --swaps 0 python tools/bench_eviction.py TRACE.bin --slots 9761 --prefill data/expert-profile.bin \ --policies fill-only,lru,lfu-decay,oracle Trace: 16,211,712 B, md5 6b5f1e44788fc13fa598d4261d5cbcde (0.1.42, 48 layers x 512 experts, 3,838 positions x k=10). Profile: 196,632 B, md5 ff1bc6544d3f2f0013e3e376632d33a8 - byte-identical to the image's `/src/data/expert-profile.bin`. <!-- albus-checkin -->
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6270700582 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#761
No description provided.