I'm exporting pytorch model to tensorrt with onnx opset_version=11. While exporting onnx to tensorrt, error occurs:
Traceback (most recent call last):
File "tensorrt_test.py", line 11, in <module>
if not parser.parse(model.read()):
IndexError: Attribute not found: pads
I know padding operation is changed in onnx ops 11, here's my pytorch sample code:
import torch
import numpy as np
from torch import nn
import onnxruntime
from torch.nn import ZeroPad2d
# register_custom_op()
torch.manual_seed(1024)
np.random.seed(1024)
model_p = 'model_pads.onnx'
class TinyModel(nn.Module):
def __init__(self):
super(TinyModel, self).__init__()
device = "cuda"
self.pads = nn.ZeroPad2d((1, 0, 2, 3))
def forward(self, inputs: torch.Tensor):
x = self.pads(inputs)
return x
def export_onnx():
device = "cuda"
model = TinyModel().to(device)
sample_input = torch.rand(10, 4).to(device)
model.eval()
torch.onnx.export(model, sample_input, model_p, opset_version=11)
print('onnx model exported. forward now...')
# forward now
out_pt = model(sample_input)
sample_input = sample_input.cpu().numpy()
ort_session = onnxruntime.InferenceSession(model_p)
ort_inputs = {ort_session.get_inputs()[0].name: sample_input}
out_onnx = ort_session.run(None, ort_inputs)
print(out_pt.cpu().numpy() - out_onnx)
if __name__ == "__main__":
export_onnx()
Duplicate of https://github.com/onnx/onnx-tensorrt/issues/378. See that thread for an answer. Fix was just added to master.
Closing since this is fixed.
Closing since this is fixed.
Fixed ??? You must be kidding ...
@kevinch-nv , can you show what version of fixed, Tensorrt 7.1? Tensorrt 7.2
I meet same error in tensorrt 7.0
meet same error in tensorrt7.0. someone can help?
Most helpful comment
Fixed ??? You must be kidding ...