Subtraction, Simplicity & Conventions review — PR #635 "Pass candidate GPUs into filter_world_sizes during planning"
Author: nero- · head c2ef797 · ignition/planning.py (+9/−5), tests/cli/test_planning.py (+32/−0) · 1 commit, 2 files, no CI checks, no reviews.
Key findings
The diff is lean and idiomatic in substance: it adds no flag, knob, config field, manifest entry, indirection layer, feature branch, or dead code. It moves one existing call later and fills in a ParameterContext field that fit() already populates — the smallest change that makes the hook usable. I found no material AGENTS.md or module-convention violation.
Three real, small subtractions remain, all mechanical and behaviour-preserving:
ignition/planning.py:566, 573, 611-613— one value (the supported GPUs) is spelled three ways, and the PR itself added bothtuple(...)conversions of the same list. Makesupporteda tuple once and reuse thefilter_gpuslocal. Deletes two conversions plus a duplicated expression. (High value, 3-line change.)tests/cli/test_planning.py:577-588— the new test hand-builds aCheckpoint, aRecipeand twoGputuples that this module's own_recipe()(:118) and_gpu()(:154) fixtures already build, and that every other test in the file uses. Replacing them drops ~12 lines to ~4 and removes a one-off "140 GiB free == total" GPU that exists nowhere else. (High value.)tests/cli/test_planning.py:591, 593, 595, 596—reserve_bytes=0is a no-op: the default is already 0 and no fixture in the file sets it. Delete four kwargs. (Low value, pure noise.)
Nothing else should be deleted: the if chosen is not None: re-split at :578 is forced by moving the filter after GPU resolution (it is not speculative structure), no wrapper or fallback branch was introduced, and both in-repo filter_world_sizes overrides (tests/cli/test_planning.py:81, tests/cli/test_commands.py:55 (not opened)) need no change.
S1 (high) — One value, three spellings; two of the conversions were added by this PR
ignition/planning.py:565-574, verbatim:
world_sizes = recipe.checkpoint_tensor_parallel(checkpoint)
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))
and the second copy of the same conversion, ignition/planning.py:611-613, verbatim:
candidate_sizes = candidate_params.filter_world_sizes(
world_sizes, replace(pre_context, root=candidate_params, gpus=tuple(supported))
)
supported is built as a list at :566, converted to a tuple at :573 (new in this PR), and converted to a tuple again at :612 (also new in this PR). The expression "which GPUs should the filter see" therefore exists in two places that must be kept in sync.
Concrete replacement. Make the one list a tuple and reuse the one local:
:566→supported = tuple(gpu for gpu in gpus if gpu.supported):574unchanged (gpus=filter_gpus):611-613→candidate_sizes = candidate_params.filter_world_sizes(world_sizes, replace(pre_context, root=candidate_params, gpus=filter_gpus))
Net: two tuple(...) conversions and one duplicated expression deleted; behaviour identical.
Why it is provably equivalent at :612: candidates() returns before reaching :611 whenever chosen is not None — ignition/planning.py:608-610, verbatim:
def candidates(candidate_params: RecipeParameters = params, *, flags: frozenset[str] = explicit_flags) -> list[Plan]:
if chosen is not None:
return [fitted(chosen, candidate_params, flags=flags)]
so at :611 chosen is None and filter_gpus == tuple(supported); only root differs between the two calls, which is exactly what the PR intends.
Why tuple is safe for every other use of supported: :590 len(supported), :602 list comprehension [gpu for gpu in supported if …], :604 sorted(supported, key=…)[:world_size], :614 and :646 len(supported). All are sequence-agnostic. Assignment to supported is local to plan(); nothing returns it.
Caution — do not collapse :573 further into gpus=chosen or tuple(supported). selected can be an empty tuple (--gpus "" path), making chosen == (), which is falsy, silently falling back to all supported GPUs. The explicit chosen is not None test at :573 is the correct form and should stay.
S2 (high) — The new test rebuilds the module's own fixtures
tests/cli/test_planning.py:577-588, verbatim:
ckpt = Checkpoint("toy", "lab/toy", "a" * 40, "ToyLM",
stored_bytes=200 * GIB, device_bytes=200 * GIB, mapped_host_bytes=0)
model = Recipe(
name="toy", served_model_name="Toy", checkpoints=(ckpt,),
context=8192, page_tokens=64,
sampling_defaults=SamplingDefaults(temperature=1.0, top_p=1.0, top_k=-1),
parameters=CapabilityAwareParams(max_concurrency=4, prefill_chunk=512),
prepare=None, usage=None,
ranks=MappingProxyType({s: RankCosts(100 * MIB, 2 * MIB, 4 * GIB) for s in (3, 4)}),
)
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))
The same file already provides exactly these builders — tests/cli/test_planning.py:118 and :154-156, verbatim:
def _recipe(name="fixture", *, device_gib=60, ranks=(1, 2, 4), parameters=None):
def _gpu(index, free_gib=95, capability=(12, 0)):
return planning.Gpu(index, "NVIDIA RTX PRO 6000 Blackwell", f"GPU-{index:04d}",
96 * GIB, int(free_gib * GIB), capability)
Every other test in the file uses them — 20+ call sites (:161, :164, :167, :171, :204, :206, :209, :219, :231-232, :301, :313, :336, :347, :409, :431, :467, :485, :487, :522, :536, :539, :560, :563). This test is the sole exception in the module.
Concrete replacement (preserves all four assertions):
model = _recipe("toy", device_gib=60, ranks=(3, 4),
parameters=CapabilityAwareParams(max_concurrency=4, prefill_chunk=512))
ckpt = model.checkpoints[0]
sm120_gpus = tuple(_gpu(i) for i in range(4))
sm121_gpus = tuple(_gpu(i, capability=(12, 1)) for i in range(3))
Roughly 12 lines drop to 5, and the one-off 140 GiB total/free GPUs (used nowhere else in the file) go away.
Equivalence checked: the new test's ranks mapping is {s: RankCosts(100 * MIB, 2 * MIB, 4 * GIB)} (:585) versus _recipe's {size: RankCosts(100 * MIB // size, 2 * MIB // size, 4 * GIB)} (:143) — both arbitrary per-rank costs, and the assertions are capability-driven, not memory-driven. _gpu()'s 95 GiB free is far more than needed. The CapacityError at :592-593 still matches "needs 4" because CapabilityAwareParams returns exactly (4,) for non-SM121. Precedent for a capability-varying _gpu exists at :219 (_gpu(0, 95, (10, 3))), and for a (3, 4)-rank recipe at :167.
S3 (low) — Four no-op reserve_bytes=0 kwargs
tests/cli/test_planning.py:590-596, verbatim:
# Automatic planning on 4x SM120 selects TP4, not TP3.
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)
# Explicit and automatic planning on 3x SM121 allow TP3.
assert planning.plan(model, ckpt, sm121_gpus, selected=(0, 1, 2), reserve_bytes=0).world_size == 3
reserve_bytes already defaults to 0 — ignition/parameters.py:1405, verbatim: reserve_bytes: int = param(0, cli=False, value_type=int, scope=ParameterScope.DEPLOYMENT, in_dict=False) — and _normalize_parameters only overrides it for a non-None argument (ignition/planning.py:440-444). No fixture in this file sets a non-zero reserve, and no other test in the file passes this kwarg. Delete reserve_bytes=0 from all four calls (:591, :593, :595, :596). It reads as if it guards something; it does not.
Observed but deliberately not proposed (would add, not remove, complexity)
params.filter_world_sizes is now evaluated twice on the automatic path — ignition/planning.py:574 and again at :611 via attempt(params, …) → candidates(params, …), with candidate_params defaulting to params (:593), so the two calls are identical work. Inside the failure path it can run a third time via candidates(params, …) at :626. This is pre-existing in kind: main has the same double call at planning.py:566 and :609. Hoisting plan_sizes into candidates() would require an extra parameter or an if candidate_params is params branch — a net increase in surface for no user-visible effect — so it should be left alone, at most noted for a future refactor of the candidates/attempt nesting.
Checked and clean (not findings)
- No new flags, knobs, defaults, manifest fields, schema, or docs. Nothing user-facing, nothing to subtract at the interface level.
- No new abstraction or wrapper; the change edits existing locals in place.
- No dead or unreachable code introduced.
supportedandfilter_gpusare both used;chosenwas already used at:578,:609,:644,:649. - The
if chosen is not None:block split (:578) is not speculative structure — it is the minimal way to keep explicit---gpusvalidation after the filter moved later. No simpler shape exists without changing error ordering. params.validate(pre_context)at:563left untouched — correct for this lens; its now-asymmetric lack of GPUs is a contracts question (#2 in the case file), not a subtraction one.- Both in-repo
filter_world_sizesoverrides ignorecontext.gpus(tests/cli/test_planning.py:81,tests/cli/test_commands.py:55(not opened)), so no cleanup is owed elsewhere.
Open questions / not determinable
- Whether
reserve_bytes=0in the new test was copied from a workflow where reserve mattered, or is defensive habit; either way it is removable. - Whether the author intended
supportedto be a list for some futureappend; nothing inplan()mutates it, so tuple is safe today. - The external consumer (
local-inference-lab/hyperflare-recipesDeepSeek V4.1 TP3 PR) could not be read, so I cannot say whether it would notice thefilter_gpusrefactor — it consumes onlyPlan/ParameterContext, not these locals, so it should not.