Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #681

Raw Markdown for agents: https://autobot.eidonix.com/p/10c5ef27-181d-4947-9300-969364207d6d.md

#1 [high] Lens verdict: diff is lean; 4 concrete simplifications

PR #681 (helios/src/scheduler/policy.rs +1 net production LOC, scripts/scheduling_sim/utility.py +2/-6, docs +5/-2, 2 new Rust tests, 1 new Python test).

Verdict: production diff is genuinely small and already removes code (the unreachable peer_budget == usize::MAX arm at old policy.rs:567 and the let mut peer_budget accumulator). No new flags, config keys, fallbacks, or speculative generality. Python side is a net deletion. Suggestions below are the only worthwhile ones; nothing here justifies blocking on its own except, maybe, A.

FINDING A (high) — three copies of the same cohort-mean expression; collapse to one helper. helios/src/scheduler/policy.rs:627:

                    let mean_out = decoder_rems[..decoder_count].iter().map(|&rem| expected_at(eff_width).min(rem as f64).max(1.0)).sum::<f64>() / decoder_count as f64;

helios/src/scheduler/policy.rs:636 (identical shape, width as f64):

                                let mean_out = decoder_rems[..decoder_count].iter().map(|&rem| expected_at(width as f64).min(rem as f64).max(1.0)).sum::<f64>() / decoder_count as f64;

helios/src/scheduler/policy.rs:668-672:

            let horizon = decoder_rems[..decoder_count]
                .iter()
                .map(|&rem| (rem as f64).min(ph))
                .sum::<f64>()
                / decoder_count as f64;

All three are mean_i f(rem_i). Add one module-level helper next to the other free fns (e.g. near rounds.rs:991 forecast_tokens or in policy.rs above the impl):

fn cohort_mean(rems: &[usize], f: impl Fn(f64) -> f64) -> f64 {
    rems.iter().map(|&rem| f(rem as f64)).sum::<f64>() / rems.len() as f64
}

then let mean_out = cohort_mean(&decoder_rems[..decoder_count], |rem| expected_at(eff_width).min(rem)); and let horizon = cohort_mean(&decoder_rems[..decoder_count], |rem| rem.min(ph));. Also: :627 and :636 are the only two lines in the file (1969 lines) longer than 150 chars (search ^.{150,}$) and break the neighbouring wrapping style. Extracting the helper fixes that too. Simulator already factors this implicitly (utility.py:215-219 has one mean_out sum used by both call sites).

FINDING B (medium) — .max(1.0) is a no-op and should be deleted, not carried into the shared helper.

FINDING C (medium) — the if horizon > 0.0 guard at policy.rs:673 is unreachable; delete it and unindent the body. policy.rs:667-682:

            let ph = self.policy.coalescing_horizon_tokens.min(post_prefill as f64);
            let horizon = ...
            if horizon > 0.0 {
                // Amortize ...
                let per_token = (best_surplus_per_horizon * horizon) / initial_prefill as f64;
                if per_token.is_finite() && per_token > 0.0 {
                    bonus_log[slot] = per_token.ln();
                }
            }

coalescing_horizon_tokens > 0.0 (early return :527), post_prefill >= 1 (:561 guard post_prefill > 0), each rem >= 1 (:550) ⇒ ph > 0 and mean_i min(rem_i, ph) > 0 for decoder_count >= 1 (:567 guard). The guard is dead; the existing per_token.is_finite() && per_token > 0.0 inner guard already covers the degenerate cases. Removing it drops one nesting level from the whole amortization block (which also lets the comment block at :674-676 sit at natural indent).

FINDING D (medium) — the new test re-implements production interpolation instead of using the existing helper. helios/src/scheduler/policy_tests.rs:7002-7011:

    let expected_at = |eff_width: f64| -> f64 {
        let drafts = eff_width - 1.0;
        let full = (drafts.floor() as usize).min(curve.len());
        let frac = (drafts - full as f64).clamp(0.0, 1.0);
        let mut sum = 1.0 + curve[..full].iter().sum::<f64>();
        if full < curve.len() {
            sum += frac * curve[full];
        }
        sum
    };

This is a hand copy of policy.rs:586-598. Every width queried in this test is integral (8.0, 6.0, 4.0 — packed_per_lane 16/2, 12/2, 12/3), where the interpolation collapses to 1.0 + Σ curve[..w-1], i.e. exactly super::rounds::forecast_tokens(&curve, w) (rounds.rs:991-993), which this test file already uses at policy_tests.rs:7152. Replace the closure with |w: usize| super::rounds::forecast_tokens(&curve, w) and delete 10 lines, so the test cannot drift from production arithmetic.

FINDING E (low, optional) — parallel arrays where the neighbouring code uses tuples. policy.rs:530-533:

        let mut decoder_slots = [0usize; REQUEST_LANES];
        let mut decoder_rems = [0usize; REQUEST_LANES];
        let mut decoder_count = 0usize;
        let mut prefillers = [(0usize, 0usize, 0usize); REQUEST_LANES];

Two 512-byte parallel arrays (decoder_slots, decoder_rems) written together at :551-553 and read together, while the prefill cohort two lines below uses one tuple array. A single [(0usize, 0usize); REQUEST_LANES] of (slot, rem) matches the local convention and removes one buffer plus one index write. Only worth doing if A is taken anyway.

NOT SUGGESTED (checked and rejected):

#3 [high] Research summary

Reviewed PR #681 through the Subtraction/Simplicity/Conventions lens by reading the full diff, coalescing_prefill_log_bonus at the head (helios/src/scheduler/policy.rs:525-684), the simulator block (scripts/scheduling_sim/utility.py:203-244), the new tests, AGENTS.md, and the neighbouring helpers (rounds.rs:991 forecast_tokens, speculative_curve).

Verdict: the diff is already lean. It removes more than it adds in structure — the old let mut peer_budget accumulator and the unreachable peer_budget == usize::MAX return arm are gone, the Python side is a net −4 lines, and the PR introduces no new flag, config key, wrapper, fallback branch, or abstraction. Nothing in AGENTS.md:188-193 ("no speculative compatibility, fallback layers, or configuration switches") is violated.

Four worthwhile simplifications, all on lines this PR touches:

Also checked and explicitly not flagged: the verbose inline GraphDescriptor literals (established style in this file), add_active_decoder/coalescing_bonus helpers (near-duplicates exist but carry test-specific setup), the ph local in the simulator, and the docs clause rewrite. Details with verbatim quotes and replacement code are in the scratchpad.

#4 [high] Report-ready findings list (ordered), with replacement code

DELIVERABLE (report should be sparing: state plainly that the diff is lean, then these 4-5 items).

VERDICT PARAGRAPH: PR #681 is already lean. It removes more structure than it adds: the old let mut peer_budget accumulator and the unreachable peer_budget == usize::MAX return arm are deleted, scripts/scheduling_sim/utility.py is net −4 lines, and the PR adds no flag, config key, wrapper, fallback branch, or abstraction — compliant with AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"). The remaining opportunities are local collapses on lines the PR already edits.

[A] MEDIUM-HIGH. One cohort-mean helper instead of three copies.

            let horizon = decoder_rems[..decoder_count]
                .iter()
                .map(|&rem| (rem as f64).min(ph))
                .sum::<f64>()
                / decoder_count as f64;
fn cohort_mean(rems: &[usize], f: impl Fn(f64) -> f64) -> f64 {
    rems.iter().map(|&rem| f(rem as f64)).sum::<f64>() / rems.len() as f64
}

call sites: let mean_out = cohort_mean(&decoder_rems[..decoder_count], |rem| expected_at(eff_width).min(rem)); and let horizon = cohort_mean(&decoder_rems[..decoder_count], |rem| rem.min(ph));

[B] MEDIUM. Delete .max(1.0) on :627 and :636 (twice each per planning call). Proof it never binds: expected_at (policy.rs:586-598) returns 1.0 for eff_width <= 1.0 || mean_curve.is_empty(), otherwise 1.0 + Σ mean_curve[..] where mean_curve entries are probabilities in [0,1] raised to a positive exponent (rounds.rs:625-627), so E ≥ 1.0; and every recorded decoder has rem >= 1 (policy.rs:550 if rem > 0). Therefore min(E, rem) >= 1.0 always. Do not carry .max(1.0) into the helper; it is dead code the PR relocated (the old expected_at(..).min(peer_budget).max(1.0) was equally vacuous).

[C] MEDIUM. Delete the unreachable if horizon > 0.0 guard at policy.rs:673 and unindent its body (policy.rs:667-682 verbatim):

            let ph = self.policy.coalescing_horizon_tokens.min(post_prefill as f64);
            let horizon = decoder_rems[..decoder_count]
                .iter()
                .map(|&rem| (rem as f64).min(ph))
                .sum::<f64>()
                / decoder_count as f64;
            if horizon > 0.0 {
                // Amortize the unlocked coalescing surplus uniformly across the prefiller's
                // uncached prompt tokens so total credit sums to 1x regardless of chunking
                // and chunk sizing stays smooth under active decode waiting age.
                let per_token = (best_surplus_per_horizon * horizon) / initial_prefill as f64;
                if per_token.is_finite() && per_token > 0.0 {
                    bonus_log[slot] = per_token.ln();
                }
            }

Guards upstream make horizon > 0.0 always true: coalescing_horizon_tokens > 0.0 (:527), post_prefill > 0 (:561) so ph > 0, rem > 0 (:550), decoder_count >= 1 (:567). The inner per_token.is_finite() && per_token > 0.0 already covers degenerate values. Removing the dead branch drops one nesting level from the whole amortization block and lets the 3-line comment sit at natural indent.

[D] MEDIUM. New test re-implements production interpolation. policy_tests.rs:7002-7011 verbatim:

    let expected_at = |eff_width: f64| -> f64 {
        let drafts = eff_width - 1.0;
        let full = (drafts.floor() as usize).min(curve.len());
        let frac = (drafts - full as f64).clamp(0.0, 1.0);
        let mut sum = 1.0 + curve[..full].iter().sum::<f64>();
        if full < curve.len() {
            sum += frac * curve[full];
        }
        sum
    };

This is a hand copy of policy.rs:586-598. Every width queried here is integral (8.0, 6.0, 4.0 = packed_per_lane 16/2, 12/2, 12/3), where it collapses to 1.0 + Σ curve[..w-1] — exactly super::rounds::forecast_tokens(&curve, w) (rounds.rs:991-993), already used in this test file at policy_tests.rs:7152. Replace with let expected_at = |w: usize| super::rounds::forecast_tokens(&curve, w); (call sites at :7012, :7044-7045 take integer literals already) and delete 10 lines; the test then cannot drift from production arithmetic.

[E] LOW/OPTIONAL. policy.rs:530-533 verbatim:

        let mut decoder_slots = [0usize; REQUEST_LANES];
        let mut decoder_rems = [0usize; REQUEST_LANES];
        let mut decoder_count = 0usize;
        let mut prefillers = [(0usize, 0usize, 0usize); REQUEST_LANES];

Two parallel 512-byte arrays written together at :551-553 and read together, while the prefill cohort two lines below uses a single tuple array. Collapse to let mut decoders = [(0usize, 0usize); REQUEST_LANES]; of (slot, rem) to match the local convention; only worth doing together with [A].

EXPLICITLY NOT FLAGGED (so the report does not pad): the verbose inline GraphDescriptor literals at policy_tests.rs:6941/6956/6973 (established style: :4139, :4280, :4500; no builder exists); add_active_decoder (:6877-6885) near-duplicating the closure at :6698-6713 (that one carries test-specific acceptance seeding); coalescing_bonus (:6866-6875) policy mutation (same technique as run_burst(0.0, ..) at :6794-6845); the simulator's ph local and net-negative diff (utility.py:232-236); the 1-clause docs rewrite (docs/scheduling-runtime-design.md:222-235). The missing operator knob / default-on reach argument belongs to the other lenses, not this one.

#2 [medium] Citations verified for #681 simplicity review

Verified at PR head (e15b836):