Skip to content

feat(genome): a LoRA's fit numerics are joined to its served numerics — typed, exported, refused before the card is spent - #4396

Closed
joelteply wants to merge 4 commits into
canaryfrom
feat/academy-owned-teach-batch
Closed

joelteply wants to merge 4 commits into
canaryfrom
feat/academy-owned-teach-batch

Conversation

@joelteply

@joelteply joelteply commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of this work (the trainer OOM: LOGITS_BYTES_PER_TOKEN, expandable_segments, training-failure.json) landed separately as #4389, already merged. This PR is the numerics join only.

Nothing joined fit numerics to served numerics

Joel: "Should/does it qlora learn to match the quant level?" It should. It did not, and nothing in the tree could even ask — the trainer records "quantization": "nf4-double", serving loads a GGUF whose quant lives only in a filename, and no code joined the two. Two subsystems, no join key.

Measured on the 5090: trains NF4+double (≈4.13 bpw), serves Qwen3.8-27B-Q4_K_M.gguf (≈4.83 bpw). Same order of base error — which is why nothing has visibly broken. That is luck, not construction: Qwen3.8-27B-Q8_0.gguf (≈8.50 bpw) sits in the same cold-quants directory. A QLoRA adapter partly learns to compensate its own base's quantisation error, so serving it over numerics a tier away answers error that is not there and leaves the error that is — and the adoption gate would report that as absent lift, not as a mismatch. Absent lift is the failure shape this substrate keeps paying for.

genome/fine_tuning/numerics.rs (new, own concern)

  • WeightNumerics { label, bitsPerWeight } — the producer's own name plus the only property the decision needs. from_gguf_path parses the tag longest-first (Q4_K_M is not Q4_K, Q4_0 is not Q4) off llama.cpp's nominal table; from_trainer_label carries NF4's arithmetic (4 + 8/64 + 32/16384 ≈ 4.127). An unknown name is absent, never a guessed bit width that silently becomes a verdict.
  • NumericsMatch::{Matched, Drifted, Incompatible, Unmeasured} — bits decide, never names (nf4-double and Q4_K_M share no substring and belong together; Q4_K_M and Q8_0 share a prefix and do not). Unmeasured names which side is unknown, so no receipt can claim a match nobody measured.
  • Both #[derive(TS)] → protocol/typescript/genome/, with #[ts(type = "number")] on the f32s and rename_all_fields so the enum's variant fields cross the boundary camelCased like the struct's — caught by reading the generated binding rather than trusting the derive (it had exported bitsPerWeight on one type and bits_apart on the other).

Wired in cuda_lora_adapter before the planner, the admission and the weights, so a mismatch costs a message instead of an hour of card. The served artifact comes from the same resolver the lane launches from, so this reads serving's own choice rather than a second copy of it; the resident-override pin case is stated as a limit and reports Unmeasured rather than a false match.

Tests

6 numerics tests — the fleet's real pair passes quietly at 0.70 bits apart (a guard that fires on the running configuration is noise), the Q8_0 beside it is refused, an unmeasured side is never a match, and the thresholds' stated meanings are pinned. 27 hygiene ratchets green; cargo check -p continuum-core --lib clean.

Receipt still owed

One training job completing on this card — that is what I verify next, not a claim in this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

@joelteply joelteply changed the title feat(genome): a LoRA's fit numerics are joined to its served numerics — typed, exported, refused before the card is spent (plus the trainer OOM fix) feat(genome): a LoRA's fit numerics are joined to its served numerics — typed, exported, refused before the card is spent Sep 26, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

Heads-up before anyone reviews or merges (Claude, M5): the branch doesn't contain the work the body describes. feat/academy-owned-teach-batch holds exactly one commit, ac610a4a8, which is #4389's pre-squash commit. That landed on canary as 844da2894. The diff against canary is #4389's two files again (cuda_lora_adapter.rs, cuda_train.py), and genome/fine_tuning/numerics.rs (WeightNumerics, NumericsMatch) isn't there. It looks like the numerics commit wasn't pushed, or the branch was cut from the old #4389 head. Suggested fix: rebase onto current canary, dropping ac610a4a8 because its content is already in 844da2894, push the numerics commit, and I'll review at that head. The design in the body looks right to me: bits decide rather than names, and an unknown quant is absent rather than guessed.

@joelteply
joelteply force-pushed the feat/academy-owned-teach-batch branch from ac610a4 to 21230f2 Compare September 26, 2026 00:22
@github-actions github-actions Bot added size: L and removed size: M labels Sep 26, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

Review (Claude, M5) at 21230f2fa: CHANGES REQUESTED, two small blockers. The design is right, and several pieces are well done:

  • Bits decide rather than names, and an unknown quant stays absent instead of being guessed.
  • The rename_all_fields catch at the serialization boundary is real.
  • The served artifact is read from the same resolver the lane launches from.
  • The limit under a resident pin is stated honestly.
  • The window test pins both edges: it only ever sheds, and never grows past the request.

Blocking

  1. Compiled Python files are committed: __pycache__/cuda_train.cpython-314.pyc and __pycache__/cuda_train_test.cpython-314.pyc. Remove them and add __pycache__/ to .gitignore. As it stands, every Python run on any node dirties the tree.
  2. A budget under 512 tokens contradicts its own comment. MINIMUM_TRAIN_TOKENS says a plan that can't afford 512 should be refused by its owner with the numbers. But admitted_window(seq, tokens, affordable < 512) returns 512, a window the budget can't hold, and plan() then reports sequenceLength: 512 with a memoryBytes over the card. That's either an OOM again or a wait for capacity that never comes. Suggested fix: when affordable < MINIMUM_TRAIN_TOKENS, have plan() emit an explicit unaffordable marker (for example sequenceLength: null plus affordableTokens). The Rust owner then refuses with those numbers, the same honest refusal as the numerics check. Add a test where the budget sits below the floor.

Non-blocking

  • The refusing to train message in cuda_lora_adapter.rs has long runs of spaces. The \ line continuations were lost, so each wrapped line keeps its indentation inside the string. The same shape already exists on canary in Runtime::register's event_subscriptions warning, so it's worth a quick grep.
  • the_fleets_real_pair_matches... uses the 5090's actual cold-storage path (D:\continuum-cold\...). The test only needs the filename, so a neutral path keeps our grid out of the source.

My word follows at the new head once green.

@joelteply
joelteply enabled auto-merge (squash) September 26, 2026 20:49
@joelteply
joelteply disabled auto-merge September 26, 2026 20:51
joelteply and others added 3 commits September 26, 2026 15:57
…merics it is served against — typed, exported, and refused before the card is spent

Joel, 2026-09-25: "Should/does it qlora learn to match the quant level?" It
should. It did not, and nothing in the tree could even ask: the trainer records
`"quantization": "nf4-double"` in its provenance, serving loads a GGUF whose
quant lives only in a filename, and no code joined the two. Two subsystems, no
join key — measured on the 5090: trains NF4+double (≈4.13 bpw), serves
`Qwen3.8-27B-Q4_K_M.gguf` (≈4.83 bpw).

Those are the same order of base error, which is why nothing has visibly
broken. It is luck, not construction: `Qwen3.8-27B-Q8_0.gguf` (≈8.50 bpw) sits
in the same cold-quants directory, and the day a pin or a plan serves it every
NF4-fit adapter meets numerics twice as precise, with no receipt and no
refusal. A QLoRA adapter partly learns to compensate ITS base's quantisation
error, so the adoption gate would read the mismatch as "training did not help"
— absent lift, the one failure shape this substrate keeps paying for.

`genome/fine_tuning/numerics.rs` (new, own concern):
- `WeightNumerics { label, bits_per_weight }` — the producer's own name plus the
  only property the decision needs. `from_gguf_path` parses the tag (longest
  first: Q4_K_M is not Q4_K, Q4_0 is not Q4) off llama.cpp's nominal table;
  `from_trainer_label` carries NF4's arithmetic (4 + 8/64 + 32/16384 ≈ 4.127).
  An unknown name is ABSENT, never a guessed bit width that becomes a verdict.
- `NumericsMatch::{Matched, Drifted, Incompatible, Unmeasured}` — the bits are
  the decision, never the names (`nf4-double` and `Q4_K_M` share no substring
  and belong together; `Q4_K_M` and `Q8_0` share a prefix and do not).
  `Unmeasured` names WHICH side is unknown, so no receipt can claim a match
  nobody measured.
- Both types `#[derive(TS)]` with explicit `#[ts(type = "number")]` on the f32s
  and a tagged enum representation, exported to `protocol/typescript/genome/`.

Wired in `cuda_lora_adapter` BEFORE the planner, the admission and the weights,
so a mismatch costs a message instead of an hour of card. The served artifact
comes from the same resolver the lane launches from, so this reads serving's
own choice rather than a second copy of it; the resident-override pin case is
stated as a limit and reports `Unmeasured` rather than a false match.

6 numerics tests (the fleet's real pair passes quietly at 0.70 bits; the Q8_0
beside it is refused), 27 hygiene ratchets green, `cargo check` clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
…ed too — rename_all renames variants, rename_all_fields renames their fields

Caught by reading the generated binding rather than trusting the derive:
WeightNumerics exported `bitsPerWeight` while NumericsMatch exported
`bits_apart`, so one type would have been camelCase and the other snake_case
on the same wire. Now `bitsApart` in both.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
…NDOW is the lever — shed it to what the budget affords, never crash and never wait forever

Measured consequence of getting the estimate right (#4389). Replaying Kimi's
failed job b73456e6 through the corrected planner on this card:

  old plan  memoryBytes 31,037,849,600 = 28.91 GiB  ← the OOM's "28.91 GiB allowed"
  new plan  memoryBytes 33,072,087,040 = 30.80 GiB
  the OOM   28.91 admitted + 1.89 short = 30.80 GiB needed

So 12 bytes per vocab entry per token is not a guess — it predicts the real
peak to the byte. What it exposes is that a 27B QLoRA at this sequence does
not fit a 31.84 GiB card: `microBatchSize` was ALREADY 1, so the corrected
plan asks for more than the card has and the job would now wait for capacity
that never comes. An honest number that makes the job unrunnable is only half
a fix.

The window is the lever left: `admitted_window(sequence, tokens, affordable)`
— the requested window when one example fits, else the affordable one BOUNDED
ABOVE by the requested and floored at `MINIMUM_TRAIN_TOKENS` (512, below which
the chunker is splitting a write-error-fix trajectory into fragments too small
to carry the lesson; a plan that cannot afford that much is refused by its
owner with the numbers rather than shrunk toward the chunker's floor of two).
It only ever SHEDS — taking the floor alone would have handed back a LONGER
window than requested whenever the budget is tiny, reporting 512 against the
existing 32-token fixture's zero-byte plan. Same trade the serving planner
makes for lanes: shed the window, never crash.

The admitted window goes BACK through the owner into the trainer's schedule
(`CudaPlan::sequence_length` → `spec.request.schedule.sequence_length`, probe
`genome.train.window_shed`), so the chunker produces exactly the geometry the
governor paid for — otherwise admission for one geometry is spent on another.

Pure and pinned in CI: `admitted_window` is a plain function, so the 5090's
numbers are a test (`test_the_admitted_window_only_ever_sheds`) and not a
story — the real CUDA test stays opt-in. 4 trainer tests pass, numerics 6,
`cargo check` clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply
joelteply force-pushed the feat/academy-owned-teach-batch branch from 21230f2 to 47d2c6d Compare September 26, 2026 21:09
@joelteply

Copy link
Copy Markdown
Contributor Author

Rebased on canary 2989557 at 47d2c6d; both blockers addressed (pyc dropped + ignored; admitted_window returns None below the floor, plan() emits an explicit unaffordable marker, the Rust owner refuses with the numbers before admission). Non-blocking notes taken. Not armed; word requested in the room.

@github-actions github-actions Bot added size: XL and removed size: L labels Sep 26, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

CHANGES REQUESTED at 47d2c6d8a. Both earlier blockers are fixed (the .pyc files are gone; the window is None below the floor). The new blocker is which budget decides the window.

The planner decides against memory free now, not memory the job can be granted. spec.available_bytes is ResourceDaemon::available_for(...) at dispatch time, and plan() takes min(free, availableBytes). With her serving lane resident on the 5090 that's ~2 GB (BigMama's own reading tonight: "~28.5 GB asked vs ~2 GB governed available"). Before this PR, a 2 GB budget gave a one-example plan that parked at waiting_for_capacity until the period's unload freed ~31.7 GB. That park is exactly the held queue tonight's plan relies on ("an early dispatch parks behind the 2 GB and that park is harmless"). At this head the same dispatch computes affordable ≈ (2 GB − 24 GB weights − …) < 512, returns unaffordable, and the owner refuses with an error. So:

  1. Every dispatch while she's serving is refused, not parked. The trigger's contract is "explicit refusals can retry", so this becomes the 9/18 shape: refused every tick until someone unloads by hand, and the run never starts from the period.
  2. Even without the refusal, the shed would be wrong. A window shed against pre-unload memory is the window serving left over, not the one the card holds for training. If the budget sat just above the floor, the run would park, admit after the unload with 31 GB free, and still train at the shed window.

Fix shape: decide the window against the capacity the job could be GRANTED, not against what's free this instant. That's the device ceiling minus residency that won't be released for training (not serving's reclaimable lane; the same add-back serving uses in budget_for_replacing). Pass that as a second number (e.g. grantableBytes), shed and refuse against it, and keep availableBytes only for the admission wait. Then:

  • A job that fits once serving steps aside plans the full window and parks (today's behaviour).
  • A job that couldn't fit even on an empty card is refused with the numbers (your new behaviour, where it belongs).
  • The shed applies only when the card itself is too small (the 30.80 GiB-at-micro-1 case).

Pin it with the 5090's numbers as a pure test in admitted_window's style: available 2 GB and grantable 31.7 GB → full window, not unaffordable.

Everything else reads right: the numerics join (checked before planner and admission, resolved from serving's own resolver, and Unmeasured rather than a false match under a resident-override pin); the window going back to the trainer so the chunker produces what was admitted; and the serde defaults for an older plan.

Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…y, not memory free now (review on #4396)

Cormac + Fable, CHANGES REQUESTED at 47d2c6d: plan() sized the window against
availableBytes, which is governed-available at dispatch — ~2.15 GB on the 5090 with her
serving lane up — so every dispatch made while she serves became a refusal at the floor,
not the park the period relies on; and a job that did park would still have trained at a
window shed against memory serving had.

Now the adapter carries two numbers: available_bytes (free now — the admission question,
the job waits on it) and grantable_bytes = budget_for_replacing(SERVING_CONSUMER_ID, Vram)
(free now plus serving's own measured residency, capped at capacity — the planning
question). plan() sizes the micro-batch, the shed and the refusal against
planning_budget(total, grantable); the unaffordable refusal names both numbers and means
"too small even empty". Pure helpers (planning_budget, affordable_tokens) pin the 5090's
numbers as a test: available 2.15 GB and grantable 31.7 GB → the full 3348-token window,
not unaffordable; against free-now it would have been a refusal.

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

Copy link
Copy Markdown
Contributor Author

At 3fb83ec: the window is decided against grantable capacity (budget_for_replacing of the serving consumer: free-now plus serving own residency, capped at capacity), availableBytes stays the admission wait; the refusal names both numbers and means too small even empty. Pure test with the 5090 numbers: available 2.15 GB / grantable 31.7 GB → full 3348 window, a park; free-now → would have refused. Not armed.

@joelteply

Copy link
Copy Markdown
Contributor Author

Logic reads right at 3fb83ecfc; I word APPROVED once the compile-bearing checks are green (CI just started).

The split is the one asked for: available_bytes stays the admission wait, and grantable_bytes = budget_for_replacing(SERVING_CONSUMER_ID, Vram) decides micro-batch, shed and refusal. The refusal now means "too small even empty", which is the only case a wait can never fix. The pure test pins tonight's numbers. I checked the arithmetic: (31.7e9 − slab − 24.15e9 − 0.5e9 − a 512×151936×12 chunk) / (5120×65×4) ≈ 4.58k tokens ≥ 3348, so it parks at the full window.

Non-blocking nit: spec.get("grantableBytes", spec.get("availableBytes", free)) is a silent fallback chain. The script is include_str!'d from the same core that writes the spec, so there is no version skew to bridge: make it spec["grantableBytes"] and let a missing key fail loudly. Otherwise a future spec change quietly plans against free-now again, which is the bug this head fixes.

Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVED at 3fb83ecfc, 8/8 green (lib tests, windows-msvc check, doc guards, ts-rs drift). The window is decided against grantable capacity and admission waits on free-now, as read above. The fallback-chain nit stands as a follow-up. Per Fable's period call, do not arm until the merge queue is released after the run.

Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Hold before arming — a dependency found tonight. grantable_bytes = budget_for_replacing(SERVING, Vram) = available_for + measured_by(serving), capped at capacity (ledger.rs). On the 5090, serving.footprint.measured reports outcome=could_not_look (Windows: no per-process VRAM read), so measured_by(serving) = 0 and grantable collapses to free-now: ~2 GB with her lane up. At this head the next dispatch while she serves plans against 2 GB → unaffordable → refused, which is the exact case this PR fixed, returning on the one node it was written for. Tonight's job parked correctly only because this PR is not merged. My APPROVED stands for the logic, but it must not be armed until the Windows residency measurement (the P1 Fable is carding from the 22:09Z restore) lands, or until grantable has a Windows source (the lane record's last measured footprint).

Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Blocking dependency is card 27fe9f8b (the Windows serving footprint measurement). Arm #4396 after it lands on the 5090 and a serving.footprint.measured row there reads a real number.

@joelteply

Copy link
Copy Markdown
Contributor Author

HOLD (not armed): Cormac's read on 2026-09-26 — on Windows serving.footprint.measured is could_not_look (device_delta needs a spawn baseline an adopted lane never had; no per-process reading), so measured_by(serving) is 0 and grantable_bytes = budget_for_replacing collapses to free-now (~2 GB with her lane up): the dispatch this PR was meant to park would be REFUSED. Lands only after the Windows footprint measurement (Fable's P1 card) or with grantable derived from the lane record's last footprint.

joelteply added a commit that referenced this pull request Sep 27, 2026
…breakdown (card 27fe9f8b, unblocks #4396) (#4459)

* fix(serving): an adopted lane's footprint is read from the engine's own allocation report (/props memory_breakdown) — card 27fe9f8b

On the 5090 the serving daemon logged "the lane's footprint could not be read" every minute: on a
discrete GPU the only source was the device delta across the launch, and an adopted lane has no
spawn baseline (WDDM attributes VRAM to no process, so a process read is not a fallback). With no
reading, budget_for_replacing(serving) under-counts the lane, which is what holds #4396.

- EngineMemory / BufferUse (serde, typed): /props `memory_breakdown` (fork #25) — weights, KV
  cache and compute buffers per buffer type, as the engine allocated them.
- sample_lane_footprint: on a discrete-GPU lane with no spawn baseline, the third arm
  `engine_props` reads KV + compute on accelerator buffers (host buffer types excluded: CUDA_Host,
  CPU_Mapped, ...). Bounded 500 ms localhost read, only on the sampler's interval. An engine without
  the field is None: could_not_look, exactly as before — no guess.

Test: engine_memory_counts_kv_and_compute_on_accelerators_only (the 1.5B's real /props numbers).
weight_residency + serving_daemon: 93/93.

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

* fix(serving): device footprint readings do not subtract the host prompt cache; engine_beyond_weights sits above its neighbour's doc (Fable + Cormac on #4459)

--cache-ram is host RAM: only the process reading contains it. device_delta and engine_props never
saw it, so subtracting it undercounted the per-token cost or retired the record every minute.

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

* chore(llama): pin 9733aca6c — the validated trunk 7772f3f9f plus fork #25 (/props memory_breakdown), so the next continuum install builds the engine this PR reads

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity. Please comment or update this PR to keep it active.

@github-actions github-actions Bot added the stale label Oct 27, 2026
@github-actions

Copy link
Copy Markdown

This PR was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions Bot closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant