Subtractive report · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/f5a843b6-f76f-477c-891b-85ab929fed77.md

Subtraction review of PR #540 (helios: cost-refresh recovery, prompt+output SAM copy-drafts, calibrated wide copy-verify), head e5a69669

Key findings

Verdict: minimal already. The change is +4,306/−310 across 33 files (pr_files), and I could only confirm about 140 lines (~3%) of removable code, spread over 5 places, none of it carrying behaviour a caller relies on. No blocker; nothing in the PR is a part that serves no purpose, and the four behaviours it claims are each implemented once and measured. The previous commit e5a69669 already removed what earlier revisions of this review flagged (SAM conditional/context API, MatchSource, SamConfig, test-only accessors, empty RefreshState::idle, the doubled copy-match algorithm, the duplicated copy-round search body, the three draft_source wire ladders, the stale doc paragraphs) — I re-checked each of those removals in the code at this head and they are gone.

Ranked by lines saved:

  1. Should fix — ~46 lines: the test-only CURVE_EVALUATIONS thread-local and the two tests that assert an internal call count.
  2. Should fix — ~12 lines: the 3-ordering cohort preamble is written twice (rounds.rs:1019-1030 duplicates :785-803), plus one whole-curve clone() per copy shape at :925.
  3. Nit — ~14 lines: base_zero/pending_value_zero/refresh_expected re-derive what ValueRate::new(0, expected, _).score already is.
  4. Nit — ~20 lines: history_proposal, DecodedHistory::lookup, select_shape_with_drafts and the two draft_source: None "any source" branches are production-dead/unreachable after this PR.
  5. Nit — ~25 lines: duplicated validation clause, triplicated dimension check, duplicated min-match constant, duplicated doc sentences.

Below, each finding gives file:lines, what goes, the smaller replacement, and why nothing is lost.


1. Should fix — about 46 lines: test-only call-count instrumentation

Where: helios/src/scheduler/rounds.rs:30-33 (the #[cfg(test)] thread_local! CURVE_EVALUATIONS with the doc comment "Powered-curve evaluations on this thread, for tests that bound planning work"), the bump inside powered_curve at rounds.rs:565-566, and the two tests helios/src/scheduler/policy_tests.rs:6292-6311 (mixed_refresh_value_reuses_each_decoding_lanes_forecast) and :6313-6331 (decode_refresh_value_reuses_each_decoding_lanes_forecast).

What goes: the thread-local, its bump, and both tests. ~46 lines.

What replaces it: nothing. The grep for CURVE_EVALUATIONS returns the definition, the bump and four reads in those two tests only — no production reader. The tests assert evaluations <= shapes.len() * decoding.len() / batches * decoding.len(), i.e. an implementation detail, plus a trivially-true existence check (candidates.iter().any(|c| c.kind == … && c.expected > 0.0)).

Why nothing is lost: the optimisation the counter guards is literal in the code it was added with — zero_duration[slot] = values[slot].decode(tokens, 0.0) (policy.rs:1052-1056), read in the mixed branch (policy.rs:1100-1101) and summed once (policy.rs:1292) — one forecast, two decode calls. A call-count assertion cannot fail if the sharing is later refactored into an equally cheap form, so it protects nothing a reader of that code cannot see. Note cost.rs:15-19 (ENTRY_LOOKUPS) is the same pattern but is pre-existing on main, so it is not part of this PR.

2. Should fix — about 12 lines: the 3-ordering cohort preamble written twice, and one full curve clone per shape

Where: helios/src/scheduler/rounds.rs:785-804 (select_host_allocated_candidate) and helios/src/scheduler/rounds.rs:1019-1030 (packed_round_candidates, GPU branch). Both repeat, byte for byte:

for ordering in 0..3 {
    order.clear();
    order.extend(available.iter().map(|&slot| (slot, match ordering {
        0 => full[slot], 1 => base[slot], _ => full[slot] / limits[slot] as f64 })));
    let rank = |a: &(usize, f64), b: &(usize, f64)| b.1.total_cmp(&a.1).then(a.0.cmp(&b.0));
    let cohort = shape.batch.min(shape.tokens);
    if (1..order.len()).contains(&cohort) {
        order.select_nth_unstable_by(cohort - 1, rank);
        order.truncate(cohort);
    }
    order.sort_unstable_by(rank);
    frontier.clear();

What goes: one copy of the preamble; one ordered_cohort helper serves both call sites (both already have full, base, limits, order, frontier in scope at rounds.rs:776-783 and :1006-1014). ~10 lines, and one fewer place for the comparator to drift (the same comparator also exists at utility.rs:181).

Separately, helios/src/scheduler/rounds.rs:920-926:

let mut probabilities = vec![Vec::new(); REQUEST_LANES];
for &slot in &copy_available {
    let curve = copy_curves[slot].get_or_insert_with(|| self.wide_copy_curve(request, optimistic));
    probabilities[slot] = curve.clone();
}

clones an entire completion_token_capacity-1-length curve per wide copy shape per plan. build_host_prefix_ranking (rounds.rs:505-527) only reads probabilities[slot][position], and HostPrefixRanking.probabilities is only read as a slice (rounds.rs:781, :816, :841), so borrowing the curve (or building the ranking from the cached copy_curves plus a slot map) removes the clone — a per-plan allocation removal rather than a line-count win, ~2 lines.

Why nothing is lost: identical iteration order, identical ranking. Finding 3's base_zero correction is compatible (checked against rounds.rs:1007-1075).

3. Nit — about 14 lines: three accumulators re-derive ValueRate::new(0, expected, _)

Where: helios/src/scheduler/utility.rs:122-131 — ValueRate::new(duration_ns = 0, expected_value, _) sets score = expected_value. Then:

What goes: base_zero, pending_value_zero and the second lane_value(..., 0, …) pass. What replaces it: compute expected once where the candidate is built, and in compare_refresh (policy.rs:1349-1354) compare the stored values directly — a.expected.total_cmp(&b.expected) — instead of constructing two zero-duration ValueRates (both durations are 0, so the leading ordinal in ValueRate::compare, utility.rs:134-139, is a tie and the result is identical).

Why nothing is lost: duration_ns + expected already determines the rate (utility.rs:122-139); the extra accumulators compute the same number by hand. Keeping expected on Candidate is right — it is the real second quantity for refresh ranking — only the duplicated rate arithmetic goes. This also drops one powered_curve/lane_value pass per mixed resized plan.

4. Nit — about 20 lines: code this PR left with no production caller

All verified by grep at head e5a69669:

What replaces them: the tests re-point at request_history_proposal / lookup_with_match_len; the None arm goes. Why nothing is lost: the ring behaviour stays reachable as the SAM fallback path, so the pre-existing coverage the tests exercise is unchanged.

5. Nit bundle — about 25 lines


What I deliberately did not flag (checked in code, keep)

Open questions / limits