MCPcopy Create free account
hub / github.com/pytorch/pytorch / unpack_var_sequence

Method unpack_var_sequence

torch/_dynamo/variables/nn_module.py:91–121  ·  view source on GitHub ↗
(self, tx)

Source from the content-addressed store, hash-verified

89 return
90
91 def unpack_var_sequence(self, tx):
92 # implement list/iter/tuple/etc calls
93 base = tx.output.get_submodule(self.module_key)
94 if isinstance(base, torch.nn.ModuleDict):
95 result = []
96 for name, submod in base.items():
97 name_var = variables.ConstantVariable.create(name)
98 tx.output.register_attr_or_module(
99 submod,
100 self.module_key,
101 name,
102 source=NNModuleSource(GetItemSource(self.source, name)),
103 )
104 result.append(name_var)
105 return result
106
107 assert isinstance(
108 base, (torch.nn.ModuleList, torch.nn.ParameterList, torch.nn.Sequential)
109 ), typestr(base)
110 assert self.source
111 result = []
112 for idx, submod in enumerate(base):
113 result.append(
114 tx.output.register_attr_or_module(
115 submod,
116 self.module_key,
117 idx,
118 source=NNModuleSource(GetItemSource(self.source, idx)),
119 )
120 )
121 return result
122
123 def call_hasattr(self, tx, name: str) -> "VariableTracker":
124 mod = tx.output.get_submodule(self.module_key)

Callers 1

unpack_var_sequenceMethod · 0.45

Calls 9

isinstanceFunction · 0.85
NNModuleSourceClass · 0.85
GetItemSourceClass · 0.85
typestrFunction · 0.85
get_submoduleMethod · 0.45
itemsMethod · 0.45
createMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected