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

Method run_node

caffe2/python/onnx/backend.py:206–241  ·  view source on GitHub ↗
(cls, node, inputs, device='CPU', opset_version=_known_opset_version, outputs_info=None)

Source from the content-addressed store, hash-verified

204 # opset_version if you don't want this to version.
205 @classmethod
206 def run_node(cls, node, inputs, device='CPU', opset_version=_known_opset_version, outputs_info=None):
207 super(Caffe2Backend, cls).run_node(node, inputs, device=device,
208 outputs_info=outputs_info, opset_version=opset_version)
209
210 value_infos = []
211 device_option = get_device_option(Device(device))
212 ws = Workspace()
213 with core.DeviceScope(device_option): # temporary!
214 if isinstance(inputs, dict):
215 for key, value in inputs.items():
216 ws.FeedBlob(key, value)
217 value_infos.append(onnx.helper.make_tensor_value_info(
218 name=key,
219 elem_type=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[value.dtype],
220 shape=value.shape).SerializeToString())
221 else:
222 assert len(node.input) == len(inputs), "{}: expected {} but got {}".format(
223 node.op_type, len(node.input), len(inputs))
224 for key, value in zip(node.input, inputs):
225 ws.FeedBlob(key, value)
226 value_infos.append(onnx.helper.make_tensor_value_info(
227 name=key,
228 elem_type=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[value.dtype],
229 shape=value.shape).SerializeToString())
230
231 ops = []
232 cbackend = C.Caffe2Backend(cls._dummy_name)
233 ops_str = cbackend.convert_node(node.SerializeToString(), value_infos, opset_version)
234 for s in ops_str[0] + ops_str[1]:
235 op = caffe2_pb2.OperatorDef()
236 op.ParseFromString(s)
237 op.device_option.CopyFrom(device_option)
238 ops.append(op)
239 ws.RunOperatorsOnce(ops)
240 output_values = [ws.FetchBlob(name) for name in node.output]
241 return namedtupledict('Outputs', node.output)(*output_values)
242
243 @classmethod
244 def _create_tensor_filling_op(cls, onnx_tensor, name=None):

Callers 3

_test_relu_graphMethod · 0.45
test_relu_graphMethod · 0.45
test_gemmMethod · 0.45

Calls 8

WorkspaceClass · 0.90
get_device_optionFunction · 0.85
isinstanceFunction · 0.85
namedtupledictFunction · 0.85
DeviceClass · 0.50
itemsMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45

Tested by 3

_test_relu_graphMethod · 0.36
test_relu_graphMethod · 0.36
test_gemmMethod · 0.36