From 9b03de2be9d9348d1a56cf50f9cec2f7fe4d2cee Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 29 Oct 2026 08:39:37 +0100 Subject: [PATCH] serve: the deferred adaptive planning is opt-in (LELEKA_SERVE_ADAPT_DEFER=on); default is the earlier order Measured on the 5090 (seed off, upstream profile, frozen 245k corpus, turns 1-4, per round, spans of the same runs): deferral moved round.adapt 0.108 ms into the draft's shadow (adapt_deferred 0.085-0.092) but round.apply_pending rose from 0.157/0.169 to 0.255-0.278 because the swap copies start later and are the critical path: apply+adapt 0.251 (no defer) against 0.340-0.370 (defer). A net loss of about 0.09-0.12 ms per round, so it is no longer the default. Co-Authored-By: Claude Sonnet 5.5 --- .../src/qwen_forward/original_serve_host.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/leleka-runtime/src/qwen_forward/original_serve_host.rs b/crates/leleka-runtime/src/qwen_forward/original_serve_host.rs index ebf2320a..30c9430b 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_serve_host.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_serve_host.rs @@ -97,7 +97,7 @@ pub(in crate::qwen_forward) struct OriginalServeHost<'a, 'ctx> { window_origin: Option, /// A draft launched behind the enqueued commit, completed after the publication (`launch_draft`). launched: Option, - /// The round whose adaptive swaps are still to be planned and queued (`LELEKA_SERVE_ADAPT_DEFER`, default on): the host does that + /// The round whose adaptive swaps are still to be planned and queued (`LELEKA_SERVE_ADAPT_DEFER=on`, default off): the host does that /// work while the GPU runs the draft instead of before the commit and the draft are enqueued. deferred_adaptation: Option, } @@ -247,10 +247,12 @@ impl<'a, 'ctx> OriginalServeHost<'a, 'ctx> { } } -/// `LELEKA_SERVE_ADAPT_DEFER=off`: plan and queue the adaptive swaps before the commit (the earlier order; the A/B control). +/// `LELEKA_SERVE_ADAPT_DEFER=on`: plan and queue the adaptive swaps after the draft is launched instead of before the commit. OFF by default: measured on the +/// 5090 (seed off, frozen 245k session, turns 1-4, per round) it moved 0.09 ms of host work out of the commit path but the swap copies then start later and the +/// next round's `apply_pending` waits 0.10 ms longer (0.17 -> 0.26 ms), a net loss of about 0.09 ms (docs/experiments/decode-tail-5090.md). fn adapt_defer() -> bool { static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| !std::env::var("LELEKA_SERVE_ADAPT_DEFER").is_ok_and(|v| v == "off" || v == "0")) + *ON.get_or_init(|| std::env::var("LELEKA_SERVE_ADAPT_DEFER").is_ok_and(|v| v == "on" || v == "1")) } impl<'a, 'ctx> OriginalServeHost<'a, 'ctx> { @@ -456,7 +458,7 @@ impl<'a, 'ctx> NativeServeHost<'ctx> for OriginalServeHost<'a, 'ctx> { // run on the tier's own stream beside the commit and the draft (no work for the all-CPU tier). // The planning and the queueing are host work (0.6 ms on an adaptation round) that sat between the window and the commit/draft // launch; with the deferral they run once the draft is launched (`run_deferred_adaptation`) or, at the latest, at the join, - // always before the next round's `apply_pending`. LELEKA_SERVE_ADAPT_DEFER=off runs them here as before. + // always before the next round's `apply_pending`. Opt-in (LELEKA_SERVE_ADAPT_DEFER=on); by default they run here as before. if adapt_defer() { if self.deferred_adaptation.is_some() { return Err(Error::IdentityMismatch);