Repository navigation
feat(llama): vendored-fork llama_model_get_tensor — the slice-2 per-expert-paging primitive - #2039
Merged
Merged
Conversation
… 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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reusingtensors_by_name(the same mapllama_internal_get_tensor_mapexposes), 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 stackedffn_*_expstensor. The only thing llama.cpp's public API was missing was a way to get theggml_tensor*for a named weight from a loaded model — the internalllama_model::get_tensorexisted 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-corecompiles against it, andbindings.rscarriesllama_model_get_tensor. TheLiveUploadPagerthat 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