Skip to content

fix(serving): on a discrete GPU the board credits serving with what its engine holds on the device, not the host process's RSS (card 741f5eec) - #4850

Merged
joelteply merged 1 commit into
canaryfrom
741f5eec/serving-the-plan-decides-from-bytes-with
Oct 7, 2026
Merged

joelteply merged 1 commit into
canaryfrom
741f5eec/serving-the-plan-decides-from-bytes-with

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Measured on the 5090, 2026-10-07 (BigMama). Kimi's served window flapped between
33,024 and 69,724 every few seconds while the plan's branch never changed: usable
bytes alternated between two exact values, 1.40 GiB apart, the board's live serving
budget swinging 1.75 GiB. Twelve board reads with her full engine resident showed
measured 0 and externalBytes = physicalUsedBytes, 31.3 GB. The board had never
credited her engine with a byte.

The cause: ServingConsumer's physical credit read the lane process's host memory
(anon_footprint_of + model_file_bytes_of). On a discrete card that is the wrong
quantity, since the engine's real holding is VRAM and no RSS contains it. On Windows
both reads are the not-macos-not-linux arm and return None. So serving's
replace-myself budget (available + measured_by(serving)) was just free VRAM, and any
external churn, a dead process's allocations releasing in steps, swung her window
2x. A relaunch sized before the old memory released saw almost nothing; that is
Fable's half, card fb58db2e, which now reads a board that knows its own engine.

  • EngineDeviceCredit (serving_consumer.rs): on a discrete GPU, the credit is what the
    ENGINE reports holding on the device, from /props: model_weight_buffers on the
    accelerator plus memory_breakdown's KV and compute buffers, both already parsed by
    weight_residency. That is attribution-correct where a device delta is not: a delta
    would credit a game started after spawn.
  • A reading counts only for the engine it was read from (pid match): a pre-relaunch
    reading is never the successor's, the gap is 0, and an unreadable /props is no
    credit. On a discrete card it never falls back to the host read, which would credit
    the wrong memory. Unified memory and CPU placement keep the host read unchanged.
  • The serving daemon refreshes it every tick (5 s), ahead of the once-a-minute
    per-token sample and unconditionally, because the engine's holding is serving's own
    even while other work lives in it, and a once-a-minute credit would read a fresh
    relaunch as nobody's for a minute. One local /props call per tick. Probe
    serving.credit.engine_device, on change only.

Test: a_discrete_engine_is_credited_its_own_device_holding_and_nothing_else (credit
for the engine it was read from; nothing for a previous engine, the gap or an
unread /props; the host read only off a discrete card). Not compiled on IntelMac
(its CPU serves residents); CI builds and tests, windows-msvc included.

Co-Authored-By: Claude Opus 5.5 (1M context) [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…ts engine holds on the device, not the host process's RSS (card 741f5eec)

Measured on the 5090, 2026-10-07 (BigMama). Kimi's served window flapped between
33,024 and 69,724 every few seconds while the plan's branch never changed: usable
bytes alternated between two exact values, 1.40 GiB apart, the board's live serving
budget swinging 1.75 GiB. Twelve board reads with her full engine resident showed
measured 0 and externalBytes = physicalUsedBytes, 31.3 GB. The board had never
credited her engine with a byte.

The cause: ServingConsumer's physical credit read the lane process's host memory
(anon_footprint_of + model_file_bytes_of). On a discrete card that is the wrong
quantity, since the engine's real holding is VRAM and no RSS contains it. On Windows
both reads are the not-macos-not-linux arm and return None. So serving's
replace-myself budget (available + measured_by(serving)) was just free VRAM, and any
external churn, a dead process's allocations releasing in steps, swung her window
2x. A relaunch sized before the old memory released saw almost nothing; that is
Fable's half, card fb58db2e, which now reads a board that knows its own engine.

- EngineDeviceCredit (serving_consumer.rs): on a discrete GPU, the credit is what the
  ENGINE reports holding on the device, from /props: model_weight_buffers on the
  accelerator plus memory_breakdown's KV and compute buffers, both already parsed by
  weight_residency. That is attribution-correct where a device delta is not: a delta
  would credit a game started after spawn.
- A reading counts only for the engine it was read from (pid match): a pre-relaunch
  reading is never the successor's, the gap is 0, and an unreadable /props is no
  credit. On a discrete card it never falls back to the host read, which would credit
  the wrong memory. Unified memory and CPU placement keep the host read unchanged.
- The serving daemon refreshes it every tick (5 s), ahead of the once-a-minute
  per-token sample and unconditionally, because the engine's holding is serving's own
  even while other work lives in it, and a once-a-minute credit would read a fresh
  relaunch as nobody's for a minute. One local /props call per tick. Probe
  serving.credit.engine_device, on change only.

Test: a_discrete_engine_is_credited_its_own_device_holding_and_nothing_else (credit
for the engine it was read from; nothing for a previous engine, the gap or an
unread /props; the host read only off a discrete card). Not compiled on IntelMac
(its CPU serves residents); CI builds and tests, windows-msvc included.

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

Copy link
Copy Markdown
Contributor Author

Reviewed. Approve (as a comment: shared account). The shape is right: on a discrete card the credit is the engine's own device accounting, credited only to the pid it was read from, with 0 in the gap and never host RSS in its place, and the pure device_answer is tested for each arm.

Set the post-deploy expectation correctly, though. Kimi's engine on the 5090 reports, right now (/props, engine-a 5e3961b10):

CUDA0 bytes
model (model_weight_buffers) 18,247,720,960
context (KV) 6,684,934,144
compute 1,238,712,576
total credited 26,171,367,680 (≈26.2 GB)

The board reads physicalUsedBytes 31.322e9, so after this lands measured should read about 26.2 GB, not ~31 GB, and about 5 GB stays external. What's in that 5 GB that this breakdown can't see: the CUDA runtime and driver context of the engine process, buffers allocated outside the llama context (the vision projector's own clip context, and the MTP draft's buffers if they're separate), cuBLAS workspaces, and the desktop's own GPU use. If someone checks for "31 GB" and sees 26, that's correct, not a regression.

Non-blocking:

  1. During /train, the training context's allocations sit in a second llama context. Unless /props folds them into memory_breakdown, a training window will still show as external churn on the board. That's worth a probe the first time training runs under this.
  2. The ~5 GB remainder could later be closed by reading the engine pid's own device usage (NVML per-process on Windows), keeping /props as the attribution.

joelteply added a commit that referenced this pull request Oct 7, 2026
…re-homes; a climb still coalesces

2026-10-07, the 5090: after Kimi's engine crash her lane relaunched at 2,304 (sized while the
dying engine still held VRAM) and served there, ready, for an hour. The plan alternated 33k/70k
(the board's budget toggled; #4850 fixes the credit), and the re-home streak reset on every rise
(plan_flat = plan <= previous tick's plan), so a lane far below BOTH plan values never reached
the 3 sustained ticks. Kimi, needing 52k, could not fit.

The rule plan_flat existed for the boot staircase (2026-09-02: a re-home per stair was 16 model
loads). It now resets only on a NEW HIGH for the current streak: a climb still coalesces into
one relaunch at its top, and a plan moving below a high it already reached keeps counting. Every
streak reset clears the high with it (reset_rehome_streak), so a stale peak cannot make a later
climb read as flat.

Tests (one mod, beside the jitter test): a_lane_far_below_an_alternating_plan_re_homes (fails on
canary: never fires) and a_climbing_plan_coalesces_into_one_re_home_at_its_top (the staircase
guard had no test). All 94 serving_daemon tests pass.

Card fb58db2e (convergence half; sizing a relaunch after the predecessor's memory releases is
the other half).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 0810a41 into canary Oct 7, 2026
7 checks passed
@joelteply
joelteply deleted the 741f5eec/serving-the-plan-decides-from-bytes-with branch October 7, 2026 05:46
joelteply added a commit that referenced this pull request Oct 7, 2026
…re-homes; a climb still coalesces (#4851)

* fix(serving): a lane far below a plan that alternates under its high re-homes; a climb still coalesces

2026-10-07, the 5090: after Kimi's engine crash her lane relaunched at 2,304 (sized while the
dying engine still held VRAM) and served there, ready, for an hour. The plan alternated 33k/70k
(the board's budget toggled; #4850 fixes the credit), and the re-home streak reset on every rise
(plan_flat = plan <= previous tick's plan), so a lane far below BOTH plan values never reached
the 3 sustained ticks. Kimi, needing 52k, could not fit.

The rule plan_flat existed for the boot staircase (2026-09-02: a re-home per stair was 16 model
loads). It now resets only on a NEW HIGH for the current streak: a climb still coalesces into
one relaunch at its top, and a plan moving below a high it already reached keeps counting. Every
streak reset clears the high with it (reset_rehome_streak), so a stale peak cannot make a later
climb read as flat.

Tests (one mod, beside the jitter test): a_lane_far_below_an_alternating_plan_re_homes (fails on
canary: never fires) and a_climbing_plan_coalesces_into_one_re_home_at_its_top (the staircase
guard had no test). All 94 serving_daemon tests pass.

Card fb58db2e (convergence half; sizing a relaunch after the predecessor's memory releases is
the other half).

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

* fix(serving): fire the re-home only on a tick whose plan is the streak's high (BigMama on #4851)

A re-home relaunches at the fire tick's plan; on an alternating plan a low tick would land the
lane at the low value (33k, under Kimi's 52k) and owe a second relaunch, while launching the
remembered high would use a budget the tick did not plan. The high tick is both. The alternation
test now asserts the landing tick is a high one.

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

---------

Co-authored-by: Claude Opus 5.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