Skip to content

feat(llama): Model::upload_expert — K3 slice-2 Model-A weight-write primitive - #2040

Merged
joelteply merged 1 commit into
canaryfrom
feat/k3-upload-expert-ffi
Jul 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/k3-upload-expert-ffi

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The per-expert weight-write the genome path consumes

Model::upload_expert(layer, expert_index, gate, up, down) replaces one expert's weights in the three resident stacked projection tensors (blk.{layer}.ffn_{gate,up,down}_exps) of a loaded model — via the shipped llama_model_get_tensor (#2039) + the already-public ggml_backend_tensor_set.

  • Offset from the live tensor's own nb[2] (ggml's quant-aware per-expert stride) — no parsed-stride guessing, correct for any quantization.
  • Fail-loud: absent tensor (not MoE / wrong layer), expert_index out of range, or byte-len ≠ the live stride.

The decided split (roadmap Phase B, with BigMama)

The MoE kernel indexes the stacked tensor by the router's logical expert id, so writing at slot expert_index implies the full tensor is resident. Therefore:

  • B.A — weight-WRITE (this PR): replace an expert in place. Consumer is the per-expert genome path (Feature/phase 4 daemon generator #226 LoRA-specialize, Phase 4: Rust Workers, Daemon Infrastructure, and System Improvements #228 surgical training), not a pager — page_in/evict is meaningless when all slots are resident.
  • B.B — true per-expert paging: a K-slot tensor + a logical→physical router remap (a kernel fork, not get_tensor). That's where LiveUploadPager lives; gated on Gate-A numbers (only build the fork if cold-CPU-compute measurably bottlenecks the K3 persona). BigMama holds it.

Scope

Compile-validated (llama crate builds clean against the #2039 shim). Dormant — nothing calls it until the genome path does; behavioral validation is Gate B on a loaded MoE.

🤖 Generated with Claude Code

…rimitive

The per-expert weight-WRITE the genome path (#226 specialize an expert via LoRA, #228
surgical training) consumes. Replaces expert `expert_index`'s weights in the three resident
stacked MoE projection tensors (blk.{layer}.ffn_{gate,up,down}_exps) with the given bytes,
via the shipped llama_model_get_tensor (#2039) + ggml_backend_tensor_set. Offset is computed
from each LIVE tensor's own nb[2] (ggml's quant-aware per-expert stride, expert dim outermost
of {n_embd,n_ff,n_expert}) — no parsed-stride guessing, correct for any quant.

This is weight-REPLACEMENT into a loaded model (full tensor resident), NOT paging — per the
decided slice-2 split (roadmap Phase B.A): A = weight-write (this, now, feeds the genome);
B = true K-slot per-expert paging (needs a router remap primitive, a kernel fork, gated on
Gate-A numbers — BigMama holds LiveUploadPager for it).

Fail-loud: absent tensor / expert out of range / byte-len ≠ live stride. Compile-validated;
behavioral validation is Gate B (needs a loaded MoE). Dormant — nothing calls it until the
genome path does.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 5c7fc43 into canary Jul 27, 2026
4 checks passed
@joelteply
joelteply deleted the feat/k3-upload-expert-ffi branch July 27, 2026 03:16
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