Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c20fd88
server: --cache-ram is the ONE host budget of the prompt cache and ev…
joelteply Nov 16, 2026
79a63b3
server: a mind switch is a sequence move, in milliseconds, through th…
joelteply Nov 16, 2026
a8388c4
server: prefetch the next mind from flash into the pool while others …
joelteply Nov 16, 2026
22ba0d9
minds: her bytes stay in RAM until her file has landed; insert never …
joelteply Nov 16, 2026
5111d28
minds: every named reply carries the switch receipt (page, where she …
joelteply Nov 16, 2026
53457df
server: learn a past turn on a side sequence (her own sequence never …
joelteply Nov 16, 2026
ad10873
server: /props.context_geometry.resident_minds {enabled, lanes, parke…
joelteply Nov 16, 2026
f78f45f
learn: the side replay decodes in n_batch chunks; its failure frees t…
joelteply Nov 16, 2026
e3795f9
minds: a flashed mind's checkpoints go down with her (written into he…
joelteply Nov 16, 2026
cb5bb2f
Merge remote-tracking branch 'origin/fable/one-host-budget-s4' into f…
joelteply Nov 16, 2026
0793fa6
minds + one host budget (#138 merged in): parked minds' checkpoints a…
joelteply Nov 16, 2026
1cd4db0
one host budget: making room counts only what stays resident, and her…
joelteply Nov 16, 2026
793bd18
minds: /minds/prefetch refuses, typed, a stream meant for another eng…
joelteply Nov 16, 2026
8a53bd5
minds: the engine issues its own incarnation token (resident_minds.in…
joelteply Nov 16, 2026
e8ee0b2
minds + learn: every reply value a frozen typed enum (Codex: callers …
joelteply Nov 16, 2026
5b5e22a
minds: POST /learn/release frees an abandoned turn's learn pin, where…
joelteply Nov 16, 2026
97019d6
minds: a learn pin is a unique id, never a position (Codex: two turns…
joelteply Nov 16, 2026
6f6221a
minds: slot erase asserts its own result again (my e8ee0b2f4 put the …
joelteply Nov 17, 2026
0df8dc4
checkpoint policy test: its ckpt carries the learn pin the policy rea…
joelteply Nov 17, 2026
7643fb9
minds: /props reports the parked CAPACITY (fixed) and the free count …
joelteply Nov 17, 2026
945a742
minds: page and checkpoint lengths are checked part by part, never as…
joelteply Nov 17, 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
11 changes: 11 additions & 0 deletions common/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,17 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
params.n_parallel = value;
}
).set_env("LLAMA_ARG_N_PARALLEL").set_examples({LLAMA_EXAMPLE_SERVER}));
add_opt(common_arg(
{"--minds"}, "N",
"continuum: minds the engine keeps resident beside its lanes, each as its own parked sequence of the unified "
"KV pool (a mind switch is a sequence move, never a serialization); the core's resident count, 0 = off",
[](common_params & params, int value) {
if (value < 0) {
throw std::invalid_argument("error: --minds must be >= 0\n");
}
params.n_minds = value;
}
).set_env("LLAMA_ARG_MINDS").set_examples({LLAMA_EXAMPLE_SERVER}));
} else {
add_opt(common_arg(
{"-np", "--parallel"}, "N",
Expand Down
3 changes: 2 additions & 1 deletion common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ struct llama_context_params common_context_params_to_llama(const common_params &
auto cparams = llama_context_default_params();

cparams.n_ctx = params.n_ctx;
cparams.n_seq_max = params.n_parallel;
// continuum: every resident mind keeps its own sequence (lanes + parked minds) in the unified pool
cparams.n_seq_max = params.n_parallel + std::max<int32_t>(0, params.n_minds);
cparams.n_rs_seq = params.speculative.need_n_rs_seq();
cparams.n_outputs_max = std::max(params.n_outputs_max, 0);
cparams.n_outputs_max_per_seq = std::max(params.n_outputs_max_per_seq, 0);
Expand Down
5 changes: 5 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ struct common_params {
int32_t n_keep = 0; // number of tokens to keep from initial prompt
int32_t n_chunks = -1; // max number of chunks to process (-1 = unlimited)
int32_t n_parallel = 1; // number of parallel sequences to decode
int32_t n_minds = 0; // continuum: minds kept resident beside the lanes (parked sequences); the core's count
int32_t n_sequences = 1; // number of sequences to decode
int32_t n_outputs_max = 0; // max outputs in a batch (0 = n_batch)
int32_t n_outputs_max_per_seq = 1; // max outputs per sequence
Expand Down Expand Up @@ -1155,6 +1156,10 @@ enum ggml_opt_optimizer_type common_opt_get_optimizer(const char *);
struct common_prompt_checkpoint {
int64_t n_tokens;

// continuum: held for a turn the core will learn (its served prompt's end, n_prefix - 1): never evicted or
// superseded until that turn is learned on a side sequence or abandoned
uint64_t pin = 0; // continuum: the learn pin holding it (unique per engine process; 0: not pinned)

// (optional) id of the task that created the checkpoint
int id_task = -1;

Expand Down
2 changes: 1 addition & 1 deletion common/speculative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ common_params common_base_params_to_speculative(const common_params & params) {

result.cache_type_k = params_spec.cache_type_k;
result.cache_type_v = params_spec.cache_type_v;
result.n_outputs_max = params.n_parallel;
result.n_outputs_max = params.n_parallel + std::max<int32_t>(0, params.n_minds); // one row per sequence, parked minds included
result.n_outputs_max_per_seq = 1;

// dflash/dspark decode the whole noise block in a single pass and sample every block position on the backend
Expand Down
19 changes: 19 additions & 0 deletions tests/test-server-checkpoint-policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct ckpt {
int64_t n_tokens;
int id_task;
int serial; // identity: a checkpoint is the same one only if its serial matches
uint64_t pin = 0; // nonzero: held for learning (common.h server_prompt_checkpoint::pin)
};

using store = std::list<ckpt>;
Expand Down Expand Up @@ -51,6 +52,23 @@ static void head_survives_a_full_store_across_many_acts() {
}
}

// regression for the pin added on #139: a checkpoint pinned for learning is never the victim, and a store whose
// every candidate is pinned yields end() so the caller defers instead of erasing a learner's checkpoint
static void a_pinned_checkpoint_is_never_evicted() {
store s;
for (int i = 0; i < 4; ++i) {
s.push_back({ 9655 + i * 1000, i, i });
}
s.front().pin = 0;
std::next(s.begin(), 1)->pin = 7;
auto victim = checkpoint_to_evict(s, /*view_end=*/100000);
require(victim != s.end() && victim->pin == 0, "the victim is unpinned");
for (auto & c : s) {
c.pin = 1 + (uint64_t) c.serial;
}
require(checkpoint_to_evict(s, 100000) == s.end(), "all pinned: no victim");
}

static void the_pre_fix_rule_loses_the_head() {
const size_t capacity = 4;
store s;
Expand Down Expand Up @@ -142,6 +160,7 @@ static void a_cold_prompt_with_view_spans_makes_her_head() {

int main() {
a_cold_prompt_with_view_spans_makes_her_head();
a_pinned_checkpoint_is_never_evicted();
head_survives_a_full_store_across_many_acts();
the_pre_fix_rule_loses_the_head();
capacity_one_keeps_only_what_fits();
Expand Down
3 changes: 3 additions & 0 deletions tools/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ add_library(${TARGET} STATIC
server-common.cpp
server-common.h
server-context.cpp
server-mapped-file.cpp
server-mapped-file.h
server-mind.h
server-train.cpp
server-context.h
server-stream.cpp
Expand Down
9 changes: 8 additions & 1 deletion tools/server/server-checkpoint-policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ inline bool checkpoint_at_user_start(bool view_spans, bool store_empty, int64_t
// The checkpoint to erase to make room for one more. With view spans (view_end >= 0) her head (the
// oldest) is her restore point when her next prompt diverges before her view end, so the oldest AFTER
// it goes first; the head goes only when it is all there is. Without view spans, the oldest goes.
// A checkpoint pinned for learning is never the victim; end() when every candidate is pinned.
template <typename List>
typename List::iterator checkpoint_to_evict(List & checkpoints, int32_t view_end) {
auto victim = checkpoints.begin();
if (view_end >= 0 && checkpoints.size() >= 2) {
++victim;
}
while (victim != checkpoints.end() && victim->pin != 0) {
++victim;
}
if (victim == checkpoints.end() && !checkpoints.empty() && checkpoints.front().pin == 0) {
return checkpoints.begin(); // only her head is left unpinned
}
return victim;
}

Expand All @@ -48,7 +55,7 @@ size_t erase_superseded_checkpoints(List & checkpoints, const Checkpoint & kept,
const auto * head = &checkpoints.front();
size_t erased = 0;
for (auto it = checkpoints.begin(); it != checkpoints.end();) {
if (&*it != head && it->id_task != id_task) {
if (&*it != head && it->id_task != id_task && it->pin == 0) {
on_erase(*it);
it = checkpoints.erase(it);
++erased;
Expand Down
16 changes: 16 additions & 0 deletions tools/server/server-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ json server_slot_stats::to_json() const {
base["draft_n_accepted"] = n_draft_accepted;
}

if (mind_hi != 0 || mind_lo != 0) {
static const char * names[] = { "none", "lane", "parked", "flash", "ram", "new", "adopted", "flash_pool_full" };
char page[33];
std::snprintf(page, sizeof(page), "%016llx%016llx", (unsigned long long) mind_hi, (unsigned long long) mind_lo);
base["mind"] = {
{"page", page},
{"from", names[(size_t) mind_came_from]},
{"switch_ms", mind_switch_us / 1000.0},
{"generation", mind_generation},
};
if (mind_pin != 0) {
base["mind"]["pin"] = mind_pin;
base["mind"]["pinned_at"] = mind_pinned_at;
}
}

return base;
}

Expand Down
12 changes: 12 additions & 0 deletions tools/server/server-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,19 @@ json format_response_rerank(
//

// shared between server_slot and server_task_result_*
// Continuum fork: where the mind a request named came from when she took the lane (server-context-minds.inc)
enum class mind_from : uint8_t { none, lane, parked, flash, ram, fresh, adopted, flash_pool_full };

struct server_slot_stats {
// the switch receipt (a request that named its mind): her page, where her state came from, how long the
// switch took and her state's generation (it advances each time her state moves)
uint64_t mind_hi = 0, mind_lo = 0;
mind_from mind_came_from = mind_from::none;
int64_t mind_switch_us = 0;
uint64_t mind_generation = 0;
uint64_t mind_pin = 0; // learn_pin: the pin's id (what /learn/release takes; unique per engine process)
int64_t mind_pinned_at = -1; // learn_pin: the pinned checkpoint's position (information only)

uint64_t n_prompt_cached = 0;
uint64_t n_prompt_processed = 0;
uint64_t n_gen = 0;
Expand Down
Loading
Loading