Skip to content

feat(inference): cold_expert_offload_ot — -ot builder for K3 slice-1 physical expert paging - #2036

Merged
joelteply merged 4 commits into
canaryfrom
feat/k3-act-buft-override
Jul 27, 2026
Merged

joelteply merged 4 commits into
canaryfrom
feat/k3-act-buft-override

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

My half of the buft-override relaunch joint (#22, with BigMama's ServingExpertPager)

K3 slice-1 physical expert paging, layer-granular. Experts are stacked per layer (blk.N.ffn_*_exps is one tensor = all that layer's experts), so -ot/--override-tensor — which places whole tensors — pages at layer granularity. The residency planner owns the VRAM fit and produces PlacementRequest.hot_layers (the real blk.N that fit GPU); this emits the inverse: cold → CPU as one -ot value.

cold_expert_offload_ot(hot_layers, n_layers) -> Option<String>:

  • cold = (0..n_layers) minus hot_layers → blk\.(c1|c2|..)\.ffn.*_exps=CPU
  • Robust by construction: dense (non-MoE) blocks in range are inert (no ffn_*_exps to match), so it needs only the hot set + block count, never the exact MoE-layer set.
  • Block index \.-anchored both sides (blk.3 ≠ blk.31); covers all four stacked projections.
  • None when nothing is cold (never an empty -ot, which llama-server rejects).

Pure + unit-tested (mixed, all-hot→None, empty-hot→all, out-of-range ignored, zero→None).

Scope

The consumer half only. The wiring — ServingTarget.expert_placement + the -ot injection at the Command build + the relaunch diff beside adapter_paths() — lands when BigMama's PlacementRequest struct merges (seam settled on airc: { gguf_id, n_layers, hot_layers }). True per-expert paging (no relaunch) is slice-2: a ~5-line llama.cpp fork exposing the internal llama_model::get_tensor + the already-public ggml_backend_tensor_set sub-range upload.

🤖 Generated with Claude Code

…e-1 physical expert paging

My half of the buft-override relaunch joint (#22, with BigMama's ServingExpertPager). Experts
are STACKED per layer (blk.N.ffn_*_exps is one tensor = all that layer's experts), so
-ot/--override-tensor — which places WHOLE tensors — pages MoE experts at LAYER granularity.
The residency planner owns the VRAM fit and produces PlacementRequest.hot_layers (the real
blk.N indices that fit GPU); this emits the inverse: cold = (0..n_layers) minus hot_layers,
offloaded to CPU as one -ot value `blk\.(c1|c2|..)\.ffn.*_exps=CPU`.

Robustness by construction: dense (non-MoE) blocks in the range are HARMLESS — they have no
ffn_*_exps tensor so their pattern is inert, which is why the builder needs only the hot set
+ the total block count, never the exact MoE-layer set. Block index is `\.`-anchored on both
sides so blk.3 never matches blk.31; the pattern covers all four stacked projections
(gate/up/down/gate_up). Returns None when nothing is cold (never an empty -ot, which
llama-server rejects) — the caller omits the flag.

Pure + unit-tested (mixed hot/cold, all-hot→None, empty-hot→all, out-of-range hot ignored,
zero layers→None). The wiring — ServingTarget.expert_placement + the -ot injection at the
Command build + the relaunch diff beside adapter_paths() — lands when BigMama's
PlacementRequest struct merges. True per-expert paging (no relaunch) is slice-2: a ~5-line
llama.cpp fork exposing the internal llama_model::get_tensor + the already-public
ggml_backend_tensor_set sub-range upload.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ce-1 buft-override seam

The K3 relaunch places experts via llama.cpp -ot, which places WHOLE stacked
tensors (blk.N.ffn_*_exps = all of layer N's experts in one blob). So slice-1
placement is LAYER-granular, not per-expert (per-expert is slice-2's upload fork).
This lands the pager's half of the seam with M5's -ot builder (#2036):

- plan_layer_residency (expert_residency.rs): aggregates the per-expert priority
  (the ONE ranking authority) to a per-layer score, fits whole layers by
  layer_bytes (= expert_bytes * n_experts_per_layer) within the 0.80 serving VRAM
  budget. Returns real blk.N indices, ascending. Degenerate-safe (unsized → place
  nothing). The pager owns the fit so the launcher never overflows.

- PlacementRequest { gguf_id, n_layers, hot_layers } (placement.rs): the shared
  seam type M5's llama_server.rs consumes — hot_layers = GPU-resident blk.N,
  complement -ot'd to CPU; n_layers = total block count (the -ot ceiling).

- ServingExpertPager::tick_layer_placement + mark_layer_relaunched (serving_pager.rs):
  the slice-1 driver pass — builds the decayed+predicted activation (shared with the
  per-expert tick via current_activation), plans hot layers, and decides relaunch on
  hot-layer-set churn beyond the threshold (a process respawn reloads every weight,
  so a 1-layer flap must not thrash it). LayerPlacementOutcome carries the request +
  needs_relaunch.

Seam locked with M5 on airc: I own the VRAM fit, she owns the -ot args + the
ServingTarget.expert_placement relaunch diff. Two new tests pin the layer fit and
the driver relaunch-signal. cargo check --lib --tests clean on the 5090 (capacity
files); the only build errors are the pre-existing tests/ unix harness (Windows).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply and others added 2 commits July 26, 2026 20:03
…K3 slice-1 consumer)

Completes my consumer half of the buft-override relaunch joint. ServingTarget now carries
Option<PlacementRequest> (BigMama's #2037 seam type); ServingTarget::expert_ot_value()
delegates to cold_expert_offload_ot(hot_layers, n_layers); and the spawn Command build
injects --override-tensor <value> right after --lora when a placement is present (None /
all-hot → no flag, since llama-server rejects an empty -ot).

The relaunch on a hot-set change is DECIDED by the pager (serving_pager's relaunch_needed),
NOT the probe-based ensure_model_serving diff — there is no API to read a running server's
-ot, so the placement can't be probed; the pager tracks served-vs-desired and drives the
respawn, which rebuilds the ServingTarget with the new placement and this applies it.

All existing ServingTarget construction sites default expert_placement: None (eval lanes run
the whole model; the base serving target starts unpaged). The one remaining bridge — the
ServingExpertPager attaching Some(placement) to the live lane's target — is BigMama's
serving_pager lane; the consumer is ready for it.

NOTE: this branch temporarily merges feat/layer-placement-seam (#2037) for the
PlacementRequest type; rebases onto canary once #2037 lands (dropping the merged commits).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: L and removed size: M labels Jul 27, 2026
joelteply added a commit that referenced this pull request Jul 27, 2026
…ce-1 buft-override seam (#2037)

The K3 relaunch places experts via llama.cpp -ot, which places WHOLE stacked
tensors (blk.N.ffn_*_exps = all of layer N's experts in one blob). So slice-1
placement is LAYER-granular, not per-expert (per-expert is slice-2's upload fork).
This lands the pager's half of the seam with M5's -ot builder (#2036):

- plan_layer_residency (expert_residency.rs): aggregates the per-expert priority
  (the ONE ranking authority) to a per-layer score, fits whole layers by
  layer_bytes (= expert_bytes * n_experts_per_layer) within the 0.80 serving VRAM
  budget. Returns real blk.N indices, ascending. Degenerate-safe (unsized → place
  nothing). The pager owns the fit so the launcher never overflows.

- PlacementRequest { gguf_id, n_layers, hot_layers } (placement.rs): the shared
  seam type M5's llama_server.rs consumes — hot_layers = GPU-resident blk.N,
  complement -ot'd to CPU; n_layers = total block count (the -ot ceiling).

- ServingExpertPager::tick_layer_placement + mark_layer_relaunched (serving_pager.rs):
  the slice-1 driver pass — builds the decayed+predicted activation (shared with the
  per-expert tick via current_activation), plans hot layers, and decides relaunch on
  hot-layer-set churn beyond the threshold (a process respawn reloads every weight,
  so a 1-layer flap must not thrash it). LayerPlacementOutcome carries the request +
  needs_relaunch.

Seam locked with M5 on airc: I own the VRAM fit, she owns the -ot args + the
ServingTarget.expert_placement relaunch diff. Two new tests pin the layer fit and
the driver relaunch-signal. cargo check --lib --tests clean on the 5090 (capacity
files); the only build errors are the pre-existing tests/ unix harness (Windows).


Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

Co-authored-by: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply merged commit 4378c97 into canary Jul 27, 2026
4 checks passed
@joelteply
joelteply deleted the feat/k3-act-buft-override branch July 27, 2026 01:16
joelteply added a commit that referenced this pull request Jul 27, 2026
…ide relaunch LIVE

The daemon-reconcile half of the K3 bridge, completing the buft-override relaunch
end to end. ServingDaemonModule now holds the served MoE model's ServingExpertPager
(via moe_serving_context, keyed by model_id, rebuilt on a model change) and, each
reconcile, calls compute_expert_placement:

  governed VRAM ceiling → tick_layer_placement → hot expert LAYERS that fit →
  ServingTarget.expert_placement = Some(PlacementRequest)

M5's launcher (#2036) turns that into the `--override-tensor` cold-complement at
the spawn Command, and the existing target-diff respawn fires when it changes. The
placement is DEBOUNCED via committed_placement: it only re-commits when hot-layer
churn passes RELAUNCH_LAYER_CHURN_THRESHOLD, so a 1-2 layer flap never respawns the
(every-weight-reloading) llama-server; a real task shift does.

Gate-seeded, so the FIRST placement already pins the model's inherently-preferred
expert layers before a live hit; live hits refine it. Dense models / zero budget /
unresolved GGUF → None (served with no override, exactly as before).

Glass-boxed per Joel: a `serving.k3_placement` probe emits the load-bearing
quantities (model, budget, hot/total layers, relaunch?) every pass — the K3
residency decision is observable at the RTOS-probe seam, not a silent guess.

The sync Mutex is never held across an await (reconcile_to_plan is sync). This is
the last continuum-side mile: K3 physically pages its expert layers on the 5090 as
the served workload shifts. cargo check --lib green on the 5090 native toolchain.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply added a commit that referenced this pull request Jul 27, 2026
…e serving daemon, LIVE (#2038)

* feat(capacity): moe_serving_context — GGUF → sized, gate-seeded ServingExpertPager

The construction half of the K3 daemon bridge. moe_serving_context(gguf_path, id,
margin, threshold) composes three tested GGUF reads — locate_layer_sets (MoE detect
+ per-layer expert geometry), gguf_keys::block_count (total blocks = the -ot
ceiling), and locate_gate_magnitudes (the router's baked per-expert preference) —
into a MoeServingContext { pager, n_experts_per_layer, n_layers }. Dense models
return None (served with no override, as before).

The gate seed matters: the pager's FIRST tick_layer_placement already pins the
model's inherently-preferred expert layers to GPU before a single live hit, then
refines as real activations arrive — K3 gets a sensible static residency
immediately and an adaptive one over time.

Also retargets tick_layer_placement from &SystemProfile to a raw
serving_budget_bytes: u64, so the serving daemon can pass its governed VRAM ceiling
(the resource-board authority) instead of re-probing hardware. plan_layer_residency
already took the budget directly; this just stops the wrapper from assuming a
SystemProfile the daemon doesn't hold.

Next: the daemon reconcile wiring (hold the context per served model, tick it, set
ServingTarget.expert_placement) — M5's #2036 landed the None hook + the -ot builder
for it. cargo check --lib --tests clean on the 5090.

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

* feat(serving): wire the K3 pager into the serving daemon — buft-override relaunch LIVE

The daemon-reconcile half of the K3 bridge, completing the buft-override relaunch
end to end. ServingDaemonModule now holds the served MoE model's ServingExpertPager
(via moe_serving_context, keyed by model_id, rebuilt on a model change) and, each
reconcile, calls compute_expert_placement:

  governed VRAM ceiling → tick_layer_placement → hot expert LAYERS that fit →
  ServingTarget.expert_placement = Some(PlacementRequest)

M5's launcher (#2036) turns that into the `--override-tensor` cold-complement at
the spawn Command, and the existing target-diff respawn fires when it changes. The
placement is DEBOUNCED via committed_placement: it only re-commits when hot-layer
churn passes RELAUNCH_LAYER_CHURN_THRESHOLD, so a 1-2 layer flap never respawns the
(every-weight-reloading) llama-server; a real task shift does.

Gate-seeded, so the FIRST placement already pins the model's inherently-preferred
expert layers before a live hit; live hits refine it. Dense models / zero budget /
unresolved GGUF → None (served with no override, exactly as before).

Glass-boxed per Joel: a `serving.k3_placement` probe emits the load-bearing
quantities (model, budget, hot/total layers, relaunch?) every pass — the K3
residency decision is observable at the RTOS-probe seam, not a silent guess.

The sync Mutex is never held across an await (reconcile_to_plan is sync). This is
the last continuum-side mile: K3 physically pages its expert layers on the 5090 as
the served workload shifts. cargo check --lib green on the 5090 native toolchain.

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

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply restored the feat/k3-act-buft-override branch August 21, 2026 12:40
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