Skip to content

Instantly share code, notes, and snippets.

@apivovarov
apivovarov / trt_quintize_resnet50.md
Last active March 29, 2024 00:13
TensorRT Quantize Resnet50 TRT

Quantize Resnet50 model with TensorRT

Intro

TensorRT supports two approaches to prepare model for Quantization - Calibration or Training

First we need to add/replace regular model nn.Layers with TRT pytorch_quantization.nn layers. Quantization layers will gather statistics required for quantization.

Once the model is modified we can use the following approaches to gather statistics before quantization:

  1. Calibrate pre-trainer model
  2. Train (1 epoch) pre-trainer model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
In [1]: import faiss
In [2]: import numpy as np
In [4]: d = 32
In [5]: m = 4
In [6]: c = 6
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.