Ask Your Question
2

What is the method to apply torch quantization on floating point values for the purpose of reducing the number of bits from FP64 to 8 bits?

asked 2023-06-04 04:48:52 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-04 05:13:01 +0000

nofretete gravatar image

The method to apply torch quantization on floating-point values for reducing the number of bits from FP64 to 8 bits involves the following steps:

  1. Define a model or a module in PyTorch that contains the floating-point parameters and tensors that need to be quantized.

  2. Instantiate a QuantStub() object and insert it in the forward pass of your model, just before the first layer you want to quantize.

  3. Instantiate a DeQuantStub() object and insert it in the forward pass of your model, immediately after the last layer you want to quantize.

  4. Define a qconfig dictionary that specifies the quantization configuration for the model. In this case, we need to set the weight and activation bit-widths to 8 bits, and set the forward_passes_per_calibration to 1.

  5. Call the torch.quantization.quantize_dynamic() function, passing in the model to be quantized, the qconfig dictionary, and any other required arguments.

  6. Freeze the parameters of the quantized model by calling the torch.jit.script() function on the quantized model.

  7. Save the quantized model and use it for inference.

The above steps will create a quantized model in which the floating-point weights and activations are replaced with 8-bit quantized values for efficient computation on hardware platforms with limited computational resources.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-04 04:48:52 +0000

Seen: 9 times

Last updated: Jun 04 '23