Recommendation: Changes Requested
This draft PR targets a legitimate compilation-throughput bottleneck in shared ignition/preparation/ code with a small footprint (+58/−18 across 4 files) and no per-model branches or artifact-format breaks. However, the current implementation introduces two verified system-level blockers: (1) per-worker nested Inductor subprocesses (compile_threads up to 8 with worker_start_method="subprocess") are unbudgeted against host/unified RAM, ignore CPU affinity, and multiply per local rank in multi-GPU _prepare_ranks (scaling up to 8 nested subprocesses per worker precisely when RAM is tightest); and (2) ForwardCache.prepare_many sets compile_threads=min(24, os.cpu_count() or 1) in the parent rank process, spawning persistent, unbudgeted Inductor worker pools during artifact binding/loading across every local rank without shutdown before materialization or capture. In addition, the hardcoded 1 GiB discrete compile_reserve cap silently overrides the default 4 GiB headroom on every discrete export, Windows thread partitioning is masked by a mock-only guard, and main-vs-PR baseline evidence and green CI are still needed.
Merge Risk
Level: High
- Every compiled-forward preparation path is affected across single-GPU, multi-GPU TP, integrated (GB10), and discrete (SM103/SM120/SM121) hosts: multi-rank hosts (
ForwardCache._prepare_ranks) and memory-constrained / integrated hosts can now severely oversubscribe CPU cores and host/unified RAM with unbudgeted nested Inductor subprocesses (N_local_ranks × workers × inner_threads) plus persistent parent-rankAsyncCompilepools (N_local_ranks × min(24, cpus)). - Default discrete compile-time device reserve drops silently from 4 GiB to 1 GiB (
ignition/preparation/bootstrap.py:35,compile_pool.py:51) alongside a ~1.6× worker-count increase (704 MiBper worker, only32 MiBabove the unverified672 MiBclaim), increasing OOM risk on tighter-VRAM SM120/SM121 workstations without an isolatedmain-vs-PR benchmark. - No GPU preparation tests run in CI, and CI on head
3400e3ais currently failing while open Ready-To-Merge PR #597 modifies the samecompile_pool.py/aot.pycoordination paths.
Walkthrough
ignition/preparation/compile_pool.py: Lowers_DISCRETE_WORKER_DEVICE_BYTESfrom1 GiBto704 MiB(:24-25); caps discrete device-sidecompile_reserveatmin(headroom_bytes, 1024 << 20)incompiler_resources(:49-55) while leaving integrated GPUs and host-RAMCompilerResources.headroom(:62) unchanged; replacescompile_threads=1inCompilePool.__init__withinner_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers)))and setsworker_options["worker_start_method"] = "subprocess"whenos.name != "nt"(:137-144).ignition/preparation/aot.py: ChangesForwardCache.prepare_many's outer Inductor patch fromcompile_threads=1tocompile_threads=min(24, os.cpu_count() or 1)(:901-903), leavingDeferredCompiledForward.materialize_for_captureatcompile_threads=1(:688).tests/preparation/test_compile_pool.py: Updates discrete worker capacity assertions (10 → 16at 12 GiB free / 2 GiB headroom,:43-45;3 → 4at 3 GiB free,:376-388), splitstest_compilation_preserves_configured_headroombyintegrated(:443-452), and updatescompile_threads/worker_start_methodexpectations (:25-30,:381-388,:391-398,:548-551).tests/preparation/test_forward_compile_options.py: UpdatesCompilePooloption assertions (:282-284) and addstest_prepare_many_scales_inductor_compile_threads_with_cpu_count(:333-342).
Pre-merge Checks
- [PASS] Security / malicious screen: No prompt injection, shell execution, credential exposure, or unsafe deserialization introduced across the 4 changed files.
- [WARN] Charter & value fit: Lives in shared
ignition/preparation/with no per-model branches or artifact-format breaks and targets SM103/SM120/SM121, but lacks amain-vs-PR benchmark on a served/discrete workload, silently clamps explicitheadroom_byteson the default discrete path, and violatesdocs/preparation-development.md:317-318/docs/design-review.md:81-84resource-release invariants. - [WARN] Related / duplicate / conflict check: No commits to these files on
mainsince branch point, but open PR #597 (reviewedReady To Merge) modifiesallocate_workersincompile_pool.pyand_prepare_ranksinaot.py; this PR also partially reversesc8d4c324's single-thread-per-worker policy without citing or benchmarking against it. - [WARN] Tests & verification evidence: Description cites local CPU pytest subsets and a single combined-stack GB300 export (
359.8 s) with nomainbaseline, no peak RAM/VRAM telemetry, and no SM120/SM121 measurement; CI on head3400e3ais failing (.github/workflows/python-cpu.yml(not opened) runs the full CPU suite).
Blockers
-
Nested Inductor subprocess fan-out breaks host/unified RAM and CPU admission budgets — and multiplies across local ranks and low-RAM hosts (
ignition/preparation/compile_pool.py:137-144,ignition/preparation/aot.py:1086, 1097-1099,ignition/preparation/host_memory.py:13-16, 31).- Verified behavior & impact:
CompilePool.__init__computesinner_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers)))and enablesworker_start_method="subprocess"on POSIX, whilecompiler_resources(compile_pool.py:60-62) andallocate_workers(:76-92) still charge only one outer worker (FORWARD_WORKER_BYTES = 32 GiB, or_WORKER_BYTES = 2 GiBin the minimum-allowance fallback at:88-92). Each nested Inductor subprocess importstorch/triton, runsruntime_patches.apply()(ignition/runtime_patches/workers.py:21-23), and invokes Triton/ptxas compilation in its own process. This fails in three concrete ways:- Multi-rank host multiplication: In
ForwardCache._prepare_ranks(aot.py:1086, 1097-1099),allocate_workersbudgets workers across all ranks on a host, then each rank independently createsCompilePool(self.device, options=self.options, workers=workers[share]). BecauseCompilePool.__init__dividesos.cpu_count()by this rank'sself.workersrather than the host's total admitted workers, a 4-GPU 32-core SM120 workstation admitting[2, 2, 2, 2]spawns4 × 2 × min(8, 32 // 2) = 64nested Inductor subprocesses (plus 8 outer workers) on 32 cores; a 72 GiB host with[1, 1, 0, 0](test_compile_pool.py:455-464, 0 GiB spare above the 8 GiB headroom) spawns2 × 1 × 8 = 16unbudgeted nested subprocesses. - Inverse scaling on memory-constrained and integrated (GB10) hosts: The tighter RAM is (forcing
self.workers == 1, including the 10–12 GiB minimum-allowance fallback atcompile_pool.py:88-92and unified-memory GB10 runs as intest_compile_pool.py:391(True, 1, 8)), the largerinner_threadsbecomes — hitting the maximum8nested subprocesses right when the host has the least RAM available. - CPU affinity bypass: Outer worker counts respect
os.sched_getaffinity(0)viahost_memory.cpu_workers()(compile_pool.py:42,host_memory.py:31), whereascompile_pool.py:139-140reads rawos.cpu_count(). A 3-CPU cgroup/taskset rank (test_compile_pool.py:535-542) admits 3 workers and then assigns up to8threads each =24concurrent compile subprocesses on 3 CPUs.
- Multi-rank host multiplication: In
- Concrete fix: Pass total local-host admitted workers (and remaining host/unified RAM budget from
allocate_workers) intoCompilePool, derive CPU budget fromhost_memory.cpu_workers()(affinity-aware) divided by total local-host workers, and capinner_threadsagainst remaining host/unified RAM (e.g., pricing each additional nested worker at_WORKER_BYTESand forcinginner_threads = 1under the minimum-allowance fallback or when remaining RAM cannot cover nested workers).
- Verified behavior & impact:
-
ForwardCache.prepare_manyspawns persistent, unbudgeted parent-rank Inductor worker pools across binding/warmup without shutdown or rank/affinity bounds (ignition/preparation/aot.py:901-906, 1053, 1229,ignition/preparation/aot.py:423-425, 980).- Verified behavior & impact:
prepare_manywraps the entire_prepare_many/_prepare_rankslifecycle intorch._inductor.config.patch(compile_threads=min(24, os.cpu_count() or 1)).- Contrary to the comment (
"Allow fallback/binding compilation to parallelize"), theBindingMismatchfallback recompile ataot.py:980callsaot_forward(forward, options=self.options)→standalone_compile(..., options={'config_patches': _compile_options(options)})(aot.py:423-425), which always carries_OPTIONS['compile_threads'](min(16, cpu_count),compilation.py:30) and overrides the outer24patch. - Instead, the outer
24patch affectsself._load(...)(deserialize_bundled_cache_entryataot.py:66, called in_restoreat:1053and in"Load and warm compiled forwards"at:1229) and_warm(...)inside the parent rank process. Whenever binding/loading enters Inductor'sAsyncCompile, Inductor starts a process-global singletonSubprocPoolof up to24persistent worker processes per rank (up toN_local_ranks × 24on a multi-GPU host, ignoring affinity and host/unified RAM). - Unlike
CompilePool.__exit__(compile_pool.py:167-169), nothing inignition/shuts down Inductor's parent-processAsyncCompilepool beforematerialize(), warmup, or CUDA graph capture (capture.py:140-188), leaving those workers resident in host/unified RAM through capture. This directly violatesdocs/preparation-development.md:317-318("artifact binding starts no additional compiler pool") anddocs/design-review.md:81-84("Release compiler resources before materializing preparation caches"), and contradictsDeferredCompiledForward.materialize_for_capture(aot.py:688), which stays atcompile_threads=1.
- Contrary to the comment (
- Concrete fix: Restore
torch._inductor.config.patch(compile_threads=1)inForwardCache.prepare_many(aot.py:903). If parent-rank binding or fallback recompilation is measured to need parallelism, scope it strictly to the compiling operation, bound threads bycpu_workers() // local_ranksand available host/unified RAM (reusingself.options['compile_threads']rather than a hardcoded24), and explicitly shut down Inductor'sAsyncCompilepool beforematerialize()and graph capture.
- Verified behavior & impact:
Should Fix
-
Hardcoded
1 GiBdiscretecompile_reservecap silently overrides default and user-configured headroom (ignition/preparation/compile_pool.py:49-62,ignition/preparation/bootstrap.py:35, 134).- Because
BasePreparationConfig.headroom_bytesdefaults to4 GiB(bootstrap.py:35, plusplan.reserve_bytesat:134),min(headroom_bytes, 1024 << 20)silently reduces the compile-time device reserve from4 GiB(or larger explicit--reserve) to1 GiBon every discrete export — not only "when large runtime reserves are configured" as the PR description states. Meanwhile,CompilerResources.headroom(compile_pool.py:62) keeps the8 GiBhost floor andhost_memory.candidate_scratch_limit/tuning_limits(host_memory.py:160, 172) still honour fullheadroom_byteson discrete GPUs. - Fix: Drop the hardcoded
1024 << 20override (see Subtract / Simplify #1), or if a separate compile-time device reserve is needed, split it into its own PR with explicit plan/config visibility (docs/design-review.md:89-90,AGENTS.md:456-460) and tight-VRAM SM120/SM121 validation.
- Because
-
Missing
main-vs-PR benchmark, worst-case 704 MiB VRAM proof, and green CI (.github/workflows/python-cpu.yml:30-33(not opened),ignition/preparation/compile_pool.py:24-25).- The PR provides only one combined-stack GB300 (
SM103, 288 GB HBM) wall-clock number (359.8 s) with nomainbaseline, no worker/thread counts, no peak host-RSS or device-VRAM measurements, and no measurement on SM120/SM121 workstations. Lowering_DISCRETE_WORKER_DEVICE_BYTESfrom1 GiBto704 MiBleaves only32 MiB(~4.8%) slack above the unverified672 MiBfigure (replacing the previous comment noting "about 0.7 GiB for Kimi K3's 93-layer forwards"). Additionally, CI on head3400e3ais failing while the PR description lists only local green subsets. - Fix: Resolve the failing CI check on head, provide an isolated
main-vs-branch A/B benchmark (wall-clock compile time, worker/thread counts, peak host RSS, and peak device VRAM) on SM120/SM121 (and optionally GB300), and document the worst-case single-worker VRAM measurement justifying704 MiB.
- The PR provides only one combined-stack GB300 (
-
Windows thread partitioning and
"spawn"preservation are untested, andhasattr(os, "cpu_count")exists only for a mock (ignition/preparation/compile_pool.py:139,tests/preparation/test_compile_pool.py:467-476).test_windows_compiler_workers_fit_host_ram_with_larger_device_budgetmonkeypatchescompile_pool.ostoSimpleNamespace(name="nt")(omittingcpu_count), sohasattr(os, "cpu_count")incompile_pool.py:139falls back toNone→inner_threads = 1instead of testing Windows partitioning. No test assertsworker_start_methodon theos.name == "nt"branch (test_compile_pool.py:29-30andtest_forward_compile_options.py:283-284only assert whenos.name != "nt").- Fix: Remove
hasattr(os, "cpu_count")when switching tocpu_workers()(Blocker 1), and add/update a Windows-path test asserting bothcompile_threadsand thatworker_start_methodis not overridden to"subprocess"(preserving"spawn"from_OPTIONSon Windows).
-
Coordinate with Ready-To-Merge PR #597 and consider splitting bundled concerns (
ignition/preparation/compile_pool.py,ignition/preparation/aot.py).- Open PR #597 (reviewed
Ready To Merge) adds per-GPU-SKUgroups=admission toallocate_workersand updates_prepare_ranks; any host-wide worker/thread budgeting here should rebase cleanly onto #597's multi-group admission. Splitting the discrete worker VRAM sizing (704 MiB) from the nested/parent Inductor threading changes (AGENTS.md:198) will also let each change be benchmarked and merged independently.
- Open PR #597 (reviewed
Subtract / Simplify
- Delete the
1 GiBdiscretecompile_reserveclamp (ignition/preparation/compile_pool.py:49-55) and restoreheadroom_bytesdirectly in both expressions (:52,:55). Keeping_DISCRETE_WORKER_DEVICE_BYTES = 704 << 20alone already delivers most of the discrete worker-count increase (10 → 14workers at 12 GiB free / 2 GiB headroom;8 → 11at 4 GiB default headroom) without silently overriding configured headroom, adding a secondsharedconditional, or rewritingtest_compilation_preserves_configured_headroom(tests/preparation/test_compile_pool.py:443-452). - Collapse
CompilePool.__init__'s thread calculation (ignition/preparation/compile_pool.py:137-144): remove the mock-drivenhasattr(os, "cpu_count")guard (:139) and the unreachablemax(1, self.workers)guard (:140—:134-135already rejectsworkers < 1), and reuse the already-importedcpu_workers()(compile_pool.py:20). - Remove the standalone
24cap inForwardCache.prepare_many(ignition/preparation/aot.py:903) and restorecompile_threads=1(matchingaot.py:688anddocs/preparation-development.md:318), removing both the fourth distinctcompile_threadsauthority andtest_prepare_many_scales_inductor_compile_threads_with_cpu_count(tests/preparation/test_forward_compile_options.py:333-342).
Nits
- Replace formula-mirroring test assertions with concrete literals (
tests/preparation/test_compile_pool.py:28,tests/preparation/test_forward_compile_options.py:282): both recomputemin(8, ...)inline instead of pinning concrete expected values liketest_compile_pool.py:376-377. - Verify nested-process teardown on
SIGINT/ pool exit (ignition/preparation/compile_pool.py:167-169,tests/preparation/test_native_processes.py:123-162):test_cli_interrupt_leaves_no_compiler_processesonly spawns a single-levelSubprocPool(1); onceCompilePoolworkers spawn nestedworker_start_method="subprocess"Inductor children, add coverage ensuring no orphaned grandchild processes remain on interrupt or failure.
Dropped on verification
- Upstream Blocker claiming nested Inductor workers each initialize a 672 MiB CUDA context and must multiply
_DISCRETE_WORKER_DEVICE_BYTESbyinner_threads: Dropped as overstated on the device-VRAM axis. Under default_OPTIONS(ignition/preparation/compilation.py:28,'triton.autotune_at_compile_time': False), Inductor'sAsyncCompilesubprocesses compile Triton/C++ kernels on CPU rather than initializing full CUDA contexts and constant-folding buffers like the outer_compile_forwardworker (compile_pool.py:108-112). The verified blocker is host/unified RAM and CPU process overcommit (Blocker 1), while the704 MiBsingle-worker VRAM estimate only lacks empirical worst-case proof (Should Fix 2). - Upstream claim that
aot.py:903'scompile_threads=min(24, ...)governsBindingMismatchfallback recompilation: Corrected on verification.aot.py:980callsaot_forward(forward, options=self.options)→standalone_compile(..., options={'config_patches': _compile_options(options)})(aot.py:423-425), where_compile_optionsalways supplies_OPTIONS['compile_threads'](min(16, cpu_count),compilation.py:30), overriding24. Blocker 2 accurately scopes the bug to parent-rank_load/_warmspawning persistentAsyncCompilepools. - Upstream Minor claiming
_prepare_many'slen(pending) >= compiler.workersgate is a separate high-water-mark / head-of-line-blocking defect: Dropped as duplicate of Blocker 1; the pending-queue gate (aot.py:948-949) is unchanged and not independently broken once worker × inner-thread budgets are bounded. - Upstream suggestion to turn all four constants (
704 MiB,1 GiB,8,24) into new CLI/config switches: Dropped/narrowed. Adding configuration switches for internal sizing constants conflicts withAGENTS.md:188-190;_DISCRETE_WORKER_DEVICE_BYTESmatches existing_WORKER_DEVICE_BYTESstyle and needs empirical measurement rather than a flag, while the real contract violation is the1 GiBclamp silently overriding user-configuredheadroom_bytes(Should Fix 1). - Upstream claim flagging
ForwardCache.__init__strippingcompile_threadsfrom the cache key (aot.py:825) as an "unrecorded switch" defect: Dropped as low-signal; strippingcompile_threadsfrom the artifact cache key is pre-existing and intentional so compiled artifacts remain portable across hosts with different core counts. - Upstream standalone Minor flagging
DeferredCompiledForward.materialize_for_capture(aot.py:688) staying atcompile_threads=1: Subsumed into Blocker 2, sincecompile_threads=1during artifact materialization is the intended invariant (docs/preparation-development.md:318) thataot.py:903broke away from.