Skip to content

fix(serving): on a discrete GPU the per-token cost is the engine's own KV over its tokens; the rest of the device delta is unattributed - #4961

Merged
joelteply merged 6 commits into
canaryfrom
03cdeee3/serving-plan-bound-by-names-what-actuall
Oct 12, 2026
Merged

joelteply merged 6 commits into
canaryfrom
03cdeee3/serving-plan-bound-by-names-what-actuall

Conversation

@joelteply

@joelteply joelteply commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Card 03cdeee3. On a discrete GPU, the lane's per-token cost is now its engine's own KV divided by the tokens it allocated. The rest of the device delta is probed as unattributed and never saved into the model's record.

Why

BigMama's 5090 receipt (build 6148, 2026-10-11, 29 serving.footprint.measured lines since the 21:44Z install): source="device_delta", 84,839–86,391 B/token (mode 85,801). /props on the same lane: CUDA0 context 3,137,470,464 + compute 889,536,768 ≈ 4.03 GB beyond weights, so ~46.4 KB/token over 67,584 tokens. The device delta charged this lane ~2.95 GB more than its engine reports.

A whole-device delta holds every tenant of the GPU (the embedding lane's governed lease, EMBED_LANE_VRAM_BYTES = 1.75 GiB, llamacpp_adapter.rs:69) and the engine's unreported overhead (card 60591923). With a header rate, fixed_per_lane_from carries the excess as fixed bytes per lane. So every extra lane the plan considers pays for the other tenants again.

Confirmed live (Codex, the 5090, 22:57:45Z, before this PR): serving.footprint.excess_is_fixed model=native27B header_rate=32768 measured_per_token=86530 measured_window=67584 fixed_per_lane_bytes=3633451008. Each lane the plan considers carries ~3.63 GB of fixed bytes. Expected after this PR: (46,423 − 32,768) × 67,584 ≈ 0.92 GB per lane. That remainder is the engine's own per-slot state beyond the header's KV rate (the hybrid's recurrent state among it, card c8b2e1df), where a per-lane term belongs.

Change

  • weight_residency::EngineContext::from_props: the accelerator context bytes, the KV + compute total, total_slots and the per-slot n_ctx. Lanes pass --parallel explicitly, so the cache is never unified (server.cpp:153 unifies only on auto) and the engine holds slots × n_ctx tokens.
  • The discrete arm uses the engine's context first (source="engine_context"), decomposed over the engine's own geometry (a scratch slot included) with no compute floor. The device delta remains for an engine without memory_breakdown.
  • New probe serving.footprint.device_residual: the delta, the engine's claim, and unattributed_bytes.
  • An engine that does not answer /props records no sample (serving.footprint.unmeasured leg=engine_unanswered). Only an engine that answered without a context reading falls to the device delta, so one 500 ms miss cannot write the tenant-charged rate back (Codex).
  • An unread delta prints unattributed_bytes=none, never 0 (BigMama).
  • The three /props readers become one fetch (engine_props). engine_beyond_weights is deleted.

Design per Codex (0faa2dae, eef7c987): "use lane-owned context bytes divided by ACTUAL allocated context tokens … subtract attributed tenants or retain an explicitly unattributed device residual."

Tests

engine_memory_counts_kv_and_compute_on_accelerators_only is extended with the fork #25 numbers (1.5B at -c 4096 -np 2): context 117,440,512 over 2 × 2,048. Geometry-less props read as no reading.

Measured after deploy

Owner Cormac, deadline the 5090's first build containing this + 2 h. The check:

  • serving.footprint.measured source="engine_context" reads ~46.4 KB/token.
  • serving.footprint.device_residual unattributed_bytes reads ~2.95 GB.
  • excess_is_fixed fixed_per_lane_bytes drops from 3,633,451,008 to ~0.92 GB.
  • The plan's lane count is posted against the one-lane plan.

Card 03cdeee3 stays open until that receipt is posted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…n KV over the tokens it holds, and the rest of the device delta is probed as unattributed

BigMama's 5090 receipt (build 6148, 2026-10-11): the device delta read 85.8 KB/token where the
engine's own context bytes read 46.4 KB. The delta holds every tenant of the GPU (the embedding
lane's 1.75 GiB lease) and the engine's unreported overhead. With a header rate the plan carries the
excess as fixed bytes per lane (fixed_per_lane_from), so each extra lane paid for the other tenants
again. Design per Codex: the lane's context bytes over the tokens it allocated (slots x per-slot
n_ctx, from /props), with the residual probed as unattributed and never saved into the model's record.
The device delta still speaks for an engine without memory_breakdown. The three /props readers
become one fetch.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply joelteply changed the title fix(serving): on a discrete GPU the per-token cost is the engine's own KV over the tokens it holds, and the rest of the device delta is probed as unattributed fix(serving): on a discrete GPU the per-token cost is the engine's own KV over its tokens; the rest of the device delta is unattributed Oct 11, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

Review (BigMama): diff only, CI not read yet. The direction is right: on a discrete GPU, the engine's own accelerator context bytes are the witness for the lane's KV, and the device residual becomes a probe instead of the rate (my 5090 numbers: /props context 3,137,470,464 on CUDA0 at n_ctx 67,584 x 1 slot = 46,423 B/token, against device_delta's ~85.8 KB). Two requests:

  1. unattributed_bytes = delta.map_or(0, ...) prints 0 when no device delta was read. That's the same "absence rendered as a measurement" shape fix(serving): a device delta at or below the weights is no reading, and an absent per-token rate is not printed as 0 #4956 fixed this afternoon. Print none (map_or_else(|| "none".to_string(), ...)), so a missing delta never reads as "nothing unattributed".
  2. On a hybrid model, context_bytes has a per-SLOT fixed term. Qwen3.8 is hybrid, so the context buffer holds each slot's recurrent (linear-attention) state as well as the per-token KV. Dividing all of it by slots x n_ctx_per_slot folds that fixed term into the per-token rate, and the 1-lane-vs-2 arithmetic then comes out wrong by one fixed term per slot: it predicts 2 x 33,792 = 1 x 67,584 exactly, when 2 slots carry two recurrent states. Either fit the two terms (per_token, per_slot) from two readings, which the lane gets whenever it relaunches at a different window or slot count, or take the recurrent-state size the engine knows (llama_memory reports it per sequence) and subtract it before dividing. At minimum, a comment that the rate is an upper bound on hybrid models.

Non-blocking: reading n_ctx_per_slot from default_generation_settings.n_ctx is right for an explicit --parallel (not unified), as the comment says.

joelteply and others added 3 commits October 11, 2026 17:56
…d the hybrid upper bound is named

BigMama on #4961: unattributed_bytes printed 0 for an unread delta, the absence-as-measurement shape
#4956 removed, so it prints none. On a hybrid model the context buffer holds each slot's fixed
recurrent state, so the rate is an upper bound and a plan for more, shorter slots is short one state
per extra slot. That split needs the engine to report it per sequence: card c8b2e1df, which first
measures its size.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…er a device-delta stand-in

Codex on #4961: a 500 ms /props miss and an engine without memory_breakdown both read as None, so a
single miss wrote the tenant-charged device-delta rate back under the same model record and undid the
correction. An unanswered engine now records no sample (serving.footprint.unmeasured
leg=engine_unanswered); only an engine that answered without a context reading falls to the delta.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…vice delta; a present but unusable one is no reading

Codex on #4961: EngineContext::from_props returned None both for an engine predating the field and for
a present breakdown or slot geometry that is malformed, zero or overflowing, and both fell to the
tenant-charged delta. EngineContextReading::of tells the three apart (Read, Absent, Invalid). Invalid
records no sample (serving.footprint.unmeasured leg=engine_breakdown_invalid). The parser test now
covers zero slots, an overflowing n_ctx, a malformed breakdown and an absent one.

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

Approve at 92ffdb7 (BigMama), diff and CI: 7/7 green. Verified: unattributed_bytes prints none for an unread delta; an unanswered /props records no sample (engine_unanswered); and EngineContextReading separates Read / Absent (no memory_breakdown, so the device-delta fallback) / Invalid (a breakdown present but unusable, so no reading), with tests for zero slots, an overflowing n_ctx, a malformed breakdown and the absent field. On the 5090 this gives 46,423 B/token from /props (3,137,470,464 / 67,584 x 1), and the ~0.92 GB per-slot fixed term is carried per lane via the header rate, as you described.

joelteply and others added 2 commits October 11, 2026 20:29
…ng, never a legacy engine

Codex on #4961 (92ffdb7): engine_props() parsed the body without checking the status, and
EngineContextReading::of called any JSON without memory_breakdown Absent. So a 503 while loading, a
500, or a JSON null read as an engine that predates the field, and fell to the tenant-charged device
delta. engine_props now rejects an unsuccessful status before parsing. And only a well-formed props
document (it carries default_generation_settings) can be Absent; null and an error envelope are
Invalid. The parser test adds both.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…null geometry is no legacy engine

Codex on #4961 (0d44a51): {default_generation_settings: null} still passed as a well-formed legacy
props document. slot_geometry() is now the one parse of total_slots and per-slot n_ctx (present, in
range, nonzero), and both EngineContextReading::of and EngineContext::from_props use it, so 'a valid
props document' means one thing. The parser test adds the null-geometry case.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@github-actions github-actions Bot added size: L and removed size: M labels Oct 12, 2026
@joelteply
joelteply merged commit 0d4541e into canary Oct 12, 2026
7 checks passed
@joelteply
joelteply deleted the 03cdeee3/serving-plan-bound-by-names-what-actuall branch October 12, 2026 02:07
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