Correctness, Contracts & System-Level Consequences review — #639 "ignition: tune discrete CompilePool sizing and scale Inductor compile threads"
Head 3400e3a, base main, +58/−18 in 4 files (ignition/preparation/compile_pool.py, ignition/preparation/aot.py, tests/preparation/test_compile_pool.py, tests/preparation/test_forward_compile_options.py). Verdict: request changes. The thread/start-method half is a real fix, but it is priced by nothing; the sizing half silently relaxes the discrete compile reserve on the default path and raises worker counts with no main baseline.
Key findings
- Blocker — admission pricing was not updated for the new fan-out.
compile_pool.py:139-143gives every outer compiler worker up to 8 Inductor threads andworker_start_method="subprocess"(i.e. real nested processes), but the host is still charged oneFORWARD_WORKER_BYTES = 32 GiBslot per worker (host_memory.py:15,compile_pool.py:60-61) and the device is still charged one 704 MiB single-process footprint per worker (compile_pool.py:24-25,:55). A host/GPU admitted for N slots can now run up to 8N compiler processes — exactly what main's one-thread policy existed to prevent. - Major —
aot.py:903puts up to 24 Inductor threads in the parent rank for the whole_prepare_manybody: binding, warmup, and theBindingMismatchfallback recompile, i.e. the phase where all compiled forwards are resident. Contradictsdocs/preparation-development.md:318("artifact binding starts no additional compiler pool"), ignores the configured_OPTIONS['compile_threads'](compilation.py:30), and is recorded nowhere (stripped from the cache key ataot.py:825). - Major — affinity vs
cpu_countmismatch. Thread budgets come fromos.cpu_count()(compile_pool.py:139-140,aot.py:903) while worker counts come fromlen(os.sched_getaffinity(0))(host_memory.py:31). A 3-CPU cgroup/taskset rank that admits 3 workers gets 8 threads each = 24 compilations on 3 CPUs — the exact casetest_explicit_forward_workers_are_bounded_by_cpu_affinityprotects on the process side. - Major — one-sided reserve clamp silently changes the default path.
compile_pool.py:51clamps the device reserve to 1 GiB on discrete whileCompilerResources.headroomkeeps the 8 GiB host floor (:62). With the default plan headroom of 4 GiB (bootstrap.py:35), every discrete export's compile-time device reserve drops 4 GiB → 1 GiB, not just "large runtime reserves" as the description frames it. - Minor/Major — Windows thread partitioning and
spawnpreservation are unasserted, andDeferredCompiledForward.materialize_for_capturekeepscompile_threads=1(aot.py:688), leaving two conflicting thread policies in one file. - Minor — tests mirror the implementation formula rather than pinning values, and the description's evidence has no
mainbaseline, no worker/thread counts, and is on a 288 GB GB300 where the reserve change matters least.
Areas confirmed sound (not overstating)
- No on-disk/artifact contract break.
ForwardCache.__init__stripscompile_threadsfrom the hashed option set (aot.py:823-827), so existing compiled forwards still load; no proto, core, captured-graph, CLI or config-key contract changes. - Patch identity survives the new nesting.
_compile_forwardre-appliesruntime_patches.apply()in the outer worker (compile_pool.py:100-101) andruntime_patches/workers.py:21-23does so inside Inductor's own workers, withinitialize_inductor_workerinstalled onsubproc_pool/async_compile.worker_start_method="subprocess"is consistent with the SPAWNSubprocPoolatcompile_pool.py:160, and Windows keeps'spawn'from_OPTIONS(compilation.py:31-32). The stated daemonic-restriction fix is coherent with the code. - Right layer. Shared
ignition/preparation/code, no per-model branches, no new hardware target. - Structure unchanged.
_prepare_many's concurrency gate (aot.py:948-949,len(pending) >= compiler.workers) and the per-worker options plumbing (compile_pool.py:161-162passingself.options) are still correct in shape.
1. Correctness, Safety & Platform Parity
Finding 1 — Blocker: workers are priced as one process but now run a process tree (host side)
ignition/preparation/compile_pool.py:137-144:
# 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
self.options is passed verbatim to every _compile_forward (compile_pool.py:161-162), hence to aot_forward(forward, options=options) (:112) and torch._inductor.standalone_compile(..., options={'config_patches': ...}) (aot.py:423-425). Host admission, however, is untouched:
ignition/preparation/host_memory.py:13-16:
_WORKER_BYTES = 2 << 30
# Conservative concurrency estimate; complete-forward tracing can outgrow kernel tuning workers.
FORWARD_WORKER_BYTES = 32 << 30
_HEADROOM_BYTES = 8 << 30
compile_pool.py:60-61 still returns host_memory.FORWARD_WORKER_BYTES as worker_bytes, and allocate_workers subtracts exactly one of those per worker (compile_pool.py:76-84). Main's rationale is deleted by this PR (compile_pool.py:137-138 on main: "Nested Inductor pools would escape the host's admitted process budget") — the mechanism it guarded is now reinstated without the price changing.
Impact: at head, 32 admitted workers on a 128-core host (test_compile_pool.py:377 case (32, 95, 32, 2)) may run 64 concurrent Triton/ptxas/NVCC compilations against 32×32 GiB of priced slots; 8 workers × 8 threads = 64 compilations on a host admitted for 8 slots. Peak RSS during preparation is now a function of scheduling luck, not of available_bytes(). That is the failure #242 reports (a rank that cannot host a compiler dying mid-export), amplified. Also contradicts docs/preparation-development.md:314-318 ("budgets compiler workers ... against available system RAM").
Fix: either multiply worker_bytes by inner_threads in compiler_resources, or bound inner_threads by the admitted host-RAM budget instead of by CPU count alone — the principle used by 468415d1 and f9aec99c for integrated GPUs.
Finding 2 — Major: affinity-limited ranks get the whole machine's thread budget
compile_pool.py:139-140 uses raw os.cpu_count(), while the worker budget is affinity-derived:
host_memory.py:31:
available = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else os.cpu_count() or 1
and compile_pool.py:42 caps workers by cpu_workers().
tests/preparation/test_compile_pool.py:535-542:
def test_explicit_forward_workers_are_bounded_by_cpu_affinity(monkeypatch):
...
monkeypatch.setattr(host_memory.os, "sched_getaffinity", lambda _: set(range(3)))
...
assert compile_pool.CompilePool("cuda:0", compile_workers=32).workers == 3
That rank then computes inner_threads = min(8, 96 // 3) = 8 on a 96-core machine → up to 24 Inductor compile processes inside a 3-CPU cgroup, an 8× oversubscription and a direct reversal of the invariant that test was written to hold. Same bug in aot.py:903 (min(24, os.cpu_count() or 1) ignores affinity entirely).
Fix: derive both from host_memory.cpu_workers() (which already closes over sched_getaffinity) instead of os.cpu_count().
Finding 3 — Minor: Windows thread partitioning and "spawn" preservation are untested, and the test that "covers" Windows exercises a fallback that cannot occur on Windows
tests/preparation/test_compile_pool.py:467-476:
def test_windows_compiler_workers_fit_host_ram_with_larger_device_budget(monkeypatch):
...
monkeypatch.setattr(compile_pool, "os", SimpleNamespace(name="nt"))
...
pool = compile_pool.CompilePool("cuda:0", headroom_bytes=8 << 30)
assert (pool.workers, pool.options["compile_threads"]) == (1, 1)
SimpleNamespace(name="nt") has no cpu_count, so the new hasattr(os, "cpu_count") guard at compile_pool.py:139 resolves to None → inner_threads = 1. The assertion therefore pins the fallback, not Windows behaviour. Grep for worker_start_method in tests finds only == "subprocess" assertions (test_compile_pool.py:30, test_forward_compile_options.py:284); nothing asserts 'spawn' survives on the nt path.
Impact: the description claims "spawn" is "preserved on Windows", and a real 64-core Windows host with 8 workers will now run 8-thread Inductor spawn pools inside ProcessPoolExecutor spawn workers (compile_pool.py:157-158) — never exercised in CI or by any test. Fix: monkeypatch os.name on the real module (or add cpu_count to the namespace) and assert both inner_threads and worker_start_method on the nt path.
Finding 4 — Minor: two conflicting thread policies left in aot.py, one uncovered
ignition/preparation/aot.py:688:
def materialize_for_capture(self):
with _guard_code_cache(self.cache.root / 'guards'), torch._inductor.config.patch(compile_threads=1):
bound = self.cache._load(self.owner, self.path, required=True, before_run=self.before_run)
The streaming-capture path (capture.py:175-182 via materialize_for_capture) binds at 1 thread while _prepare_many now binds and warms at up to 24. Either the difference is deliberate (then it needs a comment and a line in the description) or it was missed. No test covers it. Fix: state the rationale or make the policies uniform; add coverage.
Finding 5 — Minor: nested-process shutdown/blast radius is now two-level and untested
compile_pool.py:167-169 only calls self.pool.shutdown(). With per-worker Inductor subprocess pools, a single failed or slow forward now leaves up to inner_threads grandchildren per worker. test_cli_interrupt_leaves_no_compiler_processes (tests/preparation/test_native_processes.py:123-162) still builds a bare SubprocPool(1) with default options and therefore does not cover the tree this PR creates. Fix: add a SIGINT-during-compile test that asserts no orphaned compile processes when a CompilePool worker holds nested Inductor workers.
2. Unintended System-Level Consequences
Finding 6 — Blocker (same defect, device side): 704 MiB no longer bounds a worker
ignition/preparation/compile_pool.py:22-25:
# Device memory one compiler worker can hold: its CUDA context plus Inductor's constant folding.
_WORKER_DEVICE_BYTES = 2 << 30
# A discrete GPU worker holds only device memory (~672 MiB measured for CUDA context and Inductor constant folding).
_DISCRETE_WORKER_DEVICE_BYTES = 704 << 20
compile_pool.py:52-55:
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)
The 672 MiB measurement is of one process ("initialize a CUDA context", per the PR's own Why). Each admitted worker can now spawn up to 8 Inductor compile processes that each initialize CUDA/triton state, while capacity still divides free memory by one 704 MiB unit. Combined with finding 7 (reserve 4 GiB → 1 GiB), a 12 GiB-free discrete part goes from 10 workers on main to 16 at head (test_compile_pool.py:43-45), each potentially fanning out 8×. No test, artifact or measurement covers the fan-out footprint — every device input is monkeypatched (test_compile_pool.py:383-384).
Impact: on SM120/SM121 workstations and on multi-rank hosts sharing one discrete GPU, the new admission math can OOM during preparation, which is worse than under-admitting: the export dies after minutes of work. Fix: price device bytes as device_bytes × inner_threads, or keep one Inductor thread per worker and only raise the worker count; tie the constant to a measured maximum, not an average single process.
Finding 7 — Major: the reserve clamp is one-sided, undocumented, and changes the default for every discrete export
compile_pool.py:49-62:
# 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)
...
return CompilerResources(capacity, available, limit,
host_memory.FORWARD_WORKER_BYTES + (device_bytes if shared else 0),
max(host_memory._HEADROOM_BYTES, headroom_bytes if shared else 0))
The clamp feeds only device capacity and the empty-cache probe; CompilerResources.headroom — which allocate_workers subtracts from host memory (:73-84) — still floors at 8 GiB on discrete. So the same configured number is now honoured in full on integrated GPUs, clamped to 1 GiB for device admission on discrete, and floored at 8 GiB for host admission. bootstrap.py:35 sets headroom_bytes: int = 4 << 30, so the default discrete export loses 3 GiB of compile-time device protection, not only hosts with "large runtime reserves". The behaviour change is visible only in a test expectation change (test_compile_pool.py:446-452: a 71.5 GiB headroom no longer raises MemoryError on discrete but still does on integrated) and is never stated in the description's Result section.
Impact: (a) users who raised [memory] reserve to keep a discrete GPU safe at runtime silently lose that protection during compilation — with reserve = 0, compile_reserve becomes 0 and nothing is reserved at all; (b) #242's host-RAM side (CompilerResources.headroom, the 8 GiB floor) is untouched, so this looks adjacent to that bug without addressing it. Fix: make the discrete compile reserve a named constant derived from the measured footprint (_DISCRETE_WORKER_DEVICE_BYTES * capacity), keep configured headroom behaviour explicit, and document the default 4 GiB → 1 GiB change in the PR.
Finding 8 — Major: up to 24 Inductor threads in the parent rank across binding/warmup/fallback recompile
ignition/preparation/aot.py:901-906:
# 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)):
return self._prepare_many(functions, signatures, progress=progress,
coordinator=coordinator, materialize=materialize, warmup=warmup,
before_run=before_run, stream=stream)
The patch spans the entire _prepare_many: worker scheduling, self._load(...) binding of every artifact, _warm(...) warmup, and the fallback recompile at aot.py:977-980 (bound = BoundForward(aot_forward(forward, options=self.options), forward, False)), which runs in the parent rank. That is the phase in which loaded forwards are kept live while the rest are warmed (aot.py:965-1005, with release_unused(generation=0) between items). Main's value was 1, with the comment "Compiler workers own parallel compilation; artifact binding needs no second worker pool." Consequences:
- Docs contract:
docs/preparation-development.md:314-318states "artifact binding starts no additional compiler pool". An in-process 24-thread Inductor pool is not aCompilePool, but it is a compiler pool running during binding/warmup and it escapescompiler_resources/allocate_workersentirely (compile_pool.py:37-96). - Memory: transient RSS during prep now includes up to 24 concurrent Triton/ptxas compilations in the rank that is also holding compiled forwards and binds;
_HEADROOM_BYTES = 8 GiB(host_memory.py:16) andrelease_unused()were sized for a one-thread parent. - Unrecorded switch: the value ignores the configured
_OPTIONS['compile_threads'] = min(16, os.cpu_count() or 1)(compilation.py:30) and hardcodes a different cap (24); it is stripped from the cache key (aot.py:823-827) and absent fromreproduction_arguments/Plan.to_dict(), so an export's thread policy cannot be reconstructed from its metadata — the same objection Autobot raised on #509.
Fix: keep compile_threads=1 for binding, and run only the fallback recompile under one explicitly bounded pool derived from host_memory.cpu_workers()/_OPTIONS['compile_threads']; record the value in the plan/reproduction arguments.
Finding 9 — Minor: unbounded concurrent-compile high-water mark; head-of-line blocking unchanged
_prepare_many gates on worker count only (aot.py:948-949: if len(pending) >= compiler.workers: finish()), so a slow worker holding 8 nested compiles still occupies exactly one slot while the GPU/CPU high-water mark depends on which workers happen to have live nested compiles. Not a regression in the gate, but there is now no admission check on the true process count. Fix: if nested threading stays, gate on workers × inner_threads against the same budget.
3. Architecture, Contracts & Charter Compliance
- Global default change without opt-in or served-workload evidence. Per the charter ("Bring real evidence ... benchmarks showing an actual speedup over
mainon a served workload (#210)") and#639's own claim set: the description gives one wall-clock number (DeepSeek-V4.1 101/101 forwards in 359.8 s on GB300/SM103) with nomainbaseline, no worker/thread counts, no memory samples, and on a 288 GB HBM part — the hardware where a device-reserve reduction matters least. The change binds on SM120/SM121 workstations, which is where the A/B is missing. - "Be explicit and pin everything. No magic defaults." Four new hardcoded, unconfigurable numbers:
704 << 20(compile_pool.py:25),1024 << 20(:51),8(:140),24(aot.py:903).[preparation]options no longer express thread policy anywhere:_OPTIONS['compile_threads']survives only as the worker-count cap (compile_pool.py:42-44). - Partial reversal of a deliberate policy.
c8d4c324(Luke Alonso) admits "one Inductor thread each"; #122's author withdrew per-compiler threading measurements because that mechanism no longer exists on main. #639 reinstates multi-threaded compiler workers in a new form without citing that history or re-measuring it. - Generated defaults vs docs.
docs/model-preparation.md:234anddocs/cli-design.md:1463(not opened) describe compiler sizing only generically ("Automatic memory-bounded sizing"); the per-worker device formula is undocumented before and after, and no doc/comment outside the touched lines is updated. - No linked issue. #242 (host-RAM side) is the closest open report and remains unfixed here; the daemonic-multiprocessing failure that motivates
worker_start_method="subprocess"is not filed anywhere. - Bundling. Three separable concerns in 58 lines (device estimate, reserve clamp, thread/start-method policy); #509's review objected to exactly this pattern.
- Coordination. #597 is open, reviewed "Ready To Merge", and edits the same
compile_pool.py/aot.py; whoever lands second rebases.mainhas no commits to these files since the branch point.
Layer placement itself is fine: shared preparation code, no per-model branch, no new hardware target, no wire/proto/captured-graph contract touched.
4. Tests & Claim Accuracy
Finding 10 — Minor: assertions copy the implementation formula
tests/preparation/test_compile_pool.py:28:
assert pool.options["compile_threads"] == min(8, 16 // expected)
tests/preparation/test_forward_compile_options.py:282:
assert pool.options['compile_threads'] == max(1, min(8, (os.cpu_count() or 1) // max(1, pool.workers)))
These mirror compile_pool.py:140 verbatim, so a wrong partition passes as long as implementation and test are edited together. The new test_prepare_many_scales_inductor_compile_threads_with_cpu_count (test_forward_compile_options.py:333-342) monkeypatches aot.ForwardCache._prepare_many out and only proves the number reaches config.patch — not that the scope should cover binding/warmup, nor that 24 threads are safe with forwards resident. Fix: pin literal expected values per case (as the parametrized case at :377 already does for workers) and assert the policy scope.
Finding 11 — Minor: description claims vs the diff
- "when large runtime reserves are configured" — inaccurate scope.
bootstrap.py:35defaultsheadroom_bytes = 4 << 30, so every discrete export's compile-time device reserve falls tomin(4 GiB, 1 GiB) = 1 GiB(compile_pool.py:51). Verified by the test change attest_compile_pool.py:446-452. - Worker-count delta never quantified. 10 → 16 workers at 12 GiB free / 2 GiB headroom (
test_compile_pool.py:43-45vs main's 10), 3 → 4 at 3 GiB free (:374-388). Silent ~1.6× concurrency increase; not in the description. - "subproc pool on POSIX ... daemonic restrictions" — plausible and consistent with
compile_pool.py:160, but no issue, log or reproducer is cited; and sincecompile_threads=1was what disabled nested pools, the requirement is self-inflicted by the same PR. - Omitted before/after fact:
aot.py:688'scompile_threads=1was left alone, so the description's "After" is incomplete foraot.py. - Verification vs CI: the description lists only green local unit runs, while CI is failing on head
3400e3a(CI-runner infra noise itself is out of scope; the contradiction with the claimed verification is not). - Skips: "GPU-gated preparation unit tests were skipped" is accurate and repo-wide (no workflow runs them), which is precisely why no test validates that 704 MiB is safe under 8× fan-out.
Open questions
- Why is CI red on
3400e3a, and does the failure touch these files? - What
compile_workers/headroom_bytesdid the DeepSeek-V4.1 and Inkling-2-Small exports use, and what does the same export take onmain? Without that pair the sizing half has no evidence. - Is 704 MiB safe for the largest shipped forward (the replaced comment named "Kimi K3's 93-layer forwards"), and specifically per nested Inductor process? Where is the 672 MiB measurement?
- Is the 8 GiB host-RAM headroom floor on discrete (
compile_pool.py:62) intentional while the device reserve is clamped (#242's remaining half)? - Was
materialize_for_capture'scompile_threads=1(aot.py:688) left alone deliberately? - Which of #597 and #639 lands first, and does #597's
groups=work assume the 8-worker/1-thread world?