Correctness and contracts report · NVIDIA/hyperflare-inference #635

Raw Markdown for agents: https://autobot.eidonix.com/p/9fd41a07-9b9e-4d14-804d-a90ac422bc98.md

Review: PR #635 — Pass candidate GPUs into filter_world_sizes during planning

Lens: Correctness, Contracts & System-Level Consequences. Head c2ef797, base main, 2 files, +41/−5.

Key findings

  1. Major — explicit --gpus now hands unsupported devices to the filter, pre-empting the architecture diagnostic. filter_gpus = chosen (ignition/planning.py:573) is taken from the raw gpus tuple, while the unsupported-device CapacityError stays below the filter at :587-589. A capability-aware recipe (exactly the shape the PR's own test blesses) returns () and the new empty-plan_sizes UsageError at :575-576 fires instead: wrong cause, and exit 2 instead of exit 4.
  2. Major (same root, contract angle) — the new ordering reverses the intent written in the adjacent comment. ignition/planning.py:580-581 says explicit parameter UsageErrors must surface "before falling back to a generic capacity/GPU-count error"; the empty-size UsageError now sits above that params.validate and above the hardware check it can mask.
  3. Minor — the hook sees two different GPU sets for the same deployment (whole supported host set on automatic, exact selection on explicit — :573 vs :573/:612), and still cannot see world_size, although fit()/Plan.parameter_context pass both. No doc states the semantics (docs/preparation-development.md:32-36).
  4. Minor — undisclosed error-precedence swap vs main: the out-of-range --gpus UsageError moved above the empty-plan_sizes UsageError (main:566-568, 573-575 → head :568-576). Both exit 2, so message-only, but the description's "moved … explicit --gpus bounds checks ahead of" implies all --gpus validation moved, which is what makes finding 1 possible.
  5. Minor — test coverage gaps: no unsupported-explicit-GPU case (the two user-facing strings have zero repo-wide test coverage), the second call site (:611-613, relief path) is untested for the new argument, multi-host topology_gpu untested (disclosed), and no CI ran on c2ef797.
  6. Sound, no findings: no concurrency/hot-path/memory/blast-radius surface (plan() is CLI setup only), backward compatible, no owner sign-off contract triggered, right architectural layer per the charter, no metric/rate-span change, platform-neutral.

Area 2 & 1 — Unintended system-level consequences, ordering and safety

1. Major — unsupported explicitly selected GPUs reach filter_world_sizes, masking the architecture CapacityError

ignition/planning.py:566-576 (PR head, verified):

    supported = [gpu for gpu in gpus if gpu.supported]
    chosen = None
    if selected is not None:
        if 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)}")
        chosen = tuple(gpus[index] for index in selected)
    filter_gpus = chosen if chosen is not None else tuple(supported)
    plan_sizes = params.filter_world_sizes(world_sizes, replace(pre_context, gpus=filter_gpus))
    if not plan_sizes:
        raise UsageError(f"no supported tensor-parallel size remains for {checkpoint.alias} with the selected parameters")

And the check that is now unreachable for such a recipe — ignition/planning.py:587-589:

        for gpu in chosen:
            if not gpu.supported:
                raise CapacityError(f"GPU {gpu.index} ({gpu.name}) is not an {SUPPORTED_ARCHITECTURES} device")

Gpu.supported is self.capability in SUPPORTED_CAPABILITIES where SUPPORTED_CAPABILITIES = ((8, 7), (10, 3), (11, 0), (12, 0), (12, 1)) (ignition/planning.py:37, 51-53). So an SM89/SM90 device is not supported, yet on the explicit path it is handed to the recipe's filter verbatim; on the automatic path the same device is filtered out by tuple(supported) (:573).

The new test's filter is precisely the capability-aware shape that converts this into a mask, tests/cli/test_planning.py:571-575:

        def filter_world_sizes(self, world_sizes: tuple[int, ...], context: ParameterContext) -> tuple[int, ...]:
            sizes = super().filter_world_sizes(world_sizes, context)
            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)

For context.gpus == (SM89,) the all(...) is False and any world size the recipe restricts to SM121 collapses; if super() is also narrowed (the real recipes in this space restrict TP entirely per architecture), plan_sizes is () and :576 raises.

Impact (concrete, one command): ignition export MODEL --gpus 0 on a single unsupported device changes from GPU 0 (<name>) is not an SM87, SM103, SM110, SM120, or SM121 device (CapacityError, exit 4) to no supported tensor-parallel size remains for <alias> with the selected parameters (UsageError, exit 2). Exit codes are contract: ignition/errors.py:13-22 (UsageError.exit_code = 2, CapacityError.exit_code = 4) and docs/cli-design.md:1533-1534 ("Preparation exit codes are 0 for success, 2 for usage, 3 for fetch, 4 for capacity, and 5 for preparation"). A user is told their parameters are wrong when their hardware is unsupported, and any script branching on exit 4 stops branching correctly. The automatic path still reports the hardware correctly via :590-591, so the two paths now diagnose the same mismatch differently.

Fix (no API change, no model logic in core): filter what the filter is told — filter_gpus = tuple(gpu for gpu in chosen if gpu.supported) — or, preferably, move the for gpu in chosen: if not gpu.supported loop from :587-589 above the filter_world_sizes call at :574, so the hardware diagnosis wins and filter_world_sizes never sees a device planning itself declares unsupported. Add the missing test: explicit --gpus naming one SM89/SM90 device must raise the architecture CapacityError.

This is bounded to recipes that inspect context.gpus; both in-repo overrides ignore it (tests/cli/test_planning.py:81-85, tests/cli/test_commands.py:55), so no existing test flips — which is also why the hole is invisible today.

2. Major addendum — the ordering contradicts the precedence intent stated in the code

ignition/planning.py:575-586 (verified verbatim):

    if not plan_sizes:
        raise UsageError(f"no supported tensor-parallel size remains for {checkpoint.alias} with the selected parameters")
    sizes = " or ".join(map(str, plan_sizes))
    if chosen is not None:
        if len(chosen) not in plan_sizes:
            # Let parameter validation surface explicit UsageErrors (such as TP restrictions)
            # before falling back to a generic capacity/GPU-count error.
            params.validate(replace(pre_context, gpus=chosen, world_size=len(chosen)))

The comment states the design intent — specific parameter UsageErrors first, generic capacity errors second. The new empty-size UsageError (:575-576) now precedes both that params.validate (:582) and the architecture CapacityError (:587-589). Validated against the existing SM103 guard, which is what that comment protects (tests/cli/test_planning.py:105-106: if any(gpu.capability == (10, 3) for gpu in context.gpus): raise UsageError("--sharded-prefill is not qualified on SM103; …")). That test still passes because SM103 is in SUPPORTED_CAPABILITIES, so its filter returns sizes and :576 does not fire — the guard survives only because the architecture happens to be "supported". Any recipe that expresses "not on this architecture" as a size restriction (the whole point of this PR) gets the generic sentence instead.

Fix: same as finding 1 — resolve supported/chosen, vet the chosen group for unsupported architecture (and run the explicit params.validate when the size is wrong), then call filter_world_sizes with an already-vetted set. That preserves the PR's contribution (GPUs resolved before filtering) without inverting the documented precedence.

3. Minor — asymmetric context.gpus between automatic and explicit planning, and world_size still absent

ignition/planning.py:573 vs ignition/planning.py:611-613 (verified):

    filter_gpus = chosen if chosen is not None else tuple(supported)
...
        candidate_sizes = candidate_params.filter_world_sizes(
            world_sizes, replace(pre_context, root=candidate_params, gpus=tuple(supported))
        )

Fix: add one sentence to docs/preparation-development.md near :32-36 fixing the semantics (all supported host GPUs on automatic planning, the exact --gpus selection otherwise, never a per-candidate subset, world_size is None), and use the same tuple(supported)-filtered set at both call sites unless the asymmetry is deliberate.

4. Minor — error-precedence swap versus main is real but undisclosed, and the PR text overstates what moved

main (ignition/planning.py:565-576, verified at ref=main): the filter and the empty-size UsageError run before the --gpus bounds check.

    plan_sizes = params.filter_world_sizes(world_sizes, pre_context)          # main:566
    if not plan_sizes:
        raise UsageError(f"no supported tensor-parallel size remains for …")  # main:567-568
    sizes = " or ".join(map(str, plan_sizes))
    supported = [gpu for gpu in gpus if gpu.supported]
    chosen = None
    if selected is not None:
        if any(index >= len(gpus) for index in selected):
            raise UsageError(f"--gpus … names a GPU this host does not have;")  # main:573-575

Head order is inverted (:568-576). For an input that fails both ways — --gpus 9 on a 1-GPU host and parameters leaving no size — the user now sees the --gpus message instead of the parameter message. Both are UsageError/exit 2, so impact is diagnostic only. The description's "Pre-GPU params.validate(pre_context) and out-of-range --gpus error behavior are unchanged" is literally true per call but omits the precedence change, which AGENTS.md:88-94 (explicit before/after transition) asks for. The second half — "moved supported GPU filtering and explicit --gpus bounds checks ahead of params.filter_world_sizes()" — reads as if all --gpus validation moved; the unsupported-device check did not, and that gap is finding 1. Fix: state the reordering explicitly and either restore or document the precedence.


Area 3 — Architecture, contracts, charter

No findings. Verified:

Area 2 (concurrency/memory) and metric-span check — sound

plan() is a one-shot CLI setup path only: ignition/cli/preparation.py:70-79 (derive, used by export and _prepare), ignition/cli/serve.py:200 and :422 (debug-serve), ignition/cli/bench.py:186-188. No runtime request path calls it (the unrelated scheduler.plan() in ignition/bench/runner.py:141 (not opened) / ignition/direct/server.py:323 (not opened)). No locks, queues, buffers or allocation amplification are added — one list comprehension and one call move. No stale-state hazard: pre_context is a frozen dataclass built per call (:556-562) and replace(...) at :574/:612 creates fresh instances. No metric/rate/admission span is touched; the {"plan": …} JSON on stderr (ignition/cli/serve.py:440, ignition/bench path) comes from Plan.to_dict() (ignition/planning.py:383-420), which does not include context.gpus and is unchanged. Unix/Windows parity unaffected: Gpu.capability/Gpu.supported are platform-neutral (ignition/planning.py:42-53); the Windows _integrated_memory path only feeds total/free (:76-86).

Area 4 — Tests and claim accuracy

tests/cli/test_planning.py:568-596 (+32/−0, the only test added) covers four cases on synthetic homogeneous tuples:

    sm120_gpus = tuple(planning.Gpu(i, "SM120", f"GPU-{i}", 140 * GIB, 140 * GIB, (12, 0)) for i in range(4))
    sm121_gpus = tuple(planning.Gpu(i, "SM121", f"GPU-{i}", 140 * GIB, 140 * GIB, (12, 1)) for i in range(3))
    assert planning.plan(model, ckpt, sm120_gpus, reserve_bytes=0).world_size == 4
    with pytest.raises(CapacityError, match="needs 4"):
        planning.plan(model, ckpt, sm120_gpus[:3], selected=(0, 1, 2), reserve_bytes=0)
    assert planning.plan(model, ckpt, sm121_gpus, selected=(0, 1, 2), reserve_bytes=0).world_size == 3
    assert planning.plan(model, ckpt, sm121_gpus, reserve_bytes=0).world_size == 3

Gaps, all cheap to add in the file's own idiom:

  1. No unsupported-capability explicit --gpus case — the exact hole in finding 1. Repo-wide search for the user-facing strings finds them only in ignition/planning.py:570, 576 and ignition/cli/serve.py:543; the architecture message (:589) has no test at all, before or after this PR.
  2. Second call site untested for the new gpus= argument (:611-613, reached only on the relief path at :626/:643); all four new plans fit on the first attempt() (140 GiB free, 200 GiB device weights over 3–4 ranks).
  3. Multi-host untested. The only non-synthetic source of context.gpus is the topology path feeding ignition/cli/serve.py:421; no test exercises --ranks planning. The PR discloses the synthetic-GPU limitation honestly, so this is a disclosed gap, but it is the motivating path (docs/TODO.txt:263-267, RoCE TP2/TP3 qualification).
  4. Unverified claim: "CUDA_VISIBLE_DEVICES="" pytest -q tests/cli/test_planning.py passed (7 passed, 0 failed)". The file has exactly seven def test_ functions (tests/cli/test_planning.py:159, 223, 298, 402, 479, 521, 568), consistent, but no CI check ran on c2ef797 although .github/workflows/python-cpu.yml:3-33 (not opened) triggers on pull_request and runs pytest tests/ -q with CUDA_VISIBLE_DEVICES="". I could not run the suite here; the claim is consistent but unverified.

Verdict

The concept and the layer are right — resolve GPUs first, then filter, with policy in the recipe. Do not reject on architecture grounds. Before merge it needs: (a) the filter call to never receive devices planning declares unsupported (fixes findings 1 and 2 and restores the precedence the comment at :580-581 documents), (b) one contract sentence in docs/preparation-development.md, and (c) one test for explicit --gpus naming an unsupported architecture.

Open questions / could not verify