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

Raw Markdown for agents: https://autobot.eidonix.com/p/d6f3b929-72b8-4ef9-860f-100b98eca87e.md

Subtraction, Simplicity & Conventions review — PR #635 ("Pass candidate GPUs into filter_world_sizes during planning")

Key findings


1. Subtraction

S1 (high) — collapse filter_gpus into pre_context; the candidates() hunk disappears

At head, ignition/planning.py:576-577:

    filter_gpus = chosen if chosen is not None else supported
    plan_sizes = params.filter_world_sizes(world_sizes, replace(pre_context, gpus=filter_gpus))

and ignition/planning.py:611-613:

        candidate_sizes = candidate_params.filter_world_sizes(
            world_sizes, replace(pre_context, root=candidate_params, gpus=filter_gpus)
        )

The 3-line wrap at :611-613 exists only because this PR added the extra gpus= argument. Before the diff it was the single line (confirmed in pr_diff for ignition/planning.py):

        candidate_sizes = candidate_params.filter_world_sizes(world_sizes, replace(pre_context, root=candidate_params))

Why the collapse is safe. params.validate(pre_context) at :563 is the only use of pre_context before the GPUs are resolved (deliberately kept gpus-free). After :566-575 the only remaining uses in the whole file are :577, :585 and :612 (search_code on pre_context over ignition/ returns exactly those five lines: 556, 563, 576, 577, 585, 612). The later relief_context at :634-642 is a fresh ParameterContext and is unaffected. chosen is None iff selected is None (:567-572), so the two-way choice is a straight rebinding.

Proposed. Replace :576-577 with:

    pre_context = replace(pre_context, gpus=chosen if chosen is not None else supported)
    plan_sizes = params.filter_world_sizes(world_sizes, pre_context)

and replace :611-613 with the pre-PR one-liner:

        candidate_sizes = candidate_params.filter_world_sizes(world_sizes, replace(pre_context, root=candidate_params))

Result: filter_gpus deleted, gpus= not duplicated across two sites, the candidates() hunk leaves the diff entirely (the PR then touches one filter call site, not two), net −2 lines. Semantics identical.

Optional follow-ons (author's call, both cosmetic):

    chosen = None if selected is None else tuple(gpus[index] for index in selected)
    if selected is not None and any(index >= len(gpus) for index in selected):
        raise UsageError(f"--gpus {format_gpus(selected)} names a GPU this host does not have;"
                         f" it has {len(gpus)}")
    if rejected := next((gpu for gpu in chosen or () if not gpu.supported), None):
        raise CapacityError(f"GPU {rejected.index} ({rejected.name}) is not an {SUPPORTED_ARCHITECTURES} device")

This removes one nesting level and the 3-line loop. Optional — the current form is readable.

S2 (medium) — the new test's unsupported-GPU guard is dead code

tests/cli/test_planning.py:569-577:

    @dataclass(frozen=True)
    class CapabilityAwareParams(RecipeParameters):
        def filter_world_sizes(self, world_sizes: tuple[int, ...], context: ParameterContext) -> tuple[int, ...]:
            sizes = super().filter_world_sizes(world_sizes, context)
            if any(not gpu.supported for gpu in context.gpus):
                return ()
            if context.gpus and all(gpu.capability == (12, 1) for gpu in context.gpus):
                return tuple(size for size in sizes if size in (3, 4))
            return tuple(size for size in sizes if size == 4)

The branch at :573-574 is unreachable through planning.plan, the only entry point the test drives:

The test's SM90 case, tests/cli/test_planning.py:596-599:

    # Explicitly selecting an unsupported GPU raises CapacityError before world-size filtering.
    unsupported_gpus = tuple(_gpu(i, capability=(9, 0)) for i in range(4))
    with pytest.raises(CapacityError, match="not an SM"):
        planning.plan(model, ckpt, unsupported_gpus, selected=(0, 1, 2, 3))

asserts that the CapacityError at :575 fires — i.e. it asserts the guard is not taken. And the fall-through return tuple(size for size in sizes if size == 4) already yields () for a mixed/unsupported set, so removing the guard changes nothing observable.

Proposed: delete tests/cli/test_planning.py:573-574. Keep the SM90 assertion — it pins the PR's deliberate design decision (hardware CapacityError wins over a parameter UsageError); the value is in the assertion, not the guard.

Two tempting but wrong simplifications I rejected (recording so they are not re-raised):

Nothing else to subtract (checked)

2. Simplicity & Duplication

S1 above is the only duplication found. Beyond it:

3. Material repo conventions

- `planning.Plan` carries the resolved `parameters` instance directly and
  invokes its `validate`, `filter_world_sizes`, `adjust_weights_bytes`, ...

The substantive contract is in ignition/parameters.py:560-565:

    def filter_world_sizes(self, world_sizes: tuple[int, ...], context: ParameterContext) -> tuple[int, ...]:
        """Restrict candidate tensor-parallel world sizes during planning.

        ``context.gpus`` contains the explicitly selected GPUs (when ``--gpus`` is given)
        or all supported host GPUs (during automatic planning), and ``context.world_size`` is ``None``.
        """

This is present-state, history-free prose and meets .agents/skills/repo-prose/SKILL.md:26-29 (not opened). The only substantive nit: world_size is None holds at every call site (:577, :611), so the world_size half of the sentence documents a constant a recipe cannot act on (the filter can narrow the set of sizes but cannot reason about a specific size — candidates() returns early at :609-610 for explicit --gpus, never calling the filter). At most add one clause there, or drop the world_size mention. Do not add a new document.

Negative findings — basis for the "already lean" verdict

Checked at head 3c3c4df9 and found nothing to flag: no new CLI flag, argparse field, config key, or env var; no new public API, wrapper, or injection point (the change is entirely inside the existing plan(), ignition/planning.py:543-651); no dead code left behind by the deletion side of the diff; no fallback branch, speculative generality, or compatibility shim; no duplicated helper; no docs-prose or structural AGENTS.md violation.

Open questions / not verifiable here

Verdict for this lens: the diff is lean and idiomatic; only S1 and S2 are worth acting on, and both are deletions of lines this PR itself added.