Skip to content

Commit e311287

Browse files
authored
Revert "[SWDEV-554558] [dynamo] Use BINARY_SUBSCR for pre-graph bytecode for regular dict ac…" (#2800)
Reverts #2669 This commit broke HF dashboard, JIRA: https://ontrack-internal.amd.com/browse/SWDEV-565195 @jataylo suggested we revert this commit.
1 parent 130d937 commit e311287

File tree

4 files changed

+5
-43
lines changed

4 files changed

+5
-43
lines changed

test/dynamo/test_dicts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Any, Optional, Tuple
1515

1616
import torch
17+
import torch._dynamo.config
1718
import torch._dynamo.test_case
1819
import torch._dynamo.testing
1920
import torch._functorch.config

torch/_dynamo/guards.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
ConstDictKeySource,
100100
DefaultsSource,
101101
DictGetItemSource,
102-
DictSubclassGetItemSource,
103102
FlattenScriptObjectSource,
104103
FloatTensorSource,
105104
FSDPNNModuleSource,
@@ -1080,7 +1079,7 @@ def get_guard_manager_from_source(self, source):
10801079
example_value=example_value,
10811080
guard_manager_enum=guard_manager_enum,
10821081
)
1083-
elif istype(source, (DictGetItemSource, DictSubclassGetItemSource)):
1082+
elif istype(source, DictGetItemSource):
10841083
assert base_guard_manager # to make mypy happy
10851084
assert isinstance(base_example_value, (dict, collections.OrderedDict))
10861085
if isinstance(base_guard_manager, DictGuardManager):

torch/_dynamo/source.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -601,44 +601,7 @@ def __post_init__(self):
601601
def guard_source(self):
602602
return self.base.guard_source()
603603

604-
def reconstruct(self, codegen: "PyCodegen"):
605-
# Load dict
606-
codegen(self.base)
607-
608-
# Load key
609-
if isinstance(self.index, Source):
610-
codegen(self.index)
611-
else:
612-
codegen.append_output(codegen.create_load_const(self.index))
613-
codegen.append_output(create_instruction("BINARY_SUBSCR"))
614-
615-
def name(self):
616-
if isinstance(self.index, ConstDictKeySource):
617-
return f"{self.base.name()}[{self.index.name()}]"
618-
else:
619-
return f"{self.base.name()}[{self.index!r}]"
620-
621-
622-
# Same as DictGetItemSource but used for dict.__getitem__ calls to ensure that
623-
# torch.compile does not run the overridden __getitem__ method
624-
@dataclasses.dataclass(frozen=True)
625-
class DictSubclassGetItemSource(ChainedSource):
626-
# Key to access in the dictionary. It can be one of the the following types
627-
# 1) ConstDictKeySource
628-
# 2) constant - like string, integer
629-
index: Any
630-
631-
def __post_init__(self):
632-
from .variables import ConstantVariable
633-
634-
assert isinstance(
635-
self.index, ConstDictKeySource
636-
) or ConstantVariable.is_literal(self.index)
637-
638-
def guard_source(self):
639-
return self.base.guard_source()
640-
641-
def reconstruct(self, codegen: "PyCodegen"):
604+
def reconstruct(self, codegen):
642605
# reconstruct dict.__getitem__(dct, key)
643606

644607
# Load dict.__getitem__

torch/_dynamo/variables/builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
ConstDictKeySource,
9393
ConvertIntSource,
9494
DictGetItemSource,
95-
DictSubclassGetItemSource,
9695
FloatTensorSource,
9796
GetItemSource,
9897
GradSource,
@@ -1275,8 +1274,8 @@ def build_key_value(i, k, v):
12751274
source_key = ConstDictKeySource(self.get_source(), i)
12761275
key = LazyVariableTracker.create(k, source_key)
12771276

1278-
source_value = DictSubclassGetItemSource(base, source_key)
1279-
res_value = LazyVariableTracker.create(v, source_value)
1277+
source_value = DictGetItemSource(self.get_source(), source_key)
1278+
value = LazyVariableTracker.create(v, source_value)
12801279

12811280
return key, value
12821281

0 commit comments

Comments
 (0)