Created
August 28, 2020 00:17
-
-
Save sandeepkumar-skb/17b8a2a380c9db49877786a18a37bfe0 to your computer and use it in GitHub Desktop.
Running TRTorch on ResNet50 Torchvision model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import trtorch | |
import torch | |
import torchvision.models as models | |
rn50 = models.resnet50(pretrained=True).cuda().eval() | |
inp = torch.randn((1, 3, 224, 224), device='cuda') | |
rn50_jit_traced = torch.jit.trace(rn50, inp) | |
rn50_jit_scripted = torch.jit.script(rn50) | |
compile_settings = { | |
"input_shapes" : [ (1, 3, 224, 224)], | |
#"op_precision" : torch.half, | |
"workspace_size" : 1<<30, | |
} | |
trtorch_rn50_traced_model = trtorch.compile(rn50_jit_traced, compile_settings) | |
trtorch_rn50_scripted_model = trtorch.compile(rn50_jit_scripted, compile_settings) | |
rn50_output = rn50(inp) | |
rn50_trt_traced_output = trtorch_rn50_traced_model(inp) | |
rn50_trt_scripted_output = trtorch_rn50_scripted_model(inp) | |
print(torch.max(torch.abs(rn50_output - rn50_trt_traced_output))) | |
print(torch.max(torch.abs(rn50_output - rn50_trt_scripted_output))) | |
print(torch.max(torch.abs(rn50_trt_traced_output - rn50_trt_scripted_output))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to run:
At the time of the script I ran
docker run -it --gpus=all --ipc=host -v=<path>:/host nvcr.io/nvidia/pytorch:20.03-py3
wget https://github.com/NVIDIA/TRTorch/releases/download/v0.0.3/trtorch-0.0.3-cp36-cp36m-linux_x86_64.whl
pip install trtorch-0.0.3-cp36-cp36m-linux_x86_64.whl
python TRTorch_resnet50.py