Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
75 changes: 72 additions & 3 deletions core/continuum-proving-types/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,47 @@ pub struct PageCost {
pub bytes_per_s: Measured<f64>,
}

/// A fixed holder of engine memory.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Holder {
Weights,
/// The compute graph: one for the shared pool under `--kv-unified`.
ComputeGraph,
/// The speculative draft model's weights and compute. Its KV grows with the pool, so it is
/// `ModelProfile::draft_kv_bytes_per_token`, not here.
Draft,
/// The multimodal projector's weights and reserved compute.
Projector,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HolderBytes {
pub holder: Holder,
pub tier: Tier,
pub bytes: Measured<u64>,
}

/// One model as served on this node.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ModelProfile {
pub model: ModelId,
pub weight_bytes: Measured<u64>,
/// KV plus recurrent state per token (the engine's `memory_breakdown`).
pub state_bytes_per_token: Measured<u64>,
/// Everything the engine holds whatever the minds do, each where it lives. The prompt cache is
/// not one: it is a divisible claim that sheds first, cleared with the minds' claims (the fork's
/// `memory_breakdown` and `resident_state`, llama.cpp#91). Before #91 the draft and the
/// projector were invisible, and the plan inferred them from the process footprint.
pub holders: Vec<HolderBytes>,
/// Attention KV per token of a sequence's context.
pub kv_bytes_per_token: Measured<u64>,
/// The speculative draft's KV per token of the pool (0.53 GB at 257,536 tokens on the M5,
/// ~2,048 B/token); `Unmeasured` on a model served without a draft.
pub draft_kv_bytes_per_token: Measured<u64>,
/// A hybrid model's recurrent state, fixed per sequence whatever its length. Folding it into the
/// per-token rate overstates long sequences and short-changes many short ones (card c8b2e1df).
/// `Unmeasured` until the fork reports it apart from the KV.
pub recurrent_bytes_per_sequence: Measured<u64>,
pub prefill: RateCurve,
pub decode: RateCurve,
pub page: Vec<PageCost>,
Expand Down Expand Up @@ -112,4 +145,40 @@ mod tests {
assert_eq!(wire["memory"][0]["bytes"], serde_json::json!({ "state": "unmeasured" }));
assert_eq!(serde_json::from_value::<NodeProfile>(wire).expect("de"), declared);
}

// what this catches: a model profile that cannot carry what the fork reports, which is how the
// plan went wrong on the M5 (it saw weights and KV, not the draft, the projector or the graph).
#[test]
fn a_model_profile_carries_every_fixed_holder_and_the_recurrent_split() {
use crate::provenance::{Source, Spread};
let slug = |s: &str| Slug::try_from(s.to_string()).expect("slug");
let measured = |value: u64| Measured::Measured {
value,
at_ms: 1_793_710_260_000,
source: Source { kind: slug("engine/resident-state"), node: slug("m5") },
samples: 1,
error: Spread::NotYetMeasured,
};
let holder = |holder, bytes| HolderBytes { holder, tier: Tier::Unified, bytes: measured(bytes) };
let model = ModelProfile {
model: crate::closed::ModelId::try_from("continuum-ai/qwen3.6-35b-a3b-GGUF".to_string()).expect("model id"),
holders: vec![
holder(Holder::Weights, 20_690_000_000),
holder(Holder::ComputeGraph, 1_870_000_000),
holder(Holder::Draft, 2_630_000_000), // 1.34 weights + 1.29 compute; its KV is per token
holder(Holder::Projector, 900_000_000),
],
kv_bytes_per_token: measured(8_317),
draft_kv_bytes_per_token: measured(2_048),
recurrent_bytes_per_sequence: Measured::Unmeasured {},
prefill: RateCurve::Points { points: vec![] },
decode: RateCurve::Points { points: vec![] },
page: vec![],
checkpoint_bytes: measured(94_600_000),
slots: Measured::Unmeasured {},
};
let wire = serde_json::to_value(&model).expect("ser");
assert_eq!(wire["recurrent_bytes_per_sequence"], serde_json::json!({ "state": "unmeasured" }));
assert_eq!(serde_json::from_value::<ModelProfile>(wire).expect("de"), model);
}
}
23 changes: 23 additions & 0 deletions core/continuum-proving-types/src/reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ pub enum OutcomeKind {
Unfulfilled,
}

/// Where the engine resumed the act's prompt from (`llama-server`'s `lcp after reuse`, its checkpoint
/// restores, and the core's page probes). The tokens it then re-read are `Timing::prefill_tokens`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "from", rename_all = "snake_case", deny_unknown_fields)]
pub enum Resume {
/// Her KV was resident in the slot, and the engine kept this many tokens of it.
SlotPrefix { kept: u32 },
/// Rolled back to a context checkpoint ending at this token (a hybrid model resumes only there).
Checkpoint { at: u32 },
/// Paged in from disk, and the engine kept this many tokens of the page.
PageRestored { kept: u32 },
/// The page was refused, and the act prefilled cold. The class names why (`adapter_identity`,
/// `no_space`), never the engine's message.
PageRefused { class: Slug },
/// Nothing was reusable.
Cold {},
}

/// One act, with no words in it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand All @@ -206,6 +224,9 @@ pub struct ActReduction {
/// joins it from `delib.act.reasoning_budgeted` by persona and time.
pub reasoning_budget: Joined<u32>,
pub allocation: Joined<AllocationReduction>,
/// Joined from the engine log and page probes by slot and time; going forward the capture binds
/// it by request id.
pub resume: Joined<Resume>,
/// Tokens of each view item, in order (count and size, no words).
pub view_items: Vec<u32>,
pub delivery: Delivery,
Expand Down Expand Up @@ -245,6 +266,7 @@ mod tests {
}},
"reasoning_budget": { "join": "ambiguous", "candidates": 2 },
"allocation": { "join": "unresolved" },
"resume": { "join": "exact", "value": { "from": "page_refused", "class": "adapter_identity" } },
"view_items": [1200, 300],
"delivery": { "outcome": "completed", "elapsed_ms": 125000, "attempts": 1 },
"outcomes": ["tool_error"]
Expand Down Expand Up @@ -277,6 +299,7 @@ mod tests {
&["request", "tools", "0", "name"],
&["response", "value", "tool_calls", "0", "name"],
&["response", "value", "tool_calls", "0", "args"],
&["resume", "value", "class"],
];
for path in slots {
let mut v = reduction_json();
Expand Down
Loading