Recommendation: Ready To Merge
PR #641 cleanly fixes a verified memory-accounting bug in compiler_resources() and a peer-rank flush ordering gap in ForwardCache._prepare_ranks() without relaxing any headroom invariant, worker budget, or artifact/API contract. The core resample logic, widened worker-cap flush triggers, deadlock-free collective error propagation, and isolated CPU unit tests are all verified sound at head d82fcfc. Only minor optional simplifications (avoiding a redundant second empty_cache() / duplicate POSIX available_bytes() reads) and confirming .github/workflows/python-cpu.yml (not opened) CI is green on d82fcfc remain before merge.
Merge Risk
Level: Low
- Scoped to one-shot forward-compilation worker admission (
ignition/preparation/compile_pool.py:38-64,ignition/preparation/aot.py:1068-1074); serving hot paths, CUDA graph capture contracts,CompilerResourcesfields,allocate_workers()admission math (compile_pool.py:67-98), and exported core formats are untouched. - Multi-rank synchronization and failure propagation remain deadlock-free:
torch.cuda.empty_cache()runs inside the existingtry/exceptahead ofdist.barrier(group=group)(aot.py:1068-1074), so any flush failure is folded intoerrorand surfaced collectively afterall_gather_object(demand, ...)(aot.py:1081-1085, 1130-1131). - Discrete-GPU and Windows (
os.name == "nt") paths are validated by mocked CPU unit tests rather than live hardware (disclosed in the PR description), and.github/workflows/python-cpu.yml(not opened) CI has not yet reported a run ond82fcfc.
Walkthrough
ignition/preparation/compile_pool.py:26: Extracts_DEFAULT_MAX_WORKERS = 8from the previous inline literal.ignition/preparation/compile_pool.py:46-64: Computesworker_bytes,headroom, andmax_workersahead of sampling; clampsavailable = min(available, free)before the flush check whensharedis true; triggerstorch.cuda.empty_cache()whenavailable - headroom < max_workers * worker_bytes(integrated) orfree - headroom_bytes < max_workers * device_bytes(discrete); and resamples bothfreeandavailable = min(host_memory.available_bytes(), free)after flushing on unified memory (while resampling onlyfreeon discrete GPUs).ignition/preparation/aot.py:1068-1074: Callstorch.cuda.empty_cache()immediately afterrelease_unused()inside the existingtry/exceptblock precedingdist.barrier(group=group)inForwardCache._prepare_ranks(), ensuring peer ranks on a shared host flush cached CUDA segments before any rank samples host memory.tests/preparation/test_compile_pool.py:538-683: Adds well-isolated pytestmonkeypatchunit tests covering POSIX and Windows (os.name == "nt") unified-memory host resampling across reclamation thresholds, discrete-GPU capacity recovery (default and explicitcompile_workers > 8), flush skipping when memory already coversmax_workers, and_prepare_ranks()release_unused -> empty_cache -> barrier -> compiler_resourcesordering on both success and failure.
Pre-merge Checks
- [PASS] Security / malicious screen: Pure Python preparation and test changes across 3 files; no prompt injection, shell execution, credential handling, or unsafe deserialization introduced.
- [PASS] Charter & value fit: Fixes a reproducible physical-memory accounting defect in shared
ignition/preparation/code with no new flags, env vars, dependencies, or per-model branches, directly aligned withdocs/preparation-development.md:305-318and SM121/GB10 goals. - [WARN] Related / duplicate / conflict check: Clean against
main(no conflicting commits since base) and disjoint from open Ready-To-Merge PR #597 (allocate_workers/ GPU-name keying). Open draft PR #639 (currentlyChanges Requestedwith 2 blockers) editscompiler_resources()and lowers_DISCRETE_WORKER_DEVICE_BYTESto704 << 20, which would conflict with the1 GiBdiscrete expectations intests/preparation/test_compile_pool.py:608-610; whichever lands second will need a rebase. - [WARN] Tests & verification evidence: Author reports
160 passed, 0 failedon 5 targeted preparation test files plus a live 3-node SM121 (3× GB10) before/after export +flare runqualification (explicitly noting paired branches#635andhyperflare-recipes#103, which are orthogonal to memory resampling). Confirm.github/workflows/python-cpu.yml(not opened) (.venv/bin/python -m pytest tests/ -q,.github/workflows/python-cpu.yml:30-33(not opened)) is green ond82fcfcbefore merging; discrete-GPU, >1-worker-per-host, and Windows paths are CPU-mock-only.
Blockers
None.
Should Fix
None.
Subtract / Simplify
- Optional: avoid the redundant second
torch.cuda.empty_cache()on multi-rank (ignition/preparation/aot.py:1070,ignition/preparation/compile_pool.py:55-57). InForwardCache._prepare_ranks(), every rank already runstorch.cuda.empty_cache()ataot.py:1070beforedist.barrier(group=group), then immediately callscompiler_resources()ataot.py:1076. Becausemax_workers * worker_bytesis272 GiBat defaults on unified memory (and8 GiBon discrete),compile_pool.py:57immediately invokes a second no-op flush and resamples memory. Allowing_prepare_ranks()to skip re-flushing (e.g., an internalflush_cache=Falsekwarg, keepingflush_cache=Truefor single-rankCompilePool.__init__ataot.py:921/compile_pool.py:133) avoids the duplicate flush and extra sample pass. - Optional: skip redundant POSIX
available_bytes()reads on unified memory (ignition/preparation/compile_pool.py:51-60). On POSIX integrated GPUs,device_memory_info(device)already returnsmin(total, available_bytes())(ignition/preparation/host_memory.py:107-110), so callinghost_memory.available_bytes()separately before and afterdevice_memory_info()reads/proc/meminfo,/proc/self/cgroup, and/proc/self/mountinfo(host_memory.py:51-100) four times per call instead of two. Matchinghost_memory.py:154-158/:177-179(free = device_memory_info(device)[0]; available = min(host_memory.available_bytes(), free) if os.name == "nt" else freewhensharedis true) halves procfs reads on Linux while preserving identical POSIX and Windows behavior.
Nits
- Description precision: In the live 3× GB10 export, the reported
[1, 1, 1]worker count comes from restoring the 1-worker-per-host4 GiBminimum-allowance floor (ignition/preparation/compile_pool.py:87-94, with~13.3 GiBavailable vs8 GiBheadroom), whereas "unlocking additional compiler workers" (>1 worker per host and discrete worker recovery) is verified by the new CPU unit tests (tests/preparation/test_compile_pool.py:579, 605-623) rather than the live GB10 run. Consider tightening that sentence and referencing related issue #242. - Optional docs note:
docs/model-preparation.md:489-495(DGX Spark) remains accurate as written; a brief sentence noting that cached PyTorch CUDA allocator segments are flushed before compiler-worker admission could be added there in this PR or a follow-up.
Dropped on verification
- Upstream
F2("min(available, free)is a no-op on POSIX / the metric change is inert on GB10"): Verified false. Onmain,availablewas sampled beforetorch.cuda.empty_cache(), never resampled after it, and then clamped viaavailable = min(available, free)afterward — discarding every reclaimed byte on GB10. Atd82fcfc,compile_pool.py:60resampleshost_memory.available_bytes()post-flush, which directly fixes GB10; the pre-flush clamp at:53-54also preservesavailable <= totalon POSIX when no flush runs and clamps againstmem_get_infofree on Windows. - Upstream
S1("main's trigger already fired in the reported case; narrow:55-56toavailable - headroom < device_bytes"): Verified incorrect and buggy. First,maincheckedfree - headroom_bytes < device_bytes(2 GiB) usingheadroom_bytes(default4 GiB,ignition/preparation/bootstrap.py:35,134), notheadroom = max(8 GiB, headroom_bytes)(compile_pool.py:49), so at8435 MiBwith4–5 GiBheadroom_bytes,mainwould not even have flushed. Second, narrowing to< device_bytes(2 GiB) would skip flushing wheneveravailable - headroomis in[2 GiB, 4 GiB)and still crash withMemoryErroragainst the4 GiBminimum-allowance floor (compile_pool.py:90-92, e.g., issue #242's11575 MiBfailure). - Upstream
S2("sample()helper cutsavailable_bytes()calls from 4 to 2 and fixes discrete staleness"): Verified arithmetically wrong and technically inverted. The proposedsample()helper still callsavailable_bytes()insidedevice_memory_info()and again directly (still 4 calls on POSIX integrated), and resamplingavailable_bytes()on discrete GPUs adds unnecessary procfs reads becausetorch.cuda.empty_cache()frees discrete VRAM, not host RAM (tests/preparation/test_compile_pool.py:622intentionally pinshost_samples == 1). - Upstream
F4("loop-invariant flush / unmeasured expensivecudaMallocchurn during bind/warm/capture"): Dropped as overstated.compiler_resources()runs once per export (not in a loop) ahead of a multi-minute compile phase;aot.py:1070already flushes unconditionally on multi-rank; warmup usesCoreStorage'stransient()VMM pool (capture.py:113,131-140); andretain_transient_backing()callstorch.cuda.empty_cache()on exit (core_storage.py:261). - Upstream
F5("flush frequency scales with CPU count, not memory demand"): Dropped.max_workers(compile_pool.py:50) is the exact upper bound on workerscompiler_resources()can admit for that rank; scaling the trigger withmax_workersavoids pointless flushes on low-core hosts while allowing recovery when explicitcompile_workers > 8is requested. - Upstream
F3("empty_cache()insideretain_transient_backing()withoutseal_low_window()"): Dropped as pre-existing and unsupported.compile_pool.pyonmain,ignition/preparation/tuning.py:601, andignition/preparation/core_storage.py:573all calltorch.cuda.empty_cache()withoutseal_low_window(),retain_transient_backing()seals on exit (core_storage.py:250) ahead of serving graph capture (capture.py:155,172), and the live 3-node GB10 export passeddevice_address_floorexport (runtime_core.py:427) cleanly. - Upstream
F1("sharedtry/exceptskipsempty_cache()ifrelease_unused()raises ataot.py:1068-1073"): Dropped as zero-impact. Anyrelease_unused()exception setserrorand aborts_prepare_ranks()collectively ataot.py:1084-1085beforeallocate_workers()ever runs. - Upstream Open Question #5 ("unqualified
torch.cuda.empty_cache()only clears current device"): Dropped as incorrect; PyTorch'storch.cuda.empty_cache()takes no device argument and clears cached blocks across all initialized CUDA devices. - Upstream Value Prop / Dossier ("combined-stack evidence violates
AGENTS.md"): Downgraded to a Pre-merge Checks note rather than a blocker; the PR explicitly discloses#635(planningfilter_world_sizes) andhyperflare-recipes#103(TP3 recipe) and holds both constant between the failing "Before" run (MemoryErrorat2.5s) and passing "After" run.