Subtraction, Simplicity & Conventions review — PR #597 (1acb1f05)
Key findings
Verdict first: the diff is broadly lean and idiomatic. No new configuration knob, CLI flag, environment switch, extension point, or speculative compatibility layer is introduced anywhere in the four changed Python surfaces. The rule this repo most often sees violated — AGENTS.md:188-193, "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement" — is not violated here, and the scope is authorized by a demonstrated defect (AGENTS.md:165-169: mixed-SKU ranks sharing one paths[name, variant]). The five items below are reductions in diff size and coupling, not grounds for rejection. I found no dead code left behind from the pre-1acb1f05 revision (gpu_tag and heterogeneous are fully gone from aot.py).
What is worth cutting, in value order:
- The
(compilation_variant, gpu_name)key is built twice in two modules, in two different quote styles (aot.py:944-945vsinductor_tuning.py:247-248) — one helper collapses both and stops "what gets shared" from silently diverging from "what gets validated". _share_artifacts(root=None)is dead generality plus aPath.resolve()heuristic (aot.py:698, 710, 721-724); both production call sites passroot, and theNonebranch exists only to keep one test call site unchanged. The filter can be deleted outright by masking peer lists with thegpu_namesarray already gathered ataot.py:934-936.- The same
(host, GPU group)partition is computed twice in two idioms (compile_pool.py:76-83nested comprehension vsaot.py:1001-1005hand-rolledzipscan); onehost_groups()helper also letsgroupsbecome a required argument instead of thegroups = hostsoverload. - The new test file re-derives production cache-root hashing (
test_mixed_gpu_inductor_keying.py:25-27) rather than constructing the realForwardCacheastest_forward_cache_root.py:13-20already does, and 6 of its 12 parametrized cases assert one identicalMemoryError. - Minor: the
_prepare_ranksdocstring (aot.py:914-925) restatesdocs/preparation-development.md:353-369almost verbatim.
1. Duplicated variant-key construction across two modules (highest value)
ignition/preparation/aot.py:944-945:
def _variant_key(forward):
return (getattr(forward, "compilation_variant", "shared"), gpu_name)
ignition/preparation/inductor_tuning.py:247-248:
gpu_name, _ = cuda_device_identity(self.device)
variant_key = (getattr(bound.owner, 'compilation_variant', 'shared'), gpu_name)
Two independent definitions of the same identity tuple, in two modules, with different quoting and one hidden inside a closure that captures gpu_name from the enclosing scope. The aot copy decides which artifacts are shared and which rank compiles a variant (:953, :1113, :1132, :1155); the inductor_tuning copy decides which ranks must agree on an Inductor kernel inventory. Changing the default ("shared") or adding a component in one place silently decouples the two contracts, and the failure would surface as a kernel mismatch at serving time rather than a compile error.
Simplification: define it once next to cuda_device_identity, which both modules already share:
def forward_variant(forward, device):
"""Return the `(compilation_variant, gpu_name)` key that identifies a compiled forward."""
return (getattr(forward, "compilation_variant", "shared"), cuda_device_identity(device)[0])
Then delete _variant_key from _prepare_ranks and call forward_variant(forward, self.device) at :953/:1113/:1132/:1155, and replace inductor_tuning.py:247-248 with the single line variant_key = forward_variant(bound.owner, self.device). No new dependency edge: aot.py:929 already reads from .inductor_tuning import InductorSelections, cuda_device_identity.
2. _share_artifacts(root=None) — optional parameter that exists only for a test
ignition/preparation/aot.py:698 and :710:
def _share_artifacts(owned, group, ranks, root=None):
...
target_root = None if root is None else Path(root).resolve()
ignition/preparation/aot.py:721-724:
missing = {path for index, compiled in enumerate(digests) if index != me
for path, digest in compiled.items()
if (target_root is None or Path(path).resolve().parent == target_root)
and not current(path, digest)}
Plus three lines of docstring (:703-705) explaining the root branch. Both production call sites already pass it — aot.py:1104-1105 and aot.py:1170:
_share_artifacts([sorted({path for path, _ in compiled.values()}) for compiled, _ in outcomes],
group, ranks, root=self.root)
so every reachable call has root set, and the target_root is None half of the comprehension condition is dead in production. This is exactly the "fallback layer without a concrete requirement" pattern of AGENTS.md:188-193, introduced to avoid touching existing tests.
Simplification (preferred): drop the parameter and the resolve() heuristic entirely. gpu_names is already gathered at aot.py:934-936, and owned is built per rank at :1104; blanking the peer lists before the gather removes foreign-SKU paths before _share_artifacts ever sees them, e.g. pass [[path for path in compiled_paths if gpu_names[index] == gpu_name] ...], leaving the function with zero new branches and a one-line docstring. Minimum fix if the parameter stays: make it required (def _share_artifacts(owned, group, ranks, root):) and update the single test call site. Note that this is the same code the Correctness lens flags, so one deletion satisfies both lenses.
3. The (host, group) partition is computed twice, in two idioms
ignition/preparation/compile_pool.py:70 and :76-90:
groups = hosts if groups is None else groups
...
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)
]
...
if limit < len(active_groups):
raise ValueError(
f"host {host!r} has {len(active_groups)} active compiler groups but worker limit {limit}"
)
ignition/preparation/aot.py:1001-1011:
for host, dev_name in dict.fromkeys(zip(coordinator.hosts, gpu_names)):
members = [
index for index, (h_name, g_name) in enumerate(zip(coordinator.hosts, gpu_names))
if h_name == host and g_name == dev_name
]
if not any(counts[index] for index in members):
continue
Two independent O(n²) implementations of the identical subgrouping rule, one nested-comprehension, one zip-scan-and-filter, in two modules, driven by the same two arrays (coordinator.hosts, gpu_names). The aot side must reproduce allocate_workers' notion of "active" exactly (if not any(counts...): continue) or workers get allocated to a group that then balances nothing — an unenforced invariant between two files. The groups = hosts if groups is None else groups overload (:70) additionally makes "group name equals host name" a meaningful identity, which is only ever exercised by the homogeneous path.
Simplification: one helper, e.g. in compile_pool.py:
def host_groups(hosts, groups):
"""Return `{(host, group): [rank indices]}` for every `(host, group)` subgroup, in rank order."""
members = {}
for rank, key in enumerate(zip(hosts, groups)):
members.setdefault(key, []).append(rank)
return members
allocate_workers derives active_groups from host_groups(hosts, groups).values() (filtering any(counts[rank])), and _prepare_ranks replaces :1001-1005 with for (host, dev_name), members in host_groups(coordinator.hosts, gpu_names).items(). That removes one comprehension, the duplicated scan, and the "active" invariant. With groups then required, CompilePool.__init__ (compile_pool.py:161) passes ["local"] and the host-name overload disappears.
4. New test file re-derives production root hashing and over-asserts one failure
tests/preparation/test_mixed_gpu_inductor_keying.py:25-27:
def _sku_root(base, gpu_name):
"""Mirror `ForwardCache.__init__`, which hashes the GPU product name into `self.root`."""
return Path(base) / hashlib.sha256(gpu_name.encode()).hexdigest()[:12]
This is a hand-copied paraphrase of the real derivation in ForwardCache.__init__, and the docstring admits it ("Mirror …"). If the hash, its truncation length, or the intervening directory level changes, the test keeps passing against a fake root while production writes elsewhere. The repo already has the right pattern for this — tests/preparation/test_forward_cache_root.py:13-20 constructs the real cache with the device properties patched:
properties = types.SimpleNamespace(name="RTX PRO 6000 Blackwell", major=12, minor=0, multi_processor_count=188)
monkeypatch.setattr(torch.cuda, "get_device_properties", lambda device: properties)
configured = aot.ForwardCache(namespace={"model": "root"}, device="cpu", root=tmp_path)
Delete _sku_root and build the roots via ForwardCache(..., device="cpu") with get_device_properties monkeypatched to each SKU name, as that existing test does.
Also redundant in the same file, :242-247:
@pytest.mark.parametrize("available_gib", [12, 39, 40, 41, 42, 71])
def test_allocate_workers_is_monotonic_and_rejects_underbudgeted_multi_sku_hosts(available_gib):
resources = [compile_pool.CompilerResources(1, available_gib << 30, 16, 32 << 30, 8 << 30)] * 4
groups = [MAXQ, MAXQ, WORKSTATION, WORKSTATION]
with pytest.raises(MemoryError, match="no capacity"):
compile_pool.allocate_workers(resources, [2, 2, 2, 2], ["host"] * 4, groups=groups)
Six parameter values asserting one identical exception carries the same information as one interior value (e.g. 40) plus the adjacent 72 GiB admission case already present at :262-266; cutting five cases removes ~10 lines and 5 test-collection entries without losing the monotonic boundary, which the 72 GiB case pins from the other side. Likewise :256-259 re-tests the homogeneous fallback already covered by test_compile_pool.py:509-517 (test_minimum_worker_allowance_preserves_one_worker_per_host).
One structural note: :19 imports the private fixtures _Artifact, _Forward, _Pool, _replace_gpu_preparation from a sibling test module, which the Discovery Dossier records as being rewritten by #584 — this new file is coupled to another test file's internals with no shared fixture module.
5. Minor: docstring duplicates the design doc
ignition/preparation/aot.py:916-920:
Each forward compiles once per `(compilation_variant, gpu_name)` key using un-suffixed
on-disk filenames inside each SKU's GPU-partitioned `self.root`, while cross-architecture
rank groups are rejected. Each `(compilation_variant, gpu_name)` compiles on a rank that
selects it, from that rank's own forward, unless an idle peer on the same host with the
same GPU product name borrows it and compiles it from the owner's traced forward metadata.
restates docs/preparation-development.md:353-369 ("… Cache roots and publication.lock acquisitions are partitioned per (host, GPU product name) pair in deterministic sorted order, keeping un-suffixed artifact filenames inside each GPU product name's cache root.") almost sentence for sentence. The rationale now lives in two places and will drift; per AGENTS.md:52-60 the design belongs in the doc. Replace :916-924 with two lines stating only what a caller must know (compiles once per (compilation_variant, gpu_name); cross-architecture groups raise; see docs/preparation-development.md).
Checked and found lean (so the list above is not read as a rejection)
cuda_device_identity(inductor_tuning.py:21-26) is five lines, no wrapper, correctly made public rather than imported privately from a sibling module._publication_lock(aot.py:789-816): the per-(host, str(root.resolve()))key loop issues the same number ofdist.barriercalls per turn asmain's per-host loop (ack, barrier, barrier), so the change adds no synchronisation rounds; thekeys = [None]/holder = Truesingle-rank defaults are preserved._prepare_ranks' capability gate (aot.py:933-942) is minimal and uses no new abstraction;InductorSelections.warmcorrectly dropped its duplicate capability check (inductor_tuning.py:247), so no dead branch remains there.- No env vars, no new CLI surface, no unused imports, and no residue from the withdrawn
gpu_tag/heterogeneousdesign. - Test volume is defensible for the behaviours touched apart from the redundancy in finding 4.
Open questions / not verified
- Whether
_share_artifactsever needs to share nested subdirectories: the exact-parent filter in finding 2 means nested artifacts would silently stop being shared cross-host. This is a Correctness-lens question, but the fix in finding 2 (mask peer lists) sidesteps it entirely, which is another argument for deletion over patching. - I did not re-run the five CPU test files, so the
103 passedfigure remains the author's claim; there is still no pytest invocation under.github/workflows/, so no figure here is CI-verified. - Not re-litigated in this lens (Correctness-lens items per the Dossier): the ~72 GiB mixed-host admission floor, the
ValueErrorper-SKU worker floor, and the still-cross-SKUwarm/_reconcilewinner election. I note only that finding 2's deletion would also remove one of the code paths those lenses touch. pr_filesstill reports the stale4 files, +467/−44shape; the true scale is larger (docs edited, test file grown past +400), so treat any size figure as provisional.