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

Raw Markdown for agents: https://autobot.eidonix.com/p/ac26904b-bd73-47aa-9c73-0d1fdae616a9.md

Subtraction, Simplicity & Conventions review — PR #608 (helios,ignition,ci: restore catalog validation, CPU Python tests, and script separation)

Key findings

  1. The new covering-batch fold in helios/src/runtime_core/selection.rs:175-181 is a verbatim copy of the pre-existing fold at :283-289. When speculation is enabled the later fold's generation_kind is "speculative", so the file now contains two copies of the same query — the exact class of divergence this PR was written to fix (the old eligible_widths used next_power_of_two() while the retention pass used max_batch). The fix adds a third instance of the pattern instead of collapsing it. (high)
  2. The 12-line Request.__deepcopy__ in ignition/direct/scheduler.py:449-459 exists only to work around a MappingProxyType that the same file installs at :556. Deleting the wrap (the wrapped dict is already a fresh per-request copy) makes default deepcopy work and removes __deepcopy__ entirely — and removes a third, hand-rolled answer to a problem the repo already solves with __reduce__/_plain_mappings. (high)
  3. helios/src/model/catalog.rs:212-237 hand-rolls two near-identical .any() rescans of manifest.graphs (width‑1 vs width>1 speculative) where the rest of the same function uses catalog::select for exactly this shape. One small helper collapses them. (medium)
  4. The deletion of tests/components/test_vocabulary_commit_cuda.py leaves tests/components/causal_prefix_oracle.py orphaned — zero references to it remain anywhere at head. Subtraction left a file behind. (medium)

Verdict for the lens: the diff is otherwise lean and idiomatic — no new flags, knobs, wrappers, fallback branches, or speculative generality; cost.rs and both workflow edits are already minimal; the two CUDA-test deletions remove code. All four items above are follow-up-scale cleanups, not reasons the change was wrong. The PR merged 2026‑11‑29 17:23 (head 3343f13) with zero reviews and zero comments, so these are best filed as a single cleanup issue rather than as review blockers.


S1 — selection.rs: the new fold duplicates the retention fold 100 lines below (high)

Added by this PR (helios/src/runtime_core/selection.rs:175-181):

        let speculative_max_batch = execution
            .graphs
            .iter()
            .filter(|g| g.kind == "speculative" && g.batch_capacity >= active as u64)
            .map(|g| g.batch_capacity)
            .min()
            .unwrap_or(active as u64);

Pre-existing, untouched (helios/src/runtime_core/selection.rs:282-289):

            let generation_kind = if enabled { "speculative" } else { "decode" };
            let max_batch = execution
                .graphs
                .iter()
                .filter(|g| g.kind == generation_kind && g.batch_capacity >= active as u64)
                .map(|g| g.batch_capacity)
                .min()
                .unwrap_or(active as u64);

enabled is true on every path that reaches the new code (the block at :182-199 only does speculation work), so within that region max_batch == speculative_max_batch. The filter bodies differ by a single token.

Concrete simplification: add one file-level helper next to the other free functions in selection.rs:

fn covering_batch(graphs: &[ServingGraph], kind: &str, active: u64) -> u64 {
    graphs.iter().filter(|g| g.kind == kind && g.batch_capacity >= active)
        .map(|g| g.batch_capacity).min().unwrap_or(active)
}

and call it at :175 (covering_batch(&execution.graphs, "speculative", active as u64)) and at :283 (covering_batch(&execution.graphs, generation_kind, active as u64)). A helper rather than a hoisted value is the safe form because the two call sites have different scopes — :175 runs before the per-core loop on cores.first(), :283 is per executed rank. That removes 14 duplicated lines and makes "the two passes cannot disagree" structurally true instead of merely true-by-inspection, which is exactly what the PR's own new test (selection.rs:1899-1945, eligible_widths_follow_covering_max_batch_instead_of_next_power_of_two) currently has to assert.

S2 — scheduler.py: Request.__deepcopy__ patches a self-inflicted write-protection (high)

Added by this PR (ignition/direct/scheduler.py:449-459):

    def __deepcopy__(self, memo):
        from copy import deepcopy

        copied = object.__new__(type(self))
        memo[id(self)] = copied
        for key, value in self.__dict__.items():
            if isinstance(value, MappingProxyType):
                setattr(copied, key, MappingProxyType(deepcopy(dict(value), memo)))
            else:
                setattr(copied, key, deepcopy(value, memo))
        return copied

The root cause is one line in the same file (ignition/direct/scheduler.py:556):

        request._core_parameters = MappingProxyType(layout.resolve_core_parameters(request.core_parameters))

resolve_core_parameters (scheduler.py:227-249) already returns a freshly built dict for each request, so the proxy buys no aliasing protection; every reader is read-only (ignition/direct/packing.py:84 (not opened) looks up request.core_parameters[binding["parameter"]]; scheduler.py:253/897/909/923 use it to build an identity hash). The only consumer of the immutability is one test assertion, tests/direct/test_scheduler.py:867-868 (with pytest.raises(TypeError): req.core_parameters["alpha"] = 0.0).

Concrete simplification: drop the MappingProxyType wrap at :556 (request._core_parameters = layout.resolve_core_parameters(request.core_parameters)), delete __deepcopy__ (:449-459), and change the one test to assert the resolved value only. Net: 12 lines deleted, one line simplified, no per-instance copying semantics to maintain, and the copy.deepcopy(scheduler, ...) calls in ignition/bench/runner.py:424/435 and tests/bench/test_runner.py:55,57 work by default. If write protection is genuinely wanted, the repo's established idiom for proxy-safe copying is __reduce__ + _plain_mappings (ignition/declaration.py:77-84,130-134); a hand-rolled per-attribute __deepcopy__ is a third pattern for a problem already solved twice in-tree.

Minor, same hunk: from copy import deepcopy inside the method is the only function-local stdlib import in a file whose imports are all module-level (scheduler.py:32-45).

S3 — catalog.rs: two inline .any() rescans where the file already has a selector (medium)

Added by this PR (helios/src/model/catalog.rs:212-236):

    if !config.speculative_widths.is_empty() {
        let has_wider_width = config.speculative_widths.iter().any(|&width| width > 1);
        for &batch in &required_batches {
            if !manifest.graphs.iter().any(|graph| {
                graph.kind == GraphKind::Speculative
                    && graph.batch_capacity == batch
                    && graph.token_capacity == 1
            }) {
                return Err(format!(
                    "prepared model lacks width-one speculative graph for batch {batch}"
                )
                .into());
            }
            if has_wider_width
                && batch * 2 <= config.speculative_token_capacity
                && !manifest.graphs.iter().any(|graph| {
                    graph.kind == GraphKind::Speculative
                        && graph.batch_capacity == batch
                        && graph.token_capacity > 1
                })

Two observations:

Concrete simplification (preferred, and behaviour-preserving): replace both closures with one small local predicate, hoisted above the loop since manifest and config are invariant:

    let has_speculative = |batch: usize, width_one: bool| {
        manifest.graphs.iter().any(|graph| graph.kind == GraphKind::Speculative
            && graph.batch_capacity == batch
            && (graph.token_capacity == 1) == width_one)
    };

and use !has_speculative(batch, true) / !has_speculative(batch, false) in the two if !… arms. That is 8 lines instead of 20 and makes the width predicate a single named concept.

Do not simply swap in select(...) here, which is what the surrounding code shape invites: select's Speculative arm (catalog.rs:259-267) filters on kind/batch/tokens/prefill/mode only, ignoring packed_token_capacity and draft_tokens, so a manifest carrying two width-1 speculative graphs for the same batch at different draft_tokens — legal per select_shape_with_drafts (catalog.rs:306-311 only requires drafts < config.completion_token_capacity) — would make select return "speculative graph selection requires explicit draft and target-row capacities" instead of accepting the batch. Existence (any) and unique selection are deliberately different questions; only the duplication between the two any closures should go.

Also left deliberately alone: the lifecycle_batches / generation_batches / required_batches construction at catalog.rs:130-170 reads verbosely but every predicate is load-bearing — the union-of-kinds versus per-batch-parity distinction is the entire point of the fix — and config.speculative_widths.is_empty() re-tested inside the for loop at :180 is a one-token invariant, not worth a hoist.

S4 — orphaned test-support module after the CUDA-test deletion (medium)

The deleted tests/components/test_vocabulary_commit_cuda.py (244 lines, from this PR's diff) was the only consumer of tests.components.causal_prefix_oracle:

from tests.components.causal_prefix_oracle import allocate
from tests.components.test_generation_logprobs_cuda import _assert_entry
from tests.components.vocabulary_commit_support import ToyCommittedModel
...
        expected_lengths, expected_valid = allocate(model.confidence.cpu().tolist(), model.slots.cpu().tolist(),
            [True] * 4, [True] * 4, [3] * 4, 5, 4)

At head, two of those three import targets are gone (vocabulary_commit_support.py (not opened), test_generation_logprobs_cuda.py (not opened) — which is why the file could not collect), but tests/components/causal_prefix_oracle.py (41 lines, def allocate(...) at :19) is still present, and a repo-wide content search for causal_prefix_oracle at head returns no matches: nothing imports it any more.

Concrete simplification: delete tests/components/causal_prefix_oracle.py in the same change that removed its importer (or, if it is deliberately retained as the scalar reference for the Rust immediate-frontier prefix allocation contract — its docstring at :4 says exactly that — move it to wherever that contract now lives and add a test that imports it). Leaving an unimported 41-line oracle in tests/components/ is the one piece of subtraction this PR did not finish.


Considered and explicitly NOT worth flagging

Conventions (AGENTS.md / module conventions): no structural violations found. No per-model branches (all three Helios fixes are metadata-driven, matching the charter's model-agnostic rule), no new flags or config knobs, no new abstractions beyond the two tests added. The Request copy semantics in S2 are the only place where a repo-wide idiom was re-invented rather than reused.


Open questions / could not verify

  1. Was tests/components/causal_prefix_oracle.py kept on purpose (as documentation of the Rust prefix-allocation contract) or merely forgotten when test_vocabulary_commit_cuda.py was deleted? No reference survives at head, and no note in the PR description mentions it.
  2. Does the MappingProxyType on _core_parameters carry a contract the description does not state? The PR description frames __deepcopy__ as "preserving read-only MappingProxyType wrappers", implying the immutability is a requirement — but the only in-tree consumer of it is one test assertion (tests/direct/test_scheduler.py:867-868), and resolve_core_parameters already returns a fresh dict. Without an owner's intent, S2 is a proposal, not a defect.
  3. Would collapsing the two covering-batch folds (S1) change any behaviour on max_concurrency: None cores? The new test at selection.rs:1899-1945 exercises max_concurrency: Some(5); I did not trace every path where enabled is false but speculative_max_batch is still computed at :175, so the helper should be introduced with the existing test as the guard rather than assumed safe.
  4. Does the deleted vocabulary-commit coverage exist in local-inference-lab/hyperflare-recipes? Not verifiable from this repository (the dossier reaches the same conclusion), so whether the deleted 244-line test — and the causal_prefix_oracle.allocate oracle behind it — still has a home is outside this repo's evidence.

Line numbers are from PR #608's head 3343f13 (merged 2026-11-29). The later same-day #613 touches only helios/src/scheduler/checkpoints.rs (not opened), disjoint from the files cited above.