[RFC/Experiment] Colibri Native Residency Engine: cost-aware expert caching and paged KV prefixes #884
Replies: 2 comments
|
@JustVugg, before any proposal acceptance or runtime refactor, I completed a real-trace Phase 0 pilot on a DigitalOcean H200 and wanted to add the evidence here. The result is encouraging, but I am keeping the runtime claim deliberately conservative. What was tested
I collected 13 real routing traces: 8 training traces and 5 held-out traces covering coding, chat, reasoning, multilingual, and long-context prompts. MTP, cache-aware routing, speculative/pilot loads, and repinning were disabled during collection so the traces describe the ordinary GLM CPU-routing path. Artifacts were kept outside the repository on the ephemeral server: The offline simulator and its tests are in the local experiment worktree: Held-out simulator resultThe comparison is against uniform LRU under the same expert-residency byte budget. Categories are equally weighted, and the gate requires at least 10% mean felt-wait improvement with no category more than 3% worse.
The LRU dynamic allocator was effectively neutral in this pilot, around 0.0-0.4% improvement, and did not meet the 10% gate. The frequency candidates passed the nominal category gate at all three budgets. I also perturbed felt cost independently at representative layers 3, 30, and 60 by Runtime qualificationThe simulator result is not yet a runtime speedup claim. The current GLM engine still admits every demand miss and promotes the bounded tail of each 64-expert block. No runtime frequency-admission implementation was added before posting this update. The first H200 runtime checks show why this distinction matters:
These are pilot measurements, not an N>=5 ABBA benchmark. They demonstrate that hit rate alone is not the objective: existing I/O/compute overlap changed tok/s more than the cache-size change. An unrecognized InterpretationThis is the strongest result so far:
If you support continuing Phase 0, I suggest the next reviewable step is that narrowly scoped GLM prototype followed by interleaved ABBA runs reporting tok/s, p50/p99 latency, felt wait, physical bytes read, admissions, rejections, evictions, migration bytes, and exact output identity. If it fails that runtime gate, I will document the negative result rather than promote the policy. |
|
Post-merge review of the Phase 0 simulator found three methodological gaps that should be corrected before interpreting the pilot as evidence for runtime admission. I opened the two implementation defects separately so they stay reviewable:
The third gap is experimental rather than a parser bug: Before any runtime prototype, I suggest adding paired arms with equivalent initial state:
The runtime checks already showed that hit rate alone is not the objective, so keeping this qualification strict is useful. I am not proposing runtime code while these offline comparisons remain confounded. |
Uh oh!
There was an error while loading. Please reload this page.
@JustVugg, I would like your opinion on this direction before anyone writes implementation code.
I reviewed the current cache, storage, and KV mechanisms across the five model families available on
dev: GLM-5.2, Kimi K3, Inkling, OLMoE, and DeepSeek V4.My conclusion is not that Colibri needs an external cache service. It needs a common native residency engine that applies Valkey-like bounded-memory and eviction discipline to inference-native objects.
There would be no daemon, sockets, RESP protocol, serialization layer, RDB, or AOF. The system would live inside the C runtime and operate directly on expert bundles, prepared tensor layouts, and KV blocks.
The objective would not be to maximize cache hit rate. It would be:
Why this may be worth investigating
Colibri already has several effective caches, but each engine implements a different subset:
The project already has most of the required mechanisms:
.coli_usagehistories;mmap, mirrors, and multiple drives;PIPEandio_uring;The missing piece is a common mathematical and lifecycle model.
Adding more model families currently means implementing another cache structure, another admission policy, another set of counters, and another interpretation of memory capacity. Qwen and other future engines will increase that duplication unless there is a reusable seam.
This proposal is intended to reduce that friction, not add a new framework around every model.
Evidence from current measurements
Cache residency can be a major performance lever when storage is on the critical path:
But the measurements also show why hit rate alone is not the correct objective:
The policy must account for the actual critical path, topology, and object-preparation cost.
Two different cache problems
Expert residency
The key is approximately:
A hit can avoid storage reads, repacking, decompression, or GPU upload.
This primarily affects decode on systems where the full routed-expert bank does not fit in RAM and VRAM.
Token-prefix residency
The key is approximately:
A hit avoids prefill computation and primarily improves TTFT.
These must remain separate object classes with separate policies and metrics. An expert hit and a prefix-token hit do not save the same work.
Proposed architecture
I suggest a Colibri Native Residency Engine, or CNRE, embedded in the C runtime.
It would manage inference-native objects rather than generic byte strings:
Object identity
An expert object should include:
A KV object needs additional identity:
Tokens alone are insufficient. Inkling audio already demonstrates this: two payloads may use identical placeholder tokens while carrying different audio frames.
Object lifecycle
Every cacheable object would follow a state machine:
A
READYobject is published only after its entire read, validation, decompression, packing, and backend preparation have completed.Duplicate misses should use single-flight loading:
Active users hold leases. An object with a live lease cannot be evicted while a CPU matmul or GPU operation still references it.
DeepSeek V4's
ExpertStorealready contains much of the correct lifecycle contract and could be the architectural starting point.Memory tiers
Tier 0: VRAM execution-ready
Contains the exact representation consumed by CUDA, Vulkan, or Metal.
A tensor that still requires repacking or upload is not a complete Tier-0 hit.
Tier 1: RAM execution-ready
Contains CPU-ready expert slabs or objects prepared for efficient upload.
Pools should be separated by NUMA node, format, and geometry where necessary.
Tier 2: compressed RAM
Optional and experimental.
A compressed hit materializes into a bounded working slot before execution. This tier should exist only when:
The weights are already heavily quantized, so large compression ratios should not be assumed. Existing ANS results suggest a real but incremental opportunity, not a universal 2x gain.
Tier 3: mapped or direct-I/O backing
Depending on measured platform behavior:
Tier 4: checkpoint storage
Expert weights are immutable and reconstructible.
Eviction should therefore be:
not:
The checkpoint is already the specialized backing store for weights. Only derived state such as KV may justify writeback or persistence.
Mathematical policy
For object
i, candidate tiert, and planning horizonH:Define utility as:
The important input is critical-path cost, not loader service time.
A 20 ms read that completely overlaps computation does not save 20 ms of visible latency when cached. Colibri already distinguishes read service from felt wait in parts of the telemetry; the residency engine should use felt wait.
Admission rather than automatic pollution
Many LRU designs are effectively:
That lets one-use experts evict objects with demonstrated reuse.
A better initial structure would be:
A demand miss can execute from a temporary working slot without automatically entering the resident cache.
Admission occurs only when:
Frequency, recency, and reuse distance should be kept as separate signals:
Reuse-distance distributions can estimate:
without requiring a predictive model or transition table in the first implementation.
Unlike a general key/value system, Colibri's object population is small enough to maintain exact counters: roughly 20,000 GLM experts and 82,000 Kimi experts.
Dynamic budgets per layer
Using the same number of cache slots for every MoE layer is not generally optimal.
For every layer
l, estimate:The marginal value of another slot is:
Allocate the next available slot or byte to the layer with the largest marginal benefit per byte.
This water-filling approach naturally gives:
The same policy can support future model families without hardcoded assumptions about expert count, layer count, or tensor width.
Preventing migration churn
Colibri's measurements show that frequent repinning can regress performance through rereads, uploads, and synchronization.
A promotion should happen only when:
The engine should enforce:
Extensibility for future model families
The residency engine should not contain a growing switch statement for GLM, Kimi, Inkling, OLMoE, DeepSeek, Qwen, and every future model.
Each engine should provide a small adapter describing capabilities and object operations:
The generic residency core should know nothing about model semantics, tensor names, or routing math.
A new model engine would choose which capabilities it supports:
Unsupported capabilities remain absent rather than emulated.
This would preserve Colibri's current one-C-file-per-model style while avoiding a new cache implementation per model.
The intended integration path should be incremental:
KV-prefix extension
The second object family would be paged host KV.
Immutable prefix blocks
Split host KV or recurrent state into bounded blocks, potentially beginning with the 64-token granularity already used by parts of the CUDA KV path.
Copy-on-write tails
Conversations sharing the same system prompt or long prefix reference the same immutable blocks.
When they diverge:
Prefix-aware scheduling
Before copying KV between slots, route the request to the slot already owning the longest compatible prefix.
Copying becomes a fallback rather than the first solution.
KV eviction policy
KV utility should be:
A 123 MB prefix that avoids tens of seconds of prefill can be more valuable per byte than many expert objects.
What to borrow from Valkey
Useful principles:
Things not proposed:
What this does not solve
A residency engine will not raise the fully resident compute ceiling by itself.
When all useful experts are already in RAM or VRAM, current measurements show that the limiting terms are:
This proposal targets disk-bound and mixed-residency systems, plus TTFT from repeated prefixes. It should not be presented as a universal 2x decode optimization.
Experimental plan
I recommend approval only for Phase 0 first.
Phase 0: offline simulator
Replay real routing traces through:
Simulator inputs:
Outputs:
Advance only if held-out workloads predict:
Phase 1: telemetry normalization
Give every engine comparable measurements without changing decisions:
Phase 2: opt-in GLM RAM policy
Add one experimental policy:
No new prefetch, no routing change, and no output change.
Compare against the existing policy under exactly the same memory budget.
Phase 3: second-engine adapter
Adopt the common interface in one structurally different engine, likely Kimi or DeepSeek V4, to prove the abstraction is not GLM-specific.
Phase 4: paged KV-prefix index
Begin in GLM because it already has multiple slots, persisted KV, cross-slot adoption, and continuous batching.
Phase 5: compressed RAM tier
Only if the simulator and decompression measurements show a positive disk-bound operating region.
Phase 6: shared-memory multiprocess mode
Only if Colibri later runs multiple processes for the same model and measurements show meaningful duplicate anonymous residency. This is not part of the default architecture.
Acceptance criteria
Expert residency
On at least two disk-bound systems:
And:
KV prefixes
For workloads with reusable prefixes:
And:
Method
.coli_usage;Contribution commitment
If Phase 0 demonstrates a robust held-out benefit and the maintainers approve the direction, I would be willing to dedicate myself to implementing and integrating it incrementally across Colibri.
This would be an upstream-first contribution with no strings attached:
The design, simulator, experimental methodology, results, implementation notes, and user-facing documentation would all be developed directly in this repository, under the project's existing license, review process, and maintainer governance.
I would simply do the work. The resulting architecture and documentation would become part of Colibri and remain available to the project and its community.
Integration would remain incremental and reviewable:
If the simulator or runtime experiments produce a negative result, I would document that result in the repository with the same rigor. The contribution would still leave Colibri with reusable traces, a cost model, and evidence preventing the community from repeating an unproductive direction.
Relationship to existing discussions
This connects several existing lines of work without replacing them:
ExpertStore, and Kimi, Inkling, and OLMoE LRU implementations.The difference is that this proposal asks for one mathematical residency objective and one reusable lifecycle contract, rather than another model-specific cache or prefetch heuristic.
Questions
@JustVugg, would you support Phase 0 as a research contribution before any runtime refactor?
If it demonstrates a robust benefit and the direction is approved, I would be willing to lead the implementation and integration as an upstream contribution, with all code, experimental evidence, and documentation living in this repository under the project's existing governance. No strings attached; I would simply do the work.
More specifically:
ExpertStorelease contract be treated as the starting interface?If the simulator produces no robust held-out gain, publishing that negative result should be considered the completion of Phase 0 rather than a failed contribution.
All reactions