brevitas icon indicating copy to clipboard operation
brevitas copied to clipboard

QuantRelu's forward reasoning process

Open YZW-explorer opened this issue 3 years ago • 6 comments

Hello author, I am still trying to use pytorch to simulate the quantization and dequantization forward reasoning process of brevitas. I have the following two questions to ask you:

  1. When I observed the pth file, I found that QuantRelu corresponds to a value: branch1.0.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value What is this value?
  2. What is the forward reasoning process of QuantRelu? Can you give me a description like this? https://github.com/Xilinx/brevitas/issues/327#issue-900975345

YZW-explorer avatar May 29 '21 04:05 YZW-explorer

Looking forward to your reply, thank you very much !

YZW-explorer avatar May 29 '21 15:05 YZW-explorer

Hello, QuantReLU first applies a relu and then performs quantization on the output. The value of the scale factor in the pth is not necessarily the value used for relu. You check the value at runtime call the .quant_act_scale(), or export the model to ONNX with BrevitasONNXManager.export .

volcacius avatar May 30 '21 11:05 volcacius

Hello, QuantReLU first applies a relu and then performs quantization on the output. The value of the scale factor in the pth is not necessarily the value used for relu. You check the value at runtime call the .quant_act_scale(), or export the model to ONNX with BrevitasONNXManager.export .

Thank goodness you are here, hello author, please give me some time to add my questions, very grateful!

YZW-explorer avatar May 30 '21 12:05 YZW-explorer

Taking this node as an example, I did not quantize the input, so if I use pytorch to simulate the quantization and inverse quantization operation here, it is: 1.int_weight() Get the convolutional layer weight of int 2.conv_result = nn.Conv2d(int_weight(),input) 3.conv_result*weight_scale() dequantize the output value image Is that right?

YZW-explorer avatar May 30 '21 12:05 YZW-explorer

Look at this example again. If I still want to use pytorch to implement this process, are the following steps correct? 1.int_weight() Get the convolutional layer weight of int 2.input(int) = input(float)/0.1322 (scale in the Quant node) quantized input 2.conv_result = nn.Conv2d(int_weight(),input(int)) 3.conv_result*weight_scale()*0.1322 dequantize the output value image

YZW-explorer avatar May 30 '21 12:05 YZW-explorer

At the same time, I have a very special example here. Two Quant nodes are connected together. How can I solve this situation? image Looking forward to your answers to my questions, I would like to extend my sincerest thanks to the author!

YZW-explorer avatar May 30 '21 12:05 YZW-explorer