Repository navigation
fix(ignition): reconcile divergent multi-host selections, propagate peer b12x env and kernel cache, and harden ForwardCache - #668
Conversation
|
A case file has been opened for 668. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedPR #668 cleanly fixes three real multi-host prep defects—request-name-first selection reconciliation, peer
Walkthrough
Merge Risk: Medium · up to
|
|
Strong +1 from hardware testing on 2× GB10 (SM121) multi-host TP2 with
Both fixes in this PR match the exact root causes we independently diagnosed and verified on SM121 TP2 hardware. |
|
Confirming the same multi-host One small import-order detail noticed while reviewing
For |
d4d7b2d to
d6a0069
Compare
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedPR #668 cleanly fixes three real multi-host preparation defects (request-name-first reconciliation, peer
Walkthrough
Merge Risk: Medium · up to
|
…eer b12x env and kernel cache, and harden ForwardCache Multi-host preparation (`ignition export --ranks N` paired with `ignition join`, and multi-host `ignition debug-serve --ranks N`) exhibited three related cache and coordination defects: 1. Multi-host autotune non-convergence (#651): `agree_selections` (`ignition/preparation/collectives.py`) checks kernel agreement by `request.name`, whereas `reconcile_selections` keyed entries solely by `portable_declaration(plan)` and ignored any declaration with `participants <= 1`. Whenever rank-local state caused a request's portable declaration to differ across ranks, `reconcile_selections` left both ranks' selections untouched and `agree_selections` failed again on every retry. 2. Missing `Recipe.b12x_environment` and leaked `config.kernel_cache` on peer hosts: Rank zero applies `plan.recipe.b12x_environment` before importing preparation libraries (`ignition/cli/serve.py`), whereas `HostRendezvous` (`ignition/preparation/host_ranks.py`) did not transmit those settings and `join()` called `environment.apply()` before connecting to rank zero (importing `b12x.preparation` via `runtime_patches.apply()` before any peer command arrived). Peers also passed rank zero's pickled `config.kernel_cache` directly into `prepare(...)` and did not pass their local `kernel_cache` into peer `export_options(...)`. 3. `ForwardCache` environment omission, non-atomic `.bin` persistence, and corrupt-archive crashes: `ForwardCache.__init__` (`ignition/preparation/aot.py`) omitted execution-relevant `B12X_*` variables from its SHA-256 root key, allowing compiled forwards prepared under differing b12x kernel flags to collide. Three `.bin` save sites wrote directly via `save_compiled_function(str(path))` without atomic replacement, inline temporary-file writes unlinked sibling temps while file handles were still open, and `ForwardCache._load(..., required=False)` raised on truncated or corrupt cached `.bin` files instead of recovering as a cache miss. What changed: - Request-name-first selection reconciliation (`ignition/preparation/collectives.py`): - Before: `_selected_plan_catalog` discarded request names and `reconcile_selections` reconciled only shared `portable_declaration(plan)` entries. - After: `_selected_plan_catalog` retains `(request.name, variant, plan.component_id)` (using a flat tuple variant path for nested composite plans) alongside `portable_declaration(plan)` for non-collective requests. `reconcile_selections` matches shared request names first before falling back to shared portable declarations, using one `target_for` resolver for both `changed` and `configs` so all ranks enter or skip the reconcile pass in lockstep while preserving `component_id` safety. - Peer `b12x_environment` admission propagation and local `kernel_cache` remapping (`ignition/preparation/host_ranks.py`, `ignition/cli/serve.py`, `docs/multi-host.md`): - Before: `HostRendezvous` (protocol 5) sent no `b12x_environment`, `join()` ran `environment.apply()` before `knock()`, and `serve_peer` forwarded rank zero's `config.kernel_cache` unmodified and omitted `kernel_cache` from peer `export_options`. - After: `HostRendezvous` (protocol 6) accepts and validates `b12x_environment` (non-cache `B12X_*` string bindings, wired from `model.recipe.b12x_environment` in `_export_hosts` and `debug_serve`) and sends it in the `_admit` JSON reply. `knock()` validates and returns `(control, executor, b12x_environment)`, closing `control` on error. `join()` calls `source_identity()` and `knock()` before `environment.apply(configuration, (gpu,), b12x_environment)` so `b12x` and `b12x.preparation` see rank zero's recipe settings before import, and passes the peer's local `kernel_cache` to `serve_peer`. `serve_peer` remaps `config.kernel_cache` to `Path(kernel_cache)` and passes `kernel_cache` into peer `export_options(...)`. Documented this behavior in `docs/multi-host.md`. - `ForwardCache` keying, atomic persistence, and corrupt-archive recovery (`ignition/preparation/aot.py`, `ignition/preparation/compile_pool.py`): - Before: `ForwardCache.__init__` omitted `B12X_*` settings, three `ForwardCache` save sites wrote `.bin` directly, `compile_pool.py` duplicated the sibling-temp save helper, three inline atomic-write blocks in `aot.py` unlinked temp files inside the open `with` block, and `_load(..., required=False)` raised on corrupt `.bin` archives. - After: `ForwardCache.__init__` hashes sorted execution-relevant `B12X_*` bindings (`_b12x_forward_env()`, excluding host-local cache directories, worker counts, RDMA device selectors, and logging flags). Added `_atomic_write_file` (closing handles before rename or cleanup) for guard cache, artifact sharing, and lent-job writes, and shared `_save_compiled_function` across `aot.py` and `compile_pool._compile_forward`. Updated `_load(..., required=False)` to open the file outside archive error handling (treating `FileNotFoundError` as a miss), catch only genuine deserialization/archive errors (`EOFError`, `pickle.UnpicklingError`, `struct.error`, `zlib.error`, `zipfile.BadZipFile`) after closing the file handle, emit a `RuntimeWarning` naming the path and error, guard `unlink` against `OSError`, and propagate `OSError`, `MemoryError`, `torch.OutOfMemoryError`, `RuntimeError`, and `ValueError` without deleting the cached `.bin`. - Tests (`tests/preparation/test_tuning_shards.py`, `tests/preparation/test_host_ranks.py`, `tests/preparation/test_forward_cache_sources.py`, `tests/preparation/test_forward_artifact_sharing.py`): Added 2-rank Gloo reconciliation tests (divergent declarations, aliased declarations, converged `changed is False`, and `agree_selections`), rendezvous admission and `join()` import-order/socket-cleanup tests, `serve_peer` `kernel_cache` remapping and peer `export_options` tests, `ForwardCache` `B12X_*` keying, atomic-write closed-handle cleanup, and corrupt-vs-non-archive `_load` fault tests, and payload writes in `_Artifact.save_compiled_function`. Expected result: Multi-host peer ranks receive rank zero's `recipe.b12x_environment` before importing `torch`/`b12x` and store compiled forwards under their own host-local `kernel_cache`, `reconcile_selections` converges rank-divergent declarations for shared request names before `agree_selections` (Related: #651), and `ForwardCache` partitions compiled forwards by execution-relevant `B12X_*` flags (causing a one-time recompile for recipes that declare `b12x_environment`), writes cache files atomically with closed-handle cleanup, and warns and recovers on corrupt `.bin` archives without discarding valid entries on transient I/O, OOM, CUDA, or contract errors. Validation and limitations (rebased onto `origin/main` `cb191a93`, run against editable FlashInfer `5c41b6ebd` in `/home/luke/projects/flare/.venv`): - Targeted preparation and CLI CPU suites (325 tests across `test_host_ranks.py`, `test_forward_cache_sources.py`, `test_forward_artifact_sharing.py`, `test_forward_compile_options.py`, `test_compile_pool.py`, `test_tuning_shards.py`, `test_tuning_replicas.py`, `test_checkpoint_source.py`, `test_dcp_selection_groups.py`, `test_core_boundary.py`, and `tests/cli/`): 325 passed, 0 failed. - Full CPU suite (`CUDA_VISIBLE_DEVICES="" pytest tests/ -q`): 2515 passed, 458 skipped, 3 failed due to local shared-venv environment mismatches unrelated to this diff (`test_source_identity.py` comparing `flare_heliopause` built against an older checkout's `helios/src`, `test_runtime_triton.py` against a pre-patched Triton install, and `test_inspect_forward_kernels.py` hitting a dangling `/home/luke/.cache/flare/kernels` host symlink; rerunning `test_inspect_forward_kernels.py` with a writable `HOME` passed 1/1). All 15 tests in `tests/preparation/test_native_processes.py` passed, plus 100/100 standalone `[orphan]` iterations. - Single-GPU CUDA tests on RTX PRO 6000 Blackwell SM120 (`FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0` across `test_inductor_tuning_cuda.py`, `test_capture_order_cuda.py`, `test_scratch_cuda.py`, `test_graph_local_scratch_cuda.py`, `test_recorded_export_graph_cuda.py`, `test_capture_cublas_workspace_cuda.py`): 18 passed, 5 skipped (`torchrun`-gated TP2 cases), 0 failed. - TP2 distributed CUDA tests on 2x RTX PRO 6000 Blackwell SM120 (`FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 -m pytest tests/preparation/test_inductor_tuning_cuda.py -k "tp2 or distributed"`): 5 passed, 0 failed. - Not run: Rust crate tests (no Rust files modified), live 2-host GB10 SM121 TP2 `ignition export` + `ignition join` of GLM-5.3, and paired `local-inference-lab/flashinfer#199` (tested against local FlashInfer `5c41b6ebd`). End-to-end live 2x GB10 convergence for #651 remains to be confirmed on hardware. Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b Signed-off-by: Luke Alonso <lalonso@gmail.com>
d6a0069 to
e09529b
Compare
|
Rebased onto
@flare-autobot please re-review. |
Why
Multi-host preparation (
ignition export --ranks Npaired withignition join, and multi-hostignition debug-serve --ranks N) fails or risks cache corruption across three coupled paths:agree_selections(ignition/preparation/collectives.py) checks kernel agreement byrequest.name, whereasreconcile_selectionskeyed entries solely byportable_declaration(plan)and skipped any declaration withparticipants <= 1. Whenever rank-local state caused a request's declaration to differ between ranks,reconcile_selectionsleft both ranks' selections untouched andagree_selectionsfailed again on every retry.Recipe.b12x_environmentand leakedconfig.kernel_cacheon peer hosts: Rank zero appliesplan.recipe.b12x_environment(for exampleB12X_W4A16_A4_PREFILL=1on GLM-5.3 andB12X_W4A16_SMALL_M_HOST_BARRIER_RESET=0on Kimi) viaenvironment.applybefore importingtorch,triton, orb12x(ignition/cli/serve.py). On peers,HostRendezvous(ignition/preparation/host_ranks.py) did not transmitb12x_environment, andjoin()calledenvironment.applybeforeknock()(which invokedruntime_patches.apply()and importedb12x.preparationbefore connecting to rank zero).serve_peeralso passed rank zero's pickledconfig.kernel_cacheunmodified intoprepare(...)and did not forward the peer's localkernel_cacheinto peerexport_options(...).ForwardCacheenvironment omission, non-atomic.binpersistence, and corrupt-archive crashes:ForwardCache.__init__(ignition/preparation/aot.py) omitted execution-relevantB12X_*environment variables from its SHA-256 cache root key, allowing compiled forwards prepared under different b12x kernel flags to collide. ThreeForwardCachesave sites wrote.binarchives directly withsave_compiled_function(str(path))without atomic rename, three inline temp-file writers unlinked sibling temp files while handles were still open, andForwardCache._load(..., required=False)raised instead of recovering as a cache miss when loading a truncated or corrupt.binarchive.This PR pairs with
local-inference-lab/flashinfer#199, which bumps collided b12xcandidate_contract_versioncounters, adds deterministic AST/source fingerprinting toTuningContract, gates unusedsplit_fc1_scales/shared_input_scalesflags inMoeDecodeQuery, and landsflashinfer#67. Neither PR requires the other to merge first.What changed
ignition/preparation/collectives.py):_selected_plan_catalogdiscarded request names andreconcile_selectionsreconciled only entries whoseportable_declaration(plan)appeared on more than one rank._selected_plan_catalogrecords(request.name, variant, plan.component_id)(using a flat tuple variant path(*variant, count)for nested composite plans) alongsideportable_declaration(plan)for non-collective requests (request.collective is None).reconcile_selectionsmatches shared request names across ranks first so rank-divergent declarations for the same request adopt rank zero's selected configuration beforeagree_selections, and falls back toportable_declarationmatching for shared declarations whose request names differ across ranks. Bothchangedand localconfigsuse onetarget_forresolver so all ranks enter or skip the reconcile pass in lockstep while preservingcomponent_idsafety.b12x_environmentadmission propagation and localkernel_cacheremapping (ignition/preparation/host_ranks.py,ignition/cli/serve.py,docs/multi-host.md):HostRendezvous(PROTOCOL = 5) sent nob12x_environment,join()ranenvironment.apply(configuration, (gpu,))beforeknock(), andserve_peerforwarded rank zero'sconfig.kernel_cacheunmodified and omittedkernel_cachefrom peerexport_options.HostRendezvous(PROTOCOL = 6) accepts and validatesb12x_environment(rejecting non-B12X_keys,B12X_COMPILE_CACHE_DIR, and non-string values; wired frommodel.recipe.b12x_environmentin_export_hostsanddebug_serve) and sends it in the_admitJSON reply.knock()validates and returns(control, executor, b12x_environment), closingcontrolon failure.join()callssource_identity()andknock()beforeenvironment.apply(configuration, (gpu,), b12x_environment)(closing both sockets on error) sob12xandb12x.preparationsee rank zero's recipe settings before import, and passes the peer's localkernel_cachetoserve_peer.serve_peerremapsconfig.kernel_cachetoPath(kernel_cache)and passeskernel_cacheinto peerexport_options(...). Documented this behavior under "Prepare the core" indocs/multi-host.md.ForwardCachekeying, atomic persistence, and corrupt-archive recovery (ignition/preparation/aot.py,ignition/preparation/compile_pool.py):ForwardCache.__init__hashed(namespace, options, torch_key(), runtime_patches.identity(), device_properties), threeForwardCache.binsave sites wrote directly without atomic rename,compile_pool._compile_forwardduplicated the sibling-temp save helper, three inline temp-file writers inaot.pyunlinked temp files inside openwithblocks, and_load(..., required=False)failed on corrupt.binarchives during restore.ForwardCache.__init__includes sorted execution-relevantB12X_*bindings (_b12x_forward_env(), excluding host-local cache directories, worker counts, RDMA device selectors, and logging flags so distinct hosts keep identical relative cache roots). Extracted_atomic_write_file(path, writer)(closing file handles before rename or temp cleanup) for guard cache,_share_artifacts, and lent-job writes, and shared_save_compiled_function(artifact, path)across all threeForwardCachesave sites andcompile_pool._compile_forward. UpdatedForwardCache._load(..., required=False)to open the file outside archive error handling (treatingFileNotFoundErroras a miss), close the handle before unlinking, catch only genuine archive/deserialization faults (EOFError,pickle.UnpicklingError,struct.error,zlib.error,zipfile.BadZipFile), emit aRuntimeWarningnaming the path and error, guardunlink(missing_ok=True)againstOSError, and propagateOSError,MemoryError,torch.OutOfMemoryError,RuntimeError, andValueErrorwithout deleting the cached.bin.PROTOCOLfrom5to6keeps the wire-version constant aligned with the_admitreply schema (mismatched checkouts are also rejected bysource_identity()). Hashing_b12x_forward_env()intoForwardCache.roottriggers a one-time forward recompile for recipes that declareb12x_environment(such as GLM-5.3 and Kimi). No Helios runtime, Protobuf schema, or exported model-core format changes.tests/preparation/):test_tuning_shards.py: 2-rank Gloo test coveringreconcile_selectionsacross rank-divergent declarations sharingrequest.name, differing request names sharingportable_declaration, fixed-pointchanged is Falseonce aligned, andagree_selectionspassing.test_host_ranks.py:HostRendezvous->knockloopback admission validation/rejection tests,serve.join()ordering and socket-cleanup tests, a clean-subprocess check verifyingtorch/b12x/flashinferare not imported beforeenvironment.apply, andserve_peertests coveringconfig.kernel_cacheremapping and peerexport_options(..., remote_cache=True, kernel_cache=peer_cache)without mutating process-globalos.environ.test_forward_cache_sources.py:B12X_*keying inclusion/exclusion tests,_save_compiled_functionand_atomic_write_fileclosed-handle-before-cleanup atomic write tests, and_loadcoverage forFileNotFoundError, corrupt-archiveRuntimeWarning+ unlink, read-onlyunlinkPermissionError,required=Truepropagation, and non-archive error propagation (torch.OutOfMemoryError,MemoryError,ENOSPCOSError,RuntimeError,ValueError, and openPermissionError).test_forward_artifact_sharing.py: updated_Artifact.save_compiled_functiontest double to write its loaded payload bytes.Expected result
recipe.b12x_environmentbefore importing preparation libraries (torch,triton,b12x) and store compiled forwards under their own host-localkernel_cache.request.name,reconcile_selectionsconverges peers to rank zero's selection beforeagree_selections.ForwardCacheisolates compiled forwards across differing execution-relevantB12X_*settings (with a one-time recompile for recipes declaringb12x_environment), writes cache files atomically with closed-handle cleanup, and warns and recovers from corrupt.binarchives without deleting valid entries on transient I/O, OOM, CUDA, or contract faults.Validation and limitations
Rebased onto
origin/main(cb191a93) and validated using/home/luke/projects/flare/.venv/bin/python(editable FlashInfer5c41b6ebd) withPYTHONPATH=.from the worktree root:CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_host_ranks.py tests/preparation/test_forward_cache_sources.py tests/preparation/test_forward_artifact_sharing.py tests/preparation/test_forward_compile_options.py tests/preparation/test_compile_pool.py tests/preparation/test_tuning_shards.py tests/preparation/test_tuning_replicas.py tests/preparation/test_checkpoint_source.py tests/preparation/test_dcp_selection_groups.py tests/preparation/test_core_boundary.py tests/cli/ -v): 325 passed, 0 failed (58.0 s).CUDA_VISIBLE_DEVICES="" pytest tests/ -q): 2515 passed, 458 skipped, 3 failed (4m48s). All 15 tests intests/preparation/test_native_processes.pypassed (plus 100/100 standalone[orphan]iterations). The 3 local failures stem from running against the shared/home/luke/projects/flare/.venvenvironment rather than this diff:test_source_identity.py::test_heliopause_build_source_identity_matches_workspace_sources:flare_heliopausein the shared venv was compiled against an older checkout'shelios/src.test_runtime_triton.py::test_replaces_stock_architecture_probe_with_pointer_width_key: the shared venv's Triton install already returns the patchedplatform_key.test_inspect_forward_kernels.py::test_inspect_forward_kernels_reads_saved_aot_artifact: host symlink/home/luke/.cache/flare/kernels -> /data/cache/flare/kernels-defaultlacks its target; rerunning with a writableHOMEpassed (1 passed in 6.3 s).FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0, RTX PRO 6000 Blackwell, acrosstest_inductor_tuning_cuda.py,test_capture_order_cuda.py,test_scratch_cuda.py,test_graph_local_scratch_cuda.py,test_recorded_export_graph_cuda.py,test_capture_cublas_workspace_cuda.py): 18 passed, 5 skipped (torchrun-gated TP2 cases), 0 failed (105.0 s).FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 -m pytest tests/preparation/test_inductor_tuning_cuda.py -k "tp2 or distributed" -v): 5 passed, 0 failed (50.5 s).ignition export+ignition joinof GLM-5.3, and pairedlocal-inference-lab/flashinfer#199. End-to-end resolution of Multi-host default autotune still fails kernel agreement after #631 was marked as completed #651 on live 2× GB10 hardware remains to be confirmed on that hardware.Related: #651
Paired FlashInfer PR: local-inference-lab/flashinfer#199
Discord: lukealonso