#1 [high] Host admission pricing unchanged while per-worker Inductor threads go 1→8
compile_pool.py:139-144 (head) sets inner_threads = max(1, min(8, (os.cpu_count() or 1) // max(1, self.workers))) and passes it as compile_threads in the per-worker Inductor options; those options reach aot_forward(forward, options=options) at compile_pool.py:112 → standalone_compile(..., options={'config_patches': ...}) at aot.py:423-425, i.e. Inductor's own AsyncCompile pool inside every outer worker; worker_start_method="subprocess" (compile_pool.py:143) makes those nested pools spawn real processes.
But host admission is untouched: host_memory.py:13-15 _WORKER_BYTES = 2 << 30, FORWARD_WORKER_BYTES = 32 << 30 ("Conservative concurrency estimate"), and compile_pool.py:60-62 still returns host_memory.FORWARD_WORKER_BYTES as worker_bytes, which allocate_workers subtracts per worker (compile_pool.py:76-84). So a host is still charged one 32 GiB slot per worker while each worker can now run 8 concurrent Triton/ptxas/NVCC compilations. main had one Inductor thread per worker ("Nested Inductor pools would escape the host's admitted process budget", compile_pool.py:137-138 on main), which is exactly what this removes. Example at head: 32 workers on a 128-core host (admitted per test_compile_pool.py:377 case (32, 95, 32, 2)) = 64 concurrent compilations for 32 admission slots; 8 workers × 8 = 64 on a host admitted for 8×32=256 GiB. Contradicts docs/preparation-development.md:314-318 ("budgets compiler workers ... against available system RAM"). Fix: scale worker_bytes (or the concurrency estimate) by inner_threads, or bound inner_threads by the admitted host-RAM budget as 468415d1/f9aec99c did for integrated GPUs.
#2 [high] 704 MiB device estimate no longer bounds a worker (it is now a process tree)
compile_pool.py:24-25 _DISCRETE_WORKER_DEVICE_BYTES = 704 << 20 with comment "A discrete GPU worker holds only device memory (~672 MiB measured for CUDA context and Inductor constant folding)" — one measured process. compile_pool.py:55 capacity = max(0, (free - compile_reserve) // device_bytes) still divides by that single-process footprint, but the per-worker options now carry compile_threads = inner_threads (up to 8, compile_pool.py:140) plus worker_start_method="subprocess" (compile_pool.py:143), so each admitted worker can spawn up to 8 Inductor compile processes that initialize CUDA/triton state (same reason the 672 MiB exists per PR text: "initialize a CUDA context").
Combined with compile_pool.py:51 compile_reserve = headroom_bytes if shared else min(headroom_bytes, 1024 << 20) (4 GiB→1 GiB on the default 1 GiB+chunk-term plan headroom, and steeply lower than the ~32 GiB headroom derived at planning.py:343-345 for long contexts), capacity on a 12 GiB-free discrete part goes 10 (main) → 16 (head, asserted at test_compile_pool.py:43-45), each of which may fan out to 8 subprocesses. There is no measurement, artifact or test for the fan-out footprint: every device input is monkeypatched (test_compile_pool.py:383-384). Fix: price device bytes as device_bytes × inner_threads (or keep 1 thread and raise worker count only), and keep the estimate tied to a measured max, not an averaged single process.
#3 [high] prepare_many now runs up to 24 Inductor threads in the parent rank across binding/warmup/fallback recompile
aot.py:903 (head): with lock, torch._inductor.config.patch(compile_threads=min(24, os.cpu_count() or 1)): wraps the whole _prepare_many body, which includes (a) worker compilation scheduling, (b) self._load(...) binding of every artifact, (c) _warm(...)/selections.warm(...) warmup - the memory-heavy phase, and (d) the BindingMismatch fallback recompile at aot.py:977-980 which runs aot_forward(forward, options=self.options) in the parent rank process. main's value was 1 with the comment "artifact binding needs no second worker pool".
Consequences verified in-file:
- Docs contradiction: docs/preparation-development.md:314-318 "Forward compilation uses memory-bounded parallel workers ...; artifact binding starts no additional compiler pool." The 24-thread Inductor pool is not a
CompilePool, but it is an in-process compiler pool active during binding/warmup, exceeding the parent rank's admitted process/thread budget:computer_resources/allocate_workersnever see it (compile_pool.py:37-96). - Memory: the parent rank is the process that must hold host RAM for
FORWARD_WORKER_BYTES(32 GiB) times workers plus the binds; host_memory.release_unused() and_HEADROOM_BYTES = 8 GiB(host_memory.py:16) were sized for 1 parent Inductor thread. 24 concurrent Triton/ptxas compilations in the rank process raise transient RSS during prep on top of the still-live compiled forwards (aot.py:965-1005 keepsloadedforwards live while warming the rest). - Cap inconsistency:
_OPTIONS['compile_threads'] = min(16, os.cpu_count() or 1)(compilation.py:30) is the configured value, yetprepare_manyhardcodes 24; per-workerinner_threads(compile_pool.py:140) ignores the configured value entirely, so[preparation] compile_workers/options no longer express thread policy anywhere. Not recorded inForwardCache.__init__cache key (aot.py:825 stripscompile_threads) nor in reproduction args (rebuild_manifest.py:231-261), matching the "unrecorded switch" objection on #509. Fix: keepcompile_threads=1for binding; run the fallback recompile inside an explicit bounded pool derived from the samecpu_workers()/_OPTIONS['compile_threads']budget, and record the value in the plan/reproduction arguments.
#4 [high] Affinity vs cpu_count mismatch: cgroup-limited rank gets whole-machine thread budget
compile_pool.py:139-140 derives the thread budget from raw os.cpu_count(), whereas the worker count comes from cpu_workers() = len(os.sched_getaffinity(0)) (host_memory.py:25-35) and compiler_resources caps it by that affinity mask (compile_pool.py:42). Test test_explicit_forward_workers_are_bounded_by_cpu_affinity (test_compile_pool.py:535-542) exists precisely to protect the cgroup/taskset-limited rank: it admits 3 workers from a 3-CPU mask on a 96-core host. At head that rank then computes inner_threads = min(8, 96 // 3) = 8, i.e. 24 Inductor compile subprocesses for one 3-CPU cgroup - 8× oversubscription, the same reversal the affinity test guards on the process side. Same mismatch in aot.py:903 (min(24, os.cpu_count() or 1)), which also ignores affinity. Fix: use len(os.sched_getaffinity(0)) (via host_memory.cpu_workers()) in both places.
#10 [high] Research summary
Reviewed #639 at head 3400e3a across its four changed files plus every direct caller (compile_pool.CompilePool/compiler_resources/allocate_workers, aot.ForwardCache.prepare_many/_prepare_many/_prepare_ranks, capture.capture_forwards, host_memory, compilation._OPTIONS, runtime_patches) and the touched tests. Findings are on the scratchpad (9 notes).
Headline problems, all verified by opening the code:
-
Admission pricing was not updated for the new fan-out (Blocker/Major).
compile_pool.py:139-144gives every outer worker up to 8 Inductor threads andworker_start_method="subprocess", buthost_memory.py:13-15(FORWARD_WORKER_BYTES = 32 GiB) andcompile_pool.py:60-62still price one worker as one 32 GiB slot, andcompile_pool.py:55still divides device free memory by the single-process 704 MiB (:24-25). A host/GPU admitted for N compile slots can now run up to 8N concurrent compiler processes; main had one thread per worker precisely to keep nested pools inside the admitted budget (compile_pool.py:137-138on main). This also contradictsdocs/preparation-development.md:314-318. -
aot.py:903puts up to 24 Inductor threads in the parent rank for the whole of_prepare_many— binding, warmup and the BindingMismatch fallback recompile — the phase where all compiled forwards are resident. Docs say "artifact binding starts no additional compiler pool"; the value (24) also ignores the configured_OPTIONS['compile_threads'] = min(16, cpu_count)and is recorded nowhere (stripped from the cache key ataot.py:825, absent fromreproduction_arguments). -
os.cpu_count()vssched_getaffinity(compile_pool.py:139-140,aot.py:903): a taskset/cgroup-limited rank gets the whole machine's thread budget — 3 admitted workers on a 3-CPU mask × 8 threads = 24 compilations, the exact casetest_explicit_forward_workers_are_bounded_by_cpu_affinityexists to protect. -
Windows path untested: the untouched test at
test_compile_pool.py:467-476monkeypatchescompile_pool.osto aSimpleNamespacewithoutcpu_count, so it exercises thehasattrfallback and no test assertsworker_start_method == 'spawn'.DeferredCompiledForward.materialize_for_capture's owncompile_threads=1(aot.py:688) leaves two conflicting policies in one file, uncovered. -
One-sided reserve clamp (
compile_pool.py:49-62): device admission clamps headroom to 1 GiB on discrete whileCompilerResources.headroomkeeps the 8 GiB floor, so the default 4 GiB plan headroom silently drops to 1 GiB for every discrete export — not only "large runtime reserves" as the description says — and #242's host side is untouched. -
Evidence/claims: no
mainbaseline, no worker/thread counts, headline number on a 288 GB GB300 where the change matters least; CI red on head while the description lists only green runs; the 10→16 worker delta is never quantified. Tests mirror the implementation formula (test_compile_pool.py:28,test_forward_compile_options.py:282) rather than pinning values.
#11 [high] Verdict, severity ordering, and areas that are sound
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 without evidence.
Ranked:
- Blocker — host/device admission pricing not updated for multi-threaded workers (notes 1 and 2): 32 GiB
FORWARD_WORKER_BYTESand 704 MiB_DISCRETE_WORKER_DEVICE_BYTESare single-process prices for what is now a process tree. Fix: multiply the priced bytes byinner_threads, or boundinner_threadsby the admitted host-RAM budget (the principle of 468415d1/f9aec99c), not by CPU count alone. - Major —
aot.py:90324 threads in the parent rank across binding/warmup/fallback recompile (note 3): contradicts docs/preparation-development.md:318, ignores the configured_OPTIONS['compile_threads'](compilation.py:30), and is recorded nowhere. Fix: keepcompile_threads=1for binding and run the fallback recompile under one explicitly bounded pool. - Major — affinity vs cpu_count (note 4). Fix:
len(os.sched_getaffinity(0))viahost_memory.cpu_workers()in both places. - Major — one-sided reserve clamp + undeclared default 4 GiB→1 GiB device-reserve change, #242 host side untouched (note 7).
- Minor/Major — Windows thread partitioning and
spawnpreservation unasserted;materialize_for_capturethread policy left at 1 and untested (notes 5, 6). - Minor — description/evidence gaps and formula-mirroring tests (notes 6, 9).
Sound (say so plainly, do not invent issues):
- 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 or CLI/config contract changes. - Patch identity is preserved through the new nesting:
_compile_forwardre-appliesruntime_patches.apply()in the outer worker (compile_pool.py:100-101) andruntime_patches/workers.py:21-23does so in Inductor's own workers, withworkers.replacements()installinginitialize_inductor_workeronsubproc_pool/async_compile;worker_start_method="subprocess"on POSIX is consistent with the SPAWNSubprocPoolatcompile_pool.py:160, and Windows keeps'spawn'from_OPTIONS(compilation.py:31-32). - Placement is right layer: shared
ignition/preparation/code, no per-model branches, no new hardware target. _prepare_many's own concurrency gate (aot.py:947-949,len(pending) >= compiler.workers) and the per-worker options plumbing (compile_pool.py:161-162passingself.options) are unchanged in structure and still correct.
#5 [medium] Windows path untested: SimpleNamespace os lacks cpu_count, so the test asserts the hasattr fallback
Windows parity: compile_pool.py:142-143 sets worker_start_method="subprocess" only when os.name != "nt". But compilation.py:31-32 sets _OPTIONS['worker_start_method'] = 'spawn' for Windows, and _compile_options(options) always merges _OPTIONS (compilation.py:35-36), so on Windows the per-worker options get worker_start_method='spawn' from defaults - untouched by this PR, fine.
The real gap: test_windows_compiler_workers_fit_host_ram_with_larger_device_budget (tests/preparation/test_compile_pool.py:467-476) monkeypatches compile_pool.os to SimpleNamespace(name="nt") (no cpu_count), so the new hasattr(os, "cpu_count") guard at compile_pool.py:139 falls back to None → inner_threads=1, and the assertion still demands (workers, compile_threads) == (1, 1). Therefore the Windows thread-partitioning path is asserted only through a fallback that cannot occur on a real Windows host, and the description's claim that "spawn" is "preserved on Windows" is untested: no test asserts worker_start_method == 'spawn' anywhere (grep: only == "subprocess" at test_compile_pool.py:30 and test_forward_compile_options.py:284). On a real Windows host with 8 workers and 64 cores, inner_threads becomes 8 and each of the 8 ProcessPoolExecutor workers gets an 8-thread Inductor spawn pool - an unvalidated configuration (ProcessPoolExecutor workers are non-daemonic, so it should work, but nothing tests it). Fix: replace the SimpleNamespace with a real os.name monkeypatch (or pass os.cpu_count into the namespace) and assert both inner_threads and worker_start_method on the nt path.
Charter tension: this is "No magic defaults / be explicit and pin everything" - three new hardcoded numbers (704 MiB, 1 GiB cap, 8) plus 24 in aot.py, none configurable, none documented (docs/cli-design.md:1463 and docs/model-preparation.md:234 describe compiler sizing only generically)."
#6 [medium] Test assertions copy the implementation formula; conflicting thread policy left in materialize_for_capture
tests at head compute expectations from the implementation instead of pinning values:
- tests/preparation/test_compile_pool.py:28
assert pool.options["compile_threads"] == min(8, 16 // expected)— mirrors compile_pool.py:140. - 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)))— verbatim copy of the implementation, so a change to the formula silently passes if implementation and test are edited together, and the test itself is CPU-count dependent (214-core CI runner → still fine because of the 8 cap, but it can't fail for a wrong partition). - New test
test_prepare_many_scales_inductor_compile_threads_with_cpu_count(test_forward_compile_options.py:333-342) monkeypatchesaot.ForwardCache._prepare_manyout, so it only proves the number reaches theconfig.patchscope; it does not prove the scope covers binding/warmup, nor that 24 threads are safe while compiled forwards are resident. No test coversDeferredCompiledForward.materialize_for_capture's owncompile_threads=1(aot.py:688), which now conflicts with the 24-thread policy in the same file: the streaming capture path (capture.py:175-182) re-loads and binds each forward at 1 thread while_prepare_manybinds at 24. Either the second policy is deliberate (then it needs a comment/why in the description and coverage) or it was missed.
#7 [medium] Device-reserve clamp is one-sided and changes the default 4 GiB→1 GiB for every discrete export
compile_pool.py:49-51 (head): compile_reserve = headroom_bytes if shared else min(headroom_bytes, 1024 << 20) feeds only capacity (line 55) and the empty-cache probe (52-54). CompilerResources.headroom at line 62 is unchanged: max(host_memory._HEADROOM_BYTES, headroom_bytes if shared else 0) → on discrete it is always the 8 GiB floor; allocate_workers subtracts it from host memory (compile_pool.py:73-84). So the device-side clamp is silently ignored on the host side, which is #242's complaint (multi-host export compiling 22 min then failing when a rank can't host a compiler). Two consequences worth reporting:
- Behaviour is now asymmetric and undocumented:
--headroom-bytes/planheadroom_bytes(bootstrap.py:35 default 4 GiB, bootstrap.py:134 passesplan.headroom_bytes + plan.reserve_bytes) is honoured fully on integrated GPUs, clamped to 1 GiB on discrete device admission, and still floored at 8 GiB on host admission. A configured 71.5 GiB headroom no longer raisesMemoryErroron discrete (test_compile_pool.py:446-452) - the description's "Result" section does not say the device reserve shrinks 4 GiB→1 GiB (default plan headroom isHEADROOM_BYTES = 1 GiB+ chunk term at planning.py:30, 343-345, plus reserve), nor that this happens for every discrete export, not only "large runtime reserves". min(headroom_bytes, 1024 << 20)is hardcoded and interacts with_DISCRETE_WORKER_DEVICE_BYTES: users who raised[memory] reserveto keep a discrete GPU safe during runtime (docs/model-preparation.md:383, 480-481) silently lose that protection during compilation; when the caller sets reserve to 0,compile_reservebecomes 0 and nothing protects the runtime reserve at all. Fix: make the discrete compile reserve a named constant derived from the measured footprint (_DISCRETE_WORKER_DEVICE_BYTES * capacity), or keep the configured headroom and raise capacity by lowering device_bytes only - and update the description to state the 4 GiB→1 GiB default change.
#8 [medium] Nested compile-process tree: shutdown/interrupt coverage gap, unbounded concurrent compile high-water mark
Tracing the concurrency/ordering consequences of the new worker_start_method="subprocess" inside spawned CompilePool workers (compile_pool.py:141-143):
- POSIX:
submit_payloadcreatesSubprocPool(self.workers, kind=SubprocKind.SPAWN)(compile_pool.py:160) — outer workers are spawned children of the rank process. Each outer worker's InductorAsyncCompileis now configured withworker_start_method="subprocess", sotorch._inductor.compile_worker.subproc_poolforks/multiprocessing.Processper compile task from a spawned child. That is what the PR says it fixes (daemonic restriction), andruntime_patches.apply()is re-applied in the outer worker via_compile_forward(compile_pool.py:101) and inside nested workers viaworkers.initialize_inductor_worker(runtime_patches/workers.py:21-23), so patch identity is preserved. That part is coherent. - Windows:
submit_payloadusesProcessPoolExecutor(..., mp_context=spawn)(compile_pool.py:157-158); those workers are non-daemonic andworker_start_methodstays'spawn'from_OPTIONS(compilation.py:31-32), so nested spawning should work, but nothing exercises it (see note on the Windows test). - Shutdown/failure blast radius:
CompilePool.__exit__only callsself.pool.shutdown()(compile_pool.py:167-169). With nested Inductor pools per worker, a single failed/slow forward now leaves up toinner_threadsextra grandchildren per worker;test_cli_interrupt_leaves_no_compiler_processes(tests/preparation/test_native_processes.py:123-162) still constructs a bareSubprocPool(1)with default options and therefore does not cover the two-level tree this PR creates. Worth a targeted test that SIGINTs a rank while a CompilePool worker holds nested compile processes. - Head-of-line blocking:
_prepare_manygates concurrency oncompiler.workersonly (aot.py:947-949if len(pending) >= compiler.workers: finish()), not on total thread count, so a slow worker with 8 nested compiles still holds one slot. No regression per se, but the effective GPU memory high-water mark now depends on how many workers happen to have live nested compiles at once, which is unbounded by any admission check.
#9 [medium] PR description claim accuracy vs the diff
Claims checked against the diff and in-repo files:
- "substituting the full runtime/KV headroom_bytes under-allocates compile workers when large reserves are configured" — inaccurate scope. bootstrap.py:35
headroom_bytes: int = 4 << 30and bootstrap.py:134plan.headroom_bytes + plan.reserve_bytesmean the default discrete export goes from a 4 GiB device reserve tomin(4 GiB, 1 GiB)= 1 GiB. planning.py:30HEADROOM_BYTES = 1 << 30plus the chunk term (planning.py:343-345) can exceed 1 GiB for any prefill chunk > 4096. So the default path relaxes too, which the description does not say. - "CompilePool workers run inside spawned SubprocPool processes, where TorchInductor requires worker_start_method="subprocess" on POSIX to spawn nested compile workers without hitting daemonic multiprocessing restrictions" — plausible and consistent with compile_pool.py:160, but no issue, log or reproducer is cited; the only in-repo trace is the new comment at compile_pool.py:137-138. Also
compile_threads=1was what disabled nested pools, so this requirement is newly self-inflicted by the same PR. - "DeepSeek-V4.1 101/101 forwards in 359.8 s ... on GB300 (SM103)" — no
mainbaseline, no worker/thread counts, no memory samples, and GB300 is a 288 GB HBM part, i.e. the hardware where a device-reserve reduction matters least. Charter requires "benchmarks showing an actual speedup overmainon a served workload (#210)". The changed admission constant is a max_models-style admission change, so an A/B on an SM120/SM121 workstation (where the 4 GiB→1 GiB reserve and 10→16 workers actually bind) is the evidence that is missing. - "Updated discrete worker device sizing... and added unit coverage for ForwardCache.prepare_many compile_threads scaling" — accurate, but the exact worker delta is never quantified in the description: 10→16 workers at 12 GiB free / 2 GiB headroom (test_compile_pool.py:43-45 vs main's 10) and 3→4 at 3 GiB free (test_compile_pool.py:374-388).
- CI is failing on head 3400e3a while the description lists only green local unit runs; nothing explains the failure. (Per instructions, not reporting CI infra noise beyond the contradiction with the claimed verification.)
- The three concerns bundled here (device estimate, reserve clamp, thread/start-method policy) are separable and individually reviewable; #509's review objected to exactly this bundling pattern.