Skip to content

refactor(genome): typed /train contract; the lease is the engine's memory budget (+ pin to the trunk with fork #23) - #4458

Merged
joelteply merged 2 commits into
canaryfrom
feat/engine-trainer-typed
Sep 27, 2026
Merged

joelteply merged 2 commits into
canaryfrom
feat/engine-trainer-typed

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The /train body was assembled field by field with json! and the status read back as raw Value:
no schema, so a renamed or missing field was a silent wrong value. Now:

Tests: genome::fine_tuning 113/113; the progress test also pins the schema (no state = no parse,
an unknown state = Unknown).

Blocking Joel's install: this PR also takes the llama.cpp pin commit to the fork trunk with #23 (the memory guard) as soon as #23 merges. That commit is what continuum install builds her engine from.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

…e), and the lease goes to the engine as its memory budget

The /train body was assembled field by field with json! and the status read back as raw Value:
no schema, so a renamed or missing field was a silent wrong value. Now:
- TrainRequest / EngineExample (serialize) and TrainStatus / TrainState / EpochReport
  (deserialize) are the one statement of the fork's wire contract. `state` is required (a body
  without one does not parse and is retried, never read as "not ours"); an unknown state is
  TrainState::Unknown and counts as possibly running.
- memory_budget_mib = the job's governed lease: the engine refuses a graph over it BEFORE
  allocating (fork #23), instead of spilling past physical VRAM on Windows.
- the footprint recorded per shape is the engine's own measured graph_mib (exact) instead of a
  sampled VRAM peak; the sampling (ResourceDaemon reads, AtomicU64) is gone.
- a run that reaches done while being cancelled leaves no adapter behind (Fable's note on #4443).

Tests: genome::fine_tuning 113/113; the progress test also pins the schema (no state = no parse,
an unknown state = Unknown).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply

Copy link
Copy Markdown
Contributor Author

Reviewed at 513d5ba (Cormac). The code reads right; my word is APPROVED once lib CI is green.

  • The /train contract is stated once, typed: TrainRequest with memory_budget_mib from the governed lease, so the engine refuses a graph over the lease BEFORE allocating it (Fix CLI module compatibility and implement basic functionality #23). EngineExample is untagged, and it serializes to exactly the two shapes the engine reads, as the test pins.
  • TrainStatus requires state (a stateless body fails to parse and is retried, never read as "not ours"), and an unknown state is Unknown, which ends the job through failed, i.e. cancel-and-wait.
  • The footprint is the engine's own measured graph_mib instead of a sampled VRAM peak, which is exact and removes the daemon sampling.
  • A cancel that races a finish removes the adapter.

Non-blocking: EpochReport takes train_loss/eval_loss as plain f64. With no eval batches the engine writes 0.0 (ggml_opt_result_loss), so that is fine. But a DIVERGING run's NaN train loss serializes as JSON null, and then every GET /train fails to parse, so the job ends as "the lane and its run are gone" after LANE_SILENCE instead of "non-finite loss". The finish already refuses a non-finite loss; Option<f64> there would let it say so.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Fable: APPROVED at 513d5ba, pending green (the word is on airc). Read in full.

Should follow soon, not blocking the install: the recorded footprint is now graph_mib alone. That is the compute graph the engine measured. It leaves out what the training run holds outside the graph: the second context's KV cache for its window, and the optimizer's static tensors (gradients and moments, in ggml-opt's static buffers). So the SECOND run of a shape leases less than it uses. The engine budget guards only the graph, so the rest is unaccounted to the governor, which is the over-commit #23 exists to stop. The first run of any shape is a calibration run that leases all free memory, so Joel's first install run is safe. Fix: record max(graph + static + training-context buffers, the physical delta the old sampler took); or have the engine report its total training allocation beside graph_mib and record that.

… allocated only if it fits, under the caller's GPU budget), #22/#24 (lived examples: tools, train:false), #5/#16 (Metal backward). This is what continuum install builds her engine from.

Validated on the 5090 at this tip (test server in a 10 GB job object): window 512 trains (graph
2.58 GB), window 6144 refused before allocating, masked examples 1979/2177 trainable, text path
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply

Copy link
Copy Markdown
Contributor Author

Fable: APPROVED at b9d2a58. The only delta since my read at 513d5ba is the pin (LLAMA_CPP_PIN and the submodule both at 7772f3f9f), and 7772f3f9f contains fork #5, #16, #22, #23 and #24 (checked with merge-base against the trunk).

@joelteply

Copy link
Copy Markdown
Contributor Author

Reviewed at b9d2a58 (Cormac). The code is unchanged since 513d5ba; the only delta is the pin. LLAMA_CPP_PIN and the gitlink both name fork trunk 7772f3f9f, which is exactly #22, #5, #16, #24 and #23 merged (git log), each of them reviewed. My word is APPROVED once lib CI is green; 3 of 7 checks were still running when I read it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply
joelteply enabled auto-merge (squash) September 27, 2026 13:54
@joelteply
joelteply merged commit 62608b2 into canary Sep 27, 2026
8 checks passed
@joelteply
joelteply deleted the feat/engine-trainer-typed branch September 27, 2026 14:06
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVED at b9d2a58 (Cormac), with CI 9/9 green. Recorded for the merge that landed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

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