-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example: How to use merge_bn correctly #542
Comments
Hi @g12bftd, bn_model = QuantizedModel(bn=True)
model = QuantizedModel(bn=False)
for l in bn_model:
if l isinstanceof(qnn.quantconv):
merge_bn(l,nextlayer)
model[index_of_corresponding_layer].copy_state_dict(l)
torch.save(model, fused_QuantizedModel.pth) Also, I would recommend defining the model using |
@MohamedA95 I am new to brevitas so is it that we need to train with the classical BN layers? If you could elaborate to a newbie such as me, as all the models that I am trying to export need to have intermediate BN layers. |
Hi @wilfredkisku, What do you mean by classical BN layers? do you mean |
@MohamedA95 Thank you for the reply. Yes, the models that I am using requires |
Yes they can be fused brevitas even has a function to do it under |
@MohamedA95 Thanks for all the help. I have been able to understand the idea behind fusing the layers. What I have done now is create two models that are similar but one with CONV + BN and the other without BN.
I am using the
But I am having issues while copying the trained weights and biases + additional quantization parameres that are present in the Quantization layers such as QuantConv2d. If I use a concize code like the one below for creating the dictionary of weights for only CONV and skipping BN (which has been fused with the CONV earlier.
I am able to copy the weights but a few parameters associated with the
I would be thankful for any help in this regard. Thanks again. |
Hi @wilfredkisku, |
Hi, this reply mentioned that we are able to train fixed-point batchnorm using BatchNorm2dToQuantScaleBias with power of two scale factors. I think it is supporting quant bn? However it is not clear to me that how it is done for batchnorm? Does the scale and bias change during training? Or it is indeed doing post training for batch norm? |
There is an architecture I would like to quantise and retrain from its floating point counterpart. I would like to incorporate the merge_bn operation supported by Brevitas. How exactly would I do this here. An overview is good but some code would be better. Note I only want to merge/fuse the Conv + BN + ReLU components. Here is my architecture:
class QuantizedModel(nn.Module):
def init(self, config):
super(QuantizedVGG, self).init()
The text was updated successfully, but these errors were encountered: