From 3c3c4df9fadbb477ce06fd516c0f40b9ee9588e9 Mon Sep 17 00:00:00 2001 From: Jonathan Gutierrez Date: Mon, 30 Nov 2026 00:40:03 -1000 Subject: [PATCH] Pass candidate GPUs into filter_world_sizes during planning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, `ignition.planning.plan()` called `params.filter_world_sizes(world_sizes, pre_context)` with `pre_context.gpus == ()` both when computing `plan_sizes` and inside `candidates()`. Recipes whose valid tensor-parallel world sizes depend on GPU architecture—such as cross-host SM121 RoCE tensor parallelism versus single-host SM120 PCIe collectives—could not inspect `context.gpus` during world-size filtering, even though `fit()` already populates `context.gpus`. Resolving `supported` and `chosen` GPUs—and validating that explicitly selected GPUs have supported architectures—ahead of `filter_world_sizes()` exposes the same GPU metadata to world-size filtering without changing `RecipeParameters` signatures, introducing model-specific logic into `ignition.planning`, or turning unsupported-hardware `CapacityError` (exit 4) into a misleading parameter `UsageError` (exit 2). In `ignition/planning.py`, built `supported` directly as a tuple, moved explicit `--gpus` bounds checks and the `if not gpu.supported:` `CapacityError` check ahead of `params.filter_world_sizes()`, passed `replace(pre_context, gpus=filter_gpus)` where `filter_gpus` is `chosen` when explicitly selected or `supported` otherwise, and passed `replace(pre_context, root=candidate_params, gpus=filter_gpus)` inside `candidates()`. Documented the `context.gpus` and `context.world_size` contract on `ParameterGroup.filter_world_sizes` in `ignition/parameters.py`. Added `test_filter_world_sizes_receives_selected_or_supported_gpus` to `tests/cli/test_planning.py` reusing `_recipe()` and `_gpu()` to cover automatic and explicit `--gpus` planning across SM120, SM121, and unsupported SM90 GPUs. Recipes can now gate valid tensor-parallel world sizes on GPU capability during both automatic and explicit `--gpus` planning while preserving hardware `CapacityError` classification for unsupported GPUs and backward compatibility for recipes that ignore `context.gpus`. Validated with `CUDA_VISIBLE_DEVICES="" pytest -q tests/cli/test_planning.py tests/cli/test_commands.py tests/cli/test_parameters.py tests/cli/test_gpu_discovery.py` (29 passed, 0 failed), covering automatic and explicit `--gpus` selection across SM120, SM121, and unsupported SM90 GPUs. Limitation: these unit tests run on CPU with synthetic `Gpu` descriptors; live 3-node SM121 export and `flare run` serving validation using this hook are provided in `local-inference-lab/hyperflare-recipes#103`. Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b Signed-off-by: Jonathan Gutierrez --- ignition/parameters.py | 6 +++++- ignition/planning.py | 22 +++++++++++++--------- tests/cli/test_planning.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/ignition/parameters.py b/ignition/parameters.py index 76bdf810a..1ed984c41 100644 --- a/ignition/parameters.py +++ b/ignition/parameters.py @@ -558,7 +558,11 @@ def validate(self, context: ParameterContext) -> None: subgroup.validate(context) def filter_world_sizes(self, world_sizes: tuple[int, ...], context: ParameterContext) -> tuple[int, ...]: - """Restrict candidate tensor-parallel world sizes during planning.""" + """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``. + """ for _, subgroup in self._subgroups(): world_sizes = subgroup.filter_world_sizes(world_sizes, context) return world_sizes diff --git a/ignition/planning.py b/ignition/planning.py index 13bbfefe6..e45d76650 100644 --- a/ignition/planning.py +++ b/ignition/planning.py @@ -563,17 +563,22 @@ def plan(recipe: Recipe, checkpoint: Checkpoint, gpus: tuple[Gpu, ...], *, params.validate(pre_context) world_sizes = recipe.checkpoint_tensor_parallel(checkpoint) - plan_sizes = params.filter_world_sizes(world_sizes, pre_context) - 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)) - supported = [gpu for gpu in gpus if gpu.supported] + supported = tuple(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) + for gpu in chosen: + if not gpu.supported: + raise CapacityError(f"GPU {gpu.index} ({gpu.name}) is not an {SUPPORTED_ARCHITECTURES} device") + filter_gpus = chosen if chosen is not None else 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") + 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. @@ -582,9 +587,6 @@ def plan(recipe: Recipe, checkpoint: Checkpoint, gpus: tuple[Gpu, ...], *, first = max(0, min(selected[0], len(gpus) - size)) example = format_gpus(range(first, first + size)) raise CapacityError(f"{checkpoint.alias} needs {sizes} GPUs; {len(chosen)} selected; use --gpus {example}") - for gpu in chosen: - if not gpu.supported: - raise CapacityError(f"GPU {gpu.index} ({gpu.name}) is not an {SUPPORTED_ARCHITECTURES} device") elif len(supported) < plan_sizes[0]: raise CapacityError(f"{checkpoint.alias} needs {sizes} {SUPPORTED_ARCHITECTURES} GPUs; this host has {len(supported)}") @@ -606,7 +608,9 @@ def automatic(world_size: int, candidate_params: RecipeParameters = params, *, 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)] - candidate_sizes = candidate_params.filter_world_sizes(world_sizes, replace(pre_context, root=candidate_params)) + candidate_sizes = candidate_params.filter_world_sizes( + world_sizes, replace(pre_context, root=candidate_params, gpus=filter_gpus) + ) return [automatic(size, candidate_params, flags=flags) for size in candidate_sizes if size <= len(supported)] def attempt(candidate_params: RecipeParameters = params, *, flags: frozenset[str] = frozenset()) -> Plan | None: diff --git a/tests/cli/test_planning.py b/tests/cli/test_planning.py index ec6d00cd0..c579da24f 100644 --- a/tests/cli/test_planning.py +++ b/tests/cli/test_planning.py @@ -563,3 +563,38 @@ class BadContextParams(RecipeParameters): bad_recipe, native, (_gpu(0),), selected=(0,), parameters=replace(bad_recipe.parameters, bad=BadContextGroup(target=100)), ) + + +def test_filter_world_sizes_receives_selected_or_supported_gpus(): + @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) + + 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)) + + # Automatic planning on 4x SM120 selects TP4, not TP3. + assert planning.plan(model, ckpt, sm120_gpus).world_size == 4 + with pytest.raises(CapacityError, match="needs 4"): + planning.plan(model, ckpt, sm120_gpus[:3], selected=(0, 1, 2)) + # Explicit and automatic planning on 3x SM121 allow TP3. + assert planning.plan(model, ckpt, sm121_gpus, selected=(0, 1, 2)).world_size == 3 + assert planning.plan(model, ckpt, sm121_gpus).world_size == 3 + # 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)) +