jakc4103 / DFQ

PyTorch implementation of Data Free Quantization Through Weight Equalization and Bias Correction.
MIT License
258 stars 45 forks source link

No quantization weight in this code? #11

Closed georgetseng1128 closed 4 years ago

georgetseng1128 commented 4 years ago

Hi, I have trace your code, but not find execution of quantize weight.

In main_cls.py, set option such --quantize, --equalize is enable with mobilenetv2. When program is done two function of cross_layer_equalization() and set_quant_minmax(), observe the forward of this function QuantNConv2d during inference, self.quant(input) is doing like fake-quantization, result is float, Then just run conv2d(), there is no quantization of weight in the process.

So my question is is there no quantization weight in this code?

quantize.py :

class QuantNConv2d(nn.Conv2d):
    """docstring for QuantNConv2d."""

    def __init__(self, in_channels, out_channels, kernel_size,
                 stride=1, padding=0, dilation=1, groups=1, bias=True, num_bits=8, momentum=0.1):
        super(QuantNConv2d, self).__init__(in_channels, out_channels, kernel_size,
                                      stride, padding, dilation, groups, bias)
        self.quant = QuantMeasure(num_bits=num_bits, momentum=momentum)

    def forward(self, input):
        input = self.quant(input)

        output = F.conv2d(input, self.weight, self.bias, self.stride,
                            self.padding, self.dilation, self.groups)

        return output
jakc4103 commented 4 years ago

quantization is done in Here before inference start. It's faster than doing quantization at each iteration, although there might be small numerical difference.

georgetseng1128 commented 4 years ago

OK, I see. Thank you reply.