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

Raw Markdown for agents: https://autobot.eidonix.com/p/1544d5a1-5878-4736-b875-a2b783a5efe6.md

Key findings

The PR is small (3 modules, +467/−44 including tests) and reads idiomatically, but it carries one clearly dead block, one branch/counter that can be halved, one rule encoded twice, one duplicated test harness, and one docs-drift item that the repo's own AGENTS.md treats as a finding. Five suggestions, ordered by value.


S1 (high) — Duplicate cross-architecture gate in InductorSelections.warm is unreachable: delete it

ignition/preparation/inductor_tuning.py:247-255:

        gpu_name, capability = _cuda_device_identity(self.device)
        variant_key = (getattr(bound.owner, 'compilation_variant', 'shared'), gpu_name)
        gathered_variants = self._gather((variant_key, capability, inventory))
        capabilities = {cap for _, cap, _ in gathered_variants}
        if len(capabilities) > 1:
            ordered = sorted(capabilities, key=lambda cap: (cap is None, cap))
            raise RuntimeError(
                f"Inductor warmup spans incompatible CUDA architectures: {ordered}"
            )

This check can never fire on any real path. warm is called from exactly two places, aot.py:1146 and aot.py:1266. The coordinator-backed instance is built in one place only, aot.py:1122 (InductorSelections(self.device, coordinator=coordinator, …)), inside ForwardCache._prepare_ranks — ~185 lines after the same gate already ran there:

ignition/preparation/aot.py:933-938:

        capabilities = {cap for _, cap in identities}
        if len(capabilities) > 1:
            ordered = sorted(capabilities, key=lambda cap: (cap is None, cap))
            raise RuntimeError(
                f"tensor-parallel ranks span incompatible CUDA architectures: {ordered}"
            )

The sorted(..., key=lambda cap: (cap is None, cap)) line is copied verbatim from aot.py:935 into inductor_tuning.py:252 — copy-paste evidence, not a second independent gate. The other InductorSelections constructions pass no coordinator (aot.py:835, aot.py:1256; also scripts/inspect_forward_kernels.py:93 (not opened)), so _gather returns [value] (inductor_tuning.py:129-131) and a cross-rank split cannot exist.

What to delete: capability from the gather payload and the 6-line check, keeping only the grouping key:

        gpu_name, _ = _cuda_device_identity(self.device)
        variant_key = (getattr(bound.owner, 'compilation_variant', 'shared'), gpu_name)
        gathered = self._gather((variant_key, inventory))
        variants = {}
        for variant, identities in gathered:
            ...

Plus the matching test, tests/preparation/test_mixed_gpu_inductor_keying.py:326-340 (test_inductor_warm_rejects_cross_architecture_ranks), which asserts a path no real call site can take; the same rejection is already covered end-to-end by test_cross_architecture_ranks_are_rejected_before_forward_sharing (:266-274). This also removes the (12, 0) capability element from every scripted reply list in _stub_inductor_warm (:277-292).


S2 (high) — allocate_workers keeps a redundant ungrouped branch and a redundant counter (~15 lines)

ignition/preparation/compile_pool.py:75-85:

        if groups is None:
            active_groups = [members]
        else:
            active_groups = [
                subgroup
                for subgroup in (
                    [rank for rank in members if groups[rank] == group]
                    for group in dict.fromkeys(groups[rank] for rank in members)
                )
                if any(counts[rank] for rank in subgroup)
            ]

With groups = hosts (the ungrouped default) the else branch degenerates to exactly [members]: dict.fromkeys(groups[rank] for rank in members) collapses to the single host name, and the comprehension yields members, then the any(counts[...]) filter is already handled by the if not jobs: continue at :73-74. So normalise the parameter once and keep one path:

        groups = hosts if groups is None else groups
        active_groups = [[rank for rank in members if groups[rank] == name]
                         for name in dict.fromkeys(groups[rank] for rank in members)]
        active_groups = [s for s in active_groups if any(counts[rank] for rank in s)]

Both existing caller shapes are unaffected: compile_pool.py:165 passes no groups (single "local" host) and the test_compile_pool.py call sites pass hosts only.

Second subtraction in the same function: admitted (:94, :103, :115) is always len(active_groups) once the guard at :116-118 has passed — the seeding loop adds at most one per subgroup and raises MemoryError if any subgroup ended empty. So:

        remaining = available - headroom
        admitted = 0
        # Seed one worker per active group so no active SKU on a mixed host is starved.
        for subgroup in active_groups:
            ...
                    admitted += 1
                    continue

becomes no initialiser, no increments, and for _ in range(limit - admitted): at :120 becomes for _ in range(limit - len(active_groups)): — non-negative because of the limit < len(active_groups) guard at :89-92.

While there: the fallback path assigns workers[rank] = 1 (:112) where the primary path uses += 1 (:101). It only works because a rank belongs to exactly one subgroup; use += 1 for consistency (or delete the fallback if it is not load-bearing — it exists purely to keep the per-SKU minimum under one host allowance, :105-109).


S3 (high) — "Same GPU" is encoded twice, and the compilation_variant getattr is duplicated

Artifacts key on a normalised tag, ignition/preparation/aot.py:939-944:

        heterogeneous = len(set(gpu_names)) > 1
        gpu_tag = "".join(ch if ch.isalnum() else "_" for ch in gpu_name).strip("_").lower()

        def _variant(forward):
            base = getattr(forward, "compilation_variant", "shared")
            return f"{base}.{gpu_tag}" if heterogeneous else base

Inductor grouping keys on the raw name, ignition/preparation/inductor_tuning.py:247-248:

        gpu_name, capability = _cuda_device_identity(self.device)
        variant_key = (getattr(bound.owner, 'compilation_variant', 'shared'), gpu_name)

compilation_variant is read with the same fallback in exactly these two places (repo-wide search returns only aot.py:943 and inductor_tuning.py:248), and the two layers answer "is this the same GPU?" with two different functions (normalised tag vs raw string), so the two equivalence relations can diverge on any pair of names that normalises together while differing raw — silently sharing artifact file names across separate Inductor groups.

Simplification: give the rule one home next to _cuda_device_identity and pass the already-suffixed variant name into warm, so warm no longer needs a GPU identity at all:

def forward_variant(forward, gpu_tag=None):
    base = getattr(forward, "compilation_variant", "shared")
    return base if gpu_tag is None else f"{base}.{gpu_tag}"

called from aot.py as _variant = partial(forward_variant, gpu_tag=gpu_tag if heterogeneous else None) and from warm on the bound forward — one key, one rule, no _cuda_device_identity import in the tuning path, and the new tests stop needing to monkeypatch it (test_mixed_gpu_inductor_keying.py:51, :278). This subsumes S1: after the capability check is gone, warm only needs one key, and the natural one is the artifact variant name — which is already what the error message at inductor_tuning.py:259 means by "equivalent compiled forward variant".

Secondary: aot.py:925 imports a private helper across modules (from .inductor_tuning import InductorSelections, _cuda_device_identity). If the identity/label logic lives in one shared function as above, the private import disappears.


S4 (medium) — New test harness duplicates _lending_rank and re-implements the production tag rule

tests/preparation/test_mixed_gpu_inductor_keying.py:23-95 (_prepare_rank) is a second copy of tests/preparation/test_forward_artifact_sharing.py:171-252 (_lending_rank), in a file that already imports four private fixtures from that very module (:17): from tests.preparation.test_forward_artifact_sharing import _Artifact, _Forward, _Pool, _replace_gpu_preparation.

Duplicated near-verbatim, e.g. test_mixed_gpu_inductor_keying.py:52-56:

          aot.ForwardCache._path = recording_path
          aot.ForwardCache._load = lambda self, forward, path, required=False, before_run=None: aot.BoundForward(
              _Artifact(lambda owner: None), forward, True
          )
          aot.ForwardCache._allocation_sizes = lambda self, path: ()

versus test_forward_artifact_sharing.py:224-226 — plus the five-attribute ForwardCache.__new__ block (:58-61), the SimpleNamespace coordinator block (:72-79), and the fork/spawn/queue/terminate block (_run_prepare :97-121).

Worse, the test re-derives the rule it is testing, :65-70:

          if gpu_name in precached_skus:
              heterogeneous = len({name for name, _ in identities}) > 1
              gpu_tag = "".join(ch if ch.isalnum() else "_" for ch in gpu_name).strip("_").lower()
              variant = f"shared.{gpu_tag}" if heterogeneous else "shared"

This is a verbatim third copy of aot.py:940. A test that recomputes the expected name cannot detect a change in that name; the assertions at :143-146 (len(artifacts) == 8, substring "max_q") already check the real output.

What to do: extend _lending_rank with the identity/precache parameters (or move the shared harness into test_forward_artifact_sharing.py and import it) and delete _prepare_rank/_run_prepare; for the pre-cache, drive it through the production naming rather than recomputing it. Mechanically this matters too: #584 rewrites test_forward_artifact_sharing.py wholesale (+1463/−4), so a second harness built on its private fixtures must be rebased twice.


S5 (medium) — Replaced behavior is still described in the docs, and new hard failures are undocumented

AGENTS.md:165-166 makes inaccurate documentation a valid change on its own, and AGENTS.md:226 points TP-preparation work at docs/preparation-development.md. Three passages describe the behavior this PR replaces and none was touched:

Additionally, --compile-workers silently became a floor of the active-SKU count (compile_pool.py:89-92 raises ValueError when limit < len(active_groups), and limit derives from --compile-workers/compile_threads at compile_pool.py:42-44), so a host that legitimately ran with --compile-workers 1 now fails at export where it previously ran slowly. No document records this or the two new RuntimeErrors. Either update those three passages (and the --compile-workers description) or state in the PR why the docs stay as-is.


What I checked and found already lean

Open questions

  1. Is the S1 test (test_inductor_warm_rejects_cross_architecture_ranks, :326-340) intended as a defensive guard for a future coordinator-bearing call site? If so the PR should say so; as written nothing can reach it, and it duplicates :266-274.
  2. Is the --compile-workers floor (compile_pool.py:89-92) intended to be documented as an operator constraint, or should it degrade (seed fewer groups) instead of raising? It overlaps #122 (configurable headroom), which edits the same admission path.
  3. Does any real pair of device names normalise identically under aot.py:940 while the raw names differ (which would re-share artifact filenames across separate Inductor groups)? No test covers a collision.