Skip to content

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

Draft
original-el8 wants to merge 1 commit into
NVIDIA:mainfrom
liquidgravityai:pr/compile-pool-scaling-and-sizing
Draft

original-el8 wants to merge 1 commit into
NVIDIA:mainfrom
liquidgravityai:pr/compile-pool-scaling-and-sizing

Conversation

@original-el8

Copy link
Copy Markdown
Collaborator

Why

Discrete GPU compiler workers initialize a CUDA context and run TorchInductor constant folding, consuming ~672 MiB of device memory and exiting before runtime allocations. Reserving 1 GiB per discrete worker and subtracting the full runtime/KV headroom_bytes from device free memory under-allocates compile workers when large runtime reserves are configured.

On high-core-count CPU hosts, pinning each CompilePool worker to compile_threads=1 and patching ForwardCache.prepare_many to compile_threads=1 leaves most host CPU cores idle during compilation and fallback artifact binding. In addition, 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.

What changed

  • ignition/preparation/compile_pool.py:
    • Before: _DISCRETE_WORKER_DEVICE_BYTES was 1 << 30 (1 GiB), compiler_resources subtracted the full headroom_bytes on both integrated and discrete GPUs, and CompilePool.__init__ forced compile_threads=1 without configuring worker_start_method.
    • After: _DISCRETE_WORKER_DEVICE_BYTES is 704 << 20 (704 MiB). compiler_resources continues to reserve full headroom_bytes on integrated GPUs with shared physical memory, and caps the discrete device-side compile reserve at 1 GiB (min(headroom_bytes, 1024 << 20)). CompilePool.__init__ partitions host CPU threads across admitted workers (max(1, min(8, (os.cpu_count() or 1) // max(1, self.workers)))) and sets worker_start_method="subprocess" when os.name != "nt" (preserving "spawn" on Windows).
  • ignition/preparation/aot.py:
    • Before: ForwardCache.prepare_many patched torch._inductor.config.compile_threads to 1.
    • After: ForwardCache.prepare_many patches torch._inductor.config.compile_threads to min(24, os.cpu_count() or 1).
  • tests/preparation/test_compile_pool.py and tests/preparation/test_forward_compile_options.py:
    • Updated discrete worker device sizing, 1 GiB discrete compile reserve, and CPU thread-partitioning expectations, and added unit coverage for ForwardCache.prepare_many compile_threads scaling.

Result

Discrete GPUs admit compile workers against their 704 MiB per-worker footprint and <= 1 GiB compile-time device reserve, while CompilePool workers and ForwardCache.prepare_many scale TorchInductor CPU compilation threads with host core count.

Verification

  • Isolated CPU-only unit tests (CUDA_VISIBLE_DEVICES="", pytest):
    • tests/preparation/test_forward_compile_options.py, tests/preparation/test_compile_pool.py, tests/preparation/test_forward_artifact_sharing.py, tests/preparation/test_host_memory.py: 146 passed, 0 failed.
    • tests/preparation/test_aot_guards.py, tests/preparation/test_preparation_reclamation.py, tests/preparation/test_core_boundary.py, tests/preparation/test_runtime_core.py, tests/preparation/test_capture_graph_metadata.py: 56 passed, 14 skipped, 0 failed (skipped tests are gated on FLARE_RUN_CUDA_TESTS=1).
  • Combined-stack GB300 (SM103) model exports:
    • DeepSeek-V4.1 preparation compiled 101/101 model forwards in 359.8 s, and Inkling-2-Small preparation compiled 148-graph forwards without SubprocPool daemonic multiprocessing errors or device OOM (combined-stack export validation alongside the isolated CPU unit suite above).

Limitations: GPU-gated preparation unit tests (FLARE_RUN_CUDA_TESTS=1) were skipped in the CPU-only run.

Discord: el8

… threads

Why:
Discrete GPU compiler workers retain ~672 MiB of device memory for CUDA context initialization and TorchInductor constant folding and exit before runtime allocations. Reserving 1 GiB per worker and subtracting full runtime headroom_bytes from device free memory under-allocates compile workers when large runtime reserves are configured. On high-core-count CPU hosts, setting compile_threads=1 in CompilePool and ForwardCache.prepare_many also leaves host cores idle, and workers inside SubprocPool require worker_start_method="subprocess" on POSIX to parallelize TorchInductor without daemonic multiprocessing errors.

What:
- ignition/preparation/compile_pool.py:
  - Before: _DISCRETE_WORKER_DEVICE_BYTES was 1 << 30 (1 GiB), compiler_resources subtracted full headroom_bytes on both integrated and discrete GPUs, and CompilePool.__init__ set compile_threads=1 without setting worker_start_method.
  - After: _DISCRETE_WORKER_DEVICE_BYTES is 704 << 20 (704 MiB). compiler_resources reserves full headroom_bytes on integrated GPUs with shared physical memory and caps the discrete device reserve at 1 GiB (min(headroom_bytes, 1024 << 20)). CompilePool.__init__ sets compile_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers))) and sets worker_start_method="subprocess" when os.name != "nt".
- ignition/preparation/aot.py:
  - Before: ForwardCache.prepare_many patched torch._inductor.config.compile_threads=1.
  - After: ForwardCache.prepare_many patches torch._inductor.config.compile_threads=min(24, os.cpu_count() or 1).
- tests/preparation/test_compile_pool.py and tests/preparation/test_forward_compile_options.py:
  - Update discrete worker sizing, 1 GiB discrete compile-reserve, and thread-partitioning expectations, and add coverage for ForwardCache.prepare_many compile_threads scaling.

Result:
Discrete GPUs size compile workers against a 704 MiB per-worker footprint and at most a 1 GiB device compile reserve, while CompilePool workers and ForwardCache.prepare_many scale TorchInductor CPU threads with host core count.

Verification and limitations:
- Isolated CPU-only unit tests (CUDA_VISIBLE_DEVICES="", pytest):
  - tests/preparation/test_forward_compile_options.py, test_compile_pool.py, test_forward_artifact_sharing.py, test_host_memory.py: 146 passed, 0 failed.
  - tests/preparation/test_aot_guards.py, test_preparation_reclamation.py, test_core_boundary.py, test_runtime_core.py, test_capture_graph_metadata.py: 56 passed, 14 CUDA-gated tests skipped, 0 failed.
- Combined-stack GB300 (SM103) model exports: DeepSeek-V4.1 preparation compiled 101/101 model forwards in 359.8 s and Inkling-2-Small preparation compiled 148-graph forwards without SubprocPool daemonic multiprocessing errors or device OOM.
- Limitations: GPU-gated preparation unit tests (FLARE_RUN_CUDA_TESTS=1) were not executed in the CPU-only run.

Design-Signed-Off-By: Jason Cook <1637905+original-el8@users.noreply.github.com>; design-review=2e5b
@original-el8
original-el8 marked this pull request as draft November 30, 2026 12:15
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 639.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 30, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

This draft PR targets a legitimate compilation-throughput bottleneck in shared ignition/preparation/ code with a small footprint, but introduces two verified system-level blockers: unbudgeted nested Inductor subprocesses per worker, and a persistent unbudgeted parent-rank AsyncCompile pool during artifact binding/loading. The hardcoded 1 GiB discrete compile_reserve cap, the mock-only Windows guard, and the missing main-vs-PR evidence and green CI also need to land first.

  • Blockers: 2 · Should fix: 4 · Subtract/Simplify: 3 · Nits: 2
Walkthrough
  • ignition/preparation/compile_pool.py: Lowers _DISCRETE_WORKER_DEVICE_BYTES from 1 GiB to 704 MiB (:24-25); caps discrete device-side compile_reserve at min(headroom_bytes, 1024 << 20) in compiler_resources (:49-55) while leaving integrated GPUs and host-RAM CompilerResources.headroom (:62) unchanged; replaces compile_threads=1 in CompilePool.__init__ with inner_threads = max(1, min(8, (cpu_count or 1) // max(1, self.workers))) and sets worker_options["worker_start_method"] = "subprocess" when os.name != "nt" (:137-144).
  • ignition/preparation/aot.py: Changes ForwardCache.prepare_many's outer Inductor patch from compile_threads=1 to compile_threads=min(24, os.cpu_count() or 1) (:901-903), leaving DeferredCompiledForward.materialize_for_capture at compile_threads=1 (:688).
  • tests/preparation/test_compile_pool.py: Updates discrete worker capacity assertions (10 → 16 at 12 GiB free / 2 GiB headroom, :43-45; 3 → 4 at 3 GiB free, :376-388), splits test_compilation_preserves_configured_headroom by integrated (:443-452), and updates compile_threads / worker_start_method expectations (:25-30, :381-388, :391-398, :548-551).
  • tests/preparation/test_forward_compile_options.py: Updates CompilePool option assertions (:282-284) and adds test_prepare_many_scales_inductor_compile_threads_with_cpu_count (:333-342).
Merge Risk: High · up to 3400e3a
  • 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-rank AsyncCompile pools (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 MiB per worker, only 32 MiB above the unverified 672 MiB claim), increasing OOM risk on tighter-VRAM SM120/SM121 workstations without an isolated main-vs-PR benchmark.
  • No GPU preparation tests run in CI, and CI on head 3400e3a is currently failing while open Ready-To-Merge PR Key compiled forward sharing and Inductor validation by GPU name #597 modifies the same compile_pool.py / aot.py coordination paths.
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings
  • ✅ Security / malicious screen: No prompt injection, shell execution, credential exposure, or unsafe deserialization introduced across the 4 changed files.
  • ⚠️ Charter & value fit: Lives in shared ignition/preparation/ with no per-model branches or artifact-format breaks and targets SM103/SM120/SM121, but lacks a main-vs-PR benchmark on a served/discrete workload, silently clamps explicit headroom_bytes on the default discrete path, and violates docs/preparation-development.md:317-318 / docs/design-review.md:81-84 resource-release invariants.
  • ⚠️ Related / duplicate / conflict check: No commits to these files on main since branch point, but open PR Key compiled forward sharing and Inductor validation by GPU name #597 (reviewed Ready To Merge) modifies allocate_workers in compile_pool.py and _prepare_ranks in aot.py; this PR also partially reverses c8d4c324's single-thread-per-worker policy without citing or benchmarking against it.
  • ⚠️ Tests & verification evidence: Description cites local CPU pytest subsets and a single combined-stack GB300 export (359.8 s) with no main baseline, no peak RAM/VRAM telemetry, and no SM120/SM121 measurement; CI on head 3400e3a is failing (.github/workflows/python-cpu.yml (not opened) runs the full CPU suite).

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants