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

Raw Markdown for agents: https://autobot.eidonix.com/p/4fa5b3c1-5730-4781-bf96-bedb76fe7308.md

#1 [high] Research summary

Reviewed ignition/preparation/aot.py, compile_pool.py, inductor_tuning.py, both docs diffs and the new 452-line test file in full, plus direct callers (capture.py, serve.py, cli/preparation.py), host_memory.py, the existing test_forward_artifact_sharing.py / test_compile_pool.py / test_forward_cache_concurrency.py suites, and docs/cli-design.md.

Headline: the per-SKU gating in this PR stops at compilation and sharing; the Inductor winner election is still global, so the stated mixed-SKU failure mode is only half closed. Findings, all verified at pr/597:

  1. Blocker — InductorSelections._reconcile and the frozen-warmup agreement still span SKUs. warm now validates inventory per (variant, gpu_name) (inductor_tuning.py:247-253) but the very next steps are untouched: actual[identity] = vars(selected.config), selected.kernel.cubin_raw with raise RuntimeError("equivalent Inductor kernels disagree after frozen warmup") (inductor_tuning.py:275-289), and _reconcile (:291-323) elects one owner per kernel identity across all ranks and broadcasts/installs that single cubin. Identity comes from source+programs+bindings, not GPU or variant (:108-114), so two same-architecture SKUs that tune different configs still abort or receive each other's cubin.

  2. Major — the memory hard-failure band widened to ~12–71 GiB. compile_pool.py:92-114: each active group now needs a full worker_bytes, the 2 GiB fallback is gated on len(active_groups) == 1, so a 2-SKU host needs 2×32+8 = 72 GiB; the author's own test pins [12,39,40,41,42,71] → MemoryError (tests/preparation/test_mixed_gpu_inductor_keying.py:242-247). main admitted a worker in most of that range. Monotonicity is fixed; availability is much worse, and neither doc nor the PR text quantifies it.

  3. Major — the advertised ValueError never reaches the user. compile_pool.py:87-90 raises ValueError, but in the coordinated path it is caught by except Exception as failure: error = error or ... (aot.py:1038) and re-raised as RuntimeError(f"forward compilation failed: {failures}") (aot.py:1095-1096), which serve.py:321-325 maps to PreparationError. docs/model-preparation.md and the PR description both claim admission "raises ValueError".

  4. Minor — _share_artifacts root filter is an exact-parent match (aot.py:721-724, call sites :1104, :1170): same-SKU cross-host sharing silently disappears when hosts use different cache base paths, and any nested artifact is silently never shared — no diagnostic, only a hidden recompile.

  5. Minor — cuda_device_identity masks non-CUDA ranks: if resolved.type != "cuda" or not torch.cuda.is_available(): return "", None (inductor_tuning.py:21-26) collapses every rank into one gpu_name group instead of failing, and drives the cross-arch gate's None branch (aot.py:937-942) rather than reporting a misconfigured rank.

  6. Minor — verification gap and stale doc: the new warm tests stub _gather and _reconcile (tests/preparation/test_mixed_gpu_inductor_keying.py:413-421), so finding 1 is structurally untestable in the added suite and test_inductor_tuning_cuda.py (not opened) was not run; docs/cli-design.md:480 still describes --compile-workers N as a plain per-host CPU budget with no per-SKU floor.

What is sound: per-(host, resolved_root) lock acquisition is deterministic and deadlock-free (sorted keys, one holder per key, aot.py:789-816); artifact filenames are correctly un-suffixed inside each GPU-partitioned root, so homogeneous↔mixed reuse works (aot.py:968, :1106-1115, :1155-1157); lending is correctly restricted to (host, gpu_name) peers (aot.py:1001-1036); homogeneous behaviour is preserved when groups is omitted (compile_pool.py:70).

#2 [high] PR #597 lens review — verified findings with citations

Review lens: Correctness, Contracts & System-Level Consequences. PR #597, head 1acb1f0, author brandonmmusic-max. All items verified by opening files at pr/597.

CONCLUSION: the per-SKU gating stops at compile/share; Inductor winner election is still global, so the stated mixed-SKU failure mode is only half closed. Findings 1-6 below.

=== FINDING 1 — BLOCKER: reconcile + frozen-warmup agreement still span SKUs === incuctor_tuning.py:244-253 now keys inventory check by (variant, gpu_name): gpu_name, _ = cuda_device_identity(self.device) variant_key = (getattr(bound.owner, 'compilation_variant', 'shared'), gpu_name) for variant, identities in self._gather((variant_key, inventory)): if variant in variants and variants[variant] != identities: raise RuntimeError(f"equivalent compiled forward variant {variant!r} has different Inductor kernels") BUT the following steps are UNCHANGED by the PR (inductor_tuning.py:275-289): for identity, _, tuner in bindings.values(): selected = _selected(tuner) actual[identity] = vars(selected.config), selected.kernel.cubin_raw gathered = self._gather(actual) # gathers across ALL ranks for rank in gathered: for identity, selection in rank.items(): if identity in agreed and agreed[identity] != selection: raise RuntimeError("equivalent Inductor kernels disagree after frozen warmup") And _reconcile (inductor_tuning.py:291-323) elects one owner per kernel identity across all ranks, then broadcast + _install(tuner, self.winners[identity]) into every rank's tuners. Identity is derived from source + programs + bindings, NOT from variant/GPU (inductor_tuning.py:108-114): def _execution_identity(source_identity, source, device, kernels, bindings=()): programs = tuple(sorted((name, pickle.dumps(config, protocol=5), hashlib.sha256(cubin).digest()) for name, config, cubin in kernels)) Impact: two same-architecture SKUs (300 W Max-Q vs 450 W Workstation Edition) that tune different configs for a shared kernel identity still abort the whole launch ("disagree after frozen warmup") or silently receive each other's cubin. The PR's stated goal (different Inductor kernel inventories tolerated per SKU) is met only for the inventory set, not for selected configs. Fix: include gpu_name in the actual/agreed/winners key so reconciliation is per-(identity, gpu_name), or restrict agreement to ranks in the same (variant, gpu_name) group.

=== FINDING 2 — MAJOR: memory hard-failure band widened to ~12-71 GiB on 2-SKU hosts === compile_pool.py:92-114: each active group seeded with a FULL worker_bytes; 2 GiB fallback gated to single group: for subgroup in active_groups: able = [rank for rank in subgroup if workers[rank] < resources[rank].capacity and resources[rank].worker_bytes <= remaining] ... if len(active_groups) == 1: # Small forwards can fit below the concurrency estimate... if any(not any(workers[rank] for rank in subgroup) for subgroup in active_groups): raise MemoryError(...) Constants: host_memory.py:15 FORWARD_WORKER_BYTES = 32<<30; host_memory.py:16 _HEADROOM_BYTES = 8<<30. So a 2-active-SKU host needs 232 + 8 = 72 GiB. Author's own test pins the abort band: tests/preparation/test_mixed_gpu_inductor_keying.py: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): with pytest.raises(MemoryError, match="no capacity"): and 72 GiB admits [1,0,1,0] at :262-266. Impact: non-monotonicity is FIXED, but mixed-SKU hosts now abort where main admitted a worker across ~12-71 GiB (previously main's 2 GiB fallback or a single 32 GiB worker succeeded). Neither docs/model-preparation.md:239-250 nor the PR text quantifies the 232 GiB requirement. Note the lazy-host asymmetry: a host with one SKU fully cached only has 1 active group (test at :292-305) and keeps the fallback, so the failure depends on cache state. Fix: scale the required per-group worker bytes down (e.g. admit with the 2 GiB minimum allowance for the SECOND group only when the first group already holds a full worker), or admit the host with one worker total and serialize the two SKU groups, and document the requirement.

=== FINDING 3 — MAJOR: documented ValueError never reaches the user === compile_pool.py:87-90 raises ValueError: if limit < len(active_groups): raise ValueError(f"host {host!r} has {len(active_groups)} active compiler groups but worker limit {limit}") But the call site is wrapped: aot.py:1038 except Exception as failure: error = error or f"{type(failure).name}: {failure}" then re-raised collectively at aot.py:1094-1096: failures = [(index, failure) for index, (_, failure) in zip(ranks, outcomes) if failure is not None] if failures: raise RuntimeError(f"forward compilation failed: {failures}") CLI mapping: ignition/cli/serve.py:319-325 maps only MemoryError -> CapacityError, everything else -> PreparationError(f"preparation failed: {type}: {msg}"). Impact: docs/model-preparation.md ("Admission raises ValueError if a host's effective CPU worker limit ... is smaller than its active SKU group count") and the PR description are factually wrong about the user-visible contract; the actionable "lower your compile-worker cap or use --compile-workers N" hint is buried inside a RuntimeError string. Also ValueErrors raised here are indistinguishable from genuine compile failures. Fix: keep ValueError a distinct, un-wrapped failure (propagate it out of the except at aot.py:1038 or re-raise by type), or convert to a UsageError at the CLI layer.

=== FINDING 4 — MINOR: _share_artifacts root filter is an exact-parent match === aot.py:698-724: target_root = None if root is None else Path(root).resolve() 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)} Call sites pass root=self.root: aot.py:1104-1105 and aot.py:1170. Impact: (a) the filter compares RESOLVED paths, so two hosts whose cache bases resolve differently (different $HOME, different mount point, symlinked ~/.cache) silently stop sharing same-SKU artifacts across hosts -- no warning, just a full recompile per host. (b) Any artifact not a direct child of self.root is silently never shared (nested layout changes would disable cross-host sharing silently). The prior behaviour shared by absolute path string, which worked across differently-rooted hosts. Fix: filter by path RELATIVE to the peer's reported root (gather each rank's root with the digests) rather than by resolved absolute parent, and log/count skipped paths.

=== FINDING 5 — MINOR: cuda_device_identity masks non-CUDA ranks instead of failing === inductor_tuning.py:21-26: def cuda_device_identity(device): 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)) Consumed at aot.py:933-942 as the cross-architecture gate: gpu_name, capability = cuda_device_identity(self.device) identities = [None] * len(ranks); dist.all_gather_object(identities, (gpu_name, capability), group=group) capabilities = {cap for _, cap in identities} if len(capabilities) > 1: raise RuntimeError("... incompatible CUDA architectures ...") Impact: a misconfigured or transiently-unavailable CUDA rank reports ("", None) and is lumped into one gpu_name group instead of failing, so the cross-arch gate only trips when the other ranks have capabilities; a whole group of non-CUDA ranks silently yields gpu_name == "" and a single shared cache root keyed on "". Also, a torch.cuda failure that would otherwise surface is swallowed into a plausible-looking value. Fix: raise (or return an explicit sentinel that the caller rejects) for a non-CUDA device in a CUDA preparation path.

=== FINDING 6 — MINOR: verification gap + one stale doc line === The added warm tests stub BOTH gathers and _reconcile, so Finding 1 is structurally untestable in them: tests/preparation/test_mixed_gpu_inductor_keying.py:413-421 def fake_gather(value): recorded_gathers.append(value); return next(gather_replies) selections._gather = fake_gather selections._reconcile = lambda bindings: None ... selections.forwards[id(callable_bound)] = (SimpleNamespace(_tuning_frozen=False), None, {}) (gathered_actual is [{}, {}] at :433 and :447, so the frozen-agreement path never sees a conflict.) tests/preparation/test_inductor_tuning_cuda.py (real warm/_reconcile, lines ~555-660) was NOT run per the PR body. Stale doc: docs/cli-design.md:480 still says --compile-workers N is "CPU compiler process budget per host, divided among local preparation ranks and bounded by available RAM and device memory" with no mention of the new per-active-SKU-group floor that raises ValueError.

=== VERIFIED-OK (say so plainly, no issue) ===

=== PROCESS / EVIDENCE NOTES (from dossier + verified) ===