Skip to content

[inductor] Match autotune cache entries to configs by typed kwarg value - #195883

Closed
bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1110/basefrom
gh/bobrenjc93/1110/head
Closed

bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1110/basefrom
gh/bobrenjc93/1110/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

User-defined autotune kernels can carry non-JSON constexpr kwargs (tuples,
plain Enum members). The autotune cache stores kwargs as JSON, so a tuple comes
back as a list and a plain Enum as its raw value, and a warm load that
reconstructs the winning Config from the JSON payload bakes the degraded value
into the kernel; matching a cached entry back to a candidate config by == is
also ambiguous when candidates differ only by type (1 vs 1.0, True vs 1).

Autotune cache matching now returns the real candidate config (preserving tuple
and Enum kwarg values) when the matching configs hold the same typed values --
a unique match or interchangeable duplicates. Distinct candidates that
serialize alike (subset kwargs, int/float or bool/int splits, which are == but
distinct Triton specializations) fall through to reconstruction from the cached
value, as before, with any tuple/Enum kwarg the candidates agree on restored;
the load re-autotunes only when the candidates disagree on the typed value
behind the cached one (MODE=Mode.A vs MODE=1). This fixes duplicate tuple-kwarg
configs re-autotuning on every warm
start.

Behavior note: this depends on the constexpr Enum-unwrapping introduced by
IntEnum and str-mixin enum members compare equal to their unwrapped values, so
they are not degraded by JSON round-tripping and match directly; only plain
Enum members require the reconstruction path.

Coordesc and dynamically added winners are reconstructed with the typed kwarg
values their candidates hold (tuple, Enum) and re-autotune only when no
candidate serializes to the cached value, or when the candidates that do
disagree on the typed value; interchangeable duplicate candidates compare on
every Config attribute, not just kwargs, by type as well as value. The
found_by_coordesc stamp is only written when coordesc will actually refine the
kernel, since the flag makes warm loads skip candidate matching entirely.

Test Plan:

python test/inductor/test_codegen_triton.py -k autotune_cache -k restore_degraded -k autotune_config -k coordesc

The matching and restoration logic is covered with SimpleNamespace configs
(and a mocked reconstruction) so it runs without Triton; the end-to-end
autotune tests need a GPU and Triton.

Authored with an AI assistant.

Co-Authored-By: Claude Fable 5.1 [email protected]

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195883

Note: Links to docs will display an error until the docs builds have been completed.

❌ 7 Cancelled Jobs, 15 Pending

As of commit 3d9cff4 with merge base 3d3d3f4 (image):

CANCELLED JOBS - The following jobs were cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: inductor"

@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Closing in favor of the canonical stack #195353-#195362 (now also #195911-#195929). Note for future readers: this change has no counterpart there yet; the code remains in this PR's history if it is wanted later.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1110/head branch November 15, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant