Add missing functions and methods for channelwise quantization (#24934)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24934
1) Functions and methods to get scales and zero_points for channelwise quantization were missing. Adding these.
2) Correctly print quantized tensors for channelwise quantization.
ghstack-source-id: 88868339
Test Plan:
buck test mode/dev caffe2/test:quantized -- 'test_qtensor\ \(test_quantized_tensor.TestQuantizedTensor\)' --print-passing-details
```
Running 1 tests
Started new test run: https://our.intern.facebook.com/intern/testinfra/testrun/1970324844629541
✓ caffe2/test:quantized - test_qtensor (test_quantized_tensor.TestQuantizedTensor) 0.161 1/1 (passed)
Test output:
> test_qtensor (test_quantized_tensor.TestQuantizedTensor) ... ok
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.161s
>
> OK
Finished test run: https://our.intern.facebook.com/intern/testinfra/testrun/1970324844629541
Summary (total time 6.61s):
PASS: 1
FAIL: 0
SKIP: 0
FATAL: 0
TIMEOUT: 0
OMIT: 0
```
To be added in a followup diff.
Current output for printing qtensors:
print(W_q.int_repr())
print(W_q)
```
> tensor([[[[-3, 0, 0],
> [ 4, -2, -4],
> [-1, -3, -2]],
>
> [[-3, 1, 3],
> [-3, -3, 3],
> [-3, -5, -1]]],
>
>
> [[[ 4, -3, -4],
> [ 4, -3, -3],
> [ 4, -1, -1]],
>
> [[ 2, -3, 0],
> [ 3, 1, 1],
> [ 2, -4, 0]]]], dtype=torch.int8)
> tensor([[[[-0.9273, -0.2318, -0.2318],
> [ 0.6955, -0.6955, -1.1592],
> [-0.4637, -0.9273, -0.6955]],
>
> [[-0.9273, 0.0000, 0.4637],
> [-0.9273, -0.9273, 0.4637],
> [-0.9273, -1.3910, -0.4637]]],
>
>
> [[[ 0.3938, -0.1575, -0.2363],
> [ 0.3938, -0.1575, -0.1575],
> [ 0.3938, 0.0000, 0.0000]],
>
> [[ 0.2363, -0.1575, 0.0788],
> [ 0.3150, 0.1575, 0.1575],
> [ 0.2363, -0.2363, 0.0788]]]], size=(2, 2, 3, 3), dtype=torch.qint8,
> quantization_scheme=torch.per_channel_affine,
> scale=tensor([0.2318, 0.0788]), zero_point=tensor([ 1, -1]))
```
Differential Revision: D16659715
fbshipit-source-id: f8d3eeaff8f618aa0cca4fd076db73318e6df946