PR #639: ignition: tune discrete CompilePool sizing and scale Inductor compile threads

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/a543768a-aca6-44d2-b270-6787aa2363f2

Opened by a workflow run, Nov 30, 2026 7:24 AM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: original-el8 (GitHub COLLABORATOR; charter-named priority contributor alongside @voipmonitor and @lukealonso; commits as "Jason Cook"), Discord el8 Motivation: Discrete-GPU compile workers only need ~672 MiB of device memory, but main reserves 1 GiB each and subtracts the full runtime headroom (4 GiB by default, or more) from device free memory, so far fewer compile workers are admitted than the GPU could hold. On high-core hosts each worker is also pinned to one Inductor thread, leaving cores idle during compilation and artifact binding; the PR gives workers more threads and caps the compile-time device reserve at 1 GiB. Scale: +58 / −18 lines in 4 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — #639 "ignition: tune discrete CompilePool sizing and scale Inductor compile threads"

Charter alignment. The change lives in shared ignition/preparation/ code with no per-model branches and targets the charter's own hardware (SM103/SM120/SM121), consistent with "keep the runtime small and model-agnostic." But it breaks two explicit rules. "Be explicit and pin everything. No magic defaults": it adds four hardcoded, undocumented, non-configurable numbers (704 MiB, 1 GiB, 8, plus a separate 24 in aot.py), one of which silently overrides a configured headroom_bytes — since bootstrap.py:35 defaults headroom to 4 GiB, every discrete export's compile reserve drops 4 GiB → 1 GiB, not the exception the "Why" describes. "Bring real evidence… benchmarks showing an actual speedup over main (#210)": the lone wall-clock figure (101/101 forwards, 359.8 s) has no main baseline, no worker or thread counts, and was taken on a 288 GB part where device memory matters least.

Novelty & status. Not obsolete — no commits to these files since the branch point — and not textually superseded by #597. But #597 answers the same question ("how many compiler workers does a host get") and is already reviewed Ready To Merge, so #639 lands second and rebases. Its central move also reverses a deliberate policy (c8d4c324, one Inductor thread per compiler) without citing it, while #122's threading measurements were withdrawn precisely because main no longer has that mechanism. No issue is linked or fixed; the idle-core and daemonic-process motivations are unfiled, and #242 — the closest tracked bug — is the host-RAM side this PR deliberately leaves untouched.

Value vs maintenance cost. The gain is plausible (~1.6× more compiler processes, up to 8× more threads per worker on discrete GPUs), but the risk is concrete: worker count comes from sched_getaffinity while threads come from raw os.cpu_count(), so a cgroup- or taskset-limited rank could launch 128 Inductor subprocesses; Windows partitioning is untested (the hasattr(os, "cpu_count") guard exists only to satisfy a mock); materialize_for_capture still patches compile_threads=1, leaving two conflicting policies in one file; and none of the new policy is recorded in the plan or reproduction_arguments — the "unrecorded switch" objection raised on #509.

Verdict: Worth it with changes. Required before merge: split the three bundled concerns; supply a main baseline on a served discrete workload; justify reversing c8d4c324; derive threads from the same affinity source as workers; cover Windows; reconcile aot.py:688; make the constants configurable and documented; rebase behind #597. As submitted — draft, CI red on head, zero engagement — it is not mergeable, but the area is legitimate and the author is a priority contributor, so this should be redirected rather than closed.

Full report Decide Value: yes (98%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, performance, area:memory, area:preparation

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance, +area:memory, +area:preparation

Subtraction and simplicity

The diff is lean in structure (+58/−18, 4 files, no new function, class, parameter, flag, or dead code) but not in knobs: each of the three code hunks adds a hardcoded number or a defensive branch. Four suggestions:

  1. Delete the 1 GiB discrete cap (compile_pool.py:48-55). compile_reserve = headroom_bytes if shared else min(headroom_bytes, 1024 << 20) is read in exactly the two places that were headroom_bytes, so deleting it restores main verbatim. It silently overrides the caller-configured headroom, which AGENTS.md:456-460 requires be described in the plan and :182-186 forbids relaxing. The 704 MiB estimate alone already gives most of the win: 12 GiB free / 2 GiB headroom → 14 workers vs main's 10 (16 with the cap); at the 4 GiB default, 11 vs 8. It is also what forces the if/else rewrite of test_compilation_preserves_configured_headroom (:440-452).

  2. Collapse compile_pool.py:137-144 to three lines using cpu_workers() // self.workers. cpu_workers is already imported at :20 and used at :42, and host_memory.py:31,35 already does the affinity mask, hasattr fallback, or 1 and max(1, …). hasattr(os, "cpu_count") exists only so the SimpleNamespace(name="nt") mock at test_compile_pool.py:470 keeps passing (AGENTS.md:194-196); max(1, self.workers) is unreachable because :134-135 already raised.

  3. One compile_threads authority, not four (compilation.py:30 min 16, compile_pool.py:140 min 8, aot.py:903 min 24, aot.py:688 still 1). aot.py:903 can use self.options['compile_threads'], always present via aot.py:823. aot.py should not ship both 24 and 1 for the same binding path; docs/preparation-development.md:317-318 still describes the =1 policy.

  4. Two test assertions re-implement the formula (test_compile_pool.py:28, test_forward_compile_options.py:282); both values are 8 — pin the literal, as :374-377 already does. The new 9-line test at test_forward_compile_options.py:333-341 folds into the existing assertion once #3 lands.

Already lean, not flagged: the 704 << 20 constant, the platform branch itself, no new API surface, the pinned-literal test changes.

Open: why materialize_for_capture stayed at 1; whether the 8 GiB host headroom floor at :62 is still intended (making the device cap an unexplained asymmetry); which of the four compile_threads authorities is meant to win; and whether #597 assumes one thread per worker.

Full report · Notes

Correctness and contracts

Verdict: request changes. The thread/start-method half of #639 is a real fix but is priced by nothing; the sizing half relaxes the discrete reserve on the default path and raises worker counts without a main baseline.

Top findings:

  1. Blocker — admission pricing unchanged for 1→8 Inductor threads/worker: compile_pool.py:139-143 sets inner_threads = max(1, min(8, (os.cpu_count() or 1) // max(1, self.workers))) plus worker_start_method="subprocess", yet host_memory.py:15 (FORWARD_WORKER_BYTES = 32 GiB) and compile_pool.py:55 (704 MiB) still price one worker as one process. N admitted slots can run 8N compiler processes.
  2. Blocker — _DISCRETE_WORKER_DEVICE_BYTES = 704 << 20 (compile_pool.py:24-25) is a single-process measurement divided into free device memory while each worker may spawn 8 CUDA-initializing subprocesses; untested (all device inputs monkeypatched).
  3. Major — aot.py:903 torch._inductor.config.patch(compile_threads=min(24, os.cpu_count() or 1)) spans all of _prepare_many: binding, warmup and the BindingMismatch fallback recompile. Contradicts docs/preparation-development.md:318, ignores _OPTIONS['compile_threads'] (compilation.py:30), recorded nowhere (stripped at aot.py:825).
  4. Major — affinity mismatch: threads from os.cpu_count() vs workers from sched_getaffinity (host_memory.py:31); the 3-CPU case guarded by test_compile_pool.py:535-542 gets 8 threads/worker.
  5. Major — one-sided clamp: compile_pool.py:51 caps the device reserve at 1 GiB on discrete while :62 keeps the 8 GiB host floor, so the default 4 GiB plan headroom (bootstrap.py:35) drops to 1 GiB for every discrete export; #242's host side untouched.
  6. Minor — Windows untested (test_compile_pool.py:467-476 uses SimpleNamespace(name="nt"), hitting the hasattr fallback), aot.py:688 keeps compile_threads=1, tests mirror the formula (test_compile_pool.py:28, test_forward_compile_options.py:282).

Sound: no artifact/contract break (aot.py:823-827), patch identity preserved through nesting, correct layer, unchanged _prepare_many gate.

Open: CI red on head; no main baseline; safety of 704 MiB under fan-out; whether the 8 GiB host floor is deliberate; whether #597 lands first.

Full report · Notes

Final review

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

Walkthrough

Pre-merge Checks

Blockers

  1. 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__ computes inner_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers))) and enables worker_start_method="subprocess" on POSIX, while compiler_resources (compile_pool.py:60-62) and allocate_workers (:76-92) still charge only one outer worker (FORWARD_WORKER_BYTES = 32 GiB, or _WORKER_BYTES = 2 GiB in the minimum-allowance fallback at :88-92). Each nested Inductor subprocess imports torch/triton, runs runtime_patches.apply() (ignition/runtime_patches/workers.py:21-23), and invokes Triton/ptxas compilation in its own process. This fails in three concrete ways:
      1. Multi-rank host multiplication: In ForwardCache._prepare_ranks (aot.py:1086, 1097-1099), allocate_workers budgets workers across all ranks on a host, then each rank independently creates CompilePool(self.device, options=self.options, workers=workers[share]). Because CompilePool.__init__ divides os.cpu_count() by this rank's self.workers rather than the host's total admitted workers, a 4-GPU 32-core SM120 workstation admitting [2, 2, 2, 2] spawns 4 × 2 × min(8, 32 // 2) = 64 nested 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) spawns 2 × 1 × 8 = 16 unbudgeted nested subprocesses.
      2. 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 at compile_pool.py:88-92 and unified-memory GB10 runs as in test_compile_pool.py:391 (True, 1, 8)), the larger inner_threads becomes — hitting the maximum 8 nested subprocesses right when the host has the least RAM available.
      3. CPU affinity bypass: Outer worker counts respect os.sched_getaffinity(0) via host_memory.cpu_workers() (compile_pool.py:42, host_memory.py:31), whereas compile_pool.py:139-140 reads raw os.cpu_count(). A 3-CPU cgroup/taskset rank (test_compile_pool.py:535-542) admits 3 workers and then assigns up to 8 threads each = 24 concurrent compile subprocesses on 3 CPUs.
    • Concrete fix: Pass total local-host admitted workers (and remaining host/unified RAM budget from allocate_workers) into CompilePool, derive CPU budget from host_memory.cpu_workers() (affinity-aware) divided by total local-host workers, and cap inner_threads against remaining host/unified RAM (e.g., pricing each additional nested worker at _WORKER_BYTES and forcing inner_threads = 1 under the minimum-allowance fallback or when remaining RAM cannot cover nested workers).
  2. ForwardCache.prepare_many spawns 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_many wraps the entire _prepare_many / _prepare_ranks lifecycle in torch._inductor.config.patch(compile_threads=min(24, os.cpu_count() or 1)).
      • Contrary to the comment ("Allow fallback/binding compilation to parallelize"), the BindingMismatch fallback recompile at aot.py:980 calls aot_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 outer 24 patch.
      • Instead, the outer 24 patch affects self._load(...) (deserialize_bundled_cache_entry at aot.py:66, called in _restore at :1053 and in "Load and warm compiled forwards" at :1229) and _warm(...) inside the parent rank process. Whenever binding/loading enters Inductor's AsyncCompile, Inductor starts a process-global singleton SubprocPool of up to 24 persistent worker processes per rank (up to N_local_ranks × 24 on a multi-GPU host, ignoring affinity and host/unified RAM).
      • Unlike CompilePool.__exit__ (compile_pool.py:167-169), nothing in ignition/ shuts down Inductor's parent-process AsyncCompile pool before materialize(), warmup, or CUDA graph capture (capture.py:140-188), leaving those workers resident in host/unified RAM through capture. This directly violates docs/preparation-development.md:317-318 ("artifact binding starts no additional compiler pool") and docs/design-review.md:81-84 ("Release compiler resources before materializing preparation caches"), and contradicts DeferredCompiledForward.materialize_for_capture (aot.py:688), which stays at compile_threads=1.
    • Concrete fix: Restore torch._inductor.config.patch(compile_threads=1) in ForwardCache.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 by cpu_workers() // local_ranks and available host/unified RAM (reusing self.options['compile_threads'] rather than a hardcoded 24), and explicitly shut down Inductor's AsyncCompile pool before materialize() and graph capture.

Should Fix

  1. Hardcoded 1 GiB discrete compile_reserve cap silently overrides default and user-configured headroom (ignition/preparation/compile_pool.py:49-62, ignition/preparation/bootstrap.py:35, 134).

    • Because BasePreparationConfig.headroom_bytes defaults to 4 GiB (bootstrap.py:35, plus plan.reserve_bytes at :134), min(headroom_bytes, 1024 << 20) silently reduces the compile-time device reserve from 4 GiB (or larger explicit --reserve) to 1 GiB on every discrete export — not only "when large runtime reserves are configured" as the PR description states. Meanwhile, CompilerResources.headroom (compile_pool.py:62) keeps the 8 GiB host floor and host_memory.candidate_scratch_limit / tuning_limits (host_memory.py:160, 172) still honour full headroom_bytes on discrete GPUs.
    • Fix: Drop the hardcoded 1024 << 20 override (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.
  2. 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 no main baseline, no worker/thread counts, no peak host-RSS or device-VRAM measurements, and no measurement on SM120/SM121 workstations. Lowering _DISCRETE_WORKER_DEVICE_BYTES from 1 GiB to 704 MiB leaves only 32 MiB (~4.8%) slack above the unverified 672 MiB figure (replacing the previous comment noting "about 0.7 GiB for Kimi K3's 93-layer forwards"). Additionally, CI on head 3400e3a is 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 justifying 704 MiB.
  3. Windows thread partitioning and "spawn" preservation are untested, and hasattr(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_budget monkeypatches compile_pool.os to SimpleNamespace(name="nt") (omitting cpu_count), so hasattr(os, "cpu_count") in compile_pool.py:139 falls back to None → inner_threads = 1 instead of testing Windows partitioning. No test asserts worker_start_method on the os.name == "nt" branch (test_compile_pool.py:29-30 and test_forward_compile_options.py:283-284 only assert when os.name != "nt").
    • Fix: Remove hasattr(os, "cpu_count") when switching to cpu_workers() (Blocker 1), and add/update a Windows-path test asserting both compile_threads and that worker_start_method is not overridden to "subprocess" (preserving "spawn" from _OPTIONS on Windows).
  4. 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-SKU groups= admission to allocate_workers and 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.

Subtract / Simplify

  1. Delete the 1 GiB discrete compile_reserve clamp (ignition/preparation/compile_pool.py:49-55) and restore headroom_bytes directly in both expressions (:52, :55). Keeping _DISCRETE_WORKER_DEVICE_BYTES = 704 << 20 alone already delivers most of the discrete worker-count increase (10 → 14 workers at 12 GiB free / 2 GiB headroom; 8 → 11 at 4 GiB default headroom) without silently overriding configured headroom, adding a second shared conditional, or rewriting test_compilation_preserves_configured_headroom (tests/preparation/test_compile_pool.py:443-452).
  2. Collapse CompilePool.__init__'s thread calculation (ignition/preparation/compile_pool.py:137-144): remove the mock-driven hasattr(os, "cpu_count") guard (:139) and the unreachable max(1, self.workers) guard (:140 — :134-135 already rejects workers < 1), and reuse the already-imported cpu_workers() (compile_pool.py:20).
  3. Remove the standalone 24 cap in ForwardCache.prepare_many (ignition/preparation/aot.py:903) and restore compile_threads=1 (matching aot.py:688 and docs/preparation-development.md:318), removing both the fourth distinct compile_threads authority and test_prepare_many_scales_inductor_compile_threads_with_cpu_count (tests/preparation/test_forward_compile_options.py:333-342).

Nits

  1. Replace formula-mirroring test assertions with concrete literals (tests/preparation/test_compile_pool.py:28, tests/preparation/test_forward_compile_options.py:282): both recompute min(8, ...) inline instead of pinning concrete expected values like test_compile_pool.py:376-377.
  2. 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_processes only spawns a single-level SubprocPool(1); once CompilePool workers spawn nested worker_start_method="subprocess" Inductor children, add coverage ensuring no orphaned grandchild processes remain on interrupt or failure.

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.