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

Method deserialize_node

torch/_export/serde/serialize.py:1152–1195  ·  view source on GitHub ↗
(self, serialized_node: Node, target: Callable)

Source from the content-addressed store, hash-verified

1150 return self.graph
1151
1152 def deserialize_node(self, serialized_node: Node, target: Callable) -> None:
1153 if target.__module__ == "_operator": # TODO(zhxchen17) Follow up on this.
1154 name = serialized_node.outputs[0].value.as_name
1155 args = self.deserialize_sym_op_inputs(serialized_node.inputs)
1156
1157 fx_node = self.graph.create_node("call_function", target, args, {}, name)
1158 self.deserialize_sym_op_outputs(serialized_node, fx_node)
1159 elif isinstance(target, torch._ops.HigherOrderOperator):
1160 assert (
1161 len(serialized_node.outputs) == 1
1162 and serialized_node.outputs[0].type in ("as_tensors", "as_tensor")
1163 ), "Only single tensor output or list of tensor output is supported for higher order operators."
1164
1165 output = serialized_node.outputs[0]
1166
1167 name = (
1168 output.value.name
1169 if output.type == "as_tensor"
1170 else None # FX will generate a name for us.
1171 )
1172 args = tuple(self.deserialize_input(input.arg) for input in serialized_node.inputs)
1173 fx_node = self.graph.create_node("call_function", target, args, {}, name)
1174
1175 if output.type == "as_tensor":
1176 self.sync_fx_node(name, fx_node)
1177 if output.type == "as_tensors":
1178 self.deserialize_multiple_outputs(serialized_node, fx_node)
1179
1180 elif isinstance(target, torch._ops.OpOverload):
1181 # For convenience: if this node returns a single tensor, name the
1182 # newly-created node after it. This ensures that these tensor values
1183 # have names that are consistent with serialized.
1184 name = (
1185 serialized_node.outputs[0].value.name
1186 if _is_single_tensor_return(target)
1187 else None # FX will generate a name for us.
1188 )
1189 args, kwargs = self.deserialize_inputs(target, serialized_node)
1190 fx_node = self.graph.create_node("call_function", target, args, kwargs, name)
1191 self.deserialize_outputs(serialized_node, fx_node)
1192 else:
1193 raise SerializeError(f"Unsupported target type for node {serialized_node}: {target}")
1194
1195 fx_node.meta.update(self.deserialize_metadata(serialized_node.metadata))
1196
1197 def deserialize_input_spec(self, i: InputSpec) -> ep.InputSpec:
1198 if i.user_input is not None:

Callers 1

deserialize_graphMethod · 0.95

Calls 13

deserialize_inputMethod · 0.95
sync_fx_nodeMethod · 0.95
deserialize_inputsMethod · 0.95
deserialize_outputsMethod · 0.95
deserialize_metadataMethod · 0.95
isinstanceFunction · 0.85
_is_single_tensor_returnFunction · 0.85
SerializeErrorClass · 0.85
create_nodeMethod · 0.45

Tested by

no test coverage detected