Hi.
In the code, function "set_quanbit()" is used to set the quantization bit for weights. However, in function "set_quanbit()", only attribute "num_bit" is modified, while attribute "bit_range" is left unchanged.
def set_quanbit(model, quan_bit = 8): for module_name in model._modules: if len(model._modules[module_name]._modules) > 0: set_quanbit(model._modules[module_name], quan_bit) else: if hasattr(model._modules[module_name], "num_bit"): setattr(model._modules[module_name], "num_bit", quan_bit) return model
Because the default initialized value of attribute "num_bit" in class "DSQConv" is 8, the attribute "bit_range" will be initialized when the "num_bit" is 8, but the attribute "bit_range" is not modified when "num_bit" is changed. This means that when we set quant_bit other than 8, the weights will not quantize correctly.
Hi. In the code, function "set_quanbit()" is used to set the quantization bit for weights. However, in function "set_quanbit()", only attribute "num_bit" is modified, while attribute "bit_range" is left unchanged.
def set_quanbit(model, quan_bit = 8): for module_name in model._modules: if len(model._modules[module_name]._modules) > 0: set_quanbit(model._modules[module_name], quan_bit) else: if hasattr(model._modules[module_name], "num_bit"): setattr(model._modules[module_name], "num_bit", quan_bit) return model
Because the default initialized value of attribute "num_bit" in class "DSQConv" is 8, the attribute "bit_range" will be initialized when the "num_bit" is 8, but the attribute "bit_range" is not modified when "num_bit" is changed. This means that when we set quant_bit other than 8, the weights will not quantize correctly.
class DSQConv(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, momentum = 0.1, num_bit = 8, QInput = True, bSetQ = True):
To fix this bug, I recommend reset attribute "bit_range" as well in function "set_quanbit()".