Skip to content
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

[dynamo] Delete DictKeysVariable - already have DictKeySetVariable #144713

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions torch/_dynamo/variables/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _binop_handlers():
# combinations. Handlers are attempted in order, and will be used if the type checks
# match. They are expected to have the signature:
# fn(tx, arg0: VariableTracker, arg1: VariableTracker) -> VariableTracker
from .dicts import DictKeysVariable, SetVariable
from .dicts import SetVariable
from .functions import BaseUserFunctionVariable, UserFunctionVariable
from .nn_module import NNModuleVariable
from .tensor import supported_const_comparison_ops
Expand Down Expand Up @@ -459,7 +459,7 @@ def expand_list_like(tx: "InstructionTranslator", lst, const):
op_handlers[operator.mul].extend(list_like_expansion_handlers)

size_or_tuple = (SizeVariable, TupleVariable)
has_set_items = (SetVariable, DictKeysVariable)
has_set_items = (SetVariable,)

def create_cmp_op_handlers(op):
def compare_by_value(tx: "InstructionTranslator", a, b):
Expand Down
29 changes: 1 addition & 28 deletions torch/_dynamo/variables/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def call_method(
if self.source:
tx.output.guard_on_key_order.add(self.source.name())
assert not (args or kwargs)
return DictKeysVariable(self)
return DictKeySetVariable(self.items.keys())
elif name == "values":
self.install_dict_keys_match_guard()
if self.source:
Expand Down Expand Up @@ -808,33 +808,6 @@ def call_method(
return super().call_method(tx, name, args, kwargs)


class DictKeysVariable(DictViewVariable):
kv = "keys"

@property
def set_items(self):
return set(self.view_items)

@property
def view_items_vt(self):
# Returns an iterable of the unpacked items
return [x.vt for x in self.view_items]

def python_type(self):
return dict_keys

def call_method(
self,
tx,
name,
args: List["VariableTracker"],
kwargs: Dict[str, "VariableTracker"],
) -> "VariableTracker":
if name == "__contains__":
return self.dv_dict.call_method(tx, name, args, kwargs)
return super().call_method(tx, name, args, kwargs)


class DictValuesVariable(DictViewVariable):
# DictValuesVariable is an iterable but cannot be compared.
kv = "values"
Expand Down
Loading