Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
//! Bedarf füllt sie die GPU ([`Need::vram_mb`] = `None`).
|
||||
//! - Instanzen mit laufenden Anfragen werden nie entladen.
|
||||
//! - Passt ein Modell nicht, werden unbenutzte Instanzen entladen, die am
|
||||
//! längsten unbenutzte zuerst. `High` darf das sofort, `Normal` und `Low`
|
||||
//! erst nach einer Schonfrist.
|
||||
//! längsten unbenutzte zuerst. `High` darf das sofort, `Normal` und `Low`,
|
||||
//! wenn die Instanz oder die Anfrage die kurze Schonfrist hinter sich hat.
|
||||
//! - Wartende Anfragen werden nach Priorität und Alter bedient. Wer nicht
|
||||
//! bedient werden kann, sperrt seine GPUs für alle, die nach ihm kommen:
|
||||
//! Freigemachter Speicher bleibt dem, für den er freigemacht wurde.
|
||||
@ -38,8 +38,10 @@ pub struct Settings {
|
||||
pub max_wait: Duration,
|
||||
/// Wartezeit, nach der `Low` als `Normal` zählt (`0` = kein Aging).
|
||||
pub aging_step: Duration,
|
||||
/// Wie lange eine Instanz unbenutzt sein muss, bevor `Normal` und `Low`
|
||||
/// sie verdrängen dürfen. `High` wartet nicht.
|
||||
/// Schonfrist: `Normal` und `Low` dürfen eine unbenutzte Instanz verdrängen,
|
||||
/// wenn sie so lange unbenutzt ist oder die Anfrage selbst so lange wartet.
|
||||
/// Das zweite verhindert, dass ein immer wieder kurz benutztes Modell
|
||||
/// Wartende beliebig lange aussperrt (#1269). `High` wartet nicht.
|
||||
pub evict_min_idle: Duration,
|
||||
}
|
||||
|
||||
@ -50,7 +52,7 @@ impl Default for Settings {
|
||||
max_waiting: 32,
|
||||
max_wait: Duration::from_secs(300),
|
||||
aging_step: Duration::from_secs(60),
|
||||
evict_min_idle: Duration::from_secs(60),
|
||||
evict_min_idle: Duration::from_secs(5),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -578,6 +580,8 @@ impl Planner {
|
||||
fn victims(&self, job: &Job, claim: Claim, priority: Priority, now: Instant) -> Vec<InstId> {
|
||||
let gpus = &job.need.gpus;
|
||||
let unloading = |i: &Inst| i.state == InstState::Unloading;
|
||||
let grace = self.settings.evict_min_idle;
|
||||
let patient_enough = now.saturating_duration_since(job.enqueued) >= grace;
|
||||
if self.fits(gpus, claim, &|_, i| unloading(i)) {
|
||||
return Vec::new();
|
||||
}
|
||||
@ -590,8 +594,8 @@ impl Planner {
|
||||
&& i.unload_blocked_until.is_none_or(|t| now >= t)
|
||||
&& i.gpus.iter().any(|g| gpus.contains(g))
|
||||
&& (priority == Priority::High
|
||||
|| now.saturating_duration_since(i.last_used)
|
||||
>= self.settings.evict_min_idle)
|
||||
|| patient_enough
|
||||
|| now.saturating_duration_since(i.last_used) >= grace)
|
||||
})
|
||||
.map(|(id, i)| (i.last_used, *id))
|
||||
.collect();
|
||||
|
||||
@ -156,10 +156,10 @@ fn instanz_mit_laufender_anfrage_wird_nie_verdraengt_auch_nicht_von_high() {
|
||||
fn high_verdraengt_sofort_normal_erst_nach_der_schonfrist() {
|
||||
let mut b = Bench::new();
|
||||
let inst = b.loaded_idle(need("a", &[0], Some(8000)), 0);
|
||||
let (_, n) = b.submit(need("b", &[0], Some(8000)), Priority::Normal, 10);
|
||||
let (_, n) = b.submit(need("b", &[0], Some(8000)), Priority::Normal, 2);
|
||||
assert!(n.is_empty(), "Normal wartet die Schonfrist ab: {n:?}");
|
||||
assert!(b.p.tick(b.at(59)).is_empty());
|
||||
let t = b.p.tick(b.at(60));
|
||||
assert!(b.p.tick(b.at(4)).is_empty());
|
||||
let t = b.p.tick(b.at(5));
|
||||
assert_eq!(unloads(&t), vec![inst]);
|
||||
assert!(matches!(
|
||||
&t[0],
|
||||
@ -333,18 +333,15 @@ fn aging_hebt_low_auf_normal_aber_nie_auf_high() {
|
||||
assert_eq!((w[0].job, w[0].effective), (low, Priority::Normal));
|
||||
assert_eq!(b.p.waiting(b.at(299))[0].effective, Priority::Normal);
|
||||
|
||||
// Wie High verdrängt die gealterte Anfrage nicht: Die Schonfrist gilt weiter.
|
||||
// Eine frische Low-Anfrage verdrängt nicht sofort, erst nach der Schonfrist (#1270).
|
||||
let mut b = Bench::new();
|
||||
let (_, a) = b.submit(need("a", &[0], Some(8000)), Priority::Normal, 0);
|
||||
let inst2 = load_of(&a).unwrap();
|
||||
b.p.load_done(inst2, true, None, b.at(0));
|
||||
let (_, _) = b.submit(need("b", &[0], Some(8000)), Priority::Low, 0);
|
||||
let (_, _) = b.submit(need("b", &[0], Some(8000)), Priority::Low, 99);
|
||||
let r = b.p.release(inst2, b.at(100));
|
||||
assert!(
|
||||
r.is_empty(),
|
||||
"gealtertes Low wartet die Schonfrist ab: {r:?}"
|
||||
);
|
||||
assert_eq!(unloads(&b.p.tick(b.at(160))), vec![inst2]);
|
||||
assert!(r.is_empty(), "frisches Low wartet die Schonfrist ab: {r:?}");
|
||||
assert_eq!(unloads(&b.p.tick(b.at(104))), vec![inst2]);
|
||||
let _ = inst;
|
||||
}
|
||||
|
||||
@ -573,3 +570,22 @@ fn gescheiterter_stopp_einer_unbekannten_instanz_aendert_nichts() {
|
||||
);
|
||||
assert!(b.p.instances().is_empty());
|
||||
}
|
||||
|
||||
/// #1269: Ein Modell, das immer wieder kurz benutzt wird, darf Wartende nicht beliebig lange aussperren.
|
||||
#[test]
|
||||
fn wer_laenger_als_die_frist_wartet_verdraengt_auch_ein_eben_benutztes_modell() {
|
||||
let mut b = Bench::new();
|
||||
let klein = b.loaded_idle(need("klein", &[0], Some(7000)), 0);
|
||||
let (_, actions) = b.submit(need("klein", &[0], Some(7000)), Priority::High, 1);
|
||||
assert_eq!(grants(&actions).len(), 1);
|
||||
let (_, actions) = b.submit(need("gross", &[0, 1], Some(18000)), Priority::Low, 2);
|
||||
assert!(unloads(&actions).is_empty(), "benutzt, darf nicht weichen");
|
||||
// Die Anfrage auf "klein" endet bei 20 s; "gross" wartet da schon länger als die Frist.
|
||||
let actions = b.p.release(klein, b.at(20));
|
||||
assert_eq!(unloads(&actions), vec![klein]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn die_schonfrist_ist_ab_werk_kurz() {
|
||||
assert_eq!(Settings::default().evict_min_idle, Duration::from_secs(5));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user