Repository navigation
Conversation
…ate_inductor
Tensor-parallel preparation aborts with `KeyError` on relocating ranks when a compiled forward's Triton bundle holds a static autotuner that the generated Python module never defines. During multi-rank preparation (`ForwardCache._prepare_ranks` in `ignition/preparation/aot.py`), `self._load` deserializes compiled forwards through `aot._load_inductor` with `frozen` false (the artifact's `_tuning_frozen` before `InductorSelections.freeze`), which invokes `relocate_inductor` (`ignition/preparation/device_binding.py`) before `InductorSelections.freeze` prunes `bundle.static_autotuners`. On the compiler rank (`target == original`) with `freeze_tuning=False`, `relocate_inductor` returns early without inspecting `static_autotuners`, and `InductorSelections.register` (`ignition/preparation/inductor_tuning.py`) ignores unreferenced `static_autotuners` entries left behind by PyTorch Inductor epilogue-fusion benchmarking (`entry.kernel_name` absent from the generated Python module). On peer tensor-parallel ranks (`target != original`) during the unfrozen load, `relocate_inductor` previously assigned `graph.source_code`, `graph.cache_key`, and `graph.device_idxs` before its loop and indexed `kernel_keys[entry_kernel.cache_key]` across every entry in `bundle.static_autotuners`. Because `_device_source` populates `kernel_keys` only from `async_compile.triton` calls present in `graph.source_code`, on an unfrozen peer load a bundled candidate whose cache key was absent from `kernel_keys` raised `KeyError`. Compiler-rank registration accepted the candidate in the TP4 reproduction, but its substring check could reject unused candidates with prefix-colliding names. When `freeze_tuning=True` (`ForwardCache._load` sets it from the `triton.autotune_at_compile_time` option), `_freeze_tuning_winners` also ran before checking bindings on both compiler and peer ranks, so an unresolved unreferenced candidate or referenced unbound kernel could fail winner freezing before missing bindings were diagnosed. In addition, `InductorSelections.register` previously mutated `self.instances` and called `_install` before checking unbound entries, collapsed duplicate unbound `cache_key` snapshots before checking names, and checked `entry.kernel_name in graph.source_code` by substring rather than exact identifier, which false-matches a prefix candidate such as `triton_tem_fused_1` when `triton_tem_fused_10` is bound (reproduced in CPU unit tests).
Dropping unreferenced `static_autotuners` entries during relocation and winner freezing is sound because any entry whose cache key has no `async_compile.triton` definition cannot be launched by the generated module, every launch in generated Inductor code names its kernel via a module-global identifier or `async_compile.triton` call string, and `InductorSelections.freeze` discards unreferenced entries on every rank anyway. This commit aligns unreferenced-candidate handling and pre-mutation validation across `ignition/preparation/device_binding.py` and `ignition/preparation/inductor_tuning.py`:
- Adds `_referenced_kernel_names(source)` (collecting AST `Name` identifiers and `async_compile.triton` string kernel names), `_source_kernel_keys(source)`, and `_filter_static_autotuners(bundle, source, bound_keys)` (deferring AST name collection until an unbound key is encountered) in `device_binding.py`, and uses `_filter_static_autotuners` in both `InductorSelections.register` and `relocate_inductor`.
- Updates `relocate_inductor` so that both `target == original` (when `freeze_tuning=True`) and `target != original` validate and filter `bundle.static_autotuners` before `_freeze_tuning_winners` and before writing `graph` or mutating any `CachingAutotuner`. Entries with `cache_key` in `bound_keys` are retained; entries absent from `bound_keys` raise `ValueError("compiled forward has unbound static Inductor kernels")` when `entry_kernel.kernel_name` is in `_referenced_kernel_names(source)`, and are removed from the bundle without mutating their device metadata or failing winner freezing when unreferenced (matching what `InductorSelections.freeze` produces on every rank).
- Updates `InductorSelections.register` to collect discovered `(identity, tuner)` pairs during AST traversal, validate every `bundle.static_autotuners` entry through `_filter_static_autotuners` before mutating state, and only then register each distinct tuner instance (including multiple globals sharing one `cache_key`), install an existing winner on each newly registered instance, and record `self.forwards`.
- Adds CPU regression tests in `tests/preparation/test_inductor_prepared_winners.py` covering serialized peer-rank unreferenced-candidate pruning, exact-identifier prefix-collision handling across compiler (`target == original, freeze_tuning=True`) and peer (`target != original, freeze_tuning in [False, True]`) ranks, pre-mutation `ValueError` rejection in `relocate_inductor` (across both compiler and peer ranks) and `InductorSelections.register`, aliased `async_compile.triton` literal kernel names with a trailing same-key unused snapshot, and multi-global shared-key tuner preservation.
On `0a8c20f4` CPU fixtures, `relocate_inductor` removes unreferenced epilogue candidates (including unresolved candidates under `freeze_tuning=True` on both compiler and peer ranks), `InductorSelections.register` ignores unreferenced candidates while preserving distinct tuners sharing a source key, and both fail closed with `ValueError` on referenced unbound kernels (including when shadowed by a later unused snapshot with the same key) without mutating `graph`, `self.instances`, or sibling autotuners. Separately, on 4x RTX PRO 6000 Blackwell (`sm_120`, TP4) using a locally patched checkout of `Flare v0.4.4` (`99339606`), skipping unreferenced `static_autotuners` entries in `relocate_inductor` unblocked `qwen38` TP4 preparation through native core export and `flare run` health startup across all four ranks; with both production files restored to `0a8c20f4` and the new tests retained, the serialized peer-load test raised `KeyError`. This changes Python preparation orchestration and its CPU tests only: `InductorSelections.register` on every rank and in single-device `ForwardCache._warm`, and `relocate_inductor` on every compiled-forward load that relocates (`target != original`) or freezes winners (a frozen artifact or `triton.autotune_at_compile_time`). It does not modify CUDA, PTX, CuTe DSL, Triton kernels, fusion, stream overlap, prepared core formats, or runtime ABIs.
Validation and limitations:
- Targeted CPU unit tests (`Python 3.12`, `torch==2.14.1+cu132`, `triton==3.8.0` on `0a8c20f4`): `CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparation/test_inductor_prepared_winners.py tests/preparation/test_aot_guards.py tests/preparation/test_inductor_workspace_lifetimes.py` passed (`32 passed` in `4.63s`; `27 passed` in `test_inductor_prepared_winners.py`, adding 9 test cases across 5 functions: `test_load_inductor_relocation_drops_unreferenced_epilogue_candidates`, `test_relocate_inductor_skips_prefix_colliding_unreferenced_candidate_in_memory[(0, True), (1, False), (1, True)]`, `test_relocate_inductor_rejects_referenced_unbound_kernel_without_partial_mutation[(0, True), (2, False), (2, True)]`, `test_register_and_relocate_reject_aliased_triton_literal_without_partial_mutation`, and `test_register_preserves_distinct_tuners_sharing_source_key`).
- Full `tests/preparation` CPU suite (`CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparation` in the same `0a8c20f4` environment): unmodified `0a8c20f4` reported `1,148 passed, 74 skipped, 2 failed`, and this change reported `1,157 passed, 74 skipped, 2 failed` (`+9` added cases). Both runs hit the same two unrelated failures (`test_inductor_template_mutations.py::test_external_bmm_replacement_retains_input_mutation_dependency[clean]` did not raise `InductorError`, and `test_runtime_triton.py::test_replaces_clean_architecture_probe_and_preserves_patched_key` saw `platform.architecture()` omit `'ELF'` under `uv`-managed Python); neither test touches `device_binding.py` or `inductor_tuning.py`.
- Revert check: reverting `ignition/preparation/device_binding.py` and `ignition/preparation/inductor_tuning.py` causes all 8 behavior-change test cases in `test_inductor_prepared_winners.py` to fail (`8 failed, 19 passed` in `2.69s`: `KeyError` on the serialized drop test, false-positive `ValueError` in `register` on all three prefix-collision cases, `KeyError` on peer `freeze_tuning=False` rejection, premature `pending coordinate-descent tuning` failure before binding validation on both `(0, True)` and `(2, True)` rejection cases, and `DID NOT RAISE ValueError` on `register` when the trailing unused same-key snapshot shadowed `'kernel_x'`; `test_register_preserves_distinct_tuners_sharing_source_key` passes with and without the source change, confirming preservation of existing multi-global registration). All `27` tests in `test_inductor_prepared_winners.py` pass with the change.
- Hardware reproduction provenance (`4x RTX PRO 6000 Blackwell`, `sm_120`, TP4, `Flare v0.4.4` `99339606`, `local-inference-lab/Qwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QAD` `dc5b8ab2` with the `qwen38` recipe): on unmodified `99339606`, `qwen38` TP4 preparation failed during `Load and warm compiled forwards` with no error on rank `0` and `KeyError` inside `relocate_inductor` on ranks `1..3` for the forward named `speculative16x5`. On a locally patched checkout of `99339606` with an uncommitted guard in `relocate_inductor` that skipped `static_autotuners` entries absent from `kernel_keys` when `entry.kernel_name` was not a substring of `graph.source_code`, `qwen38` TP4 preparation completed `Load and warm compiled forwards`, CUDA graph capture, native core export, and `flare run` health startup across all four ranks. The TP4 run exercised the substring guard. CPU tests exercised the submitted AST matcher against prefix collisions and aliased kernel names, aligned `InductorSelections.register`, and validated before freezing or mutation on `0a8c20f4`.
- Limitations: no GPU preparation was run on `0a8c20f4` with this exact submitted diff, and standalone CUDA unit tests (`tests/preparation/*_cuda.py`) were not run, including on the 4x RTX PRO 6000 host.
Design-Signed-Off-By: Gemini 4 Neon; design-review=2e5b
Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
Collaborator
|
A case file has been opened for 642. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Collaborator
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe relocation fix is structurally sound and has no blockers, but the submitted AST implementation has no green CI on head
Walkthrough
Merge Risk: Medium · up to
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tensor-parallel preparation aborts with
KeyErroron relocating ranks when a compiled forward's Triton bundle holds a static autotuner that the generated Python module never defines. During multi-rank preparation (ForwardCache._prepare_ranksinignition/preparation/aot.py),self._loaddeserializes compiled forwards throughaot._load_inductorwithfrozenfalse (the artifact's_tuning_frozenbeforeInductorSelections.freeze), which invokesrelocate_inductor(ignition/preparation/device_binding.py) beforeInductorSelections.freezeprunesbundle.static_autotuners. On the compiler rank (target == original) withfreeze_tuning=False,relocate_inductorreturns early without inspectingstatic_autotuners, andInductorSelections.register(ignition/preparation/inductor_tuning.py) ignores unreferencedstatic_autotunersentries left behind by PyTorch Inductor epilogue-fusion benchmarking (entry.kernel_nameabsent from the generated Python module). On peer tensor-parallel ranks (target != original) during the unfrozen load,relocate_inductorpreviously assignedgraph.source_code,graph.cache_key, andgraph.device_idxsbefore its loop and indexedkernel_keys[entry_kernel.cache_key]across every entry inbundle.static_autotuners. Because_device_sourcepopulateskernel_keysonly fromasync_compile.tritoncalls present ingraph.source_code, on an unfrozen peer load a bundled candidate whose cache key was absent fromkernel_keysraisedKeyError. Compiler-rank registration accepted the candidate in the TP4 reproduction, but its substring check could reject unused candidates with prefix-colliding names. Whenfreeze_tuning=True(ForwardCache._loadsets it from thetriton.autotune_at_compile_timeoption),_freeze_tuning_winnersalso ran before checking bindings on both compiler and peer ranks, so an unresolved unreferenced candidate or referenced unbound kernel could fail winner freezing before missing bindings were diagnosed. In addition,InductorSelections.registerpreviously mutatedself.instancesand called_installbefore checking unbound entries, collapsed duplicate unboundcache_keysnapshots before checking names, and checkedentry.kernel_name in graph.source_codeby substring rather than exact identifier, which false-matches a prefix candidate such astriton_tem_fused_1whentriton_tem_fused_10is bound (reproduced in CPU unit tests).Dropping unreferenced
static_autotunersentries during relocation and winner freezing is sound because any entry whose cache key has noasync_compile.tritondefinition cannot be launched by the generated module, every launch in generated Inductor code names its kernel via a module-global identifier orasync_compile.tritoncall string, andInductorSelections.freezediscards unreferenced entries on every rank anyway.What Changed
ignition/preparation/device_binding.py&ignition/preparation/inductor_tuning.py: Adds_referenced_kernel_names(source)(collecting ASTNameidentifiers andasync_compile.tritonstring kernel names),_source_kernel_keys(source), and_filter_static_autotuners(bundle, source, bound_keys)(deferring AST name collection until an unbound key is encountered), and uses_filter_static_autotunersin bothInductorSelections.registerandrelocate_inductor. Updatesrelocate_inductorso that bothtarget == original(whenfreeze_tuning=True) andtarget != originalvalidate and filterbundle.static_autotunersbefore_freeze_tuning_winnersand before writinggraphor mutating anyCachingAutotuner. Entries withcache_keyinbound_keysare retained; entries absent frombound_keysraiseValueError("compiled forward has unbound static Inductor kernels")whenentry_kernel.kernel_nameis in_referenced_kernel_names(source), and are removed from the bundle without mutating their device metadata or failing winner freezing when unreferenced (matching whatInductorSelections.freezeproduces on every rank). UpdatesInductorSelections.registerto collect discovered(identity, tuner)pairs during AST traversal, validate everybundle.static_autotunersentry through_filter_static_autotunersbefore mutating state, and only then register each distinct tuner instance (including multiple globals sharing onecache_key), install an existing winner on each newly registered instance, and recordself.forwards.tests/preparation/test_inductor_prepared_winners.py: Adds CPU regression tests covering serialized peer-rank unreferenced-candidate pruning, exact-identifier prefix-collision handling across compiler (target == original, freeze_tuning=True) and peer (target != original, freeze_tuning in [False, True]) ranks, pre-mutationValueErrorrejection inrelocate_inductor(across both compiler and peer ranks) andInductorSelections.register, aliasedasync_compile.tritonliteral kernel names with a trailing same-key unused snapshot, and multi-global shared-key tuner preservation.Claimed Result
On
0a8c20f4CPU fixtures,relocate_inductorremoves unreferenced epilogue candidates (including unresolved candidates underfreeze_tuning=Trueon both compiler and peer ranks),InductorSelections.registerignores unreferenced candidates while preserving distinct tuners sharing a source key, and both fail closed withValueErroron referenced unbound kernels (including when shadowed by a later unused snapshot with the same key) without mutatinggraph,self.instances, or sibling autotuners. Separately, on 4x RTX PRO 6000 Blackwell (sm_120, TP4) using a locally patched checkout ofFlare v0.4.4(99339606), skipping unreferencedstatic_autotunersentries inrelocate_inductorunblockedqwen38TP4 preparation through native core export andflare runhealth startup across all four ranks; with both production files restored to0a8c20f4and the new tests retained, the serialized peer-load test raisedKeyError. This changes Python preparation orchestration and its CPU tests only:InductorSelections.registeron every rank and in single-deviceForwardCache._warm, andrelocate_inductoron every compiled-forward load that relocates (target != original) or freezes winners (a frozen artifact ortriton.autotune_at_compile_time). It does not modify CUDA, PTX, CuTe DSL, Triton kernels, fusion, stream overlap, prepared core formats, or runtime ABIs.Supporting Evidence and Limitations
Python 3.12,torch==2.14.1+cu132,triton==3.8.0on0a8c20f4):CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q \ tests/preparation/test_inductor_prepared_winners.py \ tests/preparation/test_aot_guards.py \ tests/preparation/test_inductor_workspace_lifetimes.py32 passedin4.63s(27 passedintest_inductor_prepared_winners.py, adding 9 test cases across 5 functions:test_load_inductor_relocation_drops_unreferenced_epilogue_candidates,test_relocate_inductor_skips_prefix_colliding_unreferenced_candidate_in_memory[(0, True), (1, False), (1, True)],test_relocate_inductor_rejects_referenced_unbound_kernel_without_partial_mutation[(0, True), (2, False), (2, True)],test_register_and_relocate_reject_aliased_triton_literal_without_partial_mutation, andtest_register_preserves_distinct_tuners_sharing_source_key).tests/preparationCPU suite (CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparationin the same0a8c20f4environment): Unmodified0a8c20f4yielded1,148 passed, 74 skipped, 2 failed; this change yielded1,157 passed, 74 skipped, 2 failed(+9added cases). Both runs hit the same two unrelated failures (test_inductor_template_mutations.py::test_external_bmm_replacement_retains_input_mutation_dependency[clean]did not raiseInductorError, andtest_runtime_triton.py::test_replaces_clean_architecture_probe_and_preserves_patched_keysawplatform.architecture()omit'ELF'underuv-managed Python); neither test touchesdevice_binding.pyorinductor_tuning.py.ignition/preparation/device_binding.pyandignition/preparation/inductor_tuning.pycauses all 8 behavior-change test cases intest_inductor_prepared_winners.pyto fail (8 failed, 19 passedin2.69s:KeyErroron the serialized drop test, false-positiveValueErrorinregisteron all three prefix-collision cases,KeyErroron peerfreeze_tuning=Falserejection, prematurepending coordinate-descent tuningfailure before binding validation on both(0, True)and(2, True)rejection cases, andDID NOT RAISE ValueErroronregisterwhen the trailing unused same-key snapshot shadowed'kernel_x';test_register_preserves_distinct_tuners_sharing_source_keypasses with and without the source change, confirming preservation of existing multi-global registration). All27tests intest_inductor_prepared_winners.pypass with the change.4x RTX PRO 6000 Blackwell,sm_120, TP4,Flare v0.4.499339606,local-inference-lab/Qwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QADdc5b8ab2with theqwen38recipe): On unmodified99339606,qwen38TP4 preparation failed duringLoad and warm compiled forwardswith no error on rank0andKeyErrorinsiderelocate_inductoron ranks1..3for the forward namedspeculative16x5. On a locally patched checkout of99339606with an uncommitted guard inrelocate_inductorthat skippedstatic_autotunersentries absent fromkernel_keyswhenentry.kernel_namewas not a substring ofgraph.source_code,qwen38TP4 preparation completedLoad and warm compiled forwards, CUDA graph capture, native core export, andflare runhealth startup across all four ranks. The TP4 run exercised the substring guard. CPU tests exercised the submitted AST matcher against prefix collisions and aliased kernel names, alignedInductorSelections.register, and validated before freezing or mutation on0a8c20f4.0a8c20f4with this exact submitted diff, and standalone CUDA unit tests (tests/preparation/*_cuda.py) were not run, including on the 4x RTX PRO 6000 host.Authored by Gemini 4 Carbon and Gemini 4 Neon (
docs/design-review.mdprinciple 14).Discord: jcartu