Commit Graph

20 Commits

Author SHA1 Message Date
Jerry Zhang
3f72bcfcaa Remove _dequantize_per_tensor (#26681)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26681

att

Test Plan:
ci

Imported from OSS

Differential Revision: D17542833

fbshipit-source-id: 653e906b0e146763609c69ef0de7f9cf38621586
2019-09-24 10:54:56 -07:00
Dmytro Dzhulgakov
ade60f8a8d Allow per-channel QTensor accept any floating type for scales (#26676)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26676

Just makes it more user-friendly to be able to pass any floating point or int point values to scales or zero_points for per-channel quantization. It matches behavior or per tensor quantizer where those arguments are scalars (not tensors) and thus automatic casting is applied.

Test Plan: Imported from OSS

Differential Revision: D17537051

Pulled By: dzhulgakov

fbshipit-source-id: e955ccdb5b4691828a559dc8f1ed7de54b6d12c4
2019-09-23 22:29:05 -07:00
Dmytro Dzhulgakov
b93823cb65 Per-channel quantized tensor to have only a single axis (#26675)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26675

Based on offline poll, we're very unlikely to have multi-axis quantized tensors in the foreseeable future. Let's simplify API and just return int instead of list. It also matches the singular `axis` name.

Test Plan: Imported from OSS

Differential Revision: D17537052

Pulled By: dzhulgakov

fbshipit-source-id: 676abc3b251d288468aaed467b5e5ca4063b98b0
2019-09-23 22:29:01 -07:00
Dmytro Dzhulgakov
9aad4d7b5f Fix _empty_per_channel_affine_quantized to be less hacky (#26243)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26243

This is an attempt to fix _empty_per_channel_affine_quantized to be more sane. It's a factory function that nevertheless receives a Tensor argument and it throws the codegen off course.

Before people did a hacky workaround of appending _like to the function name to trick codegen, it also required non-natural argument order.

This PR explicitly allows to override the 'category' of the function to make codegen do the right thing. Now name and the argument order (in C++) make more sense.

Test Plan: Imported from OSS

Differential Revision: D17443221

Pulled By: dzhulgakov

fbshipit-source-id: c98c1c74473d8cbf637f511d26ceb949d8ae2a1a
2019-09-23 22:28:58 -07:00
Jerry Zhang
aa95c7951e _per_channel_affine_qtensor -> _make_per_channel_quantized_tensor (#26679)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26679

making it more explicit that it's a factory function.

Test Plan:
ci

Imported from OSS

Differential Revision: D17540861

fbshipit-source-id: bf66c87d6afad411afd5620cf2143a8f5596ad6b
2019-09-23 19:01:27 -07:00
Jerry Zhang
d63143dc5b _per_tensor_affine_qtensor -> _make_per_tensor_quantized_tensor (#26678)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26678

making it more explicit that it's a factory function.

Test Plan:
ci

Imported from OSS

Differential Revision: D17540862

fbshipit-source-id: 14c5a4dcc7bb85ae849c9e4e0882601005e2ed3a
2019-09-23 18:27:53 -07:00
Dmytro Dzhulgakov
ebc2365fd3 Serialization for per channel qtensor (#26339)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26339

Serializes per-channel tensor in both torch.serialization and jit. Since we didn't bind Quantizer properly yet, I chose to save a tuple representing quantizer settings. To avoid recursive tensor serialization calls, I'm using tuple instead of tensor to store scales and zero points.

driazati - please check the serialization logic. Is there a good test that compares that JIT serialization and python serialization are equivalent? (I haven't tested it yet)

Test Plan: Imported from OSS

Differential Revision: D17443222

Pulled By: dzhulgakov

fbshipit-source-id: a34758de1ffd2ec1cdc5355f5baf95284a4ccf4b
2019-09-23 13:28:11 -07:00
Jerry Zhang
95cb22f21f _dequantize_linear -> _dequantize_per_tensor (#26576)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26576

to match `quantize_per_tensor`

Test Plan:
ci

Imported from OSS

Differential Revision: D17517439

fbshipit-source-id: 8c20f9b5d2a50d0e42e4444994b0987e6204ac56
2019-09-21 11:52:19 -07:00
Jerry Zhang
2e82ee0335 quantize_linear_per_channel -> quantize_per_channel (#26575)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26575

To keep consistent with `quantize_per_tensor` we also
rename `quantize_linear_per_channel` to `quantize_per_channel`

Test Plan:
ci

Imported from OSS

Differential Revision: D17517360

fbshipit-source-id: 3af7d8f0fbe99148b79fcb1ad2fe811f776590cd
2019-09-21 11:02:17 -07:00
Jerry Zhang
254122dd4e quantize_linear -> quantize_per_tensor (#26574)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26574

Since we also have `quantized::linear`, `quantize_linear` sounds
confusing, so we plan to rename it before the branch cut

Test Plan:
ci

Imported from OSS

Differential Revision: D17514876

fbshipit-source-id: 01d9005e6ec8cb9950b9d8bba122109c389641d3
2019-09-20 21:58:48 -07:00
Dmytro Dzhulgakov
8c1354c31b Implement more support for per-channel quantization (#26240)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26240

In particular adds support for empty/empty_like which is needed for memory layouts to work.

Test Plan: Imported from OSS

Differential Revision: D17443220

Pulled By: dzhulgakov

fbshipit-source-id: 9c9e25981999c0edaf40be104a5741e9c62a1333
2019-09-19 13:39:17 -07:00
Brian Vaughan
f0c6021846 fix bug in assertNotEqual for int tensors (#25412)
Summary:
re-apply: https://github.com/pytorch/pytorch/pull/25199
but without a failing quantized test
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25412

Differential Revision: D17131303

Pulled By: nairbv

fbshipit-source-id: edf7736af3ede5e809eded72be9514e922e70db4
2019-08-30 06:52:30 -07:00
Zafar Takhirov
e8acc2ebb1 Removing future imports from the test fixtures.
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/25296

Test Plan: Imported from OSS

Differential Revision: D17090201

Pulled By: zafartahirov

fbshipit-source-id: 5a4f6ac0ea475b55d2c610e2f9f4f0cef8690e8f
2019-08-29 01:39:59 -07:00
Daya Khudia
12ea1d74f0 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
2019-08-23 15:44:16 -07:00
Daya Khudia
aba15ce904 Per Channel quantization APIs (#24935)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24935

Adding per channel qtensor creation APIs

Added two tests:

EmptyPerchannelQuantized in aten/src/ATen/test/quantized_test.cpp

test_perchannel_qtensor_creation in test/test_quantized_tensor.py
ghstack-source-id: 88888140

Test Plan: buck test mode/dev caffe2/test:quantized -- 'test_per_channel_qtensor_creation'  --print-passing-details

Differential Revision: D16696959

fbshipit-source-id: f179247cc1c461bec215e17b51263060003493a5
2019-08-23 14:49:32 -07:00
James Reed
173dc5d16f __reduce__ for QScheme (#24969)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24969

This allows pickling qscheme objects

Test Plan: Imported from OSS

Differential Revision: D16946567

Pulled By: jamesr66a

fbshipit-source-id: 57dbedb1e1aca2a2e17916eed662f727053ea926
2019-08-21 19:08:54 -07:00
Jerry Zhang
6791f395f9 support at::view and at::reshape for quantized tensor (#23046)
Summary:
att

Pull Request resolved: https://github.com/pytorch/pytorch/pull/23046
ghstack-source-id: 86840501

Differential Revision: D16368897

fbshipit-source-id: 9da232c11f21af5f850cd9545e56996a81791d00
2019-07-19 23:34:04 -07:00
Supriya Rao
3507eaf3ea Add clone() implementation for QTensor (#22510)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22510

Added a new function to implement clone operation on quantized tensors. Also added a test case which can be tested as shown in test plan.

This change is required to be able to call torch.jit.trace on quantized models.
Clone implementation calls copy_ on QTensor internally.

Differential Revision: D16059576

fbshipit-source-id: 226918cd475521b664ed72ee336a3da8212ddcdc
2019-07-05 11:24:53 -07:00
Gregory Chanan
e74b0fc87c Fix empty_like for quantized tensors. (#21978)
Summary:
empty_like uses the tensor options of `self`, rather than the passed in tensor options.  This means it messes up variable/tensor types, and ignores specifications like different dtypes.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21978

Differential Revision: D15903948

Pulled By: gchanan

fbshipit-source-id: f29946be01c543f888daef2e99fe928e7b7d9d74
2019-07-02 10:28:59 -07:00
Jerry Zhang
91bf0a9f9d Move quantized tensor tests in test_torch.py to test_quantized_tensor.py (#22089)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22089

att

Reviewed By: jianyuh

Differential Revision: D15950101

fbshipit-source-id: 70acdeeef3a05201d72f986d5a0005832efd75ff
2019-06-21 22:48:34 -07:00