You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by Chunhuan Lin via TVM Discuss <no...@discuss.tvm.ai> on 2020/04/03 08:31:24 UTC

[TVM Discuss] [Questions] [QUANTIZATION][PYTORCH] Suitable pytorch api setting for relay quantization


I'm going to use pytorch frontend to parse a pytorch model and quantize the model. However, It's not clear for me, how should I set the pytorch quantization API to get same arithmetic results as Relay. 

For example, if I set the [QConfig API](https://pytorch.org/docs/stable/quantization.html#torch.quantization.QConfig) as below, and [convert](https://pytorch.org/docs/stable/quantization.html#torch.quantization.convert) the model to a quantized one, will Relay output same results  as the quantized pytorch model?

```
my_qconfig = QConfig(activation=FakeQuantize.with_args(observer=MovingAverageMinMaxObserver,
                                                            quant_min=0,
                                                            quant_max=255,
                                                            reduce_range=True),
                     weight=FakeQuantize.with_args(observer=MovingAveragePerChannelMinMaxObserver,
                                                               quant_min=-128,
                                                               quant_max=127,
                                                               dtype=torch.quint8,
                                                               qscheme=torch.per_channel_symmetric,
                                                               reduce_range=False,
                                                               ch_axis=0))
```





---
[Visit Topic](https://discuss.tvm.ai/t/quantization-pytorch-suitable-pytorch-api-setting-for-relay-quantization/6201/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/3244e71aae2ac122020008ae931f1e552e127fd6228b842e38275219ed93e2e6).

[TVM Discuss] [Questions] [QUANTIZATION][PYTORCH] Suitable pytorch api setting for relay quantization

Posted by Chunhuan Lin via TVM Discuss <no...@discuss.tvm.ai>.

Thanks a lot for your reply!





---
[Visit Topic](https://discuss.tvm.ai/t/quantization-pytorch-suitable-pytorch-api-setting-for-relay-quantization/6201/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/b2fc47b365e0438c70401556bdeb2001e8067b2691773574f827531cd7e82c51).

[TVM Discuss] [Questions] [QUANTIZATION][PYTORCH] Suitable pytorch api setting for relay quantization

Posted by masahi via TVM Discuss <no...@discuss.tvm.ai>.

I'm not sure what you are asking. Whatever qconfig you quantize your Torch model with, the converted Relay model is equivalent to the quantized Torch model.

But due to the difference in numerics, the raw floating point output between quantized torch models and converted Relay models can be slightly different. That's why there are difference in accuracy shown in https://github.com/apache/incubator-tvm/pull/4977.

FYI this is the qconfig I'm using.
https://github.com/Edgecortix-Inc/pytorch_quantization/blob/master/tvm_qnn_evaluation/test_util.py#L28-L34





---
[Visit Topic](https://discuss.tvm.ai/t/quantization-pytorch-suitable-pytorch-api-setting-for-relay-quantization/6201/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/32685b8ebe6808ac0eca6a29c6cc590cbed0f08d248469810d1374eb0d45a1ca).