Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #639

Raw Markdown for agents: https://autobot.eidonix.com/p/71472b0c-1b15-456f-be41-d53abc179af1.md

#1 [high] Lens: subtraction review of #639 — 4 findings

Diff is small (+58/−18) but each of its three code hunks adds a hardcoded knob or a fallback branch. Findings, ranked:

F1 (delete, don't patch) — the 1 GiB discrete headroom cap. ignition/preparation/compile_pool.py:48-55 verbatim: device_bytes = _WORKER_DEVICE_BYTES if shared else _DISCRETE_WORKER_DEVICE_BYTES # Integrated GPUs share physical memory with the host; discrete compile workers exit before # runtime allocations, so cap their device-side reserve at 1 GiB. compile_reserve = headroom_bytes if shared else min(headroom_bytes, 1024 << 20) if free - compile_reserve < device_bytes: torch.cuda.empty_cache() free = device_memory_info(device)[0] capacity = max(0, (free - compile_reserve) // device_bytes) Replacement = main's 4 lines, name restored: if free - headroom_bytes < device_bytes: torch.cuda.empty_cache() free = device_memory_info(device)[0] capacity = max(0, (free - headroom_bytes) // device_bytes) Adding the temp var buys nothing else (it is used in exactly 3 places, all of which were headroom_bytes). The cap silently overrides the caller-configured headroom_bytes — the only declared way to reserve runtime memory (AGENTS.md:450-460 "A setting has one of three homes... so the plan... describe what was prepared"; "Reject weakened guarantees" 182-186). It also drags the 71.5 GiB test case into an if/else rewrite (tests/preparation/test_compile_pool.py:443-452). The 704 MiB estimate alone already delivers most of the worker-count win, with headroom intact: 12 GiB free / 2 GiB headroom → (12288-2048)/704 = 14 workers vs main's 10; 4 GiB default headroom (bootstrap.py:35) → 11 vs main's 8. Cap buys 16 instead of 14 for a documented contract break. Two of the three changes in this file are separable; this is the one to drop.

F2 (collapse + de-duplicate) — thread policy block duplicates host_memory.cpu_workers() and carries two dead defences. ignition/preparation/compile_pool.py:137-144 verbatim: # Partition CPU compile threads across admitted workers and use Inductor's subprocess # pool on POSIX because CompilePool workers run inside spawned SubprocPool processes. cpu_count = os.cpu_count() if hasattr(os, "cpu_count") else None inner_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers))) worker_options = dict(options, compile_threads=inner_threads) if os.name != "nt": worker_options["worker_start_method"] = "subprocess" self.options = worker_options

F3 (one knob, not three) — ignition/preparation/aot.py:901-903: # Allow fallback/binding compilation to parallelize up to the host CPU budget. lock = nullcontext() if _locked else self._publication_lock(coordinator) with lock, torch._inductor.config.patch(compile_threads=min(24, os.cpu_count() or 1)): compile_threads now has four authorities in the package: compilation.py:30 = min(16, cpus) (the configured default, carried into every worker via _OPTIONS), compile_pool.py:140 = min(8, cpus/workers), aot.py:903 = min(24, cpus), aot.py:688 = 1. Replace 903 with the value already computed on self.options (a MappingProxyType(_compile_options(options)), aot.py:823, so the key is always present): with lock, torch._inductor.config.patch(compile_threads=self.options['compile_threads']): That deletes the 4th cap and the raw os.cpu_count() call. The PR also leaves the sibling policy behind: aot.py:687-689 still patches compile_threads=1 in DeferredCompiledForward.materialize_for_capture — the same binding/load path the new comment says should parallelize. Pick one: either materialize_for_capture uses self.cache.options['compile_threads'] too, or the 24 is withdrawn; aot.py should not carry both. Related doc drift: docs/preparation-development.md:318 ("artifact binding starts no additional compiler pool") still describes main's policy and is not updated.

F4 (tests mirror the implementation) — tests/preparation/test_compile_pool.py:28 assert pool.options["compile_threads"] == min(8, 16 // expected) and tests/preparation/test_forward_compile_options.py:282 == max(1, min(8, (os.cpu_count() or 1) // max(1, pool.workers))) re-implement the formula, so they pass for any formula. Both parametrizations yield 8 (16//2 and 16//1 both cap at 8), so pin == 8. And tests/preparation/test_forward_compile_options.py:333-341 (new, 9 lines) monkeypatches _prepare_many only to observe the config value; if F3 lands it reduces to one line next to the existing option assertions at :279-284, or disappears entirely.

#3 [high] Research summary

Subtraction/simplicity review of #639. The diff is small (+58/−18, 4 files, no new functions, flags or parameters), but each of the three code hunks adds a hardcoded knob or a defensive branch. Four findings, all in the scratchpad with verbatim quotes:

  1. The 1 GiB discrete compile_reserve cap should be deleted, not shipped (compile_pool.py:48-55). The temp variable is used in three places that were all headroom_bytes, so removing the min(headroom_bytes, 1024 << 20) restores main's four lines exactly. It silently overrides the only declared runtime-reserve setting (AGENTS.md:450-460, and "reject weakened guarantees" 182-186), and the 704 MiB estimate alone already yields most of the worker win with headroom intact: 12 GiB free / 2 GiB headroom goes 10 → 14 workers without the cap, 16 with it; at the 4 GiB default it goes 8 → 11. It is also the hunk that forces the if/else rewrite of test_compilation_preserves_configured_headroom.

  2. The thread-policy block duplicates host_memory.cpu_workers() and carries two dead defences (compile_pool.py:137-144): hasattr(os, "cpu_count") exists only so a Windows test mock that lacks the attribute keeps passing, max(1, self.workers) is unreachable because workers < 1 already raised, and os.cpu_count() re-derives a count the module already imports a helper for — one that uses sched_getaffinity, which is also what the worker budget at :42 uses. Six lines collapse to three with cpu_workers() // self.workers.

  3. compile_threads now has four authorities in one package (min(16) in compilation.py:30, min(8) in compile_pool.py:140, min(24) in aot.py:903, and still 1 in aot.py:688, which the PR left untouched and did not mention). aot.py:903 can use self.options['compile_threads'], which is always present, deleting the fourth cap. Pick one policy for materialize_for_capture instead of carrying both.

  4. Two test assertions recompute the implementation formula (test_compile_pool.py:28, test_forward_compile_options.py:282), so they pass for any formula while the parametrized value is 8 in both cases; the new 9-line prepare_many test collapses to one assertion if finding 3 lands.

Also recorded what is genuinely lean (704 MiB constant, platform branch, existing pinned-literal tests) so the review stays sparse and does not nitpick.

#4 [high] Supporting context citations for the #639 subtraction review

Anchors to cite in the report (all verified at PR head):

HELPER THAT ALREADY EXISTS (basis of F2): ignition/preparation/compile_pool.py:20 — from .host_memory import cpu_workers, device_memory_info (so cpu_workers is already imported in the very file that now calls raw os.cpu_count()). ignition/preparation/compile_pool.py:42 — limit = min(cpu_workers(compile_workers), cpu_workers()) (worker budget already affinity-aware). ignition/preparation/host_memory.py:25-35, verbatim: def cpu_workers(requested=None, *, pools=1): """Divide a host's compiler process budget among its preparation ranks.""" ... available = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else os.cpu_count() or 1 budget = available if requested is None else requested ... return max(1, budget // pools) It already does the hasattr fallback, the or 1, and the max(1, ...) that compile_pool.py:139-140 re-does.

REDUNDANCY PROOFS (F2): compile_pool.py:134-135 — if type(workers) is not int or workers < 1: raise ValueError("forward compiler pool requires a positive admitted worker count") runs before :140, so max(1, self.workers) is unreachable-defensive. compile_pool.py:157-160 — existing if os.name == "nt": ... else: SubprocPool(...) platform branch the new if os.name != "nt": mirrors.

OPTION PLUMBING (F3): aot.py:823 — self.options = MappingProxyType(_compile_options(options)); compilation.py:35-36 _compile_options always {**_OPTIONS, **...}, so self.options['compile_threads'] is always present — the replacement expression is safe. aot.py:825 — options = {name: value for name, value in self.options.items() if name != 'compile_threads'} (strips it from the cache key; unchanged by this PR). compilation.py:26-32, verbatim: _OPTIONS = {'max_autotune': True, 'emulate_precision_casts': True, 'memory_planning': True, 'memory_pool': 'combined', 'triton.cudagraphs': False, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': True, 'compile_threads': min(16, os.cpu_count() or 1)} if os.name == 'nt': _OPTIONS['worker_start_method'] = 'spawn' → NOTE: worker_start_method is ALREADY a repo-level option key with a Windows default of 'spawn'; the new branch at compile_pool.py:142-143 re-sets it only because the spawned-worker requirement differs. Worth one clause in the report: the new key is not novel, but the conditional override duplicates a policy the defaults already express. Fifth site of the same knob (context for "four/five authorities"): scripts/inspect_forward_kernels.py:83 — with (torch.no_grad(), torch._inductor.config.patch(compile_threads=1),.

DOC DRIFT (F3), verbatim docs/preparation-development.md:317-318: compilation uses memory-bounded parallel workers on both integrated and discrete GPUs; artifact binding starts no additional compiler pool. Still accurate only for main's =1; #639 does not touch it. Also docs/preparation-development.md:314-316 — "Derive preparation memory policy from hardware. Shared preparation code detects integrated GPUs and budgets compiler workers and tuning races against available system RAM" (the RAM-bounded principle the new CPU-count-only formula departs from).

CALLER OF THE CAP (F1): ignition/preparation/bootstrap.py:35 defaults headroom_bytes = 4 << 30, :134 passes plan.headroom_bytes + plan.reserve_bytes → the cap bites on the default path, not only on large reserves. UNTOUCHED SIBLING (F1/F3): compile_pool.py:62 — max(host_memory._HEADROOM_BYTES, headroom_bytes if shared else 0) (host-RAM headroom deliberately unchanged; state plainly that #639 is only the device-side half, so the 1 GiB cap creates a device/host asymmetry in one function).

TEST MOCK SHAPED BY PRODUCTION CODE (F2): tests/preparation/test_compile_pool.py:470 monkeypatch.setattr(compile_pool, "os", SimpleNamespace(name="nt")) (no cpu_count) with :476 assert (pool.workers, pool.options["compile_threads"]) == (1, 1); that passthrough is the sole reason for hasattr(os, "cpu_count").

#5 [high] Review verdict, framing, and verbatim before/after blocks

VERDICT SENTENCE: The diff is lean in structure — no new functions, classes, parameters, CLI flags, plan fields, env vars, or dead code, and 704 << 20 / +58−18 is about as small as this change can be written — but it is not lean in knobs: it adds a byte constant, a 1 GiB cap that silently overrides a configured setting, a per-worker thread formula, a worker start-method override, and a separate 24-thread cap in a second file, while leaving the sibling 1-thread patch in place. Four suggestions total; #1 is the one to drop outright.

RANKING FOR THE REPORT (most to least material):

  1. Delete the 1 GiB discrete headroom cap (compile_pool.py:48-55) — delete-not-patch, restores main exactly, removes a weakened guarantee, and shrinks the test rewrite.
  2. Collapse the thread block to cpu_workers() // self.workers and drop hasattr, max(1, self.workers), and raw os.cpu_count() (compile_pool.py:137-144).
  3. One compile_threads authority: use self.options['compile_threads'] at aot.py:903, and resolve the materialize_for_capture = 1 conflict at aot.py:688 rather than leaving two policies in one file.
  4. Tests at test_compile_pool.py:28 and test_forward_compile_options.py:282 mirror the formula; pin 8. The new test at test_forward_compile_options.py:333-341 folds into the existing assertions at :279-284 once #3 lands.

EXACT BEFORE/AFTER FOR SUGGESTION 1 (main, git show main:ignition/preparation/compile_pool.py equivalent, i.e. the − lines of the diff): if free - headroom_bytes < device_bytes: torch.cuda.empty_cache() free = device_memory_info(device)[0] capacity = max(0, (free - headroom_bytes) // device_bytes) Head (+) is the 4-line block quoted in scratchpad entry 1. Concrete instruction: delete the compile_reserve variable and the two-line comment, restore headroom_bytes in both uses, keep the 704 << 20 constant and worker_start_method/thread work (those are separable and defensible).

EXACT REPLACEMENT FOR SUGGESTION 2 (6-line block → 3): # Inductor's parallel compile worker needs a subprocess start method inside our spawned pool. threads = max(1, min(8, cpu_workers() // self.workers)) self.options = dict(options, compile_threads=threads, **({} if os.name == "nt" else {"worker_start_method": "subprocess"})) If the 3-argument dict expansion reads as too clever for the repo, the plain equivalent is self.options = dict(options, compile_threads=threads) followed by the existing one-line if os.name != "nt": self.options["worker_start_method"] = "subprocess" — still 4 lines and still deletes the two dead defences.

EXACT REPLACEMENT FOR SUGGESTION 3: with lock, torch._inductor.config.patch(compile_threads=self.options['compile_threads']): in place of ... min(24, os.cpu_count() or 1)), and in materialize_for_capture (aot.py:687-688) either compile_threads=self.cache.options['compile_threads'] or leave the 24 out; do not ship both.

CONVENTION CITATIONS TO NAME: AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"); AGENTS.md:194-199 (mocks that bypass behaviour cannot establish runtime correctness → the hasattr guard); AGENTS.md:450-460 (a setting has one of three homes, carried through the plan so the plan describes what was prepared → the 1 GiB cap and the 24 cap are unrecorded, which the dossier notes is the same objection raised on #509); AGENTS.md:182-186 (do not weaken guarantees). WHAT NOT TO RAISE: the ~672 MiB measurement lacking an artifact, CI red, no main baseline, worker-count rise, affinity divergence — correctness/claims lenses own those; here they are only cited as supporting context for the cap and the cpu_count choice.

#2 [medium] What is already lean in #639 (do not flag)