1. Problems Description
环境:Ubuntu16.04, Torch1.4, Torchvision0.5, Pytorch1.4, caffe2
笔者本意想把pytorch训练好的模型通过ONNX转换caffe2上部署,谁知在torch.save()函数时报了这个错误。
Through the investigation by Google and Pytorch offical website. NamedTensor functionality had been added from pytorch1.3, so if use pytorch1.2. this error will be dismissed, but I don’t want to go back to lower version.
So I reedit the _namedtensor_internals.py according to the following rules:
Step 1
#import torch
from torch._six import PY2
from collections import OrderedDict
Step 2
Disable the following function
#def assert_namedtensor_build(api_name):
# if not torch._C._BUILD_NAMEDTENSOR:
# raise RuntimeError('NYI: {} is experimental and a part '
# 'of our named tensors project.'.format(api_name))
Step 3
#if torch._C._BUILD_NAMEDTENSOR and tensor.has_names():
if tensor.has_names():
Step 4
Disable the following row code
#assert_namedtensor_build(namer_api_name(inplace))
Then I got it.