Repository navigation
selene,selene-manager,helios: improve prefix-cache hit rate, L1 retention, NVMe throughput, and GPU snapshot packing - #674
Conversation
|
A case file has been opened for 674. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe four prefix-cache subsystems are technically sound, well-tested (CI green on
Walkthrough
Merge Risk: Medium · up to
|
7d7dcdc to
19ce4a7
Compare
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe
Walkthrough
Merge Risk: Medium · up to
|
19ce4a7 to
0ebee3d
Compare
|
Rebased cleanly onto
Re-verified on Linux ( |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeHead
Walkthrough
Merge Risk: Medium · up to
|
0ebee3d to
45fb380
Compare
|
Review of The GPU snapshot-alias packing ( 1. Bugs1.1
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe
Walkthrough
Merge Risk: High · up to
|
45fb380 to
831c47c
Compare
|
@lukealonso Thank you for the thorough review — every item was a real catch. Rebased onto 1. Correctness bugs
2. Hot-path scheduler allocations & complexity
3. Edge cases & cleanup
Additional
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeHead
Walkthrough
Merge Risk: Medium · up to
|
831c47c to
ec2e3db
Compare
…tion, NVMe throughput, and GPU snapshot packing
Prefix-cache serving across Selene, selene-manager, and Helios suffered from
four coupled bottlenecks under multi-turn and multi-instance workloads:
resident GPU prefixes bypassed pool lookups even when a deeper prefix existed
in the shared pool, local L1 DRAM records were dropped on pool handover while
unused intake buffers reserved pinned host RAM without local disk, CUDA
snapshot-alias packing over-excluded GPU KV pages under handle-count limits
while wall-clock EMA mispriced host restores, and selene-manager writeback
relied on buffered packed writes, timer-polled waiters, and immediate clean
arena eviction.
This change updates prefix-cache lookup, retention, GPU snapshot allocation,
restore pricing, and manager NVMe writeback across the shared runtime:
- Resident-aware lookup, intake sizing, and telemetry (`selene`, `helios`):
Keep host and pool lookup active whenever a deeper prefix can extend a
partially resident GPU prefix (recomputing `pool_plan` and issuing a pool
lookup if a previously full-GPU-hit queued request loses its GPU prefix
before dispatch, and retrying local host storage at the same endpoint when a
pooled row-only hit fails restore pricing); allocate zero local intake slots
when local disk is disabled and fail startup cleanly on sub-page memory-only
budgets; preflight doomed L1 evictions before writeback; separate ready
on-disk inventory (`flare_host_cache_disk_records` / `_bytes`) from
uncommitted reservations (`flare_host_cache_disk_reserved_*`); and expose
per-level pool restore rate gauges
(`flare_host_cache_pool_inbound_bytes_per_second{level}`) using the shared
`POOL_LEVELS` ordering.
- L1 DRAM retention and non-blocking drain (`selene`, `helios`): Retain clean
`persisted_in_pool` records in L1 DRAM after pool handover with explicit
`clean_slots` accounting, decouple capture headroom from intake sizing, and
run shutdown drain without blocking request teardown.
- GPU snapshot packing, pressure eviction, and restore pricing (`helios`):
Pack shared GPU snapshot aliases using midpoint-ordered half-width spans and
per-rank handle budgeting (`plan_mapping_handles`, solving NVIDIA#451); make GPU
cache eviction pressure-aware (`evict_for_pressure`) while preserving
dual-turnover reuse protection (`is_protected`), distinguishing pinned from
unpinned overlapping pairs, and avoiding per-victim allocations via cached
`only_child` links, reusable page-ref scratch, and prefix-sum range checks;
price host restores using read-only scheduler prefill-delta estimates
(`estimate_prefill_delta_ns`, pricing every conditioned window end as
terminal) shared through `flare_selene::worth_restore` (with a narrowed
cold-start `prefill_rate` EMA sampled from `step.token_capacity` until
prefill capacities are measured); track row-restore latency separately per
source using the lower median without resetting the decay clock on failed
fetches; derive prefill observation duration from GPU timing with `wall_ns`
fallback when GPU duration is absent; and record prefill-saved seconds
directly in `Metrics::host_lookup_cost`.
- Direct compressed I/O, event-driven waiters, and arena retention
(`selene`, `selene-manager`): Use aligned whole-record `O_DIRECT` writes for
compressed v4 records (`WriteRecord` / `WritePacked`) with cross-platform
direct-I/O fallback handling, propagate `Kind::StoreInvalidated = 4` across
sharded ranks, replace polled waiters with event-driven epoch-tracked wakeups
(`writeback_waiters` / `inflight_waiters`), retain clean records in manager
RAM with buddy coalescing on eviction, and resolve waiting put offers
directly to `Present` when publication covers the offer while rechecking
upgrades and forks.
Compatibility: On-disk v4 records remain readable across `kvc=off`, `cpu`,
and `gpu` modes without re-exporting model cores or changing Protobuf schemas.
Multi-host TP deployments require matching rank builds for the new internal
rank-relay event `Kind::StoreInvalidated = 4`. Sub-page warm memory budgets
without local disk now fail startup explicitly. Public `flare-selene` trait
and struct signatures (`HostStore::begin_lookup`, `TierStore::retired`,
`TierStore::pending_pool_drain`, `HostHit.pooled`, `StoreStats` reserved/rate
fields, `worth_restore`, `levels::POOL_LEVELS`) are updated in lockstep with
workspace callers. Multi-process TP>=2 packed pool puts remain unsupported by
the existing selene-manager protocol contract.
Measured results on SM120 (4x RTX PRO 6000, baseline `5d53040e` vs pre-refactor
revision `7d7dcdcb`; rebased onto `c513e46a`):
- `DeepSeek-V4.1-Flash` TP4 (24 prompts / 72 checkpoints): GPU shared
snapshot capacity increased from 1,946 to 4,864 (+2.50x), snapshot-excluded
KV pages dropped from 5,917 to 2,390 (-59.6%, freeing 3,527 KV pages /
451K tokens), and pinned intake slots dropped from 1,600 to 0.
- `Qwen3.8-Flash-Next` TP1 (`selene-manager` 512M RAM / 1200M NVMe, 12
prompts + restart + 6-prompt reread): post-restart cache-hit tokens rose
from 66.56% to 83.23% (mean latency -28.3%, p50 -42.9%), manager RAM hits
doubled (1 -> 2), writeback waiter churn dropped 93.1% (87 -> 6), NVMe
writes dropped 11.5% (2.97 GB -> 2.63 GB), and evictions dropped 20%
(10 -> 8) with 0 NVMe errors.
- `2x GLM-5.3-Flash` TP2 (`kvc=off` + `selene-manager`, 6x3 multi-turn
A->B->A): retained 3.65 GiB (35 records) in L1 DRAM (vs 0 B), cut NVMe
write volume 26.4% (4.10 GB -> 3.02 GB), increased manager NVMe throughput
2.85x (370.5 MB/s -> 1,054.8 MB/s), cut writeback waiter churn 96.2%
(293 -> 11), and cut Turn 3 p50 latency 12.2% (0.8614s -> 0.7566s).
- `GLM-5.3-Flash` TP2 local disk (`kvc=gpu`, 1500M limit): byte-identical
compression ratios (`1.5150x` populate, `1.5166x` reread), 0 codec/verify
failures, tight eviction enforced under 1500M.
- Cross-node TCP (`2x Qwen3.8` TP1 on SM120 <-> aarch64 `selene` manager):
0 text mismatches, 88.95% partial-GPU resident-extension cache hits,
2,388.8 MB/s remote NVMe writes, 0 errors.
- Live saturation, compression under load, and fault-injection recovery on
SM120: 284/284 HTTP 200 across 16-way tight-manager storms, live manager
`SIGKILL` + reconnect, `2x GLM-5.3` TP2 VRAM/eviction bursts, `kvc=gpu` /
`cpu` / `off` 1000M local-disk saturation, live record truncation +
read-only recovery, and `DeepSeek-V4.1` TP4 64x16w bursts (0 HTTP 500s,
0 NVMe errors, 0 codec/verify failures, 0 deterministic text mismatches).
Verification: `RUSTFLAGS="-D warnings" cargo check --locked --all-targets`
clean across `selene`, `selene-manager`, `helios` (`--features
runtime-core,server`), and `flare`; Linux tests passed across `selene`
(585/585), `selene-manager` (205/205 lib + 128/128 client/pool integration),
`helios` (1,838/1,838 release lib tests excl. root-chmod and
`FLARE_TEST_TEMPLATE_DIR` tests), `flare` (254/254 release tests), and
`verification/helios-lifecycle/check.py --mutations` (8/8 TLA+ models + all
Rust mutations).
Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com>
Design-Signed-Off-By: yatesdr; design-review=2e5b
Discord: D-Rock
ec2e3db to
ffbf2dc
Compare
Why
Prefix-cache serving across Selene,
selene-manager, and Helios hits four coupled bottlenecks under multi-turn, multi-instance, and large-KV-budget workloads:O_DIRECT, blocked put waiters polled on ticks instead of waking on resource releases, clean records were evicted from manager RAM immediately after writeback, and duplicate in-flight put offers were not coalesced.What
1. Resident-aware lookup, intake sizing, and telemetry (
selene/,helios/)flare_host_cache_intake_slots == 0) when local disk storage is disabled, eliminating unused pinned host RAM and shortening host-cache initialization.flare_host_cache_disk_records,flare_host_cache_disk_bytes) from uncommitted reservations (flare_host_cache_disk_reserved_records,flare_host_cache_disk_reserved_bytes).flare_host_cache_pool_inbound_bytes_per_second{level}) acrossneighbour_gpu,host_dram,host_nvme, andremote_nvme.2. L1 DRAM retention and non-blocking drain (
selene/,helios/)persisted_in_poolrecords in L1 DRAM after pool handover with explicitclean_slotsinvariant tracking.capture_headroom_slots).3. GPU snapshot-alias packing (#451), pressure-aware eviction, and restore pricing (
helios/)helios/src/runtime_core/cache_memory.rs,helios/src/scheduler/cache_memory.rs), recovering GPU KV pages and snapshot capacity on handle-limited deployments.evict_for_pressure) driven by page, snapshot, and backing-conflict pressure.estimate_prefill_delta_ns) paired with measured per-level pool restore rates instead of wall-clock prefill EMA, track row-restore latency separately (RowRestoreLatency), derive prefill duration from GPU timing withwall_nsfallback when GPU duration is absent, and record prefill-saved seconds directly inMetrics::host_lookup_cost.4. Direct compressed I/O, event-driven waiters, clean arena retention, and offer coalescing (
selene/,selene-manager/)O_DIRECTI/O (WriteRecord,WritePacked) with exact logical-length recovery and disk-invalidation propagation (StoreInvalidated).writeback_waiters,inflight_waiters) using coalescedWindowReleaseSignalnotifications and a rotating, epoch-tracked scan (writeback_wake_epoch) that prevents duplicate checks and starvation across cursor wraparound.Presentwhen publication covers the offer while preserving independent waiter ownership and rechecking bucket, role promotion, fork count, and descendant coverage.Scope Summary
+10,106 / -1,158lines across 42 files (selene/,selene-manager/,helios/,tests/server/test_conditioned_input_cache.py,verification/helios-lifecycle/check.py, and docs indocs/api.md,docs/prefix-cache-offload.md,docs/runtime-core-design.md, andselene-manager/docs/operating.md).Compatibility and Limitations
kvc=off,kvc=cpu, andkvc=gpumodes.Kind::StoreInvalidated = 4(selene/src/shard.rs), requiring matching rank builds in multi-host TP deployments.checkpoint_memory < page_record_bytes) now fail startup cleanly (selene/src/offload.rs) rather than failing later on a 0-byte slab allocation.flare-seleneAPI updates: UpdatesHostStore::begin_lookup,TierStore::retired,TierStore::pending_pool_drain,HostHit.pooled,StoreStatsreserved/rate fields,worth_restore, andlevels::POOL_LEVELSin lockstep with workspace callers.prefill_rateEMA (sampled on single-lane prefill steps with>= 50%capacity fill) untilPrefillPredictorobserves prefill capacities, and issues a once-per-episode stale pool-lookup ticket refresh when GPU residency advances while waiting.DeepSeek-V4.1-FlashTP4). Memory-limited deployments (such asGLM-5.3-FlashTP2 with 87.6 GiB weights and 6.74 GiB cache budget per GPU) remain bounded by physical VRAM rather than CUDA virtual handle count.selene-managercontinues to reject packed (kvc=gpu/kvc=cpu) puts from multi-process TP>=2 instances per the existing manager protocol contract; compressed storage is tested on local disk (--prefix-cache-disk) and single-process configurations.O_DIRECTcold reads after restart: BecauseWritePackedusesO_DIRECTwithout populating the Linux kernel page cache, post-restart local-disk reads fetch directly from NVMe rather than kernel page-cache RAM.Measured Results (SM120 — 4× RTX PRO 6000)
Apples-to-apples A/B comparison against
5d53040eon SM120 plus cross-node TCP validation against anaarch64selenemanager. Hardware benchmarks and live saturation runs were executed on pre-refactor commit7d7dcdcbagainst5d53040e(prior to#657,#666,#663,#667,#670,#660,#665,#683, and#684); this branch is cleanly rebased ontoc513e46a(main) and re-verified across the full Linux unit/integration test suites and TLA+ mutation checks on HEAD (831c47c7):A. GPU VRAM KV Capacity Recovery (
DeepSeek-V4.1-FlashTP4, 24 prompts / 72 checkpoints)5d53040e)flare_snapshot_capacity1,9464,864flare_snapshot_backing_pages(72 ckpts)5,917(82.2/ckpt)2,390(33.2/ckpt)flare_free_kv_pagesafter 24 prompts154,062157,589flare_host_cache_intake_slots(no local disk)1,600012.7s → 0.6s)B. NVMe Spill, Tight-Limit Eviction & Post-Restart Restore (
Qwen3.8-Flash-NextTP1)--prefix-cache-memory 256M,selenemanager--memory 512M --nvme 1200M --staging 512M; 12 distinct ~6.9K-token prompts populate → restartflare(cold GPU, warm manager) → reverse reread of 6 prompts.5d53040e)flare_host_cache_intake_slots4,4480memory_records/ bytes)0(0 B)2(220 MiB)selene_put_writeback_waits_total876selene_records{tier="memory"})1(220 MiB)2(439 MiB)selene_hits_total{tier="memory"})122.97 GB2.63 GBselene_evictions_total)1080NVMe errors)66.56%(4/6 hits)83.23%(5/6 hits)mean/p50)0.5449s/0.5635s0.3907s/0.3217sC. Multi-Turn, Multi-Instance Traffic (
2× GLM-5.3-FlashTP2,kvc=off+selenemanager)2 instances on GPUs
0,1and2,3, sharedselenemanager (2Gmem /6GNVMe), 6 sessions × 3 turns routedA → B → A.5d53040e)flare_host_cache_intake_slotsper instance50400(0 B)35(3.65 GiB)flare_host_cache_bytes_out_total5.91 GB5.01 GB4.10 GB3.02 GB11.06s(370.5 MB/s)2.86s(1,054.8 MB/s)selene_put_writeback_waits_total29311mean/p50)0.9171s/0.8614s0.8456s/0.7566sOnce
flare_host_cache_pool_inbound_bytes_per_second{level="neighbour_gpu"}measured2.33 GB/s, prefill-delta pricing skipped 3 Turn-3 cross-GPU row restores that only added 1,428 tokens over an already GPU-resident 4,793-token Turn-1 prefix, saving521 MiBof restore traffic and reducing Turn 3 median latency by 12.2%.D. Compression Parity & Tight Disk Eviction (
GLM-5.3-FlashTP2,--prefix-cache-disk-limit 1500M)kvc=gpu: Byte-identical codec ratios on populate (2,425,749,504 → 1,601,203,363,1.5150×) and post-restart reread (1,212,874,752 → 799,713,689,1.5166×),0codec failures,0verify failures,99.97%reread cache-hit tokens (0.4527scold NVMeO_DIRECTread vs2.313scold prefill = 5.1× faster), on-disk footprint held at1,334.7 MBunder the1500Mlimit.kvc=cpu& cross-mode (off-over-cpu): Verified onGLM-5.3TP2 (1.5621×ratio,0.0logprob diff,0verify failures).E. Cross-Node TCP Validation (
2× Qwen3.8-Flash-NextTP1 on SM120 ↔aarch64selenemanager)0deterministic generation mismatches across cross-node TCP restore (Instance A → remote manager → Instance B).88.95%cache-hit tokens (52,146 / 58,621,p50 = 0.7159svs1.8340scold).2.84 GBto NVMe at2,388.8 MB/s(0NVMe errors,0quarantined bytes,8clean records /1.54 GiBretained in manager RAM).F. Live Saturation, Compression Under Load, and Fault-Injection Recovery (SM120,
7d7dcdcb)All 284 requests across 10 saturation and fault-injection phases returned HTTP 200 (
0HTTP 500s,0crashes,0NVMe errors,0codec/verify failures,0deterministic text mismatches):2× Qwen3.8TP1 → tight manager (256MRAM /512MNVMe /256Mstaging)11.16swall) → cooldown → 4 cross-instance reads47outcome="budget"refusals,82wb_waits,2,151store_skipped,9.53 GBwritten into512 MBNVMe (45evictions,806.6 MB/s,0NVMe errors); interleaved hot re-reads stayed100%cached (0.86sp50 vs3.90scold,0mismatches); post-storm recovery restored100%cross-instance hits (0.107sp50,0mismatches).selenemanagerSIGKILL+ restart4w) during outage → restarted manager on same socket/root → 4 writes + 4 cross-instance reads8/8HTTP 200 (1.06sp50), degraded to local GPU + L1 DRAM without stalling. After restart: both instances auto-reconnected, resumed NVMe persistence (750.8 MB/s), and achieved100%cross-instance reuse (0.112sp50,0mismatches).2× GLM-5.3TP2 GPU VRAM & snapshot wall (kvc=off+ manager)4-wayconcurrency +12 × 8-wayeviction burstTurn 310/10OK,1.35sp50,72.34%cached) and the8-wayburst (8GPU snapshot evictions,7.97 GBmanager NVMe writes at1,043.1 MB/s,31manager evictions,0NVMe errors,1.59 GiBretained in L1 DRAM).GLM-5.3TP2 local disk1000Mcap (kvc=gpuvscpuvsoff)6-way(~3.2–4.8× disk cap) + 6 re-reads across all 3 modeskvc=gpu:15.53swall,801.2 MB(12recs),1skipped,0codec/verify err;kvc=cpu:15.58swall,900.7 MB(8recs),23skipped,0codec/verify err;kvc=off:15.39swall,975.4 MB(10recs),9skipped. All 3 modes achieved100%reread hits with0mismatches.GLM-5.3TP2 live corrupt + read-only disk (kvc=gpu)8 KiB, cold restart,chmod -R a-w, 6 re-reads + 4 writes, then restoredu+w+ 4 writes0.65sp50); 1 intact record restored (4,678cached tok); read-only writes shed cleanly (disk_recordsheld at2); after restoringu+w, disk caching resumed automatically without restart (2 → 10records,793 MB).DeepSeek-V4.1TP4 high-concurrency burst16-wayconcurrency across 4× RTX PRO 6000243,587prompt tokens in15.29s(15,931tok/s),192GPU checkpoints (4,672 / 4,864snapshots still free),248cleanstore_skippedbackpressure drops,0NVMe errors.Verification
All checks re-verified on rebased HEAD (
831c47c7, atopc513e46a):RUSTFLAGS="-D warnings" cargo check --locked --all-targets: clean acrossselene,selene-manager,helios(--features runtime-core,server), andflare.seleneunit tests (Linux debug): 585/585 passed.selene-managertests (Linux debug): 205/205 lib passed + 128/128 client & pool integration passed (client86,pool_l020,pool_net6,pool_relay5,pool_store11).heliosrelease lib tests (Linux,--features runtime-core,server): 1,838/1,838 runnable passed (excluding root-chmod andFLARE_TEST_TEMPLATE_DIR-gated template tests).flarerelease tests (Linux): 254/254 passed (246bin +7+1integration).verification/helios-lifecycle/check.py --mutations(Linux): 8/8 TLA+ models + all Rust mutations passed (including222,817CacheOwnership,365,508ResponseLifecycle,13,566Speculation,8,490OffloadTransfer,7,940DispatchRing,1,710Lifecycle,1,291RankProtocol, and68CheckpointReservationobserved Rust transitions).Discord: D-Rock