Repository navigation
fix(serving): affordability charges the serve to host RAM only on unified memory — on a discrete GPU the 5090 launched --cache-ram 256 with 49 GB free - #4144
Conversation
…AM ONLY on unified memory — on a discrete GPU it lives in VRAM Measured on the 5090, 2026-09-16 23:20Z: `serving.prompt_cache.derived reason=resident_demand_kv_estimate afford_mib=0 desired_mib=256 served_ctx=132970 physical_bytes=68067782656` → `--cache-ram 256` (the hard floor) → the engine refused every state (`prompt state size 458.812 MiB exceeds cache size limit 256.000 MiB, skipping`) → Kimi 44 s prefill, cached=0, hit 0.0 — on a box with 49 GB of host RAM free. The term: `afford = physical − fp.peak_resident_bytes(ctx, lanes) − os_floor`. `peak_resident_bytes` is weights + per-lane KV + the prefill compute reserve — the on-DEVICE working set. On unified memory that IS host RAM and the subtraction is right. On a discrete GPU those bytes are in VRAM (the plan requires `fits_on_gpu`; the mmap'd weight file is reclaimable page cache) and the host pays nothing for them, so subtracting 55 GB of VRAM residency from 63 GB of host RAM was the M5's arithmetic applied to the 5090. As the window grew (54k → 145k over the relaunches) afford went to exactly 0. Now the caller derives `serve_host_bytes` by topology — `GpuMonitor::memory_mode()` through the system monitor's attached GPU (`Discrete` ⇒ 0; `Unified` or no GPU ⇒ the peak) — and hands it to the pure decision, which records it (`serve_host_bytes` on the probe). Existing tests pass the unified term and are unchanged in arithmetic; the new test reproduces the 256 on unified and the demand-sized answer on discrete from the same footprint, demand and box. Mutation-tested: ignoring topology fails at "VRAM residency costs the host nothing". `sidecar_planned_headroom_bytes` carries the same assumption for the vision sidecar; not changed here, named. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
No objection — LGTM; merge on green. The term was mine and the topology assumption was the M5's: One note for a follow-up, not this PR: Discrete ⇒ 0 assumes the working set FITS the card. Your own chain says the relaunches derived windows up to 145k — at ~256 KiB/token that KV (~36 GiB) cannot live on a 32 GB card beside 17 GB of weights, so whatever llama-server does with the overflow (fail, or spill KV to host) the host term is not zero there. The honest discrete term is |
|
Cormac's third case (Intel Mac, measured): a DISCRETE Radeon present, |
… — the same clamp the host-cache lease applies Deployed the topology fix on the 5090 (2026-09-17 01:06Z): afford went from 0 to 56,800 MiB on a 63 GB box with 31 GB of host RAM free. Honest arithmetic — two citizens whose recorded peaks grew to ~115k tokens at 256 KiB/token do need ~58 GB to hold both states — and the other failure shape: a `--cache-ram` that fills past what the box has is the pagefile thrash of 2026-08-01. `host_cache_lease_bytes` already bounds the MoE host cache by `physical − commit_charge`; the prompt cache now takes the same second ceiling (`system_commit_charge_bytes()` on Windows, `None` elsewhere), records it on the probe, and the lower of the two wins. Test: same footprint and demand, headroom alone vs commit-bound vs past-physical commit (→ the hard floor, never a wrap). Upstream and not this PR: the served window grew to 144k from a stale 176k demand_window, prompts grew to fill it (44 s prefills), and the cache demand followed — the lane-knee lane (3×~50k), not a cache clamp. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
Pushed |
…the commit charge — on a CUDA host commit is always past physical Deployed e9f7428 on the 5090 (2026-09-17 01:3xZ) and read the receipt: `commit_charge_bytes=Some(75472093184)` on a 63 GB box with 43 GB free → afford 0 → `--cache-ram 256` again. Windows commit charge on a CUDA host counts reserved-but-untouched and pagefile-backed allocations and sits chronically above physical, so `physical − commit` is the hard floor forever there. That clamp is right only where commit ≈ resident — the MoE mmap'd-expert case the host-cache lease was written for. For the prompt cache the second ceiling is the system monitor's available RAM less the OS floor; recorded on the probe as `available_bytes`. Test: headroom-only / available-bound / starved (→ hard floor). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
Two more commits on this branch from deploying it on the 5090 tonight, each with the receipt that forced it:
Both are the same shape as the PR's title: a number written on one topology (or one estimate) read as fact on another. Re-review at the branch head. |
…a declared footprint is not a second card The 5090, 2026-09-17: serving declared its footprint as `peak_resident_bytes(144640 ctx, 1 lane)` = 67.5 GB (f16-KV estimate) on a 33.6 GB card. The board's available fell to 2.3 GB, and `budget_for_replacing` = available + own-measured handed the planner 69.8 GB → `serving.plan usable_gb=54` — a budget larger than the card — which sized a 144k window the card could not hold, which drove the cache demand to 58 GB, which drove the 44 s prefills. The add-back is right (a machine serving X must be able to re-plan X); its sum is now capped at capacity, like every other number the ledger speaks. Mutation (uncapped): fails at "capped at the device, not the declaration". Ledger 17/17. Named, not here: the declaration itself over-counts KV (f16 per token against an engine that fits 31.4 GB physical at that window); the footprint should carry the engine's KV type. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
Merged after the review window on the follow-up heads (topology → available ceiling → ledger cap; last push 02:33Z, no objection by 06:15Z). Cormac's LGTM covered the first commit; the three follow-ups are recorded as merged unreviewed, each with the 5090 receipt that forced it in its message. #4152 carries the remaining wrong constant (the KV rate). |
…rs — read `full_attention_interval` from the header (#4156) The 5090, 2026-09-17: `kv_per_token = 262,144` for Qwen3.8-27B came from the header's declared geometry counting all 64 blocks as attending. The header also declares `qwen35.full_attention_interval = 4` — Gated DeltaNet linear layers with a full-attention layer every fourth; the linear layers keep a fixed recurrent state, no per-token KV. Attending layers = 64 / 4 = 16 → 65,536 bytes/token, which is what the engine measured (144k window in 31.9 GB; ~74 KiB/token including the window-scaled compute growth). On the wrong rate: serving declared 67.5 GB to the resource board on a 33.6 GB card (the ledger fiction #4144 capped), the prompt-cache demand read 3.5× high, and — once #4146 bounded the kept window by the physical fit — the served window went to 9,430 and EVERY turn failed `delib.payload.over_window` (272 in 40 min). Honest arithmetic on a wrong constant; the constant is the header's, read fully. No family knowledge: the key is read under the artifact's own arch, like every other dimension; an artifact that never wrote it attends on every layer as before. Test: the 27B header verbatim → 65,536; the same header without the interval → 262,144. Mutation (interval ignored): fails on the 27B case. #4152 stays open for the MEASURED rate (device-used deltas at launch), which would also catch a header that lies; this closes the case where it tells the truth. Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc Co-authored-by: Claude Opus 5 <[email protected]>
Measured (5090, 2026-09-16 23:20Z)
serving.prompt_cache.derived reason=resident_demand_kv_estimate afford_mib=0 desired_mib=256 served_ctx=132970 physical_bytes=68067782656→ engine launched--cache-ram 256(the hard floor) →prompt state size 458.812 MiB exceeds cache size limit 256.000 MiB, skippingon every save → Kimi 44 s prefill,cached_tokens=0,hit_rate=0.0. Host RAM free at the time: 49 GB.Cause
afford = physical − fp.peak_resident_bytes(ctx, lanes) − os_floor.peak_resident_bytesis the on-device working set (weights + per-lane KV + prefill compute reserve). On unified memory that is host RAM and the subtraction is right. On a discrete GPU it is VRAM — the plan requiresfits_on_gpu, the mmap'd weight file is reclaimable page cache — and the host pays nothing for it. Subtracting 55 GB of VRAM residency from 63 GB of host RAM is the M5's arithmetic on the 5090; as the window grew across relaunches (54k → 145k), afford reached exactly 0.Fix
The launch site derives
serve_host_bytesby topology —GpuMonitor::memory_mode()via the system monitor's already-attached GPU (Discrete⇒ 0;Unifiedor no GPU ⇒ the peak) — and hands it to the pureprompt_cache_decision, which records it on the probe (serve_host_bytes). No new detection: the same monitor the boot already consults for the VRAM ledger.Receipts
a_discrete_gpu_does_not_charge_vram_residency_against_host_ram: same footprint / demand / box → unified yieldsafford=0,desired=256(the number the 5090 launched with); discrete yieldsafford = physical − floorand the demand-sized cache. Mutation (ignore topology): fails at "VRAM residency costs the host nothing".serving_daemon::tests61/61,system_resources::monitor17/17.Named, not changed:
sidecar_planned_headroom_bytes(vision sidecar) carries the same unified assumption.Also observed on the way, filed separately: the daemon relaunched an engine that never became ready every ~95 s for 80 minutes with no readiness-timeout probe (35 launches,
ready=false active=<none>each reconcile).Review requested — 30 min to object, then merge on green.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc