1 from __future__
import absolute_import
2 from __future__
import division
3 from __future__
import print_function
4 from __future__
import unicode_literals
16 from test_pytorch_common
import flatten
23 print(
'Cannot import torch, hence caffe2-torch test will not run.')
27 def run_embed_params(proto, model, input, state_dict=None, use_gpu=True):
29 This is only a helper debug function so we can test embed_params=False 30 case as well on pytorch front 31 This should likely be removed from the release version of the code 36 model_def = onnx.ModelProto.FromString(proto)
37 onnx.checker.check_model(model_def)
38 prepared = c2.prepare(model_def, device=device)
45 for k
in model.state_dict():
46 if k
not in state_dict:
50 parameters.append(model.state_dict()[k])
52 parameters.append(state_dict[k])
54 parameters = list(model.state_dict().values())
57 for k, v
in zip(model_def.graph.input, flatten((input, parameters))):
58 if isinstance(v, Variable):
59 W[k.name] = v.data.cpu().numpy()
61 W[k.name] = v.cpu().numpy()
63 caffe2_out = prepared.run(inputs=W)
def set_default_tensor_type(t)