I want to quantize a model that I have created that uses a custom Parameter to hold the weights of several Conv2d() layers. I pass this Parameter to the forward function, which then assigns the different parts of the Parameter to the weights of the Conv2d() layers, which requires a cast to Parameter on every forward function call. This works fine for normal use, if inefficient, but when I want to use the Quantization package, the assignment throws this error:
KeyError: “attribute ‘weight’ already exists”
When I don’t use quantization, I can use the functional conv2d(), but I don’t think that is supported yet with nn.quantize. What’s the difference between a quantized model and a regular model, and how can I fix this error?
So the issue is that I was passing floatTensor to a now torch.qint8, and attempting to cast it to a Parameter. The solution is to put an if statement like so:
which works since my passed in conv_parameter should be equal to the weight stored in self.conv1, so we can just ignore the conversion to Parameter when using the quantized network.