Skip to content

Each mind's decode graph stays built and allocated across a switch - #170

Open
joelteply wants to merge 2 commits into
fable/adapter-switchfrom
fable/graph-slots
Open

joelteply wants to merge 2 commits into
fable/adapter-switchfrom
fable/graph-slots

Conversation

@joelteply

@joelteply joelteply commented Nov 28, 2026 •

Copy link
Copy Markdown

A backend scheduler holds the split and allocation of one graph, so a context serving several minds one step at a
time rebuilt, re-split and re-allocated its graph at every switch: on the M5 live (Qwen3.6-35B-A3B, four residents)
0 of 74 steps in a turn reused a graph, with 78 switches. The Core binds every mind into its one sequence, so
nothing visible to the engine told one mind's step from another's.

A graph slot is a second scheduler with its own graph results. Entering one swaps the context's scheduler, graph
results, active graph and adapter set with the slot's (four pointer swaps), so every use of the context's scheduler
is unchanged; decode() swaps back when it returns. Slots serve ubatches of one token per sequence only; prefill and
training stay on the context's worst-case scheduler.

Each mind's steps keep their graph in her own slot, keyed by whom the ubatch's sequences serve: the owner names her
when it binds her (llama_set_graph_slot_key; an unnamed sequence is keyed by its id). Whether her kept graph serves
the step is the graph's own reuse check (K/V extent, adapter set, pin and every other input), never a key derived
here; when it cannot (her K/V crossed a 256-cell block, her genes changed), she rebuilds in her own slot and no other
mind's graph is touched. A slot keeps the adapter set object its graph was built with, so that check (which compares
the set by pointer) holds when she returns; a slot made before any adapter free is dropped, since a freed address
may come back (llama_model::lora_frees). The owner sets how many slots from the minds it keeps resident
(llama_set_graph_slots; 0, the default, keeps none).

Measured on the M5 (Qwen3.6-35B-A3B Q4_K_M, Q4_0 K/V, FA, routing capture on, core stopped so the GPU is quiet,
02:15Z), test-graph-slots: four minds round-robin one token each, three adapter sets, 192 steps:
the Core's shape (one stream, each mind bound by her attached storage, named by persona id):
no slots 16.57 ms/step, 0 reused; slots 14.31 ms/step, 188 of 188 possible reused
a stream each: no slots 16.34 ms/step, 0 reused; slots 14.67 ms/step, 188 reused
four slots hold 16.5 MiB; logits bit-identical at every step in both (max |diff| 0)

Stacked: #167 (merged) → #168 lived routing → #169 adapter switch → this. #169 and this were rebased onto #168 so the line is one; #168's drop_reusable_graphs also forgets the slots' graphs.

Review asks (Codex): any path that holds the context's scheduler across a decode() return while a slot was active; memory_update's forget fires on every real memory update (if paging makes that frequent, live graphs_reused shows it); the opt exclusions in graph_slot_enter (labelled ubatch, opt_serving_continuation, a live reply's retained graph).

Validator: test-graph-slots -m <model> -ngl 99 fails on any logit difference or any rebuild of a kept graph, in both shapes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply
joelteply force-pushed the fable/adapter-switch branch from 27030ed to 35dd70c Compare November 28, 2026 02:09
@joelteply
joelteply force-pushed the fable/graph-slots branch 2 times, most recently from 64acdfe to c6f751b Compare November 28, 2026 02:15
… another mind

A backend scheduler holds the split and allocation of one graph, so a context serving several minds one step at a
time rebuilt, re-split and re-allocated its graph at every switch: on the M5 live (Qwen3.6-35B-A3B, four residents)
0 of 74 steps in a turn reused a graph, with 78 switches. The Core binds every mind into its one sequence, so
nothing visible to the engine told one mind's step from another's.

A graph slot is a second scheduler with its own graph results. Entering one swaps the context's scheduler, graph
results, active graph and adapter set with the slot's (four pointer swaps), so every use of the context's scheduler
is unchanged; decode() swaps back when it returns. Slots serve ubatches of one token per sequence only; prefill and
training stay on the context's worst-case scheduler.

Each mind's steps keep their graph in her own slot, keyed by whom the ubatch's sequences serve: the owner names her
when it binds her (llama_set_graph_slot_key; an unnamed sequence is keyed by its id). Whether her kept graph serves
the step is the graph's own reuse check (K/V extent, adapter set, pin and every other input), never a key derived
here; when it cannot (her K/V crossed a 256-cell block, her genes changed), she rebuilds in her own slot and no other
mind's graph is touched. A slot keeps the adapter set object its graph was built with, so that check (which compares
the set by pointer) holds when she returns; a slot made before any adapter free is dropped, since a freed address
may come back (llama_model::lora_frees). The owner sets how many slots from the minds it keeps resident
(llama_set_graph_slots; 0, the default, keeps none).

Measured on the M5 (Qwen3.6-35B-A3B Q4_K_M, Q4_0 K/V, FA, routing capture on, core stopped so the GPU is quiet,
02:15Z), test-graph-slots: four minds round-robin one token each, three adapter sets, 192 steps:
  the Core's shape (one stream, each mind bound by her attached storage, named by persona id):
    no slots 16.57 ms/step, 0 reused; slots 14.31 ms/step, 188 of 188 possible reused
  a stream each: no slots 16.34 ms/step, 0 reused; slots 14.67 ms/step, 188 reused
  four slots hold 16.5 MiB; logits bit-identical at every step in both (max |diff| 0)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…erves

graph_reserve rounds a ubatch up to a multiple of the sequences (three streams reserve 2049 of a 2048 ubatch); the
routing capture held exactly n_layer x n_ubatch rows, so any re-reserve with the capture on aborted at its bound
(the M5, 2026-11-28 06:32Z onward: 77 aborts, decode -> sched_reserve -> graph_reserve -> llama_route_experts,
once the core held three whole-window streams). The capture now holds the rounded ubatch's rows.

test-graph-slots: a three-stream context with the capture on, re-reserved by a setting changed after it, decodes;
it aborted at llama-lived-routing.cpp:120 without the fix (checked), and passes with it; both graph-slot arms
unchanged (max |logit diff| 0).
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