diff --git a/sgl-model-gateway/src/main.rs b/sgl-model-gateway/src/main.rs index 0d86bba4d8..c358c630be 100644 --- a/sgl-model-gateway/src/main.rs +++ b/sgl-model-gateway/src/main.rs @@ -340,6 +340,10 @@ struct CliArgs { #[arg(long, default_value_t = 64.0, help_heading = "G9i Pool Admission")] g9i_window_add: f64, + /// Pin the AIMD admission window at this value (clamped to [16, 256]); skips all window dynamics (0 = normal AIMD) + #[arg(long, default_value_t = 0.0, help_heading = "G9i Pool Admission")] + g9i_window_fixed: f64, + /// Prompt-length hard validation: 400 prompt_too_long at the front of admission when even the lower-bound estimate exceeds the context limit (default on) #[arg(long, default_value_t = true, help_heading = "G9i Pool Admission")] g9i_prompt_validation: bool, @@ -1241,6 +1245,7 @@ impl CliArgs { ledger_reconcile: self.g9i_ledger_reconcile, window_init: self.g9i_window_init, window_add: self.g9i_window_add, + window_fixed: self.g9i_window_fixed, prompt_validation: self.g9i_prompt_validation, prompt_token_limit: self.g9i_prompt_token_limit, }; diff --git a/sgl-model-gateway/src/routers/http/g9i.rs b/sgl-model-gateway/src/routers/http/g9i.rs index d508bb5f2d..2e40f2c880 100644 --- a/sgl-model-gateway/src/routers/http/g9i.rs +++ b/sgl-model-gateway/src/routers/http/g9i.rs @@ -269,6 +269,14 @@ pub struct G9iConfig { /// signals still back off exactly as before. #[serde(default = "default_window_add")] pub window_add: f64, + /// T21: pin the AIMD admission window at this value (clamped into + /// [16, 256]) — skips ALL window dynamics: additive increase + /// (window_add), multiplicative cut (x0.7), and every hold/recover + /// branch. The window is constant; every other gate (blind-node rules, + /// p_queue_cap, td_gate, prompt_too_long, ...) is untouched. 0 = off + /// (default, normal AIMD). + #[serde(default)] + pub window_fixed: f64, /// T20 (B) prompt-length hard validation (400 prompt_too_long) at the /// front of admission, before ANY gate/ledger/queue bookkeeping. /// Lower-bound estimate only (text_bytes/8 + 128 per image_url part, @@ -398,6 +406,7 @@ impl Default for G9iConfig { ledger_reconcile: default_ledger_reconcile(), window_init: default_window_init(), window_add: default_window_add(), + window_fixed: 0.0, prompt_validation: default_prompt_validation(), prompt_token_limit: default_prompt_token_limit(), } @@ -1362,21 +1371,33 @@ impl G9iState { } /// T20-testable seam of the poller's window-entry creation: insert at - /// the configured warmup start (`--g9i-window-init`, default 128), - /// refresh the known capacity, clamp into the fixed [16, 256] bounds. + /// the configured warmup start (`--g9i-window-init`, default 128) — + /// or the pinned value when `--g9i-window-fixed` > 0 (T21) — refresh + /// the known capacity, clamp into the fixed [16, 256] bounds. fn ensure_d_window(&self, node: &str, max_running: u64) { let Ok(mut windows) = self.d_windows.write() else { return; }; + let fixed = self.config.window_fixed; let e = windows.entry(node.to_string()).or_insert(DWindow { - w: self.config.window_init.clamp(WINDOW_MIN, WINDOW_MAX), + w: if fixed > 0.0 { + fixed.clamp(WINDOW_MIN, WINDOW_MAX) + } else { + self.config.window_init.clamp(WINDOW_MIN, WINDOW_MAX) + }, max_running_total: 0, }); if max_running > 0 { e.max_running_total = max_running; } - // T16: fixed pipeline-depth bounds. - e.w = e.w.clamp(WINDOW_MIN, WINDOW_MAX); + // T16: fixed pipeline-depth bounds. T21: fixed mode pins every + // refresh (1s poll cadence), so the pinned value takes effect + // without waiting for the 10s AIMD tick. + e.w = if fixed > 0.0 { + fixed.clamp(WINDOW_MIN, WINDOW_MAX) + } else { + e.w.clamp(WINDOW_MIN, WINDOW_MAX) + }; } /// T14 AIMD outer loop, 10s cadence on the poll task. Judgment input @@ -1419,10 +1440,24 @@ impl G9iState { }; let q = self.shadow_queue.as_ref().and_then(|l| l.read().ok()); let mut grew = false; + // T21: --g9i-window-fixed > 0 pins every window at the configured + // value (clamped [16, 256]) — no additive increase, no cut, no + // hold/recover logic at all. + let fixed = self.config.window_fixed; for (node, e) in windows.iter_mut() { if e.max_running_total == 0 { continue; // C13: capacity unknown -> no window judgment } + if fixed > 0.0 { + let pinned = fixed.clamp(WINDOW_MIN, WINDOW_MAX); + if e.w != pinned { + info!("G9i AIMD: {} window {:.0} -> {:.0} (fixed)", node, e.w, pinned); + grew |= pinned > e.w; + e.w = pinned; + } + metrics::gauge!("smg_g9i_admission_window", "worker" => node.clone()).set(e.w); + continue; + } // T16: fixed bounds on pipeline depth (window semantics // changed from total in-flight to pre-first-token depth). let w_min = WINDOW_MIN; @@ -3665,6 +3700,67 @@ sglang:token_usage{dp_rank=\"0\"} 0.5 assert_eq!(window_of(&st3, "http://d1:30001"), 116.0, "flag-tunable add step"); } + /// T21: --g9i-window-fixed pins the window at the configured value + /// (clamped [16, 256]) — no additive increase, no multiplicative cut, + /// no hold/recover logic; entry creation and every tick keep the pin. + /// fixed = 0 leaves normal AIMD untouched. + #[test] + fn aimd_window_fixed_pins_window() { + let cfg = G9iConfig { + enabled: true, + shadow_enabled: true, + td_admit: "enforce".to_string(), + window_fixed: 256.0, + ..Default::default() + }; + let st = G9iState::new(cfg); + set_d_snapshots(&st, &[("http://d1:30001", 0, 10_000_000, true, false)]); + // Entry creation pins immediately (no warmup climb). + st.ensure_d_window("http://d1:30001", 256); + assert_eq!(window_of(&st, "http://d1:30001"), 256.0, "fixed pins at creation"); + // No-congestion tick: no additive increase beyond the pin. + st.aimd_tick(); + assert_eq!(window_of(&st, "http://d1:30001"), 256.0, "fixed: no slow add"); + // SLO violation: no multiplicative cut. + feed_ttft(&st, 20, 15.0); + st.aimd_tick(); + assert_eq!(window_of(&st, "http://d1:30001"), 256.0, "fixed: no cut on SLO violation"); + // Hold signals (timeout + pipeline pinned over the window) skipped too. + book_ledger(&st, "http://d1:30001", 300); + st.hold_timeouts_total.store(1, Ordering::Relaxed); + st.aimd_tick(); + assert_eq!(window_of(&st, "http://d1:30001"), 256.0, "fixed: hold logic skipped"); + // Clamp rules: fixed > 256 pins at 256; fixed < 16 pins at 16. + let cfg = G9iConfig { + enabled: true, + shadow_enabled: true, + td_admit: "enforce".to_string(), + window_fixed: 1000.0, + ..Default::default() + }; + let st2 = G9iState::new(cfg); + st2.ensure_d_window("http://d1:30001", 256); + assert_eq!(window_of(&st2, "http://d1:30001"), 256.0, "fixed 1000 clamps to 256"); + let cfg = G9iConfig { + enabled: true, + shadow_enabled: true, + td_admit: "enforce".to_string(), + window_fixed: 5.0, + ..Default::default() + }; + let st3 = G9iState::new(cfg); + st3.ensure_d_window("http://d1:30001", 256); + assert_eq!(window_of(&st3, "http://d1:30001"), 16.0, "fixed 5 clamps to 16"); + // fixed = 0: normal AIMD (full regression = the existing suite; + // spot-check one SLO-ok tick here). + let st4 = p2_state("enforce"); + set_d_snapshots(&st4, &[("http://d1:30001", 0, 10_000_000, true, false)]); + set_window(&st4, "http://d1:30001", 100.0, 256); + feed_ttft(&st4, 20, 2.0); + st4.aimd_tick(); + assert_eq!(window_of(&st4, "http://d1:30001"), 164.0, "fixed=0: normal AIMD unchanged"); + } + /// AIMD hard bounds (T16: fixed pipeline-depth window [16, 256]). #[test] fn aimd_hard_bounds() {