-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Fix evaluate_expr to include suppress_guards_tls in cache key #152661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1c6178
Fix evaluate_expr to include suppress_guards_tls in cache key
aorenste e2aa64b
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste eeafea7
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste f6fed2e
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste 21eb212
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste decb05e
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste 77f7f4d
Update on "Fix evaluate_expr to include suppress_guards_tls in cache …
aorenste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3936,7 +3936,8 @@ def _add_fx_node_metadata(self, node: torch.fx.Node) -> None: | |
node.meta[SHAPEENV_EVENT_KEY] = self._last_event_index() | ||
node.meta[CURRENT_NODE_KEY] = get_current_node() | ||
|
||
def _suppress_guards_tls(self) -> bool: | ||
@staticmethod | ||
def _suppress_guards_tls() -> bool: | ||
return getattr(TLS, "suppress_guards", False) | ||
|
||
@record_shapeenv_event() | ||
|
@@ -6811,8 +6812,6 @@ def evaluate_sym_node( | |
sym_node.expr, sym_node.hint, sym_node.fx_node, size_oblivious | ||
) | ||
|
||
@lru_cache(256) | ||
@record_shapeenv_event(save_tracked_fakes=True) | ||
def evaluate_expr( | ||
self, | ||
orig_expr: sympy.Basic, | ||
|
@@ -6821,6 +6820,27 @@ def evaluate_expr( | |
size_oblivious: bool = False, | ||
*, | ||
forcing_spec: bool = False, | ||
) -> sympy.Basic: | ||
""" | ||
Given an expression, evaluates it, adding guards if necessary | ||
""" | ||
|
||
# Add extra state that evaluate_expr() depends on. | ||
suppress_guards_tls = ShapeEnv._suppress_guards_tls() | ||
return self._inner_evaluate_expr( | ||
orig_expr, hint, fx_node, size_oblivious, forcing_spec, suppress_guards_tls | ||
) | ||
|
||
@lru_cache(256) | ||
@record_shapeenv_event(save_tracked_fakes=True, name="evaluate_expr") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i mean is it bad if it stayed _inner_evaluate_expr, whats the motivation for the renaming |
||
def _inner_evaluate_expr( | ||
self, | ||
orig_expr: sympy.Basic, | ||
hint: Optional[Union[int, bool, float]], | ||
fx_node: Optional[torch.fx.Node], | ||
size_oblivious: bool, | ||
forcing_spec: bool, | ||
_suppress_guards_tls: bool, | ||
) -> sympy.Basic: | ||
try: | ||
return self._evaluate_expr( | ||
|
@@ -6852,10 +6872,6 @@ def _evaluate_expr( | |
*, | ||
forcing_spec: bool = False, | ||
) -> sympy.Basic: | ||
""" | ||
Given an expression, evaluates it, adding guards if necessary | ||
""" | ||
|
||
# TODO: split conjunctions and evaluate them separately | ||
|
||
if isinstance( | ||
44B6
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the outer most API does take shape env as input, wonder if we should have just made
this an instance field instead of global state field.
suppress_guards
and
suppress_guards_stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is used only in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it an instance var is an orthogonal issue - you'd still need to tell the cache that the variable should participate in the cache key (lru_cache doesn't automatically include instance vars in the cache key)