hadoop2xu opened a new issue, #14141:
URL: https://github.com/apache/tvm/issues/14141
想对pytorch 模型做推理, pytorch模型倒出代码如下:
import torch as torch
import torch.nn as nn
class LeNet(nn.Module):
def __init__(self):
super(LeNet, self).__init__()
layer1 = nn.Sequential()
layer1.add_module("conv1", nn.Conv2d(1, 6, 5))
layer1.add_module("pool", nn.MaxPool2d(2, 2))
self.layer1 = layer1
layer2 = nn.Sequential()
layer2.add_module("conv2", nn.Conv2d(6, 16, 5))
layer2.add_module("pool2", nn.MaxPool2d(2, 2))
self.layer2 = layer2
layer3 = nn.Sequential()
layer3.add_module("fc1", nn.Linear(16*5*5, 120))
layer3.add_module("fc2", nn.Linear(120, 84))
layer3.add_module("fc3", nn.Linear(84, 10))
self.layer3 = layer3
def forward(self, x):
x = self.layer1(x)
x = self.layer2(x)
x = x.view(x.size(0), -1)
x = self.layer3(x)
return x
y = torch.randn(1, 1, 32, 32)
model = LeNet()
jit_model = torch.jit.trace(model, y)
torch.jit.save(jit_model, "lenet_model.pth")
推理代码如下:
model = torch.jit.load("lenet_model.pth“).eval()
input_data = torch.rand([1, 1, 32, 32])
shape_list = [("input0", input_data)]
mod, params = relay.frontend.from_pytorch(module.model, shape_list)
执行报错如下:
File
"/docker_workspace/baidu/xpu/kmis/tool/anyinfer/anyinfer_v2.0/anyinfer_python/x86_64/python/tvm/relay/frontend/pytorch.py",
line 4259, in from_pytorch
_run_jit_passes(graph)
File
"/docker_workspace/baidu/xpu/kmis/tool/anyinfer/anyinfer_v2.0/anyinfer_python/x86_64/python/tvm/relay/frontend/pytorch.py",
line 3838, in _run_jit_passes
torch._C._jit_pass_inline(graph)
AttributeError: module 'torch._C' has no attribute '_jit_pass_inline'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]