Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2ef9f8e
core/llama: a safe PersonaBlocks over the fork's persona seam; the en…
joelteply Nov 18, 2026
998768e
Cargo.lock: core/llama depends on thiserror 2
joelteply Nov 18, 2026
75a7710
PersonaBlocks::bind replaces load(stream): the memory chooses the str…
joelteply Nov 18, 2026
c590d7c
LLAMA_CPP_PIN records the move to fork #147 (persona seam with bind),…
joelteply Nov 18, 2026
df35115
PersonaBlocks: reserve names only her owner, grow adds room ahead of …
joelteply Nov 18, 2026
ea955a8
PersonaBlocks is made with her owner and grows and shrinks; pin fork …
joelteply Nov 18, 2026
078bcac
Merge remote-tracking branch 'origin/canary' into fable/unified-tier
joelteply Nov 18, 2026
3d16663
The persona engine switches minds on the real 35B in ~9 ms: UnifiedTi…
joelteply Nov 18, 2026
370294f
UnifiedTier keeps a mind's custody on stale or failed epochs; streams…
joelteply Nov 18, 2026
d815ce5
Test CI dependency selection for the persona llama adapter
joelteply Nov 18, 2026
7dae370
The persona engine owns the one decode: a second decode beside it doe…
joelteply Nov 18, 2026
de0e34a
UnifiedTier binds a new mind only on a stream the engine reports empt…
joelteply Nov 18, 2026
1865973
PersonaBlocks::bind takes the owner the transfer is for, and refuses …
joelteply Nov 18, 2026
22789ec
Merge remote-tracking branch 'origin/fable/llama-persona-seam' into f…
joelteply Nov 18, 2026
16826fc
UnifiedTier checks every move before it replaces her blocks; binds na…
joelteply Nov 18, 2026
adcdcc4
Merge remote-tracking branch 'origin/fable/unified-tier' into fable/p…
joelteply Nov 18, 2026
cb57325
PersonaEngine's own refusals say the backend was not asked (TierRefus…
joelteply Nov 18, 2026
80bc49c
PersonaEngine submits the bound mind's decode through the tier and ho…
joelteply Nov 18, 2026
b5029a7
A decode reports landed only when the device is known to have finishe…
joelteply Nov 18, 2026
b84b4cb
persona-engine: a turn prefills only what her blocks do not hold, und…
joelteply Nov 18, 2026
28e0154
The in-process scheduler is the persona engine: one mind decodes at a…
joelteply Nov 18, 2026
dbdf0d2
Merge remote-tracking branch 'origin/canary' into fable/persona-engin…
joelteply Nov 18, 2026
329926a
Merge remote-tracking branch 'origin/fable/persona-engine-owner' into…
joelteply Nov 18, 2026
e34da62
persona scheduler: the driver carries no unjustified unwrap; the dead…
joelteply Nov 18, 2026
d2c3d82
ci scope: a persona-engine change runs everything the engine reaches …
joelteply Nov 18, 2026
997e30a
persona scheduler: typed scheduler errors, no Step derives it cannot …
joelteply Nov 18, 2026
17c208c
Merge canary (#6139 squashed as a53509a97) into the persona scheduler…
joelteply Nov 18, 2026
82ba460
persona scheduler: sample only her final prompt position; finish a re…
joelteply Nov 18, 2026
828eb3a
Lower the continuum-core warning baseline 12 -> 11: the win sticks (C…
joelteply Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions core/continuum-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,6 @@ vulkan = ["llama/vulkan", "continuum-kernel/vulkan", "continuum-engine/vulkan",
rocm = ["ort/rocm", "continuum-engine/rocm"]
directml = ["ort/directml", "continuum-engine/directml"]
openvino = ["ort/openvino", "continuum-engine/openvino"]
# MLX — Apple Silicon native inference path (phases A–E of continuum#897).
# Only compiles on macOS/aarch64; the adapter module is guarded by this feature
# AND by cfg(target_os = "macos") so non-Mac targets simply don't see the code.
# Phase A: flag only, no mlx-rs dep yet. Phase B will add `dep:mlx-rs` back
# once we're writing forward() and can ensure full Xcode is installed.
mlx = ["continuum-engine/mlx"]
accelerate = ["candle-core/accelerate", "candle-nn/accelerate", "candle-transformers/accelerate"]
# Linux: swap ORT from static (download-binaries) to dynamic loading.
# Avoids protobuf symbol conflict with webrtc-sys. macOS uses static (default).
Expand Down
3 changes: 2 additions & 1 deletion core/continuum-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"
publish = false

[dependencies]
continuum-persona-engine = { path = "../continuum-persona-engine" }
continuum-persona-llama = { path = "../continuum-persona-llama" }
continuum-process = { path = "../continuum-process" }
tempfile = { workspace = true, optional = true }
continuum-kernel = { path = "../continuum-kernel" }
Expand Down Expand Up @@ -83,7 +85,6 @@ coreml = []
cuda = ["candle-core/cuda", "candle-nn/cuda", "candle-transformers/cuda", "llama/cuda", "ort/cuda", "continuum-kernel/cuda"]
directml = ["ort/directml"]
metal = ["candle-core/metal", "candle-nn/metal", "candle-transformers/metal", "llama/metal", "ort/coreml"]
mlx = []
openvino = ["ort/openvino"]
rocm = ["ort/rocm"]
test-fixtures = ["continuum-kernel/test-fixtures", "dep:tempfile"]
Expand Down
17 changes: 5 additions & 12 deletions core/continuum-engine/src/inference/backends/llamacpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
//! platform-specific features (metal/cuda). This backend is the adapter
//! between Continuum's TextGenerationRequest pipeline and the safe Rust API.
//!
//! Architecture: ONE shared `Context` driven by a continuous-batching
//! scheduler (see `llamacpp_scheduler`). Each `generate()` call enqueues a
//! request that becomes one sequence (`seq_id`) in the shared batch.
//! Multiple sequences advance per decode step — weights are read once,
//! used for N sequences at once. This replaces the prior per-call-context
//! design where N concurrent generations created N independent contexts
//! that fought for memory bandwidth (each got ~1/N throughput).
//!
//! Measured 67.8 tok/s on M5 Metal with forged Qwen3.5 Q4_K_M (single seq
//! bench). With continuous batching across 3 seqs the per-stream cost
//! drops only ~10% rather than dividing by 3.
//! Architecture: ONE `Context` driven by the persona scheduler (see `persona_scheduler`): one mind
//! decodes at a time, each persona keeps her blocks between turns, and a turn prefills only what her
//! blocks do not hold. A switch is the persona engine's native bind. Measured on the M5: four minds
//! decoding at once ran 2 tok/s each; one at a time runs at the full rate.

use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand All @@ -23,7 +16,7 @@ use std::time::Instant;

use llama::{FlashAttn, KvCacheType, LoraAdapter, Model, ModelParams};

use super::llamacpp_scheduler::{GenerationRequest, Scheduler, SchedulerConfig, TokenEvent};
use super::persona_scheduler::{GenerationRequest, Scheduler, SchedulerConfig, SchedulerError, TokenEvent};
use super::SamplingConfig;
use crate::runtime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,14 @@ impl LlamaCppBackend {
Ok(())
}

/// Lazily spawn (or get) the scheduler. Single instance per backend —
/// owns the shared Context and the OS-thread driver loop.
/// Lazily spawn (or get) the persona scheduler. Single instance per backend: it owns the context
/// and the driver thread. Its window holds `STREAMS` minds' windows (the active mind and the next),
/// whatever sequence count the launch carried: one mind decodes at a time.
pub(super) fn scheduler(&self, allocation: GenerationAllocation) -> Result<&Scheduler, String> {
let per_seq = self.effective_context_length(allocation)?;
if self.config.n_seq_max == 0 {
return Err("generation requires a nonzero sequence allocation".into());
}
let total_n_ctx = per_seq
.checked_mul(self.config.n_seq_max)
let per_mind = self.effective_context_length(allocation)?;
let streams = u32::try_from(continuum_persona_llama::STREAMS).map_err(|_| "stream count exceeds native representation")?;
let total_n_ctx = per_mind
.checked_mul(streams)
.ok_or("context allocation exceeds native representation")?;
let (bound, scheduler) = self.scheduler.get_or_init(|| {
(
Expand All @@ -437,7 +436,6 @@ impl LlamaCppBackend {
n_ctx: total_n_ctx,
n_batch: self.config.n_batch,
n_ubatch: self.config.n_ubatch,
n_seq_max: self.config.n_seq_max,
flash_attn: self.config.flash_attn,
fused_gdn_ar: self.config.fused_gdn_ar,
fused_gdn_ch: self.config.fused_gdn_ch,
Expand All @@ -452,14 +450,15 @@ impl LlamaCppBackend {
"scheduler allocation changed; release the existing backend before resizing".into(),
);
}
Ok(scheduler)
match scheduler {
Ok(scheduler) => Ok(scheduler),
Err(refused) => Err(refused.to_string()),
}
}

/// Generate text. Routes through the continuous-batching scheduler:
/// the request becomes one sequence in the shared batch and tokens
/// stream back as they're sampled. Multiple concurrent generate()
/// calls share the single Context — weights are read once per decode
/// step and used to advance every active sequence in parallel.
/// Generate text through the persona scheduler: the turn continues her mind (one decodes at a
/// time, the next waits its turn) and tokens stream back as they are sampled. Concurrent
/// generate() calls are served one after another on the one context.
///
/// `active_loras` is `(id, scale)` pairs naming genes previously paged
/// in via [`ensure_adapter`]. They are resolved to live adapter handles
Expand Down Expand Up @@ -560,7 +559,9 @@ impl LlamaCppBackend {
persona_id,
};

self.scheduler(allocation)?.enqueue(req)?;
if let Err(refused) = self.scheduler(allocation)?.enqueue(req) {
return Err(refused.to_string());
}

// Collect tokens from the channel until Done/Error. We're called
// synchronously from spawn_blocking by CandleAdapter — block_in_place
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,12 @@ impl ModelCapabilities {
/// The backend: owns a `Model` plus a continuous-batching `Scheduler`.
///
/// Models are Send+Sync (read-only after load). The scheduler owns the
/// shared Context (n_seq_max sequences, single OS-thread driver loop)
/// and is the only place llama.cpp decode happens. Generate calls
/// enqueue requests and stream tokens back over channels — there's no
/// per-call context creation, no Rust-side semaphore.
/// context (two execution streams, one OS-thread driver loop; see `persona_scheduler`) and is the
/// only place llama.cpp decode happens. Generate calls enqueue turns and stream tokens back over
/// channels; one mind decodes at a time.
///
/// LoRAs are loaded into `loras` for genome paging, but per-request LoRA
/// activation is a v2 follow-up — the scheduler currently ignores
/// `active_loras` (see `llamacpp_scheduler` module docs).
/// LoRAs are loaded into `loras` for genome paging; a turn's genes are applied for her decodes
/// when she is bound.
pub struct LlamaCppBackend {
/// One temporary embedding context is admitted per loaded model.
pub(super) embedding_lane: super::embedding_lane::EmbeddingLane,
Expand All @@ -258,7 +256,7 @@ pub struct LlamaCppBackend {
pub(super) caps: ModelCapabilities,
/// Lazy-spawned scheduler. Lives behind OnceLock because spawning
/// touches the Model Arc and we want a single instance per backend.
pub(super) scheduler: OnceLock<(GenerationAllocation, Scheduler)>,
pub(super) scheduler: OnceLock<(GenerationAllocation, Result<Scheduler, SchedulerError>)>,
/// Lazy-loaded multimodal projector. Built on first `generate_with_image`
/// call from `config.mmproj_path` (so text-only backends pay zero cost).
/// Sits behind a Mutex<Option<...>> so concurrent first-call requests
Expand Down
Loading
Loading