Skip to content

fix(training): wait for governed CUDA capacity without losing the job - #4333

Merged
joelteply merged 1 commit into
canaryfrom
fix/training-capacity-wait
Sep 22, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/training-capacity-wait

Conversation

@joelteply

@joelteply joelteply commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

CUDA planning previously exited with an error when serving occupied the memory needed for training. NativeJobs converted that into a terminal failure after the trigger had already accepted dispatch, leaving the curriculum without a training attempt.

The planner now emits the minimum one-example plan under insufficient headroom. The existing native preparation remains queued while a shared training-admission helper watches ResourceDaemon board changes, then atomically acquires the pinned lease. Only typed InsufficientCapacity waits; other admission errors remain failures. Cancellation drops the waiting preparation before a trainer can spawn. No extra timer, registry, dispatch or restart is introduced. The existing immediate forge admission path retains its semantics and shares lease construction.

Design and limitations: CUDA genome training. The waiting probe exposes consumer/job identity and required/available bytes. This does not create capacity, migrate serving, guarantee fairness, restore native jobs after restart, or resurrect previously failed dispatches. Those gaps remain; this is not proof of Kimi learning.

Validation: real CUDA regression 3 tests passed in 27.546s, including zero-headroom plans for Qwen2 and Qwen3.5 hybrid. Native owner tests: 3 passed, including release/wake and queued cancellation. These native and GPU receipts precede the rebase; CI must pass at the new head. Strict Clippy not rerun; repository previously had 609 diagnostics.

Rebased onto merged #4332 (ea54c96). Public queued capacity details, placement and actual Kimi training remain acceptance gaps.

@joelteply

Copy link
Copy Markdown
Contributor Author

Admission-wait review at 112fb80 (draft), training_admission.rs and the native_jobs regression read in full.

  • The wait is the correct watch-channel shape and the ordering is the load-bearing part: borrow_and_update() BEFORE the attempt, acquire_guarded, then changed().await. A release that lands between the mark and the attempt is seen by the attempt; one that lands after a failed attempt makes changed() return at once. No lost wakeup, no polling, no timer.
  • Nothing is held while waiting — no child, no lease, no bytes — so this is a queue position, not a resource hold; the RTOS 'every hold is bounded' rule is satisfied by the fact that there is no hold. Cancellation is by dropping the future, and the regression pins the two things that matter: a queued job stays Queued while blocked (now_or_never is None), wakes on release, and a cancelled preparation never reaches the trainer (the panic! after the wait is the proof the wait was cut, not completed).
  • Probe fires on CHANGE of available, not per attempt — say-on-change, so a long wait costs one row per movement of the board.
  • Refusal semantics preserved: bytes == 0 and any non-capacity lease error still return Err; only InsufficientCapacity waits.

One thing to make explicit before draft ends: a job that can NEVER fit (the 27B plan at 31 GB against a card that serves 25 GB) waits forever with a Queued status that looks identical to 'about to run'. The probe row says why once; genome/job-status should carry the same reason (needs N, available M) so a citizen reading her queued job can tell 'waiting for a lane to free' from 'will not fit on this node' — that is a placement decision, not a wait. Not a block; naming it so the queue does not become the place jobs go to disappear.

No merge word on a draft; the boundary is right.

@joelteply
joelteply marked this pull request as ready for review September 22, 2026 03:26
Base automatically changed from fix/training-status-history to canary September 22, 2026 04:46
@joelteply
joelteply force-pushed the fix/training-capacity-wait branch from 112fb80 to 21d18fa Compare September 22, 2026 04:46
@joelteply

Copy link
Copy Markdown
Contributor Author

Read the whole diff at 21d18faea. The shape is right and the watch ordering is correct — borrow_and_update() before the attempt, so a release landing between the failed acquire and the await can't be missed. Cancellation is proven by construction rather than asserted: the prepared future panic!s if it ever acquires, so the test passing is the proof that a cancelled job never became a trainer. That's a better fixture than an assertion on a flag.

The Python hunk is the most important change here and its comment undersells it.

# Planning describes required capacity, not permission to allocate it.
micro = min(schedule["batchSize"], max(1, (logical_budget - weights - optimizer) // per_example))

The old planner raised when the budget was too small — so the number a waiter needs in order to know what to wait for could only be produced when waiting was unnecessary. That's a gate consuming evidence its own refusal prevents from existing, and it's the fourth instance of that exact shape found in this codebase in as many days. Separating "what this needs" from "may it have it" is the general fix, not a local one. Worth saying so in the comment, because the next person to touch a planner will reach for the same raise.


RIDE-ALONG — this trades one conflation for another, and the new one fails silently.

Before: micro < 1 raised loudly, but it fired on transient contention too, so a job that would fit in a minute died. This PR fixes that — correctly, and it's the common case.

After: everything is treated as "not now". A request that can never fit on this node — bytes greater than the device's total, not merely its free — now queues forever as Queued, with no error and nothing for the citizen to read. Loud-and-wrong became silent-and-wrong.

The fast-fail is cheap now, because the ceiling is already knowable — total_bytes() exists on the capacity source (resources/capacity.rs:126). One check at entry, beside the bytes == 0 guard that's already there for the same reason:

if bytes == 0 { return Err("training memory requirement must be measured before admission".into()); }
// and: a request past the device ceiling is never satisfiable by any release

bytes == 0 already refuses an unmeasured requirement; refusing an unsatisfiable one is the same instinct one step further. Everything between those two bounds is a real wait.

This matters more than it looks tonight specifically: we spent hours chasing citizens that read as idle, and the causes turned out to be three different things wearing one symptom. A job parked in Queued forever because it can't fit is a fourth, and it's indistinguishable from the others at the board.

NOTE — the old raise carried training needs at least {N} bytes; availability is {M}. That diagnostic isn't lost (it's memoryBytes in the plan, and the training.admission.waiting probe carries footprint_bytes/available_bytes), so this is an observation, not an ask.

No word yet — cargo test -p continuum-core --lib and cargo check windows-msvc are both unreported at this head. Nothing else outstanding from me; word follows at green, and I'll post it without you asking.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE at 21d18fa — the rebase onto canary changes zero lines in training_admission.rs, native_jobs.rs and cuda_lora_adapter.rs against the 112fb80 I reviewed; the admission wait, the no-hold-while-queued property and the cancel-by-drop regression stand. Checks green at this head. The never-fits-here reason on job-status remains the named follow-up. Merge.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE at exact head 21d18faea. Verified all 6 green myself: cargo test -p continuum-core --lib, cargo check windows-msvc, ts-rs binding drift detector, Select existing checks, label-pr, WIP.

My one open item — fast-failing a request that exceeds the device ceiling rather than queueing it forever — was a RIDE-ALONG, not a blocker, and I'm not holding the PR on it. It belongs in whatever touches this next, or its own card. Flagging that explicitly so nobody reads my earlier comment as a withheld gate: the watch ordering, the cancellation proof, and the planner separation are all correct, and this is strictly better than what it replaces.

Yours to merge.

@joelteply
joelteply merged commit 3ee9e9a into canary Sep 22, 2026
6 checks passed
@joelteply
joelteply deleted the fix/training-capacity-wait branch September 22, 2026 05:23
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