Skip to content

fix(serving): the lane's REAL footprint is measured off its process and feeds the plan — the arithmetic said 30 GB, the server took 47 GB, the box swapped at 7.9 t/s - #4164

Merged
joelteply merged 2 commits into
canaryfrom
fix/the-lanes-real-footprint-is-measured-and-feeds-the-plan
Sep 17, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/the-lanes-real-footprint-is-measured-and-feeds-the-plan

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What broke (card 36dd5011)

The plan fitted 8 lanes × 51,712 into 30 GB from weights 21.7 GB + kv_per_token (10 KB) × tokens. vmmap of the live server: mapped file 19.9 GB (weights), MALLOC_LARGE 25.7 GB anonymous, 25.1 GB of it swapped — compute buffers at ubatch 2048 over a 412k total context, the hybrid's recurrent state + --ctx-checkpoints, allocator slack. None of it in ModelFootprint. swap 94–96%, memory.pressure critical, 7.9 t/s per stream. The knee was measuring the swap.

Fix — the knee's shape: measured over catalog

  • inference::lane_footprint (new, ~200 lines): once a minute the serving tick reads the lane's anonymous footprint off its pid (macOS proc_pid_rusage phys_footprint = dirty + compressed, mapped files excluded → everything but the mmapped weights; Linux RssAnon + VmSwap), inverts the plan's own decomposition lanes × (compute_floor + per_token × window) into a measured per-token cost, persists it per model in state/lane-footprint.json (fresh by last write, saved on cadence — the fix(serving): the decode knee is persisted on cadence, not only when it moves — a steady lane's points aged 81 min on disk and the next boot planned unclamped #4159 lesson).
  • footprint_for → apply_measured_cost: kv_per_token rises so the plan's cost kv + kv/D equals a fresh measurement > 20% above the arithmetic; a smaller reading never lowers it (a footprint is a lower bound of the need).
  • Probe serving.footprint.measured {pid, lanes, window, anon_bytes, predicted_beyond_weights, ratio, per_token_estimate, per_token_measured}; outcome=could_not_look when the pid can't be read.

Tests

the_measured_cost_inverts_the_plans_decomposition_and_only_corrects_upward, the_record_round_trips_and_a_corrupt_one_is_forgotten, our_own_anonymous_footprint_is_positive_and_a_dead_pid_is_none, a_measured_per_token_cost_corrects_the_plans_rate_upward_only.

Acceptance

Within ~2 min of deploy: serving.footprint.measured ratio ≈ 3+ on the M5; the next plan carries fewer lanes at the same window; with #4160 the reconcile re-homes (over_knee=true); after the relaunch the probe reads ratio ≈ 1.0, vm.swapusage drains, decode p50 > 10 t/s.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…nd feeds the plan — the arithmetic said 30 GB, the server took 47 GB, the box swapped at 7.9 t/s

Measured 2026-09-17 10:2xZ on the M5 (64 GB, Ornith-1.5-35B, Metal, swap 94–96%): the
plan fitted 8 lanes × 51,712 into a 30 GB budget from weights 21.7 GB + kv_per_token
(10 KB after the header's attending-layer rate and the q8_0 halving) × tokens. vmmap of
the live server: mapped file 19.9 GB (the weights), MALLOC_LARGE 25.7 GB anonymous of
which 25.1 GB swapped — compute buffers at ubatch 2048 over a 412k total context, the
hybrid's recurrent state and --ctx-checkpoints, allocator slack; none of it in
ModelFootprint. Every lane count the plan chose was ~1.5× what the memory holds, and the
7.9 t/s per stream the knee measured was the swap, not the model.

`inference::lane_footprint`: once a minute the serving tick reads the lane's ANONYMOUS
footprint off its pid (macOS proc_pid_rusage phys_footprint — dirty + compressed, mapped
files excluded, i.e. everything but the mmapped weights; Linux RssAnon + VmSwap), inverts
the plan's own decomposition `lanes × (compute_floor + per_token × window)` into a
measured per-token cost, and keeps it per model in state/lane-footprint.json (fresh by
last WRITE, saved on cadence). `footprint_for` raises kv_per_token so the plan's cost
`kv + kv/D` equals a fresh measurement that exceeds the arithmetic by > 20%; a smaller
reading never lowers it (a footprint is a lower bound). Probe
`serving.footprint.measured {anon_bytes, predicted_beyond_weights, ratio, per_token_*}`
every sample; `outcome=could_not_look` when the pid cannot be read.

On this box: 25.7 GB / 8 lanes − 1.36 GB floor = 1.85 GB / 51,712 = 36 KB/token → the
plan lands at the lanes the memory actually holds (3 × 51k under Performance, fewer
under Comfort) and the swap — and the 7.9 t/s — goes with the surplus lanes.

Card 36dd5011.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Reviewed at the current head. Right pattern, and it already carries three of tonight's lessons without being asked. One question about the ratchet's direction that I think is worth answering before merge.

This is the fix the whole class wanted. "The plan's model of the machine disagrees with the machine" showed up three times today — kv_per_token 4× off, board attribution claiming 67.5 GB on a 33.6 GB card, and this. Measuring the live process and feeding it back is the same move the knee made against a catalog rate, and it is the only one that stops a declared constant from being able to lie.

Details that show the night's lessons landed: persisting on a cadence and not only on change; excluding mapped files so the measurement is everything BUT the mmap'd weights; and stating explicitly that a measured footprint is a LOWER bound because untouched pages are not resident. That last line is what makes "never shrink" correct rather than merely cautious, and it is pinned by a test.

The question: a monotonic ratchet over a noisy signal keeps the noise's maximum

kv_per_token_from_measured never lowers, by design and for a good reason. But the input is phys_footprint (dirty + compressed) of a process on a box that — per #4163, same card, same night — flaps its memory mode once a minute at 94–96% swap. A sample taken during a spike, or while another process is pushing the system into compression, raises this constant permanently for that model.

Concretely: one bad minute writes a per-token cost that over-reserves for the life of the record, the plan then fits fewer lanes than the box can hold, and nothing ever corrects it because smaller readings are ignored by construction. That failure is quiet and looks like conservatism.

I am not arguing for shrinking on a smaller reading — the lower-bound reasoning is right. The question is whether the RECORD should age out of its maximum: an hour-old FRESH_MS window means a bad sample rules for an hour, which is probably fine; a record that is refreshed on cadence but never re-baselined means it rules forever. If FRESH_MS expiry resets it, say so in the doc and this is a non-issue. If a stale record is kept rather than discarded, a spike is permanent.

Worth considering: take the measurement's floor rather than its instantaneous value — e.g. the minimum over the last N samples, which is still a lower bound of the need but immune to a single spike. Same monotonicity, less memory of one bad minute.

No objection to merging if the expiry answer is "it resets"; it is the difference between a self-correcting estimate and a one-way ratchet with a long memory.

…— the ratchet is measurement-vs-estimate at apply time, and FRESH_MS expiry returns to the arithmetic
@joelteply

Copy link
Copy Markdown
Contributor Author

Answer: it resets, and it is not a ratchet over its own history. observe REPLACES the record on every sample (last write wins) — the only "upward only" is measured-vs-ESTIMATE at apply time (corrects). So a spike rules for one sample interval (60 s), not for the life of the record; and past FRESH_MS the record is ignored and the plan falls back to the arithmetic, never to a remembered maximum. Doc line added to observe saying exactly that (d-only commit). On spikes themselves: the llama-server's phys_footprint is its own dirty + compressed pages — other processes pushing the box into compression don't change it (compressed still counts), and its anonymous allocations are made at launch, so the signal is flat in practice; min-over-N is a fine refinement if the probe ever shows it isn't.

@joelteply
joelteply merged commit 0587788 into canary Sep 17, 2026
6 checks passed
@joelteply
joelteply deleted the fix/the-lanes-real-footprint-is-measured-and-feeds-the-plan branch September 17, 2026 11:07
joelteply added a commit that referenced this pull request Sep 17, 2026
…GPU the lane's bytes are the device delta across the spawn

Fable's #4164 measures the lane's ANONYMOUS SYSTEM memory — right on unified memory
(the KV lives in RAM), and on the 5090 it read `serving.footprint.measured
outcome="could_not_look"`: a discrete GPU keeps the KV in VRAM, a process read
misses it entirely, and WDDM attributes VRAM to no process (`nvidia-smi
--query-compute-apps` prints [N/A] for every pid on this box). Converging #4152
and #4164 as Fable proposed: ONE consumer (`lane_footprint::observe` → the plan's
own decomposition → per-token cost), TWO sources chosen by `memory_mode()` —
unified = process anon; discrete = device used at the tick minus device used
before the spawn, minus the weights (in VRAM on this class). The baseline is read
once, right before `ensure_model_serving`; an adopted lane has none and the arm
says could-not-look rather than charging the desktop to the model. The probe
names the source.

Test with the 5090's own points (752 MiB idle; 31,914 MiB at 144k; 22,078 at
9.4k; 17 GB weights): the delta through the consumer lands at ≈74 KiB/token, the
number measured by hand last night; no baseline / no reading → None.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply added a commit that referenced this pull request Sep 17, 2026
…GPU the lane's bytes are the device delta across the spawn (#4152 ⇄ #4164) (#4167)

* fix(serving): the footprint source is per host class — on a discrete GPU the lane's bytes are the device delta across the spawn

Fable's #4164 measures the lane's ANONYMOUS SYSTEM memory — right on unified memory
(the KV lives in RAM), and on the 5090 it read `serving.footprint.measured
outcome="could_not_look"`: a discrete GPU keeps the KV in VRAM, a process read
misses it entirely, and WDDM attributes VRAM to no process (`nvidia-smi
--query-compute-apps` prints [N/A] for every pid on this box). Converging #4152
and #4164 as Fable proposed: ONE consumer (`lane_footprint::observe` → the plan's
own decomposition → per-token cost), TWO sources chosen by `memory_mode()` —
unified = process anon; discrete = device used at the tick minus device used
before the spawn, minus the weights (in VRAM on this class). The baseline is read
once, right before `ensure_model_serving`; an adopted lane has none and the arm
says could-not-look rather than charging the desktop to the model. The probe
names the source.

Test with the 5090's own points (752 MiB idle; 31,914 MiB at 144k; 22,078 at
9.4k; 17 GB weights): the delta through the consumer lands at ≈74 KiB/token, the
number measured by hand last night; no baseline / no reading → None.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(serving): the discrete arm's baseline is the TROUGH between reclaim and load, not a single read at spawn

First live receipt on the 5090 (13:1xZ): `serving.footprint.measured source="device_delta"
anon_bytes=0` — the baseline read at the spawn instant came off the board's SAMPLED
used-bytes, which still showed the dying predecessor's ~24 GB, so now − baseline −
weights collapsed to zero. A stale sample is not a baseline. Now the spawn ARMS the
baseline (u64::MAX) and every tick while no lane is ready lowers it to the minimum
sampled value — the trough after the predecessor's memory is freed and before the
successor's load. Armed-but-never-lowered reads as could-not-look, like no-baseline.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(serving): the kept-window bound follows the live drive mode — under a Ludicrous hold it plans at Performance like the plan does

A bound fixed at Comfort (32 GB × 0.80) would cap a benchmark's exam window below
what its Performance plan legitimately sizes. Physical capacity, current mode.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(serving): the operator's headroom policy is the everyday drive mode — a dedicated node plans at Performance every day

`CONTINUUM_VRAM_HEADROOM` says "a dedicated foundry sets 1.0", and the plan
budget deliberately ignored it (stacking it under the mode fraction
double-discounted). Composed instead: the policy NAMES the everyday mode —
1.0 → Performance, 0.9 → Sport, 0.8 (the default) → Comfort, byte-identical to
before — and pressure can still force Eco, a Ludicrous hold still floors it. The
pin fit-gate, the plan budget, and the kept-window bound now read the one knob.

The receipt that forced it (5090, 2026-09-17 14:31–14:55Z): dispatched a hard-rs
card to Kimi (`843a792a expr_eval`, claimed); at Comfort the 27B on 32 GB fits
1 × 37k or 2 × 11.6k, two residents made the plan pick 2 × 11,776, and a solve
turn does not fit 11.7k — 128 `over_window` / `inference_failed` on her own card,
zero acts, on a box that ran the same model at 31.9 GB all night.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(serving): the incumbent's own bytes are credited back exactly once — at the ledger when it holds the footprint, in the plan only until it does

Measured on the 5090 during Kimi's solve (2026-09-17 15:31–15:59Z): the ledger's
replace-myself budget (own footprint added back, capped at the device) handed the
daemon 30 GB at rest; `plan_serving_stable` then credited the incumbent's 17 GB of
weights AGAIN and planned 2 × 70,093 on a card whose honest fit was 2 × 47,098.
The re-home law saw a 46k "shortfall" every 105 s, fired three relaunches
mid-solve, and each launch bounded the window right back to 47,098 — two cold
turns of 12–15 s in her card for nothing.

`plan_serving_stable` keeps its credit for a caller holding the LIVE budget (its
eleven tests are untouched); `plan_serving_at_rest` is the same hysteresis with no
credit. The daemon picks by fact: once serving's VRAM attribution is on the board
the budget is at rest; before it is (the first ticks over an inherited lane, #438)
the plan's own credit still keeps the successor from fleeing its predecessor. Test:
at rest, the plan's window equals `window_within` — no shortfall exists to chase;
the live-budget path plans bigger from the same number, which is why the daemon
must not use it. Daemon 68/68 incl. #438's boot test; plan 38/38.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* style: rustfmt the two at-rest hunks

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant