# Optimize pkl model to trt model

**URL:** <https://discuss.pytorch.org/t/optimize-pkl-model-to-trt-model/184800>\
**Category:** PyTorch Live\
**Created:** [July 22, 2023, 9:13am UTC](https://discuss.pytorch.org/t/optimize-pkl-model-to-trt-model/184800 "2023-07-22T09:13:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiyaabdi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/b5a626/32.png) [@kiyaabdi](https://discuss.pytorch.org/u/kiyaabdi)\
**Post date:** [July 22, 2023, 9:13am UTC](https://discuss.pytorch.org/t/optimize-pkl-model-to-trt-model/184800/1 "2023-07-22T09:13:08Z")

</div>

hi I’m new in using tensorrt. I have a .pkl model and I don’t know how to optimize it with tensorrt. I try to convert it to onnx or torch2trt but it return this error: TypeError: forward() missing 1 required positional argument: ‘x2’  
I tried to convert pkl to pth model or json model but this work doesn’t work too and return this error: “\_pickle.UnpicklingError”  
can you please help me to optimize my model?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [July 22, 2023, 4:04pm UTC](https://discuss.pytorch.org/t/optimize-pkl-model-to-trt-model/184800/3 "2023-07-22T16:04:18Z")

</div>

Based on the error message you should check the inputs to the `forward` method of your model and make sure all requires arguments are provided, such as the `x2` argument in this case.  
Besides that I don’t know what else might be causing it as only the error message was posted.

Also, please don’t tag specific users as it could demotivate others to post a valid answer.

---

<div class="post-metadata">

**Author:** ![kiyaabdi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/b5a626/32.png) [@kiyaabdi](https://discuss.pytorch.org/u/kiyaabdi)\
**Post date:** [July 23, 2023, 4:46am UTC](https://discuss.pytorch.org/t/optimize-pkl-model-to-trt-model/184800/4 "2023-07-23T04:46:56Z")

</div>

thanks for your reply, I’ll check it again and my code is here:  
"  
device = torch.device(“cuda:0” if torch.cuda.is\_available() else “cpu”)  
net = torch.load(‘./train\_model/best.pkl’)  
net.to(device)  
net.eval()  
x = torch.ones(1, 1, 256, 256).cuda()  
model\_trt = torch2trt(net, [x])

torch.save(model\_trt, ‘best\_trt.pkl’)  
from torch2trt import TRTModule

model\_trt = TRTModule()

model\_trt=torch.load(‘best\_trt.pkl’)

total\_score = demo(data\_path, net, save\_video=args.save,vis=args.vis)  
print(f’score: {total\_score}')`"
