pytorch
810c68fb - [OpBench] fix jit tracing with quantized op/tensor by enabling `_compare_tensors_internal` to compare quantized tensors (#46772)

Commit
4 years ago
[OpBench] fix jit tracing with quantized op/tensor by enabling `_compare_tensors_internal` to compare quantized tensors (#46772) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/46772 When running `buck run caffe2/benchmarks/operator_benchmark/pt:qactivation_test -- --use_jit`, I encountered the following error P146518683. The error was traced down to the fact that `torch.allclose` does not work with quantized tensors (the error was triggered by this particular multiplication https://fburl.com/diffusion/8vw647o6 since native mul can not work with a float scalar and a quantized tensor.) Minimum example to reproduce: ```(Pdb) input = torch.ones(5) (Pdb) aa = torch.quantize_per_tensor(input, scale=1.0, zero_point=0, dtype=torch.quint8) (Pdb) bb = torch.quantize_per_tensor(input, scale=1.0, zero_point=0, dtype=torch.quint8) (Pdb) torch.allclose(aa, bb) Comparison exception: promoteTypes with quantized numbers is not handled yet; figure out what the correct rules should be, offending types: QUInt8 Float ``` Here the proposed fix is to compare quantized tensors strictly within `_compare_tensors_internal`. The other two possible fixes are: 1. convert quantized tensors to float tensors first before sending them to `torch.allclose` 2. change `torch.allclose` to handle quantized tensor. Test Plan: buck run caffe2/benchmarks/operator_benchmark/pt:qactivation_test -- --use_jit Reviewed By: kimishpatel Differential Revision: D24506723 fbshipit-source-id: 6426ea2a88854b4fb89abef0edd2b49921283796
Author
Yang Wang
Parents
Loading