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
- Major — explicit
--gpusnow hands unsupported devices to the filter, pre-empting the architecture diagnostic.filter_gpus = chosen(ignition/planning.py:573) is taken from the rawgpustuple, while the unsupported-deviceCapacityErrorstays 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_sizesUsageErrorat:575-576fires instead: wrong cause, and exit 2 instead of exit 4. - Major (same root, contract angle) — the new ordering reverses the intent written in the adjacent comment.
ignition/planning.py:580-581says explicit parameterUsageErrors must surface "before falling back to a generic capacity/GPU-count error"; the empty-sizeUsageErrornow sits above thatparams.validateand above the hardware check it can mask. - Minor — the hook sees two different GPU sets for the same deployment (whole supported host set on automatic, exact selection on explicit —
:573vs:573/:612), and still cannot seeworld_size, althoughfit()/Plan.parameter_contextpass both. No doc states the semantics (docs/preparation-development.md:32-36). - Minor — undisclosed error-precedence swap vs
main: the out-of-range--gpusUsageErrormoved above the empty-plan_sizesUsageError(main:566-568, 573-575→ head:568-576). Both exit 2, so message-only, but the description's "moved … explicit--gpusbounds checks ahead of" implies all--gpusvalidation moved, which is what makes finding 1 possible. - 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-hosttopology_gpuuntested (disclosed), and no CI ran onc2ef797. - 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))
)
- Automatic: every supported GPU on the host. Explicit
--gpus 0,1,2: exactly those three. On a mixed-capability host (a shape the repo already anticipates —ignition/cli/preparation.py:99-102requires each--tuning-gpusreplica to match "its corresponding serving GPU model and architecture"), anall(gpu.capability == (12, 1) …)predicate like the test's is False for the union, silently pruning the SM121-only size even though the SM121 subset could serve it — andautomatic()(:599-606) cannot segregate by architecture either, so the recipe has no workaround. world_sizeis stillNoneat:574and:611-613, while every later hook receives it:Plan.parameter_context(ignition/planning.py:231-239) andfit()(:469-478) carry bothgpusandworld_size. A recipe cannot ask "is TP3 valid on these GPUs", only "prune the set".- No contract text:
docs/preparation-development.md:32-36listsfilter_world_sizesamong the invoked hooks but says nothing about whatcontext.gpus/context.world_sizehold at that moment, and this PR adds nothing. The stated audience — recipe authors — has nothing to code against.
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:
- Right layer. The policy stays in a recipe
RecipeParameterssubclass through the pre-existing hook;ignition/planning.pygains no model name, flag, or capability branch (charter "Keep the runtime small and model-agnostic";AGENTS.md:382-396puts model policy inlocal-inference-lab/hyperflare-recipes). This is a genuine improvement over the pre-#499/#508 state where capability gating was hardcoded in core. - No owner sign-off triggered. No captured-graph op (
AGENTS.md:376-381), no proto/manifest field, no CLI flag, no dependency pin. - Manifests unchanged.
rebuild_manifest.from_planalready emitsgpus=plan.gpus, world_size=plan.world_size(ignition/preparation/rebuild_manifest.py:303-310), so provenance output is byte-identical. - Backward compatible.
ParameterContext.gpusalready existed with the()default (ignition/parameters.py:130);filter_world_sizes' signature is untouched (ignition/parameters.py:560-564); both call sites are insideplanning.py(:574,:611-613), and no other caller exists.
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:
- No unsupported-capability explicit
--gpuscase — the exact hole in finding 1. Repo-wide search for the user-facing strings finds them only inignition/planning.py:570, 576andignition/cli/serve.py:543; the architecture message (:589) has no test at all, before or after this PR. - 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 firstattempt()(140 GiB free, 200 GiB device weights over 3–4 ranks). - Multi-host untested. The only non-synthetic source of
context.gpusis the topology path feedingignition/cli/serve.py:421; no test exercises--ranksplanning. 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). - Unverified claim: "
CUDA_VISIBLE_DEVICES="" pytest -q tests/cli/test_planning.pypassed (7 passed, 0 failed)". The file has exactly sevendef test_functions (tests/cli/test_planning.py:159, 223, 298, 402, 479, 521, 568), consistent, but no CI check ran onc2ef797although.github/workflows/python-cpu.yml:3-33(not opened) triggers onpull_requestand runspytest tests/ -qwithCUDA_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
- Whether the error-precedence swap and the unsupported-device mask are intentional; neither the description nor any comment says.
- Whether multi-host planning (
--ranks, topology-derived GPUs) exercises the new argument correctly — untested here, and the companion DeepSeek V4.1 TP3 PR inlocal-inference-lab/hyperflare-recipes(the only real consumer and the only live evidence) is external and could not be read. - Why no CI check ran on the head despite
python-cpu.ymltriggering onpull_request. - No issue, roadmap entry, or maintainer request in-repo asks for GPU-aware world-size filtering; the rationale is the description plus the author's prior SM121/GB10 TP work (#161, #220, #433, #467).