I am a little confused about the custom observed module when I read the Quantization Custom Module API docs.
The code snippet in the docs are as follows:
# custom observed module, provided by user
class ObservedCustomModule(torch.nn.Module):
def __init__(self, linear):
super().__init__()
self.linear = linear
def forward(self, x):
return self.linear(x)
@classmethod
def from_float(cls, float_module):
assert hasattr(float_module, 'qconfig')
observed = cls(float_module.linear)
observed.qconfig = float_module.qconfig
return observed
The ObservedCustomModule
class seems to do the same as CustomModule.linear
(torch.nn.Linear
) except add the qconfig
attribute.
Can someone provide a built-in observed module for reference?
If I want to customize an observed module for quantizing conv2d
with 2 bits, what should I do?