Recommendation: Changes Requested
PR #668 cleanly addresses three real multi-host preparation defects—request-name-first selection reconciliation, peer b12x_environment / local kernel_cache propagation, and ForwardCache B12X keying with atomic .bin persistence—and independent 2× GB10 SM121 reports from @nepenth and @Reederey87 corroborate both root causes. Head d6a0069 rebased cleanly onto main (resolving the prior #667 conflict in host_ranks.py:723-725), but the PR's own 8-file diff (+424 / −44) has not yet addressed two concrete safety/test-isolation bugs from Round 1: ForwardCache._load silently unlinking valid .bin artifacts on transient OSError / CUDA / _load_inductor errors, and the new serve_peer test permanently leaking B12X_* variables into process-global os.environ.
Merge Risk
Level: Medium
- Preparation-only blast radius: All edits are confined to
ignition/preparation/,ignition/cli/serve.py, andtests/preparation/; no Helios runtime, Protobuf schema, or exported model-core format changes. Note that with#695merged onmain,reconcile_selectionsalso runs for serving-replica--tuning-gpussessions (ignition/preparation/tuning.py:521-535). - Destructive cache-recovery and one-time re-key: Hashing
_b12x_forward_env()intoForwardCache.root(ignition/preparation/aot.py:897-899) triggers a one-time forward recompile for recipes declaringb12x_environment(e.g., GLM-5.3, Kimi). More critically,_load(..., required=False)(aot.py:64-76, 1371-1380) catches blanketOSError/RuntimeError/ValueErroraround bothpath.open('rb')and_load_inductorand destructively unlinks the cached.binwithout logging. - Open-PR conflict horizon: Rebase resolved the
#667overlap cleanly (host_ranks.py:723-725), leaving active file overlap with open#597(aot.py),#678(aot.pyandtests/preparation/test_forward_cache_sources.py), and#671(host_ranks.pyandtests/preparation/test_forward_artifact_sharing.py).
Walkthrough
- Request-name-first selection reconciliation (
ignition/preparation/collectives.py:196-224, 398-449):_selected_plan_catalogrecords(request.name, variant, plan.component_id)alongsideportable_declaration(plan)for non-collective requests (request.collective is None).reconcile_selectionsmatches sharedname_keys across ranks first before falling back to shareddecl_keys, using a singletarget_forhelper for bothchangedandconfigsso all ranks enter or skip Pass 2 in lockstep while preserving component-ID safety. - Peer
b12x_environmentpropagation & localkernel_cacheremapping (ignition/preparation/host_ranks.py:201-239, 313-381, 625-726;ignition/cli/serve.py:193-197, 416-420, 551-555):HostRendezvousvalidates and storesmodel.recipe.b12x_environment(rejecting non-B12X_keys,B12X_COMPILE_CACHE_DIR, and non-string values) and sends it to peers beforeassignment(and again insideassignment).serve_peerapplies it toos.environ, remapsconfig.kernel_cacheto the peer's localkernel_cachepassed fromjoin, and forwardskernel_cacheinto peerexport_options. ForwardCachekeying, atomic.binpersistence, and corrupt-load recovery (ignition/preparation/aot.py:47-100, 868-878, 897-899, 1326, 1371-1380, 1454, 1463):ForwardCache.__init__mixes sorted execution-relevantB12X_*bindings (_b12x_forward_env()) into its SHA-256 root key; all three directsave_compiled_functioncall sites switch to sibling-temp_save_compiled_function;_share_artifactsadds temp-file cleanup;_load(..., required=False)catches_CORRUPT_ARTIFACT_ERRORS, unlinks the.bin, and returnsNone.- Tests (
tests/preparation/test_tuning_shards.py:264-325,tests/preparation/test_host_ranks.py:334-439,tests/preparation/test_forward_cache_sources.py:142-218,tests/preparation/test_forward_artifact_sharing.py:130-154, 261-262): Adds a 2-rank Gloo reconciliation test, rendezvous env validation andserve_peerenv/cache-remapping tests,ForwardCacheB12X keying / atomic-save / corrupt-load tests, and real payload writes in_Artifact.save_compiled_function.
Pre-merge Checks
- [PASS] Security / malicious screen: No credential exposure, shell injection, or untrusted input escalation;
_validate_b12x_environmentrestricts peer environment updates to non-cacheB12X_*string bindings. - [WARN] Charter & value fit: Cleanly scoped to Ignition preparation/CLI with no per-model branches or runtime flags and targets a reproducible cross-node bug (
#651), but_CORRUPT_ARTIFACT_ERRORSsilently swallows and deletes on unexplainedOSError/RuntimeErrorfaults (against charter#397). - [WARN] Related / duplicate / conflict check: Rebased cleanly onto merged
#667and#695, and supersedes closed#675(though without carrying over#675's stricter pre-import ordering injoin). Coordinates with open#597,#678(aot.py,test_forward_cache_sources.py), and#671(host_ranks.py,test_forward_artifact_sharing.py). - [WARN] Tests & verification evidence: Author ran 192 preparation CPU tests against paired
flashinfer#199and 136 CLI CPU tests; CI (.github/workflows/python-cpu.yml:29-33(not opened)) validates against pinnedflashinfer(pyproject.toml:47,rev = "5a8ceed80ccc58e11a4d49ccc910f52967699c09"). The newserve_peertest leaksB12X_*intoos.environ,torch.OutOfMemoryErroris untested, and headd6a0069has not yet been run on live 2× GB10 hardware.
Blockers
-
Narrow
_CORRUPT_ARTIFACT_ERRORS, log dropped artifacts, guardunlink, and testtorch.OutOfMemoryError(ignition/preparation/aot.py:64-76, 103-144, 1371-1380;tests/preparation/test_forward_cache_sources.py:212-217):ForwardCache._load(..., required=False)wraps bothpath.open('rb')andtorch.compiler.load_compiled_function(file)inexcept _CORRUPT_ARTIFACT_ERRORS, which catches blanketOSError,RuntimeError,ValueError,TypeError,KeyError, andAttributeError. Insideload_compiled_function,_load_inductor(aot.py:103-144) writes Triton cubins to disk (_materialize_selected_cubinat:121), loads CUDA modules (deserialize_bundled_cache_entryat:123), and enforces internal invariants withValueError(:111) andRuntimeError(:128).- Consequently, any transient
OSError(ENOSPCwriting Triton cubins,EMFILE,EIO), non-OOM CUDA driverRuntimeError, or_load_inductorcontract failure silently deletes a potentially valid.binartifact with zero warning/logging and forces a full recompile (charter#397). Additionally,Path(path).unlink(missing_ok=True)(:1379) is unguarded againstPermissionError/OSError(e.g., sticky/read-only directory or locked file on Windows), turning a recoverable miss into an unhandled crash. - At
aot.py:1377,MemoryErrorinisinstance(error, (MemoryError, torch.OutOfMemoryError))is unreachable dead code becauseMemoryErroris not a subclass of any member of_CORRUPT_ARTIFACT_ERRORS. The test attests/preparation/test_forward_cache_sources.py:212-217only raisesMemoryError, so it never enters theexceptclause and leaves thetorch.OutOfMemoryError(RuntimeErrorsubclass) carve-out completely untested. - Fix: Move
path.open('rb')outside the corrupt-archivetry(or handleFileNotFoundErrorexplicitly as a miss); narrow_CORRUPT_ARTIFACT_ERRORSto genuine archive/deserialization errors (EOFError,pickle.UnpicklingError,struct.error,zlib.error,zipfile.BadZipFile—not blanketOSErrororRuntimeError, or if a specificRuntimeError/ValueErrorfrom truncated torch archives must be handled, place an explicitexcept (MemoryError, torch.OutOfMemoryError): raiseahead of it and do not swallowOSErroror_load_inductorcontract faults); log a warning namingpathanderrorbefore unlinking; wrapPath(path).unlink(missing_ok=True)intry: ... except OSError: pass; and testtorch.OutOfMemoryErrorintest_forward_cache_sources.py.
-
Fix the process-global
os.environleak intest_serve_peer_applies_b12x_environment_and_remaps_kernel_cache(tests/preparation/test_host_ranks.py:361-362, 426-438):monkeypatch.delenv("B12X_W4A16_A4_PREFILL", raising=False)andmonkeypatch.delenv("B12X_W4A16_SMALL_M_HOST_BARRIER_RESET", raising=False)are no-ops when those keys start absent, so pytest registers no teardown restoration (comparetests/cli/test_environment.py:55-62(not opened), which explicitly works around this pytest behavior).serve_peerthen mutatesos.environdirectly viaos.environ.update(...), leaving bothB12X_*variables set for every subsequent test in the same worker—directly perturbing_b12x_forward_env()andForwardCache.rootintroduced in this PR.- Fix: Register undo entries before calling
serve_peer(e.g.,monkeypatch.setenv(k, ""); monkeypatch.delenv(k)for each key, matchingtests/cli/test_environment.py:57-62(not opened), or restoreos.environinfinally:).
Should Fix
-
Address or document the peer
b12x_environmentimport-order gap (ignition/cli/serve.py:547-555,ignition/cli/environment.py:7-9, 82,ignition/runtime_patches/__init__.py:119,ignition/runtime_patches/workers.py:26-29,ignition/preparation/host_ranks.py:297, 645-648):- In
join(),environment.apply(configuration, (gpu,))runs atserve.py:547beforeknock()andserve_peer().environment.applycallsruntime_patches.apply()(environment.py:82) →workers.register_hooks()(runtime_patches/__init__.py:119) →from b12x.preparation import register_worker_initializer(workers.py:27), sob12xandb12x.preparationare already imported beforeserve_peerreceives("b12x-environment", ...)athost_ranks.py:646-648. - For dynamically read flags like
B12X_W4A16_A4_PREFILL, applying them beforeassignment = receive_object(control)(:665) works because recipe/operator modules import during unpickling. However, any futureb12x_environmentvariable cached atb12x/b12x.preparationimport time will still diverge between rank zero (serve.py:211, 438) and peers—contradictingignition/cli/environment.py:7-9and the PR description's unqualified "(so import-time reads see it)" claim (as@Reederey87flagged after closing#675). - Fix: Either send
b12x_environmentin_admit's JSON reply (host_ranks.py:297) and callenvironment.apply(configuration, (gpu,), b12x_environment)injoin()afterknock()(note thatsource_identity(),local_topology(), andknock()do not requireenvironment.apply—rank zero already runs all three beforeenvironment.applyatserve.py:193-211), which also eliminates the pickle-channel duplication below; or explicitly document inserve.py/host_ranks.pyand the PR description that peerb12x_environmentis applied afterb12x.preparationimport and only precedes recipe/operator imports.
- In
-
Do not auto-close
#651before confirmingd6a0069on live 2× GB10 hardware:- Independent 2× GB10 SM121 TP2 reports from
@nepenthand@Reederey87strongly validate both diagnosed root causes and manual workarounds, but neither ran this PR commit itself, and CI runs against pinnedflashinfer(pyproject.toml:47) rather than pairedflashinfer#199. Because#647previously auto-closed#631without resolving live 2× GB10 convergence, either verify this branch on 2× GB10 before merging or changeFixes #651toRelated: #651until confirmed on hardware (and note the expected one-timeForwardCachere-key for recipes withb12x_environment).
- Independent 2× GB10 SM121 TP2 reports from
Subtract / Simplify
-
Collapse the duplicate
b12x_environmentwire channel and remove the unusedprepare(..., b12x_environment=None)parameter (ignition/preparation/host_ranks.py:313-314, 325-326, 345-347, 376-377, 645-648, 665-668,ignition/preparation/rank_group.py:288-290,tests/preparation/test_host_ranks.py:400-412):HostRendezvous.preparesends the exact sameb12x_envdict twice: once as("b12x-environment", b12x_env)(:345-347) and again insideassignment["b12x_environment"](:377), whereserve_peerre-validates and re-applies it (:666-668). Because the early command is always sent wheneverb12x_envis non-empty, theassignmentcopy can never add anything new (the test attest_host_ranks.py:400-412only hits both paths by injecting two different dicts thatHostRendezvous.preparenever produces).- Separately,
prepare(..., b12x_environment=None)(:314, 325-326) has no caller (rank_group.py:288-290never passes it;HostRendezvous.__init__already validates and storesself.b12x_environment). - Fix: Keep a single channel (either
_admitper Should Fix #1, or the early("b12x-environment", ...)frame), remove"b12x_environment"fromassignmentandhost_ranks.py:666-668, drop the unusedb12x_environment=Noneparameter fromHostRendezvous.prepare, and simplifytest_host_ranks.py:400-412.
-
Consolidate duplicated atomic-write blocks and fix the open-handle
unlinkin_share_artifacts(ignition/preparation/aot.py:90-100, 270-277, 868-878, 1185-1192;ignition/preparation/compile_pool.py:104, 115-123):_save_compiled_function(aot.py:90-100) is identical tocompile_pool._compile_forward(compile_pool.py:115-123, which already imports from.aotat:104), andaot.pymaintains three additional inlineNamedTemporaryFile+os.replace+unlinkblocks (:270-277,:870-877,:1185-1192).- In the newly edited
_share_artifactsblock (aot.py:870-877),try: ... finally: temporary.unlink(missing_ok=True)is nested insidewith tempfile.NamedTemporaryFile(...) as file:, so iffile.write(payload[0])fails beforefile.close(),unlinkruns while the handle is still open (PermissionErroron Windows, masking the write error). - Fix: Have
compile_pool.py:115-123call_save_compiled_function, and movetry/finallyoutside thewithblock ataot.py:870-877(or extract a single_atomic_write(path, writer)helper inaot.py).
Nits
- Nested composite variant key (
ignition/preparation/collectives.py:212-215): Passing(variant, count)instead of overwritingvariantwithcountkeepsname_keycollision-free if composite plans are ever nested. - Additional targeted test coverage (
tests/preparation/test_host_ranks.py,tests/preparation/test_tuning_shards.py): Add assertions covering peerexport_options(..., kernel_cache=kernel_cache)(host_ranks.py:723-725) andreconcile_selectionsreturningchanged is Falsewhen ranks already agree. - Wire protocol version hygiene (
ignition/preparation/host_ranks.py:41):PROTOCOLremains5despite adding the("b12x-environment", ...)message.source_identity()(source_identity.py:44-49, 95) hashesignition/and rejects mismatched checkouts in_admit(host_ranks.py:292-293), so CLI peers are protected, but bumpingPROTOCOLto6keeps the constant accurate for callers passing a customidentity. - Docs (
docs/multi-host.md:330): Add a short note under "Prepare the core" that rank zero propagatesrecipe.b12x_environmentto peers, each peer uses its own localkernel_cache, andForwardCachere-keys on execution-relevantB12X_*settings.
Dropped on verification
- Correctness F3 (
reconcile_selectionscauses rank 0 withconfigs == {}to re-autotune every job for ~2h15m): Dropped —ignition/preparation/tuning.py:521-535is untouched by this PR (pre-existing from#647/#695); Pass 2 hits warm selection caches for unchanged plans on rank 0 rather than repeating a ~2h15m cold search; andtests/preparation/test_tuning_shards.py:259explicitly expectsautotune=Trueon the reconcile replay. - Correctness F4 & Subtraction S2 (hash
Recipe.b12x_environmentinstead of ambient_b12x_forward_env()/AGENTS.md:452-460violation): Dropped —ForwardCacheis constructed inignition/preparation/capture.py:118-122without aRecipe/Planobject, and_b12x_forward_env()is cache-key hygiene (analogous totorch_key()), not an env-driven behavior toggle prohibited byAGENTS.md:452-460; hashing ambientB12X_*also protects manual CLI/benchmark overrides from silent collisions. - Correctness F5 (reconcile key
(name, variant, component_id)mismatchesagree_selectionsbarename, and unscoped byoperation_ranks): Dropped — includingplan.component_idinname_key(collectives.py:218) is a mandatory safety guard (copying a config across differentTuningContractcomponents is invalid and should fail inagree_selections), and_selected_plan_catalogexplicitly filtersif request.collective is None:(collectives.py:222), preserving DCP collective subgroup independence (tests/preparation/test_dcp_selection_groups.py:45-65). - Subtraction S4 (delete
_remap_peer_config's non-dataclasssetattrfallback athost_ranks.py:216-219): Dropped — recipes live in an external repository (local-inference-lab/hyperflare-recipes,AGENTS.md:224-225), so a 2-line fallback for mutable non-dataclass configs cannot be proven unreachable from this repository alone. - Subtraction Minor (
reconcile_selectionschosen/seen/participants helper closure atcollectives.py:413-427): Dropped — low-signal stylistic preference over 14 clear, readable lines.