Subtraction and simplicity report · NVIDIA/hyperflare-inference #632

Raw Markdown for agents: https://autobot.eidonix.com/p/5d40da73-8b1f-4b2b-b78f-b55afaf47d1d.md

Subtraction, Simplicity & Conventions — PR #632 (helios/scheduler: scale GPU prefix calibration ceiling per step across depth)

Key findings

Verdict: the production diff is already lean and idiomatic. helios/src/scheduler/rounds.rs is +15/−10: one 4-line helper plus depth: usize threaded through six functions. The threading is genuinely required by the signature change, every parameter is read (rounds.rs:49, :87, :99), every caller is updated, and there is no flag, knob, env var, config key, manifest/Protobuf/ABI field, feature gate, dead code, #[allow], TODO, or new pub surface. SURPLUS_FACTOR_MAX = 2.0 (rounds.rs:25, used :256) is correctly left flat and must not be merged with this ceiling — it is a different, per-round empirical bound. Nothing in the diff needs a redesign. What follows are three targeted cleanups and one doc cut, ranked.

Ranked suggestions:

I have deliberately not treated the depth ≥ 4 ceiling-saturation effect (prior 0.5^(d+1) × ceiling 2^(d+1) = 1.0) as a simplification. Removing or re-bounding the ceiling is a semantics decision for the Correctness lens, not a deletion; I only note that the reviewer should ask whether an unbinding bound is intended. Equally, S1 must not be read as "delete the cap" — the cap is reached identically by simpler arithmetic.


S1 — calibration_factor_max: unreachable fallback + misplaced in the const block

helios/src/scheduler/rounds.rs:10-19 (verbatim):

const POPULATION_WEIGHT: f32 = 1.0 / 64.0;
const CALIBRATION_PRIOR_WEIGHT: f64 = 4.0;
const POPULATION_CALIBRATION_MAX_WEIGHT: f64 = 64.0;
const CALIBRATION_FACTOR_MAX: f64 = 2.0;

fn calibration_factor_max(depth: usize) -> f64 {
    let steps = i32::try_from(depth.saturating_add(1)).unwrap_or(30).min(30);
    CALIBRATION_FACTOR_MAX.powi(steps)
}
const REQUEST_CALIBRATION_PRIOR_WEIGHT: f64 = 2.0;

Two defects, both structural:

(a) The fallback is redundant. unwrap_or(30) and the trailing .min(30) produce the same value, so only one of the two error paths is load-bearing; the whole conversion dance exists solely because powi takes i32. Both the overflow and the conversion-failure case are already subsumed by a single min. Total, allocation-free, identical for every input:

fn calibration_factor_max(depth: usize) -> f64 {
    CALIBRATION_FACTOR_MAX.powi(depth.min(29) as i32 + 1)
}

depth.min(29) + 1 == (depth + 1).min(30) for all usize, with no overflow and no conversion failure; 2.0^30 is finite so there is no magnitude concern. This deletes the try_from, the unwrap_or, the saturating_add, and one min.

(b) The function splits the constant block. const REQUEST_CALIBRATION_PRIOR_WEIGHT at :19 now follows a fn. Every other constant groups contiguously at :10-13 and :19-25; the helper belongs after :25 (const SURPLUS_FACTOR_MAX) with the other items, or in the DepthCalibration impl. Move it below :25.

Optional, and the reason the magic number matters: the cap 30 now appears in three places — rounds.rs:16, docs/scheduling-runtime-design.md:117 ("with exponent depth + 1 capped at 30"), helios/README.md:450 ("with depth + 1 capped at 30"). A named const CALIBRATION_FACTOR_STEPS_MAX: usize = 30; gives the docs a symbol to cite, matching how docs/scheduling-runtime-design.md:122 already cites CALIBRATION_FACTOR_MAX by identifier. Keep CALIBRATION_FACTOR_MAX (:13): it is now read only inside the helper (:17) but is named in the design doc, so it is not dead.


S2 — the ratio clamp is written twice; this PR touches both copies

helios/src/scheduler/rounds.rs:47-53:

    fn factor(self, depth: usize) -> f64 {
        if self.predicted > 1e-6 {
            (self.realized / self.predicted).clamp(0.0, calibration_factor_max(depth))
        } else {
            1.0
        }
    }

helios/src/scheduler/rounds.rs:83-91:

    fn factor(self, depth: usize, global: DepthCalibration) -> f64 {
        if self.weight == 0.0 {
            global.factor(depth)
        } else if self.predicted > 1e-6 {
            (self.realized / self.predicted).clamp(0.0, calibration_factor_max(depth))
        } else {
            1.0
        }
    }

The six-line if predicted > 1e-6 { ratio.clamp(0.0, ceiling) } else { 1.0 } block is byte-identical between the two sites, including the 1e-6 epsilon policy. The duplication predates the PR (#515 introduced it, #522 extended it), but the PR's entire subject is that clamp expression, and the diff edits line :49 and line :87 — the two copies — so this is the natural moment to give the ceiling a single definition. Extract:

fn calibration_ratio(realized: f64, predicted: f64, depth: usize) -> f64 {
    if predicted > 1e-6 {
        (realized / predicted).clamp(0.0, calibration_factor_max(depth))
    } else {
        1.0
    }
}

then DepthCalibration::factor becomes calibration_ratio(self.realized, self.predicted, depth), and RequestCalibration::factor collapses to:

    fn factor(self, depth: usize, global: DepthCalibration) -> f64 {
        if self.weight == 0.0 {
            global.factor(depth)
        } else {
            calibration_ratio(self.realized, self.predicted, depth)
        }
    }

Net −4 lines; the ceiling formula and the epsilon appear once each. Verified there is no third site to fold: calibration_factor_max is referenced only at rounds.rs:13 and :17; SURPLUS_FACTOR_MAX (:25, :256) is a separate flat bound and must be left alone.


S3 — the new test fixture duplicates an existing fixture and repeats six near-identical literals

helios/src/scheduler/policy_tests.rs:6466-6503 (verbatim, the repeated part of the new helper):

    graphs.push(crate::execution::GraphDescriptor {
        name: "speculative-b1-d0-w1".into(),
        kind: GraphKind::Speculative,
        sampling_mode: SamplingMode::General,
        handle: 100,
        batch_capacity: 1,
        draft_tokens: 0,
        token_capacity: 1,
        packed_token_capacity: 0,
        prefill_capacity: 0,
        estimated_duration_ns: 28 * MS,
        confidence_width: 0,
        tuned_bindings: vec![],
        input_bindings: vec![],
    });
    for (packed, nanos) in [
        (2usize, 29_500_000u64),
        (3, 31_200_000),
        (4, 35_000_000),
        (5, 37_000_000),
        (6, 38_800_000),
    ] {
        graphs.push(crate::execution::GraphDescriptor {
            name: format!("speculative-b1-d5-w6-p{packed}"),
            kind: GraphKind::Speculative,
            sampling_mode: SamplingMode::General,
            handle: 100 + packed,
            batch_capacity: 1,
            draft_tokens: 5,
            token_capacity: 6,
            packed_token_capacity: packed,
            prefill_capacity: 0,
            estimated_duration_ns: nanos,
            confidence_width: 5,
            tuned_bindings: vec![],
            input_bindings: vec![],
        });
    }

(A) Collapse the literals with the builder-closure idiom the repo already uses. helios/src/scheduler/cost.rs:369-383 does exactly this for repetitive speculative descriptors:

        let make = |name: &str, drafts, width, packed| GraphDescriptor {
            name: name.into(),
            kind: GraphKind::Speculative,
            sampling_mode: SamplingMode::General,
            confidence_width: drafts,

The same shape here turns 38 lines into ~15, and lets a single expression carry the invariant that manifest.rs:850 already enforces (graph.confidence_width != graph.draft_tokens → rejected): confidence_width: drafts yields 0 for the d0/w1 graph and 5 for the d5/w6 graphs — exactly the current values, so the substitution is behaviour-preserving. (GraphDescriptor has no Default impl — manifest.rs:184-204, :206 is the only impl — so .into_iter().map(...) over a small local closure, not ..Default::default(), is the right tool.)

(B) The whole helper near-duplicates an existing one. The pre-existing single_lane_packed_engine at policy_tests.rs:4300-4313 already builds a confidence_width: 7 GPU packed speculative shape on a b1 catalogue and sets capabilities.speculative_allocations; uses at :4327, :4364, :4383. The new single_lane_packed_calibration_engine (:6449-6511, uses :6544, :6583) re-plumbs the same thing with different geometry. Parameterising the existing helper (page_tokens, plus a &[(packed, nanos)] slice) and deleting the new one removes ~60 lines of duplicated catalogue plumbing. If that churn is judged too invasive for a 6,600-line test file, (A) still applies and is local to the added code.

Two nits inside the same test, both low severity:


Low — helios/README.md:446-452: a parenthetical longer than its sentence, duplicating the design doc

scaled by a request-local aged per-depth verification calibration ratio (seeded
scale-invariantly with prior weight `2` from a once-per-round population prior
capped at weight `64`, 128-token half-life, request EWMA cap `32`, clamped to
`[0, 2^(depth + 1)]` with `depth + 1` capped at `30` so a per-step ceiling of
`2` compounds across the cumulative `depth + 1`-step Rényi-2 collision
survival product `prod_{j=0..depth} sum_i q_{j,i}^2`), and crowded

The parenthetical opens at (seeded and closes after q_{j,i}^2 — 6.5 lines of parentheses inside a 3-line sentence, in the file that is the summary. The same derivation is already specified, in prose and with the code identifier, at docs/scheduling-runtime-design.md:113-123:

   to `[0.0, calibration_factor_max(depth)]` (defaulting to `1.0` when
   `predicted <= 1e-6`), where `calibration_factor_max(depth) = 2.0^(depth + 1)`
   with exponent `depth + 1` capped at `30`.

Cut the README back to clamped to `[0, 2^(depth + 1)]`) and let the design doc carry the Rényi-2 compounding argument. This is the only removable doc text: docs/scheduling-runtime-design.md:113-145 and the README are otherwise clean one-for-one replacements of the flat [0, 2] wording with no stale text left behind, and docs/mtp-design.md:173-180 (not opened) remains accurate and is correctly untouched.


What is correctly absent (said plainly, so a maintainer does not "helpfully" add it back)

Open questions

  1. Is the depth >= 4 unbinding ceiling intended? The population prior is 0.5^(d+1) (rounds.rs prior init, design doc :125 "realized == predicted == 0.5^d") and the new ceiling is 2^(d+1); their product is exactly 1.0 at every depth, so from the prior any observed ratio ≥ 1.0 saturates the [0,1] clamp. Not a subtraction finding, but the reviewer should ask.
  2. Does plan() write refresh.acceptance_credit_ns? Determines whether policy_tests.rs:6553 is deletable (nit D). I did not trace it exhaustively.
  3. Is parameterising single_lane_packed_engine (:4300-4313) acceptable to this file's owners, or is a fourth near-duplicate catalogue fixture preferred? The repo already tolerates test-fixture duplication (completion_records exists in both policy_tests.rs:161 and lifecycle_tests.rs:28 (not opened)), so (A)-only is a defensible outcome.
  4. Whether a named CALIBRATION_FACTOR_STEPS_MAX constant is wanted, given the 30 is quoted in two docs.

Not found / could not determine: no CI failure record is readable from the PR, so I cannot tell whether the red check is a formatting/clippy issue in the added test helper (which would make S3(A) moot by necessity) or the known unrelated FLARE_TEST_TEMPLATE_DIR-unset frontend fixture failures. The PR description is silent on it. I also could not verify the Rényi-2 premise in-repo (out-of-tree confidence producer), so S1/S2/S3 make no claim about the formula's correctness — only about the code shape around it.