Recommendation: Changes Requested
The core fix is technically sound with no blockers: relocate_inductor structurally eliminates the peer-rank KeyError on unreferenced epilogue-fusion candidates, replaces #185's substring check with exact AST identifier and async_compile.triton kernel-name matching, fixes duplicate-key shadowing, and preserves pre-mutation and multi-global registration invariants without affecting cross-rank collective safety. However, the submitted AST implementation has neither a green CI run on head 5f6e6a6 (the branch predates #624's CPU CI fix) nor any GPU execution (tests/preparation/test_inductor_tuning_cuda.py was not run, and the TP4 hardware unblock cited in Claimed Result came from a different uncommitted substring guard on a non-repo commit 99339606), and the frozen same-device reload path adds an avoidable redundant AST walk (_source_kernel_keys) that unconditionally parses and hashes generated modules even when static_autotuners is empty. Addressing the verification/evidence gap and collapsing the redundant AST helper will make this ready to merge.
Merge Risk
Level: Medium
- Broad preparation reach:
relocate_inductor(ignition/preparation/device_binding.py:167-211) runs on every compiled-forward load that relocates (target != original) or freezes winners (aot._load_inductoratignition/preparation/aot.py:58, reached fromStorageBackend.deserialize_compile_artifactsat:545andcompilation._compile_moduleatignition/preparation/compilation.py:302), andInductorSelections.register(ignition/preparation/inductor_tuning.py:135-175) runs once per forward per rank (aot.py:1232, 1377). - Low runtime/concurrency blast radius: No locks, collectives, wire/core formats, or CUDA/Triton kernels are modified;
ForwardCache._prepare_ranks(aot.py:1223-1238) catches per-forward load/register errors and unconditionally entersselections._check(failure), so peer-onlyValueErrorrejections cannot hang multi-rank barriers. - Verification gap drives the Medium rating: Zero CI checks have run on
5f6e6a6and zero GPU tests (includingtests/preparation/test_inductor_tuning_cuda.py:490-536, 553+) have exercised the submitted AST matcher.
Walkthrough
ignition/preparation/device_binding.py:92-130: Adds_referenced_kernel_names(source)(ASTNameidentifiers plusasync_compile.tritonfirst string argument),_source_kernel_keys(source)(CompiledTritonKernels.keyfor eachasync_compile.tritonkernel source), and_filter_static_autotuners(bundle, source, bound_keys)(retains bound keys, lazily resolves referenced names on unbound keys, drops unreferenced entries, and raisesValueError("compiled forward has unbound static Inductor kernels")on referenced unbound entries).ignition/preparation/device_binding.py:182-211: Restructuresrelocate_inductorto validate and filterbundle.static_autotunersbefore_freeze_tuning_winnersand before mutatinggraph.source_code,graph.cache_key,graph.device_idxs, or per-kernel device metadata on both the frozen same-device (not relocate) and cross-device (relocate) paths, eliminating thekernel_keys[entry_kernel.cache_key]KeyErrorat:208.ignition/preparation/inductor_tuning.py:18, 146, 165-175: Replaces#185's substring check (entries[key].kernel_name in graph.source_code) inInductorSelections.registerwith_filter_static_autotuners, buffers(identity, tuner)pairs indiscoveredso validation completes before mutatingself.instancesor calling_install, and preserves multi-global tuners sharing onecache_key.tests/preparation/test_inductor_prepared_winners.py:317-664: Adds 5 CPU unit test functions (9 parametrized cases; 27 total in the file) covering serialized peer-rank unreferenced-candidate pruning viaaot._load_inductor, exact-identifier prefix-collision handling across(0, True), (1, False), (1, True), pre-mutation rejection on(0, True), (2, False), (2, True), aliasedasync_compile.tritonliterals with trailing same-key shadow snapshots, and multi-global shared-key registration.
Pre-merge Checks
- [PASS] Security / malicious screen: No prompt injection, shell execution, credential handling, or unsafe deserialization introduced; PR metadata (
Discord: jcartu, agent-authorship disclosure) is normal process content. - [PASS] Charter & value fit: Fixes a real SM120 TP>1 preparation failure in shared
ignition/preparationwith no new flags, env vars, or model branches, and touches preparation orchestration only (permitted underdocs/design-review.md:124-134). - [PASS] Related / duplicate / conflict check: Additive to
main(completes the TP>1 peer-rank gap left untested by merged#185and fixes#185's substring matcher); nomaincommit since branch point touches the three files, and open PR#597does not modifyinductor_tuning.py:18orregister(only addscuda_device_identityat:21-26and editswarm). - [WARN] Tests & verification evidence: No
.github/workflows/python-cpu.yml(not opened) run exists on5f6e6a6(branch predates#624's CPU CI fix),tests/preparation/test_inductor_tuning_cuda.pywas not run, and the TP4 GPU run cited inClaimed Resultexercised a different uncommitted substring guard on non-repo commit99339606.
Blockers
None.
Should Fix
-
Run verification on the submitted diff and align
Claimed Resultwith what actually ran (docs/design-review.md:106-115, 171-189,tests/preparation/test_inductor_tuning_cuda.py:490-536, 553+):- Rebase onto current
main(which includes#624) so.github/workflows/python-cpu.yml(not opened) executes and passes cleanly on the PR head instead of relying on self-reported local CPU runs with two baseline failures. - Run
tests/preparation/test_inductor_tuning_cuda.pyon this exact submitted diff (at minimumtest_unreferenced_bundled_candidates_are_dropped_and_named_kernels_still_bindat:490-536, and ideally the ≥2-ranktorchruntest at:553+or a TP>1 export check if multi-GPU hardware is available) and report the actual command and result. - Tighten the
Claimed Resultparagraph so it leads with what was verified on this diff and clearly qualifies upfront that the99339606TP4 run validated an earlier substring-guard prototype rather than this submitted AST implementation (instead of leaving that distinction to the later provenance section).
- Rebase onto current
-
Collapse the duplicate AST walk and avoid unconditional parsing/hashing when
static_autotunersis empty (ignition/preparation/device_binding.py:92-130, 182-188):_source_kernel_keys(:105-114) duplicates_referenced_kernel_names'sast.walk(ast.parse(source))(:92-102) and has a single caller at:184. On every frozen same-device load (not relocate+freeze_tuning=True),:184unconditionally parses the entire generated module and computesCompiledTritonKernels.key(...)across all kernels even whenbundle.static_autotunersis empty, and parses the module a second time (:127) if any unbound entry is encountered (onmain, this branch did zero parsing).- Fix: Merge
_referenced_kernel_namesand_source_kernel_keysinto a single helper_source_kernel_refs(source, *, include_keys=False)and makebound_keys=Noneoptional in_filter_static_autotuners:- Return
[]immediately whennot bundle.static_autotuners(skipping AST parsing completely for graphs without static autotuners). - When
bound_keys is None(not relocatebranch at:184), collect bothbound_keysandreferenced_namesin one AST pass (_source_kernel_refs(source, include_keys=True)). - When
bound_keysis already supplied (relocate=Trueat:192andInductorSelections.registeratinductor_tuning.py:168), preserve the lazy fast path — do not parse or hash at all unless an unboundcache_keyis actually encountered, and then call_source_kernel_refs(source, include_keys=False)so common-path loads incur zero extra AST parses or SHA-256 hashes.
- Return
Subtract / Simplify
- Delete the dead assignment at
ignition/preparation/device_binding.py:196:retained = retained_bundle.static_autotunersis a no-op becausereplace(bundle, static_autotuners=retained)aliases the sameretainedlist and_freeze_tuning_winnersmutatesbundle.static_autotuners[:]in place at:164(keepreplace(bundle, static_autotuners=retained)itself sobundle.static_autotunersstays untouched if_freeze_tuning_winnersraises, matchingInductorSelections.freezeatinductor_tuning.py:325). - Factor repeated test scaffolding in
tests/preparation/test_inductor_prepared_winners.py:250-259, 348-356, 430-434, 444-449, 506-511, 564-568, 578-582, 640-654: Extracting two small module-level helpers (_stored_graph(source_code, bundle)and_generated_callable(graph, tuners)) removes ~50 lines of duplicatedCompiledFxGraph.__new__andrunner.__code__ = compile(...)boilerplate while keeping the existing function-local torch imports intact.
Nits
- Include kernel diagnostics in the
ValueError(ignition/preparation/device_binding.py:129): Appendentry_kernel.kernel_nameandentry_kernel.cache_key(while preserving the"compiled forward has unbound static Inductor kernels"prefix matched bytests/preparation/test_inductor_tuning_cuda.py:535andtest_inductor_prepared_winners.py:515, 589, 598) to make multi-rank logs actionable without needing a debugger. - Diagnostic script edge case (
scripts/inspect_forward_kernels.py:85-98): For a corrupt frozen artifact withordinal == 0and a referenced unbound kernel,_load_inductor(:85) now raisesValueErrorbefore thetry:block (:90), aborting a multi-artifact sweep instead of emitting JSON withregistered: false. Wrapping:85-94in the existingtry:block would preserve per-artifact reporting (do not add a drop-only bypass torelocate_inductor). - Remove duplicate comment (
ignition/preparation/inductor_tuning.py:166) and trim PR description inventory (AGENTS.md:116-121, 138-139): Line 166 repeats the rationale already documented atdevice_binding.py:118-119.
Dropped on verification
- Subtraction S2 (
replace()removal / in-placebundle.static_autotuners[:] = ...) & Correctness #4 (bundle identity change): Dropped. S2 misreadInductorSelections.freeze(inductor_tuning.py:325) as mutatingstatic_autotuners[:]in place, when:325actually usesbundle = replace(bundle, static_autotuners=snapshots). Replacing the bundle also avoids mutatingbundle.static_autotunersif_freeze_tuning_winnersraises, andaot._load_inductor(aot.py:58-82) is unaffected by the new bundle wrapper. Only the dead assignment atdevice_binding.py:196survives. - Subtraction S1's draft replacement code: Corrected before adoption. The lens's proposed
_filter_static_autotunerseagerly called_source_references(source)on the first bundle entry even whenbound_keyswas supplied, which would have introduced an extra full-module AST parse and SHA-256 kernel-hashing pass on everyregister()and peer-rankrelocate_inductor()call. - Correctness #5 ("new
ValueErrorpre-emptsregister's message-richTypeError"): Dropped as false.inductor_tuning.py:159-162'sTypeErrorchecks the opposite direction (a module-assigned kernel missing from the bundle or lacking aCachingAutotuner), which_filter_static_autotunersdoes not pre-empt. The check replaced onmain(inductor_tuning.py:170-171) already raised the exact bareValueError("compiled forward has unbound static Inductor kernels"), and peer ranks previously raised bareKeyError. Retained only as an optional diagnostic Nit. - Correctness #2's
drop_only=Truealternative forrelocate_inductor: Dropped. Adding a bypass flag to skip fail-closed validation on frozen reloads violatesAGENTS.md:182-193; only the optionaltry:scope nit inscripts/inspect_forward_kernels.py:85-98survives. - Dossier #5 ("textual import-line conflict with open PR
#597") and#584speculation: Dropped. Checkedignition/preparation/inductor_tuning.pyonpr/597:#597leaves line 18 untouched and insertscuda_device_identityat:21-26;#584is closed. - Dossier's "tests reach into torch privates like
#624repaired" and "missingflare-autobotintake comment": Dropped.test_inductor_prepared_winners.py:227-300already uses those exact torch fixtures,#624fixed unrelated Triton 3.7 text-rewrite andinspect.unwrapbugs, andpr_commentsconfirmsflare-autobotposted its case-file comment. - Value Prop's "file a separate issue for the TP4
KeyError" and Dossier #6 ("cb6187bfGB10 Xid 13 history"): Dropped as process churn / unrelated driver bug (cubin reload in_install).