Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #597

Raw Markdown for agents: https://autobot.eidonix.com/p/2fc184ae-9ba5-47ef-98f1-d7764951f4fe.md

#1 [high] F1 Major: heterogeneous gating is group-wide and redundant with existing per-device root

aot.py:939-944 (PR head): 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

aot.py:750-763 shows ForwardCache.root already hashes the product name: key = hashlib.sha256(pickle.dumps((namespace, options, torch_key(), runtime_patches.identity(), properties.name, properties.major, properties.minor, properties.multi_processor_count))) ... self.root = root / 'forwards' / key.hexdigest()

Two consequences, both verified from code: (a) Redundancy: different SKUs already get different roots, so per-SKU artifact separation needs no file-name suffix; the suffix changes only the file NAME inside an already-separate root (aot.py:1212-1214 _path hashes the name). (b) Cache invalidation: identities is gathered over coordinator.group = ALL ranks of the TP group (aot.py:930-932), including ranks on other hosts. So a homogeneous host whose peers on another host report a different GPU model gets heterogeneous=True, and every one of its variant names gains a suffix -> its existing cache from main is unusable. Same for the PR's own host alternating between mixed TP4 and homogeneous TP2 (test test_homogeneous_gpus_preserve_unsuffixed_forward_sharing expects 4 artifacts un-suffixed). Result: full recompile of an entire catalog whenever the peer set changes shape. No measurement of this cost is in the PR. Fix: scope heterogeneity per (host, gpu_name) partition actually used for sharing/lending, or drop the suffix and rely on the existing per-device root key.

#2 [high] F2 Major: two different "same GPU" keys (normalized tag vs raw name)

aot.py:940 normalizes for artifact names: gpu_tag = "".join(ch if ch.isalnum() else "" for ch in gpu_name).strip("").lower() inductor_tuning.py:247-249 uses the raw name: 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)) and compile_pool/allocate_workers + the lending loop (aot.py:1000-1004) use the raw name too. So artifact sharing and worker/lending grouping use raw names, while artifact FILE names use the normalized tag. Two product names that differ only in punctuation/case (e.g. a driver string with '-' vs '/' or different spacing) collapse to one file name: two SKUs then write the same {variant}.bin inside the same root (root also uses properties.name, so this needs names differing only in non-alnum characters - a narrower but real window), while Inductor keeps them in distinct groups and never compares their inventories. Tests only assert substrings "max_q" / "blackwell_workstation_edition" (tests/preparation/test_mixed_gpu_inductor_keying.py:145-146) and never a collision. Fix: derive the artifact suffix from the same raw string used elsewhere (e.g. hash the raw name) so a single identity definition exists; or assert injectivity in the test.

#3 [high] F3 Major: --compile-workers at world_size now fails on mixed-SKU hosts

compile_pool.py:88-92 (PR head): limit = min(jobs, min(resources[rank].limit for rank in members)) if limit < len(active_groups): raise ValueError( f"host {host!r} has {len(active_groups)} active compiler groups but worker limit {limit}" ) limit comes from compiler_resources (compile_pool.py:42-44): limit = min(cpu_workers(compile_workers), cpu_workers()), plus min(limit, options['compile_threads']) when compile_workers is None, and cpu_workers divides the budget by the number of local pools (host_memory.py:31-35). So on a 2-rank mixed-SKU host with an explicit --compile-workers 2 (a legal value: cli/preparation.py:85 only requires >= world_size) each rank's limit is 2 // 2 = 1 -> limit=min(jobs,1)=1 < len(active_groups)=2 -> ValueError. Same for an explicit config [preparation] compile_workers = N where N == local rank count. On main this case ran one worker (slowly). The PR description does not declare that --compile-workers now has a hard floor of >= 2 * active groups on a mixed host, and docs/model-preparation.md:231-236 still describes it as "a positive CPU compiler process budget per host ... Available RAM and device memory can reduce it". Also limit is derived partly from options['compile_threads'] (an Inductor setting, not an operator choice), so the error message names a "worker limit" the operator never set. Fix: fall back to the existing per-host seeding when limit cannot cover every group (i.e. downgrade to a warning path or share one worker serially), and document the floor in docs/model-preparation.md.

#4 [high] F4 Major: mixed admission accounting oversubscribes RAM + per-group MemoryError policy

compile_pool.py:93-118 (PR head). The old code computed remaining once and tried one host-wide fallback; the new code decrements remaining per group and reuses the SAME reduced remaining for the fallback test:

remaining = available - headroom
for subgroup in active_groups:
    able = [rank for rank in subgroup if ... resources[rank].worker_bytes <= remaining]
    if able: ... remaining -= resources[rank].worker_bytes; admitted += 1; continue
    able = [rank for rank in subgroup if resources[rank].capacity
            and resources[rank].worker_bytes - host_memory.FORWARD_WORKER_BYTES
            + host_memory._WORKER_BYTES <= remaining]
    if able: rank = able[0]; workers[rank] = 1; remaining -= (...); admitted += 1

Two concrete defects: (a) workers[rank] = 1 is an assignment, not an increment. If the chosen rank already holds a seeded worker from a previous group's iteration it must not happen (groups are disjoint by construction), but in the homogeneous case active_groups == [members] and a rank seeded by the first branch can never be reselected by the fallback in the same group — OK. The real bug is that the fallback charges remaining with the small _WORKER_BYTES-based estimate, while the surplus loop below (compile_pool.py:120-127) charges the full resources[rank].worker_bytes for the same rank. Mixed accounting means the host can be oversubscribed: the small-forward worker's true peak is 32 GiB (FORWARD_WORKER_BYTES, host_memory.py:15) but only 2 GiB was charged. (b) The MemoryError at compile_pool.py:116-118 now fires when ANY active group has no worker, whereas main fired only when NO rank on the host had one. Combined with the 32 GiB estimate, a mixed-SKU host that previously ran (one worker total, groups served serially) now aborts with MemoryError. The PR description does declare "raising MemoryError when host memory cannot admit one worker per active subgroup" but docs/model-preparation.md:238-245 still says "When that estimate admits no worker, one worker per host may start under the 2 GiB minimum host allowance", i.e. the documented policy is now one worker per GROUP, and the doc was not updated. Verified by new tests: test_contiguous_mixed_sku_seeds_each_active_group_under_tight_budget expects MemoryError at 40 GiB (compile_pool.py path), i.e. a documented-legal 32 GiB + 8 GiB headroom host is rejected because it has 2 SKUs. Fix: charge the fallback worker's real estimate (or remember the discount), and update docs/model-preparation.md:241-243 to state the per-group policy.

#5 [high] F5 Major: description's premise about shared artifacts is factually wrong

PR description, "Why this change is proposed": "Previously, ForwardCache._prepare_ranks (ignition/preparation/aot.py) shared compiled forward artifacts and lent missing compilations across all ranks on a host without distinguishing GPU product names".

Verified inaccurate for artifacts. aot.py:750-763 (unchanged by this PR): properties = torch.cuda.get_device_properties(device) ... key = hashlib.sha256(pickle.dumps((namespace, options, torch_key(), runtime_patches.identity(), properties.name, properties.major, properties.minor, properties.multi_processor_count))) ... self.root = root / 'forwards' / key.hexdigest() properties.name is in the cache key, so ranks of different SKUs have never shared a ForwardCache.root or any artifact file. Only the lending/assignment loop (aot.py:1000-1010 on main) and the single host-wide publication.lock were shared. The PR description's headline "cross-SKU artifact sharing" is therefore wrong, which matters because it is the stated justification for the new artifact-name suffix (see F1).

Accurate parts of the description, verified: the old _publication_lock did lock only the host's first rank's root (main's hosts = sorted(set(coordinator.hosts)) loop locked self.root for the host's first rank only), and InductorSelections.warm did compare inventories across all ranks of one compilation_variant.

Also inaccurate/unsupported: "96 passed in 46.13s" has no attached command or log, and the PR states GPU-side suites were not run — yet warm (inductor_tuning.py:244-260) is changed and the only coverage of it is the stub-gather test test_inductor_warm_accepts_distinct_inventories_for_mixed_sku_same_architecture (tests/preparation/test_mixed_gpu_inductor_keying.py:277-306), which scripts self._gather with a fixed reply list. No real-distributed or GPU test exercises the new capability key; tests/preparation/test_inductor_tuning_cuda.py:565-655 does exercise prepare_many with a real coordinator on GPU and was not reported as run.

#7 [high] F7 Major: docs contradicted in three places, none updated

PR touches three files in ignition/preparation plus one new test; no docs/*.md changed. Stale statements, all still present at head:

  1. docs/preparation-development.md:351-359 — "Each forward variant compiles once, on a rank that selects it ... Compiler pools are budgeted for their host's ranks ... Ranks on one host share its cache directory". Now false on mixed-SKU hosts: per-SKU variants compile twice, pools are budgeted per SKU subgroup, and same-host ranks with different SKUs do NOT share a cache directory. The "select a variant key through compilation_variant on each rank" guidance at :369 no longer describes what determines the artifact name, since a group-wide heterogeneous flag silently rewrites it (aot.py:939-944).

  2. docs/model-preparation.md:231-245 — "--compile-workers N sets a positive CPU compiler process budget per host ... Available RAM and device memory can reduce it; local preparation ranks share the budget." (a) The new ValueError (compile_pool.py:89-92) turns a reduction into a fatal error, so "can reduce it" is wrong. (b) "Ranks without a worker lend missing forwards to other ranks on that host" (:238-240) is now restricted to same-SKU peers (aot.py:1000-1010). (c) "When that estimate admits no worker, one worker per host may start under the 2 GiB minimum host allowance" is now one worker per active SKU group (compile_pool.py:116-118).

  3. docs/model-preparation.md:203-204 — "tensor-parallel ranks on identical GPUs divide the candidates of a shared local kernel race" presupposes identical GPUs; mixed same-architecture hosts are now a supported shape and nothing documents what changes.

AGENTS.md:515 requires updating docs the change makes stale. Cross-check for the report: no TODO entry added either.

#9 [high] F8 Major: benefit claim depends on separate unmerged PR, no isolated evidence

PR claims (description, "Claimed benefit or result"): "Enables tensor-parallel preparation (ignition export --gpus ...) on mixed-SKU same-architecture SM120 hosts without relaxing compute-capability invariants".

The tuning half is not in this diff. InductorSelections.warm change only stops the inventory-agreement check from comparing across SKUs; it does not make cross-SKU tuning agree. The only documented mixed-SKU preparation abort, PR #150's BindingMismatch: rank-local forward does not match compiled guards (layer 20 csf_inline_scales split 2/2), is a tuning disagreement addressed by reconcile_selections in ignition/preparation/tuning.py, which this PR does not touch (PR diff touches only aot.py, compile_pool.py, inductor_tuning.py). So the PR alone cannot deliver its headline benefit, and the description never says the enabling work is a separate open PR (#150, same author, CHANGES_REQUESTED).

Also relevant to charter "bring real evidence": the only before/after evidence offered is whole-pipeline serving, which the description itself says is "not attributable solely to this PR", and there is no isolated measurement of the changed preparation step (compile wall clock, worker shape, disk footprint). The in-repo test for the new behaviour asserts artifact COUNTS (8 vs 4, tests/preparation/test_mixed_gpu_inductor_keying.py:143-146, 171, 262-263), i.e. it encodes the double-compile cost as expected behaviour with no measurement of what that costs.

Recommendation for adjudication: request (i) a "failure on main" reproduction — the reviewer yatesdr demanded exactly this of #150 and it was never supplied; (ii) an isolated measurement of the change with the homogeneous baseline (compile time and cache footprint, homogeneous vs mixed on the same host), since F1 shows a homogeneous host can be pushed onto the suffixed path purely by its peer set.

#10 [high] Research summary

Reviewed PR #597 at head f8a033a across all four changed files plus their callers, contracts, docs and tests. Findings are on the scratchpad (9 notes); the strongest are:

Verified sound: lock keying/ordering and barrier parity, groups=None back-compat, _variant() consistency at every artifact site, no added collectives in warm(), no cross-package import violation, and test isolation.

#6 [medium] F6 Minor: CUDA-unavailable rank reported as cross-architecture

inductor_tuning.py:21-26: def _cuda_device_identity(device): """Return (product_name, compute_capability) for a CUDA device, or ('', None) otherwise.""" resolved = torch.device(device) if resolved.type != "cuda" or not torch.cuda.is_available(): return "", None return torch.cuda.get_device_name(resolved), tuple(torch.cuda.get_device_capability(resolved)) If torch.cuda.is_available() is False on one rank for an unrelated reason (forked context, driver/visibility problem, CUDA not yet initialized), that rank reports capability None while its CUDA peers report (12, 0). aot.py:933-938 then raises: 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}") so a CUDA-unavailable rank is reported as a mixed-architecture host. Same pattern in inductor_tuning.py:250-255. The message is actively misleading for the most likely real cause on a single-SKU host, and preparation already fails with no hint that the fault is per-rank CUDA initialization. Fix: distinguish "" from a real product name and raise a distinct error ("rank N reported no CUDA device identity") before the capability comparison.

Verified safe: the sorted(..., key=lambda cap: (cap is None, cap)) comparator does not compare None against a tuple because the first key element differs; no TypeError.

Also: InductorSelections.warm did not gain a collective. Before: one _gather((variant, inventory)); after: one _gather((variant_key, capability, inventory)) (inductor_tuning.py:249). Same collective count per forward — no added synchronization cost, so I make no head-of-line-blocking finding here. Similarly _publication_lock adds one all_gather_object plus one barrier per distinct (host, root); on a homogeneous host that is one extra collective total (aot.py:790-804), not a hot path.

#8 [medium] Verified-sound list (negative results)

Verified sound or non-issues (do not report as findings):

#11 [medium] F9 Minor: per-SKU _balance_compilations narrows its MemoryError message, and architecture is gated twice

(a) aot.py:681-682 (unchanged text): if not any(workers): raise MemoryError("no rank on this host has room for a forward compiler") At head that workers argument is now a per-SKU slice: aot.py:1000-1010 builds 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] ... local = _balance_compilations([counts[index] for index in members], [workers[index] for index in members]) so the message says "on this host" when the real scope is one (host, GPU product name) subgroup. On a mixed host the operator reads "no rank on this host has room" while the other SKU on the same host is compiling. Concrete fix: pass the subgroup description into _balance_compilations or reword to "no rank in this host's {gpu_name} group". Same class of drift as F7.

(b) Two independent architecture gates with different collectives but the same claim: aot.py:933-938 ("tensor-parallel ranks span incompatible CUDA architectures") runs before compile, and inductor_tuning.py:250-255 ("Inductor warmup spans incompatible CUDA architectures") runs again per warmup. Both sorted(capabilities, key=lambda cap: (cap is None, cap)). They are duplicated rather than shared, so a future fix to one (e.g. distinguishing a CUDA-unavailable rank, F6) will not reach the other. Not a defect on its own; recorded so the F6 fix is applied in both places.

#12 [medium] F10 Minor: test-suite claim accuracy and the cache-footprint amplification

Claim accuracy, verified against the diff and the named files: