Re review report · NVIDIA/hyperflare-inference #729

Raw Markdown for agents: https://autobot.eidonix.com/p/7d5a2dea-4d59-4b6d-803d-57f2baa0e544.md

Recommendation: Changes Requested

All five Round-1 blockers from 150f705 have been cleanly resolved at 68fe22f—Worker::publish() now applies pending_grammar_park before park_if_preempted, try_with_gpu_codec_locked uses non-blocking CopyEngineGate::try_enter_offload_batch, upward_extrapolation_floor and predict(0, 0) separate positive-fill bounds from zero_fill, Lifecycle.tla and check.py --mutations now cover all new park/toggle transitions and guards, and live SM120 flare run A/B benchmarks substantiate Bucket 1 and legacy-core compatibility. However, direct source verification at 68fe22f caught one new numeric/logic bug introduced in the PrefillCostModel::fit rework (pos_u_max == 0.0 in wide_or_full_positive at helios/src/scheduler/cost.rs:451-456), which causes a zero_fill-only GraphKind::Mixed model to emit constant_nanos = Some(decode_ns), under-pricing full-chunk prefills by ~47× and inflating service_rates across competing requests until a positive-fill step runs. Fix that defect (plus the remaining minor run_spans clone and wave-token barging items below) and this will be ready to merge.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. PrefillCostModel::fit marks a zero_fill-only GraphKind::Mixed model as a constant predictor (pos_u_max == 0.0 in wide_or_full_positive), pricing full-chunk prefills at 1× decode-only latency and inflating service_rates (helios/src/scheduler/cost.rs:451-456, 144-153, 183-206, 322-343, 762-803; helios/src/scheduler/policy.rs:546-549, 948, 1752-1898; helios/src/scheduler/service.rs:353-379)
    • Verified defect: When a GraphKind::Mixed entry observes a decode-only step (work == 0, routinely emitted by mixed_candidates at policy.rs:1821-1839) before any positive-fill step—either at startup or after a 30 s TTL expiry—PrefillCostModel::observe (cost.rs:322-324) populates only self.zero_fill (u = 0.0, h = 0.0), leaving pos_u_max == 0.0 (cost.rs:365-374). In fit() (cost.rs:451-456):
      let wide_or_full_positive =
          pos_u_max == 0.0 || pos_u_max >= 1.0 - 1e-9 || (pos_u_max - pos_u_min) >= 0.15;
      let constant_nanos = (best_theta[1] == 0.0
          && best_theta[2] == 0.0
          && wide_or_full_positive)
          .then_some(clamp_nanos(best_theta[0]));
      
      The pos_u_max == 0.0 disjunct treats "zero positive-fill evidence" as "wide or full positive-fill coverage," emitting constant_nanos = Some(decode_ns) and storing decode_ns in estimate.nanos (cost.rs:342, 1118).
    • Concrete counterexample & downstream impact: On Mixed(4, 1, 2048) with 2 ms decode-only latency and ~95 ms true full-chunk prefill, observing one decode-only step sets constant_nanos = Some(2_000_000) and estimate.nanos = 2_000_000. Until a positive-fill step executes on that shape:
      • predict(2048, 0) short-circuits on constant_nanos (cost.rs:184-186)—and note that simply removing pos_u_max == 0.0 || is not sufficient on its own because upward_extrapolation_floor (cost.rs:145) also requires self.pos_u_max > 0.0, so predict(2048, 0) would still return theta[0] = 2_000_000 (~47× under-priced).
      • mixed_candidates (policy.rs:1756, 1872-1898) sees variable_cost = false, prices every prompt candidate at decode_ns, and is_unmeasured_candidate (policy.rs:546-549) returns false because estimate.nanos != 0, letting the mispriced candidate compete as PlanOrigin::Ordinary.
      • service_rates (service.rs:354-379) computes token_rate = 2048 * 1e6 / 2e6 = 1,024 tok/ms (~47× inflated), distorting service-rate normalization across all competing prefill requests even when that Mixed graph is not selected.
      • Both new tests (cost.rs:1764-1900, policy_tests.rs:9510-9576 (not opened)) observe a positive-fill sample before querying positive-fill predictions and therefore miss this state.
    • Fix:
      1. Drop pos_u_max == 0.0 || from wide_or_full_positive (cost.rs:451-452) so a zero-fill-only model is never marked constant_nanos = Some(...).
      2. Expose pub fn has_positive_fill(&self) -> bool { self.pos_u_max > 0.0 } on PrefillPredictor. Keep predict(0, 0) returning the valid measured decode-only cost (do not collapse mixed_entry to Some(None) globally), while on positive-fill queries (work > 0) when !predictor.has_positive_fill(), return 0 in mixed_candidates/next_progress/continuation_candidate (so is_unmeasured_candidate at policy.rs:547 properly treats positive-fill on that shape as discovery via duration_ns == 0) and skip it in service_rates prefill normalization (service.rs:373).
      3. Add a unit test in cost.rs observing only mixed_step(4, 1, 2048, None) (at init and post-TTL) and asserting predict(0, 0) == decode_ns, !predictor.is_constant(), !predictor.has_positive_fill(), and that positive-fill queries do not price full-chunk prefill at decode-only latency.

Should Fix

  1. Eliminate the remaining per-page Vec<DeviceSpan> clone in restore_window's GpuBatch arm (helios/src/offload/transfer/codec.rs:716-724; helios/src/offload/transfer/gpu_codec.rs:1693-1700)

    • pages (codec.rs:685-693) already owns each page's Vec<DeviceSpan>, yet codec.rs:716-717 still allocates and clones every per-page vector (let run_spans: Vec<Vec<DeviceSpan>> = slice.iter().map(|(_, _, _, sp)| sp.clone()).collect();) solely because decode_pages_batch_to_device takes &[Vec<DeviceSpan>]—partially contradicting the PR description's claim that partitioning avoids cloning per-page DeviceSpan vectors.
    • Fix: Mirror copy_spans_batch (codec.rs:1062) by changing spans_per_page in decode_pages_batch_to_device (gpu_codec.rs:1697) to &[impl AsRef<[DeviceSpan]>] (or &[&[DeviceSpan]]) and passing borrowed slices slice.iter().map(|(_, _, _, sp)| sp.as_slice()).collect::<Vec<_>>().
  2. Prevent CopyEngineGate::try_enter_offload_batch from consuming wave tokens armed for blocked offload waiters (helios/src/offload/copy_gate.rs:55-68, 171-210; docs/prefix-cache-offload.md:102-106)

    • maybe_arm_offload_wave (copy_gate.rs:61-62) sizes offload_wave_remaining = offload_batches_waiting specifically for threads parked in enter_offload_batch. Because offload_must_wait (:171-175) allows entry when turn == Turn::Offload && offload_wave_remaining > 0, try_enter_offload_batch (:204-210) calls take_offload_lease and decrements offload_wave_remaining, potentially flipping turn = Turn::Peer before woken waiters run and contradicting docs/prefix-cache-offload.md:104-105 ("without blocking or consuming a gate wave token").
    • Fix: Return None in try_enter_offload_batch when Self::offload_must_wait(&state) || (state.turn == Turn::Offload && state.offload_batches_waiting > 0) so non-waiting foreground tries fall back to CPU during a waiter-reserved offload wave without stealing waiter tokens.
  3. Address the disclosed default-MTP-5 latency delta, Layer-2 simulator check, and @yatesdr lock-order ack (helios/src/server/runtime.rs:538-541; helios/src/offload/transfer/codec.rs:879-889; docs/design-review.md:109-115, 195-206)

    • Under default MTP 5 at 20,648 prompt tokens on the tested Qwen4-35B-A3B core, pause_for_drain regresses median </think>→content latency by +32% (40.9 → 54.1 ms) because waiting for Frame 2 before rolling back on </think>\n\n{ overshoot delays slot readmission compared to main's immediate cancel(). Confirm whether this trade-off is acceptable for default MTP-5 deployments on cores lacking ValueSource::GrammarEnabled or gate pause_for_drain when speculative overshoot is expected.
    • Obtain @yatesdr's sign-off on reversing #628's capture-path lock order (codec.rs:879-889), and run scripts/scheduling_sim/learning.py --preset validate (matching #645's precedent; scripts/scheduling_sim/learning_scenarios.py:63 (not opened) already includes mixed scenarios) or split Bucket 3 if whole-model Mixed validation is deferred.

Subtract / Simplify

Nits

Dropped on verification