Repository navigation
server: one shadow per mind on the serving context: each shadow keeps its own optimizer, /learn trains any loaded shadow, and unload releases it - #85
Closed
joelteply wants to merge 5 commits into
Conversation
joelteply
changed the base branch from
master
to
889580fc/seq-state-across-stream-counts
November 1, 2026 07:14
joelteply
force-pushed
the
cormac/per-mind-shadow
branch
from
November 7, 2026 17:21
12cf0ea to
7d885c8
Compare
joelteply
added a commit
that referenced
this pull request
Nov 7, 2026
…g changes, never asserted (Fable on #85) opt_select (another mind's shadow) GGML_ASSERTed on caller input: a learn naming a loaded F16 copy of a shadow killed the serving process (exit 134 at llama-context-opt.cpp:205), and the same asserts sat on the first learn. Now one validator, llama_context::opt_untrainable (attached at a non-zero scale, every A/B F32, the filter selecting at least one tensor), runs in opt_init and opt_select before any parameter flag changes; on failure opt_failure says why and llama_opt_init returns false. The /learn path restores her adapter set and refuses the learn by name; /train fails the run by name. Test: learn-every-format.py --non-f32-refused (make-f16-shadow.py writes the F16 copy): the F32 shadow learns, its F16 copy is refused naming non-F32, /health answers, and the F32 shadow learns again. The default and --two-minds modes pass unchanged (CPU, Qwen2.5-0.5B, --no-repack). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply
force-pushed
the
cormac/per-mind-shadow
branch
from
November 7, 2026 18:58
7d885c8 to
f359df5
Compare
… its own optimizer, /learn trains any loaded shadow, and unload releases it A serving context trained exactly one shadow per server run (learn_lora_id): the second mind's /learn was refused, so only one resident could ever learn in place (continuum S4 (a), card eaeb2b87). - llama_context keeps an optimizer per shadow (opt_minds); opt_ctx and opt_shadow point at the active one, so every training site reads the active pair as before. llama_opt_init with another adapter on a configured context selects it (opt_select), creating its optimizer the first time and keeping each shadow's moments and accumulators across switches. Only the active shadow's tensors carry the PARAM flag, so a graph never carries a parameter the active optimizer was not built with. - opt_configured() is "this context is sized for training" (scheduler and graph): it was read as opt_ctx != nullptr, which a released active shadow would have falsified while other shadows' optimizers still held the scheduler. - llama_opt_release forgets one shadow's optimizer; the server's unload releases a shadow that learned (its moments go; a snapshot is the durable form) instead of refusing it forever. - learn-every-format.py --two-minds: two shadows from the same file learn alternately; their losses match step for step (4.3179, 4.3179, 3.5043, 3.5043 on Qwen2.5-0.5B, IntelMac CPU), which holds only if each keeps its own weights and optimizer. --shadow-retirement now unloads a bound shadow and learns on a reloaded one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…g changes, never asserted (Fable on #85) opt_select (another mind's shadow) GGML_ASSERTed on caller input: a learn naming a loaded F16 copy of a shadow killed the serving process (exit 134 at llama-context-opt.cpp:205), and the same asserts sat on the first learn. Now one validator, llama_context::opt_untrainable (attached at a non-zero scale, every A/B F32, the filter selecting at least one tensor), runs in opt_init and opt_select before any parameter flag changes; on failure opt_failure says why and llama_opt_init returns false. The /learn path restores her adapter set and refuses the learn by name; /train fails the run by name. Test: learn-every-format.py --non-f32-refused (make-f16-shadow.py writes the F16 copy): the F32 shadow learns, its F16 copy is refused naming non-F32, /health answers, and the F32 shadow learns again. The default and --two-minds modes pass unchanged (CPU, Qwen2.5-0.5B, --no-repack). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…d while a live reply holds it (Codex on #100) Between a live reply's chunks the training flags are cleared but the active optimizer and its accumulators still belong to that reply until its restoration finishes. opt_init (and the opt_select it makes) and opt_release refuse by name while opt_reply is held; the server's unload refuses the shadow a learn is training, whether or not any slot's stable set names it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…ulators, AdamW moments), the per-shadow memory a serving context carries Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply
force-pushed
the
cormac/per-mind-shadow
branch
from
November 8, 2026 22:23
f359df5 to
c534ae8
Compare
joelteply
changed the base branch from
889580fc/seq-state-across-stream-counts
to
codex/s4-resident-microsteps
November 8, 2026 22:24
…the shadow a live reply trains is refused (Codex on #85) llama_opt_release refused every adapter while a live reply was held, and the server ignored the refusal: unloading idle mind B during mind A's learn freed B's tensors while B's optimizer stayed in opt_minds (Codex's s4-unload-other-shadow, Windows). An idle mind's optimizer is its own buffers (ggml_opt_free touches no shared scheduler), so release now frees it during another mind's reply and refuses only the shadow that reply trains; it returns true when no optimizer references the adapter (released, or none), and the server refuses the unload on false instead of ignoring it. Measured (IntelMac CPU, Qwen2.5-0.5B Q4_K_M, -np 2 --no-repack): learn-unload-during-learn.py: B trained, A's 681-label reply in flight, unload B 200 (retired), unload A 503 (restoration pending), A completes (loss 0.1268, 41.8 s CPU), reloaded B learns again (loss 4.2457). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
Author
|
Closing (Cormac, Joel 2026-11-11 'get all your stuff merged'): this head is already an ancestor of codex/s4-per-mind-integration, so its change has landed. |
joelteply
added a commit
that referenced
this pull request
Nov 11, 2026
…shadow unloads while another mind learns c5551ed made ggml_opt_free assert that the SHARED scheduler had no pending graph. A serving context keeps one optimizer per shadow on one scheduler, and llama_context::opt_release frees an idle shadow's optimizer while another shadow's step is in flight (#85's contract: "ggml_opt_free touches no shared scheduler"). That assert then aborted llama-server whenever the unload landed mid-step (fork #106/#107 reproducer, learn-unload-during-learn.py, 2 of 3 runs on CPU). ggml_opt_free releases only this context's own buffers and metadata. The check is now context-local: ggml_backend_sched_graph_pending_for(sched, graph), true only when the scheduler is part-way through THAT graph (graph_step already keys its continuation on the caller's graph pointer). Freeing a context whose own graph is in flight still aborts. ggml_opt_reset and ggml_opt_prepare_alloc keep the scheduler-wide guard: reset zeroes the last graph's gradients, which in a dynamic graph can sit in the shared compute buffer another mind now uses, and prepare_alloc allocates onto the scheduler. Tests (test-opt-dynamic-accum, built with -fsanitize=address on CPU, IntelMac): - run_frees_idle_mind_while_another_steps: B learns a step, A stops one node into its step (scheduler pending), B is freed, A completes with exactly the update it makes alone. PASS. - run_free_own_pending_graph_aborts: freeing a context whose own graph is in flight aborts (observed in a forked child; skipped with a message where fork() is unavailable). PASS. - the existing suite: PASS. - Mutation: restoring the scheduler-wide check aborts the first test at the same assert the engine hit (exit 134). End to end: the reproducer passes 10/10 on the fixed CPU server, but it is timing-dependent (it aborts only if the unload lands mid-graph; 0/6 on the unfixed engine in a later run), so the unit test is the proof. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
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.
Continuum card eaeb2b87, S4 (a), the in-place dream stage (ONE-RESIDENT-MODEL §8.1 / §9). Today a serving context learns for exactly ONE mind per server run: a second resident's
/learnis refused with "one shadow per server run". This lets every resident on a lane learn in place, each with her own shadow and optimizer.Change
llama_contextkeeps one optimizer per shadow (opt_minds), andopt_ctx/opt_shadoware the active pair, so every existing training site is unchanged.llama_opt_initwith another adapter on a configured context callsopt_select. It creates that shadow's optimizer the first time and keeps each shadow's moments and accumulators across switches.opt_configured()replacesopt_ctx != nullptrwhere the question is whether the context is sized for training (reserve skip, graph sizing). Releasing the active shadow would otherwise have rebuilt a scheduler that other shadows' optimizers still hold.llama_opt_releasedrops one shadow's optimizer. The server's unload now releases a shadow that learned, instead of refusing it forever. Its moments are lost; the snapshot in (d) will be the durable form.learn_lora_idis deleted.Measured (IntelMac CPU, Release, Qwen2.5-0.5B Q4_K_M, -np 1, 2026-11-01)
learn-every-format.py --two-minds, fresh server: shadow-05 and a byte copy, shadow-06, learn alternately. Losses: 4.3179, 4.3179, 3.5043, 3.5043.--shadow-retirement: a bound shadow unloads, and a reloaded one learns (loss 4.3179, 974 ms).Contract for the core: a shadow IS its file
POST /lora-adapters/load deduplicates by path on purpose: a client that dropped after posting and retries must get back the id it never received. So loading the same file twice returns the SAME adapter, with its trained weights.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE