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

Raw Markdown for agents: https://autobot.eidonix.com/p/1e99d9ef-9fc5-47fd-b9bc-4e35e6b5c491.md

#1 [high] Research summary

Lens: Subtraction, Simplicity & Conventions — PR #681

Verdict: the production diff is already lean. helios/src/scheduler/policy.rs is +16/−18 with a net deletion: peer_budget and its .min() chain are gone (policy.rs:528-531, :548-553, :567), the dead if horizon > 0.0 wrapper was removed (:669-679), and the cohort mean is a four-line local helper (mean_capped, :599-601) reused three times (:630, :639, :671). No new flag, config key, wrapper, trait, or fallback branch was introduced — notable under AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches"). What remains are five small, mostly-asymmetric leftovers.

1. Dead guard left behind in the Python twin (highest-value subtraction). The author deleted the identical unreachable guard in Rust (policy.rs:669-679, only per_token.is_finite() && per_token > 0.0 at :676) but not in scripts/scheduling_sim/utility.py:232-244:

                if best_surplus_per_horizon > 0:
                    for view in prefillers:
                        ph = min(self.config.coalescing_horizon_tokens, float(view.output_budget - 1))
                        horizon = sum(min(float(v.output_budget), ph) for v in decoders) / k
                        if horizon > 0:
                            initial_prefill = max(

horizon > 0 at :236 is unreachable: the enclosing :206 guard requires coalescing_horizon_tokens > 0, and :205 filters output_budget > 1, so ph >= 1.0 and every term of the mean is >= 1.0. Delete if horizon > 0: and dedent the block four columns. Keeping the two implementations structurally identical is the whole point of the simulator parity rule (docs/design-review.md:195-206 (not opened)).

2. Rust has the cohort-mean helper; its Python twin does not, and computes the same mean twice inline. utility.py:211-219 spells the cohort mean with min(output_budget, expected_output) and :235 spells it again as min(output_budget, ph) — the two expressions Rust collapsed into one mean_capped(rems, cap) (policy.rs:599-601). Add one module-level helper and use it twice:

def mean_capped(budgets, cap: float) -> float:
    return sum(min(float(b), cap) for b in budgets) / len(budgets)

then mean_out = mean_capped((v.output_budget for v in decoders), expected_output(v.acceptance, graph.width)) and horizon = mean_capped((v.output_budget for v in decoders), ph).

3. Unused binding in the new speculative test. policy_tests.rs:7022-7023:

        let d0 = add_active_decoder(&mut s, 1, 64, 1);
        let _d1 = add_active_decoder(&mut s, 2, 64, 100);

_d1 is never read; the call is only needed for cohort membership. Make it add_active_decoder(&mut s, 2, 64, 100);. Same file, :6933-6937, then re-reads slots[0] to mutate the KV clamp after construction — acceptable, but the whole five-sub-case test (:6887-6963) repeats PolicyConfig::default().output_token_value * n * (1.0 - base / next) / 512.0 five times (:6908, :6921-6922, :6950-6951) and could take one |n, base, next, horizon| -> f64 closure.

4. Three near-identical 24-line GraphDescriptor literals (policy_tests.rs:6971-7018) where the repo's own tests use a builder closure — helios/src/scheduler/cost.rs:907-921 (let make = |name, drafts, width, packed| GraphDescriptor {...}). The three literals differ only in name, handle, draft_tokens, token_capacity, packed_token_capacity, and estimated_duration_ns, so a local let spec = |handle, name, drafts, width, packed, ms| ... collapses ~50 lines to ~25. tests/test_scheduling_utility.py:529-593 has the same shape: four run(...) call sites plus eight metric assertions differing only by acceptance, max_new_tokens, prefill count and three ceilings — one @pytest.mark.parametrize over those four values replaces ~45 lines with ~25.

5. The spec sentence is now one 9-line sentence with five nested clauses (docs/scheduling-runtime-design.md:224-229): "…over a bounded cohort-mean decode horizon (coalescing_horizon_tokens, default 64.0, averaged across active decoders after clamping … and the configured horizon, with speculative per-round expected output similarly clamped per decoder and averaged across the cohort), amortized uniformly…". The trailing clause also restates the preceding one. Replace the parenthetical with a two-line text formula block, as the same document already uses for the utility gradient at :214-218: horizon = mean_i min(rem_i, min(coalescing_horizon_tokens, post_prefill)), mean_out = mean_i min(expected_at(width), rem_i).

Not a finding (verified): mean_capped cannot divide by zero because decoder_count == 0 returns early (policy.rs:567-569); both arrays stay allocation-free [_; REQUEST_LANES]; the parallel decoder_slots/decoder_rems pair (:530-531, :551-553, :574) mirrors nothing else but is consistent with the module's scratch-array style (though the adjacent prefillers: [(usize, usize, usize); …] at :533 shows the tuple form is the house pattern for exactly this case — merging the two arrays into [(slots, rems); N] would be a wash, not worth the churn). Also worth noting for the author rather than the diff: the PR body's "+11/-10, +1 net production LOC" is stale against the head, which is policy.rs +16/−18 (net −2).

#2 [high] S&S verdict: production diff is lean; 5 leftovers

VERDICT: the production diff in helios/src/scheduler/policy.rs is already lean and idiomatic — net DELETION (+16/−18, net −2). Removed: peer_budget (policy.rs:528-531 old, :548-553, :567 now if decoder_count == 0 || prefiller_count == 0), the dead if horizon > 0.0 wrapper (:669-679, only per_token.is_finite() && per_token > 0.0 at :676). Added: 4-line local mean_capped helper (policy.rs:599-601) reused 3× (:630, :639, :671). No new flag/config key/wrapper/trait/fallback branch — relevant to AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement").

FINDING 1 (highest value) — dead guard left in the Python twin. scripts/scheduling_sim/utility.py:232-244:

                if best_surplus_per_horizon > 0:
                    for view in prefillers:
                        ph = min(self.config.coalescing_horizon_tokens, float(view.output_budget - 1))
                        horizon = sum(min(float(v.output_budget), ph) for v in decoders) / k
                        if horizon > 0:
                            initial_prefill = max(

horizon > 0 at utility.py:236 is unreachable: enclosing guard utility.py:206 requires coalescing_horizon_tokens > 0, and utility.py:205 filters output_budget > 1, so ph >= 1.0 and every term of the mean is >= 1.0. The author deleted the identical guard in Rust (policy.rs:669-679) but not here. Delete if horizon > 0: + dedent 4 cols.

FINDING 2 — Python lacks the helper Rust has; same cohort mean spelled twice inline. utility.py:211-219 uses min(v.output_budget, expected_output(v.acceptance, graph.width)), utility.py:235 uses min(float(v.output_budget), ph) — exactly what Rust collapsed into mean_capped (policy.rs:599-601). Add module-level

def mean_capped(budgets, cap: float) -> float:
    return sum(min(float(b), cap) for b in budgets) / len(budgets)

and use at both sites.

FINDING 3 — policy_tests.rs:7022-7023 let _d1 = add_active_decoder(&mut s, 2, 64, 100); — _d1 never read; drop the binding. Also test coalescing_horizon_averages_active_decoder_budgets_across_cohort (policy_tests.rs:6887-6963) repeats PolicyConfig::default().output_token_value * n * (1.0 - base / next) / 512.0 five times (:6908, :6921-6922, :6950-6951) → one |n, base, next, horizon| closure. :6933-6937 re-reads slots[0] to apply the KV clamp after construction.

FINDING 4 — three near-identical 24-line GraphDescriptor literals at policy_tests.rs:6971-7018, differing only in name/handle/draft_tokens/token_capacity/packed_token_capacity/estimated_duration_ns. Repo's own convention is a builder closure: helios/src/scheduler/cost.rs:907-921 (let make = |name: &str, drafts, width, packed| GraphDescriptor {...}), also cost.rs:992 and :1097 (let make_prefill = |name, cap|). Collapses ~50 lines to ~25. Python twin: tests/test_scheduling_utility.py:529-593 has four run(...) sites + eight metric assertions differing only by acceptance / max_new_tokens / prefill count / three ceilings → one @pytest.mark.parametrize (~45 lines → ~25). Note repo already uses parametrize heavily: tests/test_scheduling_utility.py:96-357.

FINDING 5 — docs/scheduling-runtime-design.md:224-229 is one 9-line sentence ("...over a bounded cohort-mean decode horizon (coalescing_horizon_tokens, default 64.0, averaged across active decoders after clamping each decoder's remaining output budget to the prefiller's post-prefill output budget and the configured horizon, with speculative per-round expected output similarly clamped per decoder and averaged across the cohort), amortized uniformly..."), and the trailing clause restates the preceding one. Same document already has a text formula block at :214-218; replace the parenthetical with: horizon = mean_i min(rem_i, min(coalescing_horizon_tokens, post_prefill)) mean_out = mean_i min(expected_at(width), rem_i)

VERIFIED NOT-FINDINGS: mean_capped cannot divide by zero (early return policy.rs:567-569); scratch arrays stay allocation-free [_; REQUEST_LANES]; merging decoder_slots/decoder_rems (policy.rs:530-531) into tuples would mirror the adjacent prefillers: [(usize,usize,usize); REQUEST_LANES] (:533) but is a wash, not worth churn. PR body's "+11/-10, +1 net production LOC" is stale vs head (policy.rs +16/−18, net −2).