<jupyter_start><jupyter_text>Torch Model<jupyter_code># Load Model

args = pickle.load(open(model_path / (model_name+'_args.pkl'), 'rb'))
print(args)
channel_sizes = [args.nhid] * args.levels

model = TCN(in_channels, n_classes, channel_sizes, kernel_size=args.ksize, trt=True, apply_max=True)
model.load_state_dict(torch.load(model_path / (model_name+'.pt')), strict=False)
model.eval()

if torch.cuda.is_available():
    model.cuda()
torch_accuracy = model_accuracy(model, test_loader, num_samples=100)
torch_accuracy
torch_accuracy_1_sample = model_accuracy(model, test_loader, num_samples=1)
torch_accuracy_1_sample
torch_accuracy_200_samples = model_accuracy(model, test_loader, num_samples=200)
torch_accuracy_200_samples<jupyter_output><empty_output><jupyter_text>TensorRT Models  torch2trt using ONNX<jupyter_code># Load Model
model_trt_onnx = TRTModule()
model_trt_onnx.load_state_dict(torch.load(trt_model_path / (model_name+'_trt_onnx_amax.pt')))
trt_onnx_accuracy = model_accuracy(model_trt_onnx, test_loader, num_samples=100)
trt_onnx_accuracy
trt_onnx_accuracy = model_accuracy(model_trt_onnx, test_loader, num_samples=50)
trt_onnx_accuracy
trt_onnx_accuracy = model_accuracy(model_trt_onnx, test_loader, num_samples=150)
trt_onnx_accuracy<jupyter_output>Accuracy after 0 images: 1.0
Accuracy after 50 images: 1.0
Accuracy after 100 images: 1.0
Accuracy after 150 images: 0.9867549668874173
Accuracy after 200 images: 0.9850746268656716
Accuracy after 250 images: 0.9840637450199203
Accuracy after 300 images: 0.9867109634551495
Accuracy after 350 images: 0.9857549857549858
Accuracy after 400 images: 0.9875311720698254
Accuracy after 450 images: 0.9844789356984479
Accuracy after 500 images: 0.9860279441117764
Accuracy after 550 images: 0.9872958257713249
Accuracy after 600 images: 0.9833610648918469
Accuracy after 650 images: 0.9831029185867896
Accuracy after 700 images: 0.9800285306704708
Accuracy after 750 images: 0.9786950732356857
Accuracy after 800 images: 0.9800249687890137
Accuracy after 850 images: 0.9800235017626322
Accuracy after 900 images: 0.9811320754716981
Accuracy after 950 images: 0.9810725552050473
Accuracy after 1000 images: 0.9820179820179821
Accuracy after 1050 images: 0.9809705042816366
Accuracy after 1100 images: 0.9818[...]<jupyter_text>torch2trt using converters<jupyter_code># Load Model
model_trt_no_onnx = TRTModule()
model_trt_no_onnx.load_state_dict(torch.load(trt_model_path / (model_name+'_trt_amax.pt')))
trt_no_onnx_accuracy = model_accuracy(model_trt_no_onnx, test_loader, num_samples=100)
trt_no_onnx_accuracy<jupyter_output>Accuracy after 0 images: 1.0
Accuracy after 50 images: 1.0
Accuracy after 100 images: 0.9900990099009901
Accuracy after 150 images: 0.9801324503311258
Accuracy after 200 images: 0.9800995024875622
Accuracy after 250 images: 0.9800796812749004
Accuracy after 300 images: 0.9800664451827242
Accuracy after 350 images: 0.98005698005698
Accuracy after 400 images: 0.9825436408977556
Accuracy after 450 images: 0.9800443458980045
Accuracy after 500 images: 0.9820359281437125
Accuracy after 550 images: 0.9836660617059891
Accuracy after 600 images: 0.9800332778702163
Accuracy after 650 images: 0.978494623655914
Accuracy after 700 images: 0.9757489300998573
Accuracy after 750 images: 0.9747003994673769
Accuracy after 800 images: 0.9750312109862672
Accuracy after 850 images: 0.9753231492361927
Accuracy after 900 images: 0.97669256381798
Accuracy after 950 images: 0.9768664563617245
Accuracy after 1000 images: 0.977022977022977
Accuracy after 1050 images: 0.9752616555661275
Accuracy after 1100 image[...]<jupyter_text>torch2trt with ONNX - FP16<jupyter_code># Load Model
model_trt_onnx_fp16 = TRTModule()
model_trt_onnx_fp16.load_state_dict(torch.load(trt_model_path / (model_name+'_trt_onnx_amax_fp16.pt')))
trt_onnx_fp16_accuracy = model_accuracy(model_trt_onnx_fp16, test_loader, num_samples=100, fp16=True)
trt_onnx_fp16_accuracy<jupyter_output>Accuracy after 0 images: 1.0
Accuracy after 50 images: 1.0
Accuracy after 100 images: 0.9900990099009901
Accuracy after 150 images: 0.9801324503311258
Accuracy after 200 images: 0.9800995024875622
Accuracy after 250 images: 0.9800796812749004
Accuracy after 300 images: 0.9800664451827242
Accuracy after 350 images: 0.98005698005698
Accuracy after 400 images: 0.9825436408977556<jupyter_text>torch2trt with converters - FP16<jupyter_code># Load Model
model_trt_no_onnx_fp16 = TRTModule()
model_trt_no_onnx_fp16.load_state_dict(torch.load(trt_model_path / (model_name+'_trt_amax_fp16.pt')))
trt_no_onnx_fp16_accuracy = model_accuracy(model_trt_no_onnx_fp16, test_loader, num_samples=100, fp16=True)
trt_no_onnx_fp16_accuracy
x = torch.ones(1,1,784).cuda() * 0.3
model_trt_no_onnx_fp16(x)

import tensorrt as trt
b = trt.Builder(trt.Logger())
dir(b)
trt.__version__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07617470503001449, 'fraction_numerical': 0.21362036845373628, 'mean_word_length': 8.168880455407969, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '323389', 'license': 'MIT', 'n_tokens_mistral': 2591, 'n_tokens_neox': 1884, 'n_words': 392, 'path': '.ipynb_checkpoints/Accuracy Test-checkpoint.ipynb', 'repo_name': 'shivadb/TCN', 'size': '4831'}