How to set weight/bias in nn.quantized.Conv2d?

After executing this code

conv = torch.nn.quantized.Conv2d(3, 64, (3, 3), dtype=torch.quint8)
weight = torch.randn(64, 3, 3, 3)
weight = torch.quantize_per_channel(weight, torch.ones(64)/200, torch.zeros(64), axis=0, dtype=torch.quint8)
conv.set_weight_bias(weight, torch.zeros(64))

the error occurs:
RuntimeError: Unsupported qscheme: per_channel_affine_float_qparams

the api call is correct, but you’ll need to set the dtype for zero_point to int64 I think

weight = torch.quantize_per_channel(weight, torch.ones(64)/200, torch.zeros(64, dtype=torch.int64), axis=0, dtype=torch.quint8)

thank you. it solves the problem.

1 Like