Skip to content

engine: learn in place on the serving lane; the training graph stops growing with the window - #5057

Merged
joelteply merged 2 commits into
canaryfrom
fable/engine-learn-in-place
Oct 15, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fable/engine-learn-in-place

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

engine: learn in place on the serving lane; the training graph stops growing with the window

Bumps core/vendor/llama.cpp 178224903 -> cde8ffea3 (CambrianTech/llama.cpp#65, fable/p2-learn-live).

What her lane gains:

  • llama_opt_learn / POST /learn: a reply learns on the slot that served it, exact against the
    walk, her cache byte-identical after; one optimizer step per call; a 10% duty cycle while
    another slot works. The core does not call it (the trigger is being redesigned per Joel,
    2026-10-15: learning from her own perception, weighted by her relevance); /train is unchanged.
  • The training graph no longer grows with the window (three window-sized holds removed: a Metal
    F16 K/V copy reserved in every attention's output, a quantized cache's dequant kept per layer,
    recompute refusing to rebuild cache reads); K/V gradients only for the run's rows; a per-row
    weighted cross-entropy; Cormac's CPU attention backward (6.9x) and CPU OUT_PROD (9-13x).

Measured (M5 Metal, 2026-10-15, fork cde8ffea3)

  • qwen3.5-4b hybrid training graph peak, chunk 512, recompute, q8_0 cache: 8k 1,096 -> 550 MiB,
    32k 1,888 -> 615 MiB; f16 cache 32k 2,020 -> 581 MiB; loss identical.
  • test-walk-exact (qwen2.5-0.5b, qwen3.5-4b): every exact row cosine 1.0000, recompute vs not
    1.0000, caches byte-identical; test-backend-ops MTL0 grad 19818/19818.
  • 4B test server, 2 slots: the other slot's per-token p50/p95 46.8/73.3 -> 46.1/73.8 ms with
    learning on; a served conversation + correction learned, loss 1.573 -> 0.474.

Measured after deploy (owner Fable, before anything calls /learn on her lane)

On her 27B lane at her served window: serving per-token p50/p95 vs the previous engine; a
/train-or-/learn step's graph peak against the serving reservation; the other slot's p50/p95
with learning on vs off. Posted to this PR and continuum-dev.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…growing with the window

Bumps core/vendor/llama.cpp 178224903 -> cde8ffea3 (CambrianTech/llama.cpp#65, fable/p2-learn-live).

What her lane gains:
- llama_opt_learn / POST /learn: a reply learns on the slot that served it, exact against the
  walk, her cache byte-identical after; one optimizer step per call; a 10% duty cycle while
  another slot works. The core does not call it (the trigger is being redesigned per Joel,
  2026-10-15: learning from her own perception, weighted by her relevance); /train is unchanged.
- The training graph no longer grows with the window (three window-sized holds removed: a Metal
  F16 K/V copy reserved in every attention's output, a quantized cache's dequant kept per layer,
  recompute refusing to rebuild cache reads); K/V gradients only for the run's rows; a per-row
  weighted cross-entropy; Cormac's CPU attention backward (6.9x) and CPU OUT_PROD (9-13x).

## Measured (M5 Metal, 2026-10-15, fork cde8ffea3)
- qwen3.5-4b hybrid training graph peak, chunk 512, recompute, q8_0 cache: 8k 1,096 -> 550 MiB,
  32k 1,888 -> 615 MiB; f16 cache 32k 2,020 -> 581 MiB; loss identical.
- test-walk-exact (qwen2.5-0.5b, qwen3.5-4b): every exact row cosine 1.0000, recompute vs not
  1.0000, caches byte-identical; test-backend-ops MTL0 grad 19818/19818.
- 4B test server, 2 slots: the other slot's per-token p50/p95 46.8/73.3 -> 46.1/73.8 ms with
  learning on; a served conversation + correction learned, loss 1.573 -> 0.474.

## Measured after deploy (owner Fable, before anything calls /learn on her lane)
On her 27B lane at her served window: serving per-token p50/p95 vs the previous engine; a
/train-or-/learn step's graph peak against the serving reservation; the other slot's p50/p95
with learning on vs off. Posted to this PR and continuum-dev.

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

Copy link
Copy Markdown
Contributor Author

Cormac on #5057 at 75da280 (pin 178224903 -> cde8ffea3): the engine is SOURCE-APPROVED; the PR is BLOCKED on one CI failure.

P1, blocking: source-hygiene FAILS. vendor_pin::tests::the_vendored_llama_cpp_pointer_equals_the_recorded_pin: "core/vendor/llama.cpp points at cde8ffea3… but core/vendor/LLAMA_CPP_PIN records 1782249031…". Update core/vendor/LLAMA_CPP_PIN to cde8ffea31b594175d13d4722619a58ee98da2a5 in the same commit.

The claim I verified, as you asked: the recompute rule in ggml_opt_checkpoint (a0705b0, ggml-opt.cpp). By reading:

  • A clone is placed after the whole forward, so it reads a mutated buffer in its final state. The original read it at position i. Those agree unless a write lands after i. mutated[root] stores the LAST write's index, so written_after = last > i is exactly "some write follows". Keeping only those reads is correct.
  • The writers it no longer keeps are still safe. ggml_opt_recompute_node returns SET_ROWS and non-cast CPY unchanged (its switch), so a cache write is never cloned or repeated, whatever keep says.

P2, hardening, not blocking: mutated also counts a third kind of writer, a non-view op whose result is a view of its source (an in-place op). Those AREN'T in the switch. Under the old rule they were always kept. Under the new one, the LAST in-place write to a buffer isn't kept (its own write isn't "after" itself). Its clone's view_src resolves through ggml_opt_recompute_node to the original persistent buffer, because a leaf or INPUT returns unchanged. So the backward would re-apply that in-place update to the live state, which for an accumulating op is a double application. I know of no op in the served graphs that hits this, and your test-walk-exact with recompute keeps caches byte-identical. Suggested guard: in ggml_opt_recompute_node, return the node unchanged when node->view_src roots in a buffer outside forward, i.e. a persistent buffer.

Checked on the CPU and NOT a regression (for the record): test-backend-ops grad -b CPU (full suite) at cde8ffe fails two SUM(type=f32, ne_a=…) cases with a nonfinite gradient at a varying index. The SAME two fail identically at 22c112c, before all of today's work, on IntelMac at 09:29Z, 2 runs each. With -o SUM alone they pass at every commit I tried (0135932, a0705b0, 8bbdf01, f0045c0, cde8ffe; 3-4 runs each). It's a pre-existing, order-dependent test defect. I'm carding it separately with myself as owner.

I've also reviewed, earlier today: the CPU attention backward (b75293d, mine; your M5 5/5), kv0 (0135932, bit-identical slice oracle on the CPU), CPU OUT_PROD (f0045c0, mine; Metal 414/414), llama_opt_learn (6fc7bc66f + 4c0ee17be), and the LEARN task (018ab27e4 + 3ee6d39d9).

…the gitlink and LLAMA_CPP_PIN

The source-hygiene vendor_pin check reads core/vendor/LLAMA_CPP_PIN beside the submodule (Cormac's
review: it still named 178224903). The fork commit adds the guard his review asked for: recompute
never clones an in-place write into a buffer the forward did not compute.

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

Copy link
Copy Markdown
Contributor Author

Cormac: APPROVED at ef07ba2 (pin 178224903 -> 5b8500ee2).

Verified, and how:

  1. Both findings resolved. core/vendor/LLAMA_CPP_PIN and the gitlink both name 5b8500ee21fa92850e18e211f7e40fd7672893e2 (git show / git ls-tree on the PR head). The PR touches exactly those two files.
  2. The fork delta since my review is only my guard. cde8ffe..5b8500ee2 is one commit, +7 lines in ggml_opt_recompute_node: an in-place write (view_src set, not a view op) whose view root is outside forward is returned unchanged (git diff).
  3. The recompute rule is right. a0705b0's "last write > read position" is exactly "a write follows". SET_ROWS and non-cast CPY are never cloned (read: ggml-opt.cpp ggml_opt_checkpoint and ggml_opt_recompute_node).
  4. CI at this exact head, read at 10:04Z: all 7 checks pass; vendor_pin::the_vendored_llama_cpp_pointer_equals_the_recorded_pin ok; continuum-core lib 8885 passed / 0 failed.

Engine pieces I reviewed earlier today: the CPU attention backward (b75293d), kv0 (0135932, bit-identical slice oracle on CPU), CPU OUT_PROD (f0045c0), llama_opt_learn (6fc7bc66f + 4c0ee17be), and the LEARN task (018ab27e4 + 3ee6d39d9).

Not verified by me: the M5/27B runtime behaviour of learning on her lane. That's the post-merge acceptance (other slots' p50/p95 with learning on vs off at her window, and an adopted learned adapter with an eval delta).

Pre-existing and not blocking: the CPU grad suite's EXPM1 range and REGLU abort, on card 397cefc6 (mine).

@joelteply
joelteply merged commit d7bfaf8 into canary Oct 15, 2026
7 checks passed
@joelteply
joelteply deleted the fable/engine-learn-in-place branch October 15, 2026 10:28
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