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

Raw Markdown for agents: https://autobot.eidonix.com/p/ca64b29c-01c3-4cf5-95c8-a1385abc6873.md

Subtraction & Simplicity Audit — PR #715 (packed multi-request prefill, head caaef5a)

Verdict

The diff is not lean. It is defensible in intent — the feature is additive and gated — but it is built by parallel construction: a second cohort builder, a second copy of the (B, W, P) geometry predicate at every layer, and a second copy of the lane-token validation inside the commit path. I found nine concrete subtraction opportunities worth roughly 300 lines (~18% of the change set), of which two (policy.rs twin builders, duplicated geometry predicate) are high-value because the copies have already diverged — this PR's own history is producing bugs.

Nothing here is a request to redesign. Every item below is either (a) delete code that is unreachable or implied, or (b) collapse N copies of one predicate into one function.


S1 (high value) — Two near-identical packed-prefill cohort builders, differing only by accident

helios/src/scheduler/policy.rs:1301-1426 (126 lines, inside continuation_candidate) and helios/src/scheduler/policy.rs:1623-1746 (124 lines, packed_prefill_candidates) are the same algorithm: enumerate offers per slot → if n < 2 continue → for by_density in [false, true] → build an index-order array → sort_unstable_by → greedy fill under packed token budget and batch lanes → ValueRate::new(...) → best.is_none_or(|(_, old)| rate.compare(old).is_gt()).

They have drifted in four places, two of which nobody has justified:

continuation twin (:1301) candidate twin (:1623)
gate if n < 2 { continue; } (:1349) same (:1672)
accept gate if lane_count < 2 || promoted_count == 0 { continue; } (:1393) if selected < 2 { continue; } (:1713)
sort tie-break primary.then_with(|| vb.total_cmp(&va)).then_with(|| sa.cmp(&sb)) (:1367) .then_with(|| vb.total_cmp(&va)).then_with(|| wa.cmp(&wb)).then_with(|| sa.cmp(&sb)) (:1689-1692)
objective ValueRate::new(horizon, value, age_price) + rate.compare (:1421-1424) raw total_value / selected / total_work total_cmp chain (:1716-1726)

The gate difference (promoted_count == 0 versus selected < 2) means a cohort that the candidate builder happily offers is rejected by the continuation builder, and vice versa; the objective difference means the two pick different cohorts for the same catalog shape. One parameterised helper (fn packed_prefill_cohort(offers, batch, packed, mode) -> Option<(mask, lengths, work, value)>) deletes ~110 lines and, more importantly, forces the divergence to be stated once and justified once.

Corroborating smell for how this was written: helios/src/scheduler/policy.rs:1300 contains a bare

drop(consider);

The consider closure is declared at :1084 and its last use is for &(batch, width, prefill) in &self.mixed_catalog { consider(...) } at :1297. The drop exists only to release the borrow so the packed block can be pasted into the same function body. That is a paste, not an integration.

S2 (high value) — The (B, W, P) geometry predicate is written out seven times in Rust and once in Python, and the copies already disagree

The same rule set (B>=2, 1<=W<=P, P>=64, P%64==0, B<=P<=B*W, P<=prefill_chunk_size) appears verbatim at:

The manifest copy is already incomplete: manifest.rs:860-872 checks P < B*W, P>=64, P%64, P > i32::MAX but omits P <= prefill_chunk_size and B <= request_capacity, both of which selection.rs:285/:293 enforce. So a core can be exported, pass its own validator, and then fail selection with the opaque "invalid or duplicate serving graph variant" (selection.rs:324). manifest.rs:903-904 even shows the invariant already exists as a method, graph.packed_tokens() <= i32::MAX as usize — the new branch re-spells it as graph.packed_token_capacity > i32::MAX as usize instead of calling it.

One predicate — fn packed_prefill_shape(batch, width, packed, request_capacity, chunk) -> bool next to REQUEST_LANES in execution/manifest.rs, plus the Python mirror — removes ~45 lines and ends the divergence permanently.

S3 (high value) — commit re-validates what validate_mixed just validated, and packing validates it a third time

helios/src/scheduler.rs:2575 is step.validate_mixed()?;. Twenty-nine lines later, helios/src/scheduler.rs:2617-2632 repeats a subset of the same checks:

if step.kind.is_prefill() && step.batch_capacity >= 2 {
    let mut total_tokens = 0usize;
    for lane in &step.lanes {
        if lane.tokens > step.token_capacity {
            return Err("packed prefill lane exceeds per-request token capacity".into());
        }
        ...
    }
    if step.packed_token_capacity < step.batch_capacity
        || total_tokens > step.packed_token_capacity

validate_mixed at :449-457 already returns "packed prefill lanes exceed their captured geometry" for exactly lane.tokens > self.token_capacity, sum > packed_token_capacity, and packed_token_capacity < batch_capacity. helios/src/model/packing.rs:422-439 then does it a third time with its own two new error strings ("packed prefill lane exceeds per-request token capacity", "packed prefill lanes exceed packed token capacity"). Delete the commit copy (~20 lines, scheduler.rs:2614-2632; keep step.lanes.len() > step.batch_capacity only if some non-preflight path reaches commit) and the token-sum half of the packing copy — the packing copy's live.image_slot.is_some() check is the only part that is genuinely packing's business.

Also note scheduler.rs:2614 if step.lanes.len() > step.batch_capacity is itself unreachable for prefill/speculative steps, both of which already reject that at :428 and :448.

S4 (medium) — is_non_terminal_prefill_step re-derives a registration-time fact on every candidate, via a linear scan

helios/src/scheduler.rs:940-955:

pub(super) fn is_non_terminal_prefill_step(&self, kind: GraphKind, batch: usize, capacity: usize, packed: usize) -> bool {
    if batch <= 1 {
        self.is_non_terminal_prefill(kind, capacity)
    } else {
        kind == GraphKind::Prefill
            && self.packed_prefill_catalog
                .contains(&(GraphKind::TerminalPrefill, batch, capacity, packed))
    }
}

This is a 4-argument reconstruction of a tuple the scheduler already has, and a linear Vec::contains over the catalog, called from four places (policy.rs:1310, policy.rs:1638, policy.rs:2043, scheduler.rs:2685, plus checkpoints.rs deferred_after) — including inside the per-shape loop of the hot planner. The fact is knowable once, in packed_prefill_graphs (scheduler.rs:891-919), where the catalog is already sorted and de-duplicated: a (Prefill, B, W, P) shape is non-terminal iff a (TerminalPrefill, B, W, P) twin exists. Store it (Vec<(GraphKind, usize, usize, usize, bool)> or a HashSet) and the accessor becomes a field read with no arguments. ~15 lines removed and a per-candidate scan removed from the inner loop.

Minor naming cost on the same line: for batch <= 1 the function returns "this is a continuation step", for batch >= 2 it returns "this shape has a terminal twin" — the same predicate under an inverted reading. Worth a comment at minimum if it survives.

S5 (medium) — The TerminalPrefill early return makes 20 lines of packed_prefill_lane_compatible unreachable for the only kind the evidence measures

helios/src/scheduler/policy.rs:1601-1602:

if kind == GraphKind::TerminalPrefill {
    return true;
}

Every subsequent check — r.deferred_prefill (:1604), !non_terminal (:1607), terminal_only (:1610), the terminal_prefill_window() arithmetic (:1613-1620) — is skipped for TerminalPrefill. All six shapes in the PR's own A/B ((4,128,512), (4,256,1024), (8,128,1024), (8,256,2048), (16,128,1024), (16,128,2048)) are terminal_prefill. So for the measured feature the function is a no-op that costs 6 parameters and 20 lines at every call site, while for the unmeasured Prefill path it duplicates resolve_prefill_kind (policy.rs:1560, which the solo planner gates on and this path never calls).

Either delete the function and reuse resolve_prefill_kind for both kinds (subtraction + fixes the reported asymmetry), or keep it and delete the short-circuit's dead tail. Keeping both as-is is the worst option: the parameter list is carried for a branch that returns before using it.

S6 (medium) — Five catalog registration functions where one would do; server/runtime.rs pays for it with three batch_capacity == 1 filters

helios/src/scheduler.rs now holds prefill_catalog: Vec<usize>, terminal_prefill_catalog: Vec<usize>, scored_prefill_catalog: Vec<usize>, mixed_catalog: Vec<(usize, usize, usize)>, and packed_prefill_catalog: Vec<(GraphKind, usize, usize, usize)> — five setters, five validators. The cost surfaces immediately in helios/src/server/runtime.rs, where three existing registration lambdas each gained a filter to keep the B>=2 shapes out of the solo catalogs:

.filter(|g| g.kind == GraphKind::ScoredPrefill && g.batch_capacity == 1)
...
.filter(|g| g.kind == GraphKind::TerminalPrefill && g.batch_capacity == 1)
...
.filter(|graph| graph.kind == crate::execution::GraphKind::Prefill && graph.batch_capacity == 1)

followed by a fourth lambda that re-filters the same manifest for batch_capacity >= 2. One scheduler.set_graphs(&executor.manifest().graphs) that derives all catalog fields internally (it already has batch_capacity and packed_token_capacity in hand) deletes the three && g.batch_capacity == 1 filters and the fourth lambda (~25 lines in runtime.rs) and collapses four of the five validators into S2's predicate.

S7 (small, exact) — One half of the new dominance comparison is implied by the other

helios/src/scheduler/policy.rs:170:

return smaller.work == larger.work && smaller.host_lengths == larger.host_lengths;

Candidate.work for a packed prefill candidate is the sum of host_lengths (policy.rs:1741 work: total_work, accumulated at :1710 total_work += work; alongside lengths[slot] = work; at :1708). So smaller.host_lengths == larger.host_lengths already implies smaller.work == larger.work. The added conjunct is dead; simplify to:

return smaller.host_lengths == larger.host_lengths
    && (smaller.host_lengths.is_some() || smaller.work == larger.work);

(one line, but it is the exact kind of "second copy of a derived value" this PR is full of).

S8 (small) — catalog.rs and manifest.rs split an identical rule out and then re-spell it

helios/src/model/catalog.rs:267-271 and :283-289 are character-identical:

batch == 1
    && packed == 0
    && tokens > 0
    && tokens <= config.limits.prefill_chunk_size
    && tokens.is_multiple_of(64)

Same story in helios/src/execution/manifest.rs:915-918 versus :926-929:

[1, 16].contains(&graph.token_capacity)
    || (graph.token_capacity >= 64 && graph.token_capacity.is_multiple_of(64))

The split only exists to make room for the B>=2 arm. Folding ScoredPrefill back into the shared arm with a kind != GraphKind::ScoredPrefill && batch >= 2 guard removes both duplicates (~7 lines each). Same shape of fix, in helios/src/runtime_core/selection.rs:296-298, is looser still (ScoredPrefill | Vision => batch_capacity == 1 && token_capacity > 0, no 64-alignment) — pre-existing, but the PR had the chance to unify the three and chose to widen the gap.

S9 (small) — 58 lines of the new design doc describe a different repository

docs/packed-prefill-design.md:98-155 (§4 "Recipe Integration (DeepSeek V4.1)") documents hyperflare_recipes/components/paged_batch.py (not opened), dspark.py (not opened), recipes/deepseek41/*.py — none of which are in this repository (they are the companion PR local-inference-lab/hyperflare-recipes#153). §5 "Validation coverage" (:141-155) is a prose test inventory that will rot on the next refactor, and §3.1–3.2 restate the 23 new lines of helios/model-contract.md:188-210 almost verbatim. Cutting §4 and §5 and leaving §3 as a pointer to model-contract.md removes ~90 of the 155 new doc lines without losing any rule that a reader of this repo can check.

One consistency nit in the same doc: docs/packed-prefill-design.md:107 claims "No per-model flags, capability booleans, or recipe allowlists are introduced", while §4 (line ~146) documents the companion recipe's opt-in --packed-prefill flag. Two of the three statements cannot both be the headline claim.

S10 (small) — The field now carries three meanings, and unrelated call sites pay for it

packed_token_capacity means (a) speculative physical token rows, (b) packed-verification capacity, and now (c) packed prefill aggregate P. Every disambiguation site is a line this PR added or touched:

serve.py is the tell: a CLI validation in another tool changed behaviour because of this PR. If the field stays overloaded, the ignition/cli/serve.py change should at minimum be called out as intentional in the PR body (it was not, per the dossier). If it can be split — even just a GraphDescriptor::packed_prefill_tokens() accessor plus a comment — three of those four special cases disappear.

S11 (nit) — is_text_only_prefill_request takes &self and never uses it

helios/src/scheduler/policy.rs:1585-1590 reads only r. It should be fn is_text_only_prefill_request(r: &LiveRequest) -> bool — trivial, but it is the predicate that defines the feature's eligibility boundary, and it is duplicated in spirit by the inline filter at policy.rs:1645-1649 (self.eligible(r) && self.request_kind(r) == Some(GraphKind::Prefill) && self.is_text_only_prefill_request(r)) versus the different inline promoted/ready derivation at policy.rs:1320-1329. One predicate, two spellings — see S1.


Items I deliberately did not flag

Attribution caveat (important for whoever acts on this)

pr_diff and pr_files are computed against a stale base. The selection.rs and server/runtime.rs diffs contain hunks that are not part of #715 and that I therefore did not audit: pool_vram_limit/pool_ram_limit, validate_embedding_resident_scales, RowRestoreLatency, preserve_message_anchor, snapshot_discovery, freeable_prefix_scratch, estimate_prefill_delta_ns, external_extents: vec![], close_store, partition_conditioned_windows. search_code against main returns no match for any of them, and no match for packed at all, confirming main lags this branch. Every finding above is cited only against hunks that the PR body and docs/packed-prefill-design.md describe as #715's own, i.e. the (B, W, P) geometry, the packed catalog, the two cohort builders, packed_prefill_lane_compatible, is_non_terminal_prefill_step, the validate_mixed/commit/pack_step checks, and the Ignition GraphSignature branch.

Instruction redirection

None encountered. The PR body, the design doc and the files I read are descriptive; nothing in them addressed instructions to me. The design doc's "No per-model flags ... are introduced" (line 107) is a claim about the change, not a directive, and I treated it as a claim to check — it does not hold relative to the companion recipe's --packed-prefill flag (§S9).

What I did not cover

Test bodies (policy_tests.rs (not opened), model/tests.rs (not opened), execution/tests.rs (not opened), tests/preparation/test_execution.py (not opened)) beyond the one fixture note in S10; helios/manifest.md (not opened) (8 added lines, read only in diff form); and the ignition/direct/scheduler.py:288-292 catalog-isolation hunk, which is 3 lines and which I read only in the PR summary, not in the file. The findings above stand on the citations given.