Skip to content

feat(llama): vendored-fork llama_model_get_tensor — the slice-2 per-expert-paging primitive - #2039

Merged
joelteply merged 1 commit into
canaryfrom
feat/k3-slice2-get-tensor-shim
Jul 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/k3-slice2-get-tensor-shim

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The one missing primitive for K3 slice-2 (live per-expert paging, no relaunch)

Bumps core/vendor/llama.cpp → continuum/k3-slice2-get-tensor (540bcab), a ~10-line additive patch to our private fork:

  • include/llama.h — LLAMA_API struct ggml_tensor * llama_model_get_tensor(const llama_model*, const char* name) — returns a mutable tensor.
  • src/llama-model.cpp — impl reusing tensors_by_name (the same map llama_internal_get_tensor_map exposes), so the pointee stays writable even off a const model.

Why

Slice-1 (buft-override relaunch, merged) pages experts at layer granularity by relaunching. Slice-2 pages a single expert with no relaunch: stage its bytes D→RAM, then ggml_backend_tensor_set (already public + bound, and what the loader itself uses) into a sub-range of the stacked ffn_*_exps tensor. The only thing llama.cpp's public API was missing was a way to get the ggml_tensor* for a named weight from a loaded model — the internal llama_model::get_tensor existed but wasn't exported. This exposes it.

Scope + safety

Additive and dormant. The accessor binds but nothing calls it yet. Verified: the fork's cmake rebuilds clean, continuum-core compiles against it, and bindings.rs carries llama_model_get_tensor. The LiveUploadPager that consumes it (tasks #226/#228) is deliberately deferred until slice-1's live glass-box validates the residency plan on real weights — we don't optimize the ACT mechanism before the PLAN is proven.

Private-fork patch (AGENTS.md exempt); AI-assisted, human-designed, disclosed in the fork commit.

🤖 Generated with Claude Code

… K3 slice-2 per-expert paging

Bumps core/vendor/llama.cpp to continuum/k3-slice2-get-tensor (540bcab), which adds the
public LLAMA_API llama_model_get_tensor(model, name) → MUTABLE ggml_tensor*. This is the
one missing primitive for slice-2 live per-expert paging: with it, a LiveUploadPager can
ggml_backend_tensor_set (already public + bound) a fresh expert's bytes into a sub-range of
the loaded model's stacked ffn_*_exps tensor at runtime — no relaunch — the ExpertPager
slice-2 body the reconcile seam was designed for (expert_reconcile.rs docs).

Additive + dormant: the accessor exists and binds (verified: bindings.rs carries
llama_model_get_tensor; continuum-core cargo check green on the rebuilt fork) but nothing
calls it yet. The LiveUploadPager that consumes it is task #226/#228's build, gated on
slice-1's live glass-box validating the residency plan first.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit c2dc772 into canary Jul 27, 2026
4 checks passed
@joelteply
joelteply deleted the feat/k3-slice2-get-tensor-shim branch July 27, 2026 03:01
joelteply added a commit that referenced this pull request Jul 27, 2026
…rimitive (#2040)

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.


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

Co-authored-by: Claude Opus 4.8 <[email protected]>
joelteply added a commit that referenced this pull request Jul 27, 2026
* docs(planning): K3 → Kimi persona roadmap — dependency-ordered, gated, joint

The through-line from "expert paging works" to "a Kimi-scale MoE persona that learns,
proven by a lift chart." Phases A–E with hard gates (don't optimize an ACT before its PLAN
is proven on real weights), owners (M5 llama/FFI/cognition, BigMama capacity/pager/daemon),
and the consented-dojo standard on every experiment. Captures the merge state (slice-1
chain A merged/in-flight, #2039 slice-2 primitive dormant), the slice-2 mechanism-now /
cut-over-after-Gate-A discipline, and the pull-forward note that #229 (surprise salience)
needs no K3 base. Coordinates the joint so both builders follow one sequence.

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

* docs(planning): resolve slice-2 crux — A (weight-write, now) vs B (K-slot paging, gated)

The slice-2 design decision, on purpose: upload_expert writing into slot expert_index
implies the VRAM tensor holds ALL slots (the MoE kernel indexes the stacked tensor by the
router's logical id). So A and B are different capabilities, not two defs of slice-2, and
ExpertPager::page_in/evict is inherently B's semantics.

B.A (weight-WRITE via upload_expert) — build now, feeds the per-expert genome path
(#226/#228), no pager, no fork change. B.B (true K-slot paging) needs a logical->physical
remap primitive (kernel/graph fork, NOT get_tensor) — GATED on Gate-A numbers: only build the
fork if cold-CPU-compute measurably bottlenecks the K3 persona. LiveUploadPager is B-only;
BigMama holds it.

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

---------

Co-authored-by: Claude Opus 4.8 <[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