Skip to content

Cache symbol replacement results by replacement and range versions - #203251

Closed
laithsakka wants to merge 4 commits into
gh/laithsakka/543/basefrom
gh/laithsakka/543/head
Closed

laithsakka wants to merge 4 commits into
gh/laithsakka/543/basefrom
gh/laithsakka/543/head

Conversation

@laithsakka

@laithsakka laithsakka commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human : I am fixing some caching bugs, that makes cache misses more often, but for replace , find those shall not be effected.
since those are very important we can use a less strict requirement than _version_counter , by only tracking _replacements_version_counter and _var_to_range_version_counter.
this is for perf. we already track both counters.
ranges are needed too: _find (and so replace) can return a partially resolved replacement when the fully resolved one isn't known to fit the symbol's range, and that changes once ranges narrow.

Invalidate ShapeEnv.replace, ShapeEnv._find and SymNode.expr with _replacements_version_counter and _var_to_range_version_counter instead of the global _version_counter. Runtime asserts, axioms and divisibility changes now keep these results warm; replacement and range changes still clear them. Extend _lru_cache with a replacements_and_ranges option; all other caches continue using _version_counter.

Ranges are part of the key because _find's result depends on them. With a -> b + 1 and b -> c + d, _find(a) tries to store c + d + 1 as a's replacement. _set_replacement rejects it unless c + d + 1 is known to lie within a's range (e.g. a in [0, 100] with c, d unbounded), so _find(a) and replace(a) return b + 1 until the ranges of c and d narrow.

SymNode.expr previously keyed only on _replacements_version_counter, so after a range change it kept the less resolved result. It now checks both counters.

The symbolic op memo is fixed separately in the next diff.

Authored with an AI assistant.
@exported-using-ghexport

Differential Revision: D128486311

Differential Revision: D128486311

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes Merged ready for review Automated review passed, ready for a final review by a maintainer. release notes: fx release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants