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

Raw Markdown for agents: https://autobot.eidonix.com/p/0738c98a-4f72-4960-a955-152706533ce7.md

Key findings

Verdict: the diff is lean on the axis that matters, and the five simplifications below are all deletions inside the new plumbing — none touch the scheduling policy itself. No new flags, unsafe, environment reads, GraphKind, model branches, CLI/PolicyConfig fields, wire/ABI changes, or dead code; interpolated_prefill_duration is one self-contained pure function and docs/README/check.py (not opened) move in the same change. What the PR does add is duplicated plumbing: an ad-hoc per-slot memo threaded through five signatures (S1), one 17-line interpolation block copied verbatim twice (S2), a catalog walked twice for one boolean (S3), a second kind→catalog switch (S4), and a peer-ordering rule written four times (S5).

  1. S1 (high) — PrefillSlotPlan / prefill_slot_state / prefill_slot_nat_fit (policy.rs:79-86, :420-456) is an ad-hoc cache that duplicates one already in the tree, costs five signature changes, and is under-keyed (memoises on slot, ignoring the kind it is handed) — delete it rather than repair it.
  2. S2 (high) — the last_interp interpolation block is copy-pasted verbatim, 17 lines × 2 (policy.rs:1006-1022, :1356-1372), differing only in request→r and width→capacity; one helper removes both and the only place the two copies can drift.
  3. S3 (medium-high) — service_rates walks the same prefill catalog twice for one flipped boolean (service.rs:224-231); scan_prefill(false) subsumes scan_prefill(true), so the token_rate == 0.0 gate and the second full catalog walk both go. −9 lines, one fewer catalog walk per admission.
  4. S4 (medium) — prefill_catalog_for_terminal (policy.rs:350-358) re-implements the kind→catalog switch prefill_catalog (:342-348) already has; and it exists only to accept a pre-resolved terminal_only bool, which is what drags the natural_fit_prefill_capacity→…_for_terminal rename through six call sites.
  5. S5 (medium) — interpolated_prefill_duration states its peer-ordering rule four times (cost.rs:734-744 skip form, :759-772 accept form with a better_at_same_cap closure defined for that copy only); the hi/lo pre-filter is exactly the negation of the accept test, so one comparator and one pass replace both. −15 lines.

All line numbers at head 29f2b5b. Nothing below is a correctness bug; where a buggy workaround exists the recommendation is explicitly delete it.


S1 (high) — Delete PrefillSlotPlan, don't repair it

helios/src/scheduler/policy.rs:79-86:

#[derive(Clone, Copy, Default)]
struct PrefillSlotPlan {
    ready: bool,
    cut: Option<usize>,
    terminal_only: bool,
    nat_fit_ready: bool,
    nat_fit: Option<usize>,
}

helios/src/scheduler/policy.rs:420-456:

    fn prefill_slot_state(
        &self,
        slot_plans: &mut [PrefillSlotPlan; REQUEST_LANES],
        slot: usize,
        request: &LiveRequest,
        age_price: f64,
    ) -> (Option<usize>, bool) {
        let plan = &mut slot_plans[slot];
        if !plan.ready {
            plan.cut = self.estimated_checkpoint_cut(request);
            plan.terminal_only =
                self.prefill_requires_terminal_completion_for_age(request, plan.cut, age_price);

…and :437-456:

        let plan = &mut slot_plans[slot];
        if !plan.nat_fit_ready {
            let catalog = self.prefill_catalog_for_terminal(kind, plan.terminal_only);
            plan.nat_fit = self.natural_fit_prefill_capacity_for_terminal(

What it costs and why it is redundant:

        if !plan.nat_fit_ready {
            let catalog = self.prefill_catalog_for_terminal(kind, plan.terminal_only);

candidates() walks Prefill, TerminalPrefill, ScoredPrefill, … (:1487-1497) against one shared prefill_plans (:1486), while the pre-existing inline form recomputed the fit per (kind, slot) over effective_prefill_catalog(…), which returns the scored catalog for ScoredPrefill unconditionally. Under terminal_only == true the shared value was computed over terminal_prefill_catalog, so the ScoredPrefill iteration is priced against a terminal-catalog natural fit — an unintended change the new tests do not cover (the nat-fit tests at policy_tests.rs:7432, :7530, :7830 exercise Prefill/TerminalPrefill only). Repairing that means adding a kind dimension to a cache whose whole purpose was to avoid a ≤12-entry loop.

Concrete simplification: delete the struct (:79-86) and both helpers (:420-456); remove the prefill_plans parameter from add_candidate (:1323) and continuation_candidate (:937) and the argument at eight call sites (:988, :1003, :1334, :1353, :1460, :1520, :1524, :1530, :1536, :1936, :1940); compute (cut, terminal_only) once at the top of candidates()/phase_plan() into a local array and the nat fit inside the existing if kind.is_prefill() arm (:1518-1521), where kind is already in hand. This removes ~40 lines, five signature edits, two _ready flags, and one invariant ("nat_fit is only valid after state()") that nothing enforces.

S2 (high) — One helper instead of a verbatim 17-line copy

helios/src/scheduler/policy.rs:1006-1022:

                                && let Some(interp) = match last_interp {
                                    Some((w, pos, res))
                                        if w == work && pos == request.scheduled_consumed =>
                                    {
                                        res
                                    }
                                    _ => {
                                        let res = self.costs.interpolated_prefill_duration(
                                            following,
                                            width,
                                            work,
                                            request.scheduled_consumed,
                                        );
                                        last_interp = Some((work, request.scheduled_consumed, res));
                                        res
                                    }
                                }

helios/src/scheduler/policy.rs:1356-1372 is byte-identical apart from request→r and width→capacity:

                            && let Some(interp) = match last_interp {
                                Some((w, pos, res))
                                    if w == work && pos == r.scheduled_consumed =>
                                {
                                    res
                                }
                                _ => {
                                    let res = self.costs.interpolated_prefill_duration(
                                        kind,
                                        capacity,
                                        work,
                                        r.scheduled_consumed,
                                    );
                                    last_interp = Some((work, r.scheduled_consumed, res));
                                    res
                                }
                            }

The surrounding ns decision (interp → nat_fit == Some(width) → 0 → continue) is duplicated too: :999-1031 vs :1349-1381.

Concrete simplification: one method on RequestScheduler, e.g. fn unmeasured_prefill_ns(&self, kind: GraphKind, capacity: usize, work: usize, start: u64, nat_fit: Option<usize>, age_price: f64, last: &mut Option<(usize, u64, Option<u64>)>) -> Option<u64> returning Some(ns) / Some(0) / None, called from both sites as let Some(ns) = … else { continue };. −17 lines, and it removes the only place the two copies can drift (today one passes following/width, the other kind/capacity — the kind of asymmetry that silently diverges on the next edit). Bonus deletion: last_interp (:970, :1330) saves at most one O(entries) scan when two slots report the same (work, start), inside a loop that is already O(capacities × slots) and calls interpolated_prefill_duration per capacity — dropping it deletes 8 more lines and the w == work && pos == … guard entirely.

S3 (medium-high) — service_rates walks the same catalog twice

helios/src/scheduler/service.rs:224-231:

            token_rate = token_rate.max(scan_prefill(terminal_only));
            if token_rate == 0.0
                && terminal_only
                && self.has_active_age_priced_stream()
                && !self.prefill_must_complete_terminally_from(request, start, cut)
            {
                token_rate = token_rate.max(scan_prefill(false));
            }

scan_prefill(false) (:201-223) takes the max over all capacities in catalog, a strict superset of what scan_prefill(terminal_only) — which only adds the skip_nonterminal filter at :210-212 — considers. Inside this else if prefill branch token_rate starts at 0.0 (:166) and is set by nothing else, so the token_rate == 0.0 gate exists only to avoid re-paying a pass that need not have run.

Concrete simplification: replace all eight lines above with

            let allow_nonterminal = terminal_only
                && self.has_active_age_priced_stream()
                && !self.prefill_must_complete_terminally_from(request, start, cut);
            token_rate = token_rate.max(scan_prefill(terminal_only && !allow_nonterminal));

−9 lines and one full catalog walk per admission, with identical semantics.

S4 (medium) — prefill_catalog_for_terminal duplicates prefill_catalog, and the rename it caused

helios/src/scheduler/policy.rs:342-348 (pre-existing) and :350-358 (new):

    fn prefill_catalog(&self, kind: GraphKind) -> &[usize] {
        match kind {
            GraphKind::ScoredPrefill => &self.scored_prefill_catalog,
            GraphKind::TerminalPrefill => &self.terminal_prefill_catalog,
            _ => &self.prefill_catalog,
        }
    }

    fn prefill_catalog_for_terminal(&self, kind: GraphKind, terminal_only: bool) -> &[usize] {
        if kind == GraphKind::ScoredPrefill {
            &self.scored_prefill_catalog
        } else if terminal_only {
            &self.terminal_prefill_catalog
        } else {
            &self.prefill_catalog
        }
    }

Same three catalog fields, same switch, differing only in that the new one takes a pre-resolved terminal_only bool. Concrete simplification: 3 lines instead of 9, keeping the ScoredPrefill test first for precedence:

    fn prefill_catalog_for_terminal(&self, kind: GraphKind, terminal_only: bool) -> &[usize] {
        if kind == GraphKind::ScoredPrefill { &self.scored_prefill_catalog }
        else if terminal_only { &self.terminal_prefill_catalog }
        else { &self.prefill_catalog }
    }

or, if the caller resolves the kind up front, self.prefill_catalog(if terminal_only { GraphKind::TerminalPrefill } else { kind }). Either way the point stands: removing the duplicate switch also removes the reason for the natural_fit_prefill_capacity → natural_fit_prefill_capacity_for_terminal rename, which exists solely to accept the extra terminal_only: bool (policy.rs:393-399) and churns six call sites (:446, :447, :755, :769, :1789, plus the next_progress closure). terminal_only is just kind == TerminalPrefill once resolved, so passing the resolved GraphKind deletes both _for_terminal suffixes.

S5 (medium) — One comparator, one pass

helios/src/scheduler/cost.rs:734-744 (skip form) and :759-772 (accept form) of interpolated_prefill_duration:

            if key.tokens > capacity {
                if hi.is_some_and(|(c, cur_same, _)| {
                    key.tokens > c || (key.tokens == c && cur_same && !same_kind)
                }) {
                    continue;
                }
            } else if lo.is_some_and(|(c, cur_same, _)| {
                key.tokens < c || (key.tokens == c && cur_same && !same_kind)
            }) {
                continue;
            }

…then again at :762-772:

            let better_at_same_cap = |cur_same: bool, cur_ns: u64| {
                (same_kind && !cur_same) || (same_kind == cur_same && full_ns < cur_ns)
            };
            if key.tokens > capacity {
                if hi.is_none_or(|(c, cur_same, cur_ns)| {
                    key.tokens < c || (key.tokens == c && better_at_same_cap(cur_same, cur_ns))
                }) {
                    hi = Some((key.tokens, same_kind, full_ns));
                }
            } else if lo.is_none_or(|(c, cur_same, cur_ns)| {
                key.tokens > c || (key.tokens == c && better_at_same_cap(cur_same, cur_ns))
            }) {
                lo = Some((key.tokens, same_kind, full_ns));
            }

The is_some_and pre-filter at :734-744 is exactly the negation of the is_none_or accept test at :762-772 — the same ordering predicate written twice, in two spellings, plus a closure defined only for the second copy (and only after :749's predictor work, which the pre-filter exists to skip). 40 lines express "nearest strictly-larger measured peer, nearest measured smaller peer, preferring the same kind at equal capacity".

Concrete simplification: one local fn better(new_cap: usize, new_same: bool, cur: (usize, bool, u64), want_hi: bool) -> bool and a single pass that only calls it (dropping the pre-filter; if the predictor work is genuinely worth skipping, compute (capacity, same_kind, ns) pairs into a small local loop first and reduce with the two orderings). −15 lines, one comparator instead of four, and the two orderings become visibly symmetric.


Minor (noted, not flagged — unit-test scaffolding)

Checked and deliberately not flagged

Conventions (AGENTS.md, module structure)

No structural violation. The change adds no flag, env variable, config knob or extension point — the "one of three homes" rule is about where a new knob may live, and this adds none; whether an implicit change to the shipped balanced preset counts as a "magic default" is the design-fit lens's question, not a simplicity defect. Test placement follows the repo's convention of testing at real production entry points (phase_plan, plan_requires_feedback, candidates, service_rates). The two helper renames are unsolicited churn but are already subsumed by S4 rather than flagged separately.

Open questions / not found

  1. Does S1's deletion preserve the phase_plan path? phase_plan (policy.rs:1933) constructs its own prefill_plans for a single request across the catalog loop; the eager per-slot computation I propose must still cover TerminalPrefill's promotion of Prefill (:979-983, :1498-1502). I did not re-derive that path end to end.
  2. Is last_interp measurably useful? No profile in the PR, and the description's "host plan() 4.70×–8.65× faster" figure has no artifact behind it, so I cannot say whether keeping the memo is justified by measurement. Under the lens's rules the unmeasured memo loses to deletion.
  3. S3's semantics under prompt_logprobs. scan_prefill closes over catalog (service.rs:195-199), which selects scored_prefill_catalog before terminal_only is consulted; I did not trace whether terminal_only can be true on that path, so my replacement keeps the boolean identical either way.
  4. S5's pre-filter cost. I could not measure whether the is_some_and pre-filter's purpose was to skip the predictor work at :745-755 in a hot loop; if it was, the reduce-over-collected-pairs form is the safe rewrite rather than the single fused pass.