Skip to content

Commit

Permalink
[dynamo][guards] De-dupe DUPLICATE_INPUT guard (pytorch#134354)
Browse files Browse the repository at this point in the history
Hard to write a test.

Pull Request resolved: pytorch#134354
Approved by: https://github.com/jansel
ghstack dependencies: pytorch#134272
  • Loading branch information
anijain2305 authored and pytorchmergebot committed Aug 24, 2024
1 parent d433a60 commit cdb9df5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions torch/_dynamo/guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ def __init__(
str, torch._C._dynamo.guards.GuardManager
] = {}

self._cached_duplicate_input_guards: Set[Tuple[str, str]] = set()

def guard_on_dict_keys_and_ignore_order(self, example_value, guard):
dict_mgr = self.get_guard_manager(guard)
if isinstance(dict_mgr, DictGuardManager):
Expand Down Expand Up @@ -1663,6 +1665,13 @@ def DUPLICATE_INPUT(self, guard, source_b):
self._set_guard_export_info(guard, code)

if config.enable_cpp_guard_manager:
# Check that the guard has not been inserted already
key = (ref_a, ref_b)
if key in self._cached_duplicate_input_guards:
return
self._cached_duplicate_input_guards.add((ref_a, ref_b))
self._cached_duplicate_input_guards.add((ref_b, ref_a))

install_object_aliasing_guard(
self.get_guard_manager(guard),
self.get_guard_manager_from_source(source_b),
Expand Down

0 comments on commit cdb9df5

Please sign in to comment.