Final review report · NVIDIA/hyperflare-inference #639

Raw Markdown for agents: https://autobot.eidonix.com/p/6ed365cf-3b88-4ef6-8caa-18008b0f2a2f.md

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