Repository navigation
Inductor readback barrier: key the compile cache when a user pass is already set - #15208
Conversation
The barrier marker entered the FX / AOTAutograd cache key only when post_grad_custom_post_pass was None. With a user CustomGraphPass set before Unsloth, the key stayed the user pass uuid alone, so a warm cache written without the barrier was still served on torch < 2.14. The user pass is now wrapped: its uuid carries the marker and the user uuid, and it still runs (is_inference is forwarded for inference aware passes). A list of passes gets the marker appended; raw callables and uuid-less passes are left as is since torch bypasses the cache for them.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…areGraphPass (torch < 2.12) [skip ci]
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow up to #15000.
Problem
fix_inductor_reduction_readback_race(torch < 2.14) adds atl.debug_barrier()before a reduction kernel reloads a buffer it stored in an earlier loop. So that warm FX / AOTAutograd caches do not keep serving barrier-free kernels, it sets a no-opCustomGraphPasswhose uuid enters the cache key.That marker was only installed when
torch._inductor.config.post_grad_custom_post_passwasNone. If a user (or another library) had already set aCustomGraphPass, the key stayed that pass's uuid alone. A cache written before the fix was then still a hit, and the racy kernels came back.Fix
_key_inductor_caches_on_readback_barriernow handles the existing pass:CustomGraphPasswith a uuid is wrapped. The wrapper's uuid is(barrier marker, user uuid), so the key changes. Calling it calls the user pass. ACustomInferenceAwareGraphPassis wrapped by an inference aware subclass, sois_inferencestill reaches it.Tests
tests/test_inductor_readback_barrier.py, CPU:test_a_user_custom_graph_pass_keys_the_cache_on_the_barrier_too: the wrapped uuid carries both ids, the user pass still runs, and a second run does not re-wrap.test_an_inference_aware_user_pass_still_gets_is_inferencetest_a_list_of_user_passes_gets_the_marker_appendedtest_a_raw_callable_user_pass_is_left_alonetest_a_warm_cache_from_before_the_fix_is_not_served_with_a_user_pass: end to end with the Inductor CPU backend. A process without the fix warms the cache. A second process without the fix hits it, which shows the key is otherwise stable. A process with the fix misses.Results:
fxgraph_cache_hit == 1.GPU, Colab L4
Each row is a separate process. The kernel is a fused add plus layer norm reduction that reloads its stored buffer. The cache is first warmed by a process without the fix (the cache from before #15000). The rows below then run on that warm cache, each arm on its own copy of it.
torch 2.13.0, user
CustomGraphPassset before the fix:torch 2.13.0, no user pass (control): main and this PR both miss the warm cache and emit the barrier. torch 2.14.1 (control): the fix skips itself, and every run has the native barrier. Numerics matched eager in every run. The race itself is timing dependent, so this check covers the cache key and the kernel text, not wrong outputs.
Not covered
import unslothreplaces the marker, before and after this change.