Skip to content

Algorithm

decide(snapshot, now) is pure: the same state and time always give the same decision. Every threshold is a field of Config.

Estimates

For job j on device d, the estimate is E = max(estimator result, declared hint, what Rule O learned), or unknown. An estimate is trusted only when it comes from complete observations of this job's template (its fingerprint), not from a hint or a lower bound.

Rule P: probation

At most one job without a trusted estimate is STARTING or WARMING on a device (probation="untrusted_only", the default; "all" serializes every ramp). While it warms, it holds the device against every start, trusted jobs too, because its peak is unknown.

Rule A: admission

A candidate is admitted on d if, in every dimension:

F + Σ reservations of STABLE jobs + Σ W of warming jobs + charge ≤ capacity
  • F is the foreign usage (see below).
  • charge is one function, used by admission and by accounting. For a trusted estimate E it is min(E × m + q_d, C_d − F_d), where m is trusted_margin (1.05) when the estimate is backed by min_trusted_observations (3) observations and safety_margin (1.15) otherwise, and q_d is the device's allocation granularity (Device.alloc_granularity, 0 unless set). For an untrusted estimate it is E. The comparison is direct (never through a clamped free amount), so an overcommitted device refuses even a zero estimate.
  • W is a warming job's current usage or its charge, whichever is larger (max(charge, usage); an untrusted job counts max(E, usage)). The amount a job is admitted with is therefore exactly the amount it is charged right after its Start, in the same tick and in later ticks. The Start records the observation count and F_d (Start.observations, Start.foreign) and the reducer keeps them for the attempt, so the later ticks charge the same capped amount.
  • q_d is added once per trusted job and device, after the margin, and never to an untrusted estimate. Rationale: a job's true peak is round_up_q(x) for a continuous demand x; the margin m bounds a new job's continuous demand relative to the observed maximum (x ≤ m · E), and rounding up adds less than one block, so round_up_q(x) < E × m + q_d. Rounding hides dispersion (three identical rounded observations can come from continuous demands anywhere within one block), which is what q_d corrects; it is a physical parameter of the allocator, not a tuning knob.
  • Cap. When E × m + q_d > C_d − F_d, the charge fills the remaining capacity: the job starts only when it can run alone on the device, and nothing joins it while it warms. If it truly does not fit, its OOM while alone gives EXCEEDS_DEVICE_CAPACITY through Rule O. Without the cap such a job could never be admitted, even on an empty device.
  • Every comparison of a trusted candidate's amount with free capacity uses the charge: the fit check, the foreign-usage explanation (evaluated at F = 0 for "would fit without foreign usage"), InsufficientResources, and and the cap's explanation WaitingForExclusiveDevice(d) (a capped trusted job that waits because other managed jobs are on d; it takes precedence over the other waiting explanations except WaitingForIsolation). Warn(CapacityExceeded) keeps its meaning: a pending job's raw estimate E exceeds the device's raw capacity C, for trusted jobs too, whatever the cap does.
  • An unknown estimate needs unknown_min_free (10 % of capacity by default) to be free.

Gang jobs are admitted on all their devices or none.

Rule S: stability

A WARMING job becomes STABLE once it has warmed for min_warmup_s, and either:

  • its peak has not grown (by more than growth_tol) for stable_window_s, its step count reached stable_min_steps (if it reports steps), and it completed an epoch (if it reports epochs); or
  • it has warmed for max_warmup_s.

At that point it is reserved at peak × safety_margin.

Usage floor. A job that reports no steps does not become STABLE on a device before its usage there exceeded the device's stable_min_usage. Not even max_warmup_s overrides this. Without the floor, a job that spends its first minute loading data, with no GPU memory yet, would be "stable" at zero and reserved nothing. At max_warmup_s such a job raises NoUsageObserved instead. Its warm-up really starts when it passes the floor: min_warmup_s, the quiet window and max_warmup_s all count from that moment, so a job that keeps growing after a long data-loading phase is still STABLE no later than the crossing plus max_warmup_s.

Rule O: OOM feedback

An OOM exit grows the estimate from the room the job actually had at the OOM: by oom_growth (1.25), capped at capacity. rampgate requeues the job (Requeue(OOM), with resume=True as a flag for the runner; with a runner that checkpoints, completed epochs are not lost), and the job gets at most max_oom_retries retries. A job is failed as too big for the device only if it OOMed while it had the whole device.

Rule V: vacate

When a MarkStable or UpdateReservation pushes a device's managed load above capacity × (1 − vacate_headroom), rampgate stops the most recently admitted STABLE job (never the last job on the device) and re-queues it (Requeue(VACATED)). Forced jobs (force=True) are left out: the user started them without a capacity check and accepts the risk. They are not part of the load Rule V measures, not counted in "the last job on the device", never chosen as victims, and their own MarkStable/UpdateReservation does not trigger Rule V. Overcommitted is still raised, so the overload stays visible, and force still never skips Rule P. Preempting a STABLE job is cheap: it has finished growing. On real hardware, its memory was back about 0.15 s after it exited.

Isolation retry

A job that OOMed before it became stable retries alone: it holds the devices of its placement until no other managed job is active there. A device is held by at most one such job, the one with the oldest OOM. An isolation hold takes precedence over head-of-line holds.

Sibling hold. After a job died before its peak was measured, the other jobs with the same level-0 fingerprint wait until the template's measured peak is available to admission: until the estimator answers them with a complete record at level 0 (a peak or Rule H running record, with no newer lower bound above it). The hold applies to a PENDING job whose template is not measured on some device of its placement, while another job of the template has the isolation flag or the estimator's level-0 answer is a lower bound. Such a job waits (WaitingForSibling(job)) for, in this order: the job of the template with the oldest isolation flag (that job itself is the isolation retry); else the oldest running job of the template, whose run ends in a complete record or a flag; else the measurement candidate, the earliest held job, which runs alone under the isolation rules. So the hold never lasts forever: if the retry ends without a record (cancelled, failed), the earliest held sibling measures instead; a preempted retry keeps its flag, and the measurement completes on resume. A job waiting for a sibling never closes a device under head-of-line blocking, so it cannot block the measurement. The release is tied to the record, not to MarkStable: the running record reaches the estimator one tick after MarkStable, and the hold lasts until it does.

Foreign usage

F is what the device uses beyond the managed jobs' latest usage: other processes, the driver's own reservation. It is the maximum over the last foreign_window_s. Foreign usage blocks admission (BlockedByForeignUsage) but never triggers Rule V on its own.

Ordering

The policy proposes candidates in order. With head-of-line blocking, a candidate that is not admitted on d closes d for later candidates in the same tick.