Commit Graph

36 Commits

Author SHA1 Message Date
Vasiliy Kuznetsov
ab8a99bd36 graph mode: add hardswish inplace handling (#40284)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40284

Adds graph mode handling for inplace hardswish, and test coverage for functional hardswish.

Test Plan:
```
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_hardswish
```

Imported from OSS

Differential Revision: D22140628

fbshipit-source-id: 55a514f7dc1130d510f69ee4e611d7cb5e08d02e
2020-06-21 09:40:50 -07:00
Vasiliy Kuznetsov
c6dbfcaf9e quantized elu: graph mode handling (#40111)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40111

Adds graph mode handling for quantized elu.

Test Plan:
```
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_elu
```

Imported from OSS

Differential Revision: D22075080

fbshipit-source-id: 37fb1b9e390f2a33d47cbd025157532379b6aa64
2020-06-21 09:40:48 -07:00
Vasiliy Kuznetsov
13d54c6471 quantized elu: require observation (#40100)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40100

ELU has a range of [-1, inf]. In the original PR which added
the quantized operator we decided to pass the quantization params
from the input.  However, it makes more sense to require observation
for this op.

This PR changes the API to require observation. Next PRs in this stack
will add the eager and graph mode handling.

Test Plan:
```
python test/test_quantization.py TestQuantizedOps.test_qelu
```

Imported from OSS

Differential Revision: D22075083

fbshipit-source-id: 0ea0fd05a00cc7a5f122a2b1de09144bbd586f32
2020-06-21 09:38:28 -07:00
Zafar
9da277c635 [quant][graphmodel] linear_relu (#40021)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40021

This replaces #36889 due to significant merge conflicts

Test Plan: Imported from OSS

Differential Revision: D22087061

Pulled By: z-a-f

fbshipit-source-id: 6a65cdd3c0c0c957968a9d017902fb6d03b58150
2020-06-19 23:32:54 -07:00
Vasiliy Kuznetsov
fcc9a1e664 graph mode: move hardsigmoid op to single_input_general_value category (#40055)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40055

Noticed this while reading the `helper.cpp` file, seems like this op
should be in the `single_input_general_value` bucket.

Test Plan:
CI

Imported from OSS

Differential Revision: D22054257

fbshipit-source-id: 2ca16ff863d644cbd03c3938eeca0fb87e3e4638
2020-06-18 10:21:22 -07:00
Jerry Zhang
d4e4f13173 [quant][graphmode] Add support for detach (#40197)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/40197

Test Plan: Imported from OSS

Differential Revision: D22106544

fbshipit-source-id: 047236bf8c7cb0813563e6c7bcd41b79dfa6fb2b
2020-06-18 10:01:43 -07:00
Jerry Zhang
461aa8a1e2 [quant][graphmode] Support quantizing repeat (#39925)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39925

Test Plan: Imported from OSS

Differential Revision: D22014883

fbshipit-source-id: 3076e64948f7ebdd99355f32185e2c716b113b43
2020-06-16 12:29:11 -07:00
Jerry Zhang
181ea1acce [quant][graphmode] Support squeeze/unsqueeze (#39924)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39924

Test Plan: Imported from OSS

Differential Revision: D22014713

fbshipit-source-id: 76d6d8509062ff9203979b0d2f0cfb01778b3c2f
2020-06-16 11:03:32 -07:00
Jerry Zhang
144e8dc5a3 [quant][graphmode] Use quantizedbatch_norm in graph mode (#39911)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39911

Test Plan: Imported from OSS

Differential Revision: D22012282

fbshipit-source-id: 98af55172cbeaa7080865d6533df21647a7cedfa
2020-06-16 00:58:11 -07:00
Jerry Zhang
f37b8e73f4 [quant][graphmode] Support prim:TupleUnpack and prim::TupleConstruct (#39895)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39895

Test Plan: Imported from OSS

Differential Revision: D22009854

fbshipit-source-id: a5dab2b4f943e5e047ba9e8573088adf66f5da6b
2020-06-15 18:55:15 -07:00
Jerry Zhang
99084104b6 [quant][graphmode][refactor] isScalar check (#39892)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39892

Test Plan: Imported from OSS

Differential Revision: D22009856

fbshipit-source-id: fbc407499bcff0f25e44eedba3d6cd1225325c24
2020-06-12 10:53:35 -07:00
Jerry Zhang
246d7bb41d [quant][graphmode] Quantizing traced modules (#39826)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39826

Expanding operator test coverage to traced modules

Test Plan: Imported from OSS

Differential Revision: D21991266

fbshipit-source-id: 73b1d94caa6ad41bb0d6cbde7ba0de343da3e7ff
2020-06-12 00:55:11 -07:00
Jerry Zhang
c3d4053bc0 [quant][graphmode] Support quantized::batch_norm2d_relu fusion for tracing (#39645)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39645

This PR added quantization support for handling BatchNorm2d and ReLU(or F.relu) in both
scripting and tracing

Test Plan:
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_qbatchnorm_relu

Imported from OSS

Differential Revision: D21942111

fbshipit-source-id: 680e16076a37b96d2485d5cbc39ce9a045c319c3
2020-06-10 23:32:59 -07:00
Vasiliy Kuznetsov
5d2f6d86e5 graph mode: add quantization type enum (#39795)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39795

Replaces the `is_dynamic` bool by enums in Python and c++
graph quantization code.  This makes the code more readable
and will make it easier to modify for adding QAT logic in the future.

Test Plan:
CI, as well as
```
python test/test_quantization.py TestQuantizeDynamicScript
python test/test_quantization.py TestQuantizeScriptJitPasses
```

Imported from OSS

Differential Revision: D21981643

fbshipit-source-id: d475760407bcc794aeae92a2c696bac4acda843d
2020-06-10 21:34:23 -07:00
Jerry Zhang
7994d6e147 [quant][graphmode] Support quantization for aten::append (#39644)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39644

Test Plan: Imported from OSS

Differential Revision: D21942112

fbshipit-source-id: 8dc5871cbde9e9cc161a624c2b07e2e74bc0ff6d
2020-06-10 11:29:27 -07:00
Jerry Zhang
2a06a6935c [quant][graphmode] Support propagate dequantize for nodes with multiple outputs (#39551)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39551

e.g. prim::ListUnpack

Test Plan: Imported from OSS

Differential Revision: D21942108

fbshipit-source-id: 6fd7c972ca70692ec52c296b6a1e858324e66c12
2020-06-09 17:31:16 -07:00
Jerry Zhang
9551fb22d6 [quant][graphmode] Preserve numerics in debug option for clamp ops (#39219)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39219

We didn't model clamp ops correctly right now, this PR fixes that.

Reason is quantized clamp op quantizes the scalar arguments in the op implementation: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp#L614-L617

So we'll need to model this explicitly in the IR.
When we see a `aten::dequantize - aten::clamp(%x, %min, %max)`
we first make a scalar tensor with `aten::scalar_tensor(%scalar, ...)`, then we quantize the tensor with the same quantization parameters from the input tensor of the `aten::clamp`, dequantize the tensor, then convert the dequantized tensor to scalar using `aten::item`.

Test Plan: Imported from OSS

Differential Revision: D21831350

fbshipit-source-id: d60731459a0465d64946aabc62065d25d92faefc
2020-06-08 17:15:39 -07:00
Vasiliy Kuznetsov
ebdff07d49 instancenorm: static quant graph mode support (#39096)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39096

Hooks up instancenorm for graph mode static quant

Test Plan:
```
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_instance_norm
```

Imported from OSS

Differential Revision: D21885258

fbshipit-source-id: 650cc5b162dda044866176fea6c345082d9788ed
2020-06-07 13:38:28 -07:00
Vasiliy Kuznetsov
b443ca26c5 groupnorm: graph mode static quant support (#39095)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39095

Hooks up groupnorm to graph mode static quant

Test Plan:
```
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_group_norm
```

Imported from OSS

Differential Revision: D21885257

fbshipit-source-id: 3415c4de76181b026d2f5bfebab130fea29e1d1e
2020-06-07 13:38:22 -07:00
Jerry Zhang
6d13b583a7 [quant][graphmode] Support conv*d_relu in traced models (#39490)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39490

Test Plan: Imported from OSS

Differential Revision: D21917117

fbshipit-source-id: c96633aaaa347529cc1ca6ca1c982cfb04675ccf
2020-06-07 07:36:20 -07:00
Jerry Zhang
e4627e5dba [quant][graphmode] Fix add_relu patterns for scripting and tracing (#39455)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39455

1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan: Imported from OSS

Differential Revision: D21917118

fbshipit-source-id: e67b55cd1c070fd4238f563d933a6f10a3582ae3
2020-06-06 23:51:34 -07:00
Jerry Zhang
a8d8fc5532 [quant][graphmode] Different rule for add/add_/mul/mul_ (#38667)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38667

Test Plan: Imported from OSS

Differential Revision: D21633555

fbshipit-source-id: 03b0298e83bf4dbda41b048c0edc7bb92cd4e1df
2020-05-20 19:43:46 -07:00
Jerry Zhang
1ef77f9045 [quant][graphmode] Different rule for handling aten::cat (#38570)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38570

We changed the rule of quantizing `aten::cat`, previously `aten::cat` is considered to be
an op that should always be quantized, like `aten::conv2d`, but this is not ideal, a better
way is to quantize the output of `aten::cat` depending on whether the input is quantized, if it is
then we'll quantize the output, if not, then we will not quantize the output, since `aten::cat` works both on
quantized and non-quantized tensor.

Test Plan: Imported from OSS

Differential Revision: D21600160

fbshipit-source-id: efa957e0eaa608fffefcdfefa7f442fab45605eb
2020-05-19 11:23:35 -07:00
Supriya Rao
97abed7cbe [quant] Remove TensorListObserver (#38584)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38584

All observers will support tensor lists in future PR

Test Plan: Imported from OSS

Differential Revision: D21623464

fbshipit-source-id: c5c57ecfe14f7c3aa92b7c99d724e846132ae03b
2020-05-18 15:49:34 -07:00
Jerry Zhang
6232481cab [quant][graphmode] Add RemoveReduantDequantize pass (#38434)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38434

We insert dequantize for each use in order to produce quantization patterns that will
later be fused, after that we should also remove extra dequantize node produced by this operation.

Test Plan: Imported from OSS

Differential Revision: D21597834

fbshipit-source-id: 18dfb2760bbb08932aa4e1d06f96cfc5fb37ed88
2020-05-15 15:01:40 -07:00
Jerry Zhang
504637a171 [quant][graphmode] Support ops with fixed quantization parameters (#38278)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38278

Support ops like aten::hardsigmoid that has a fixed quantization parameters:
```
  constexpr float o_scale = 1.0f / 256.0f;
  constexpr int32_t o_zero_point = 0;
```

Ops supported:
- hardsigmoid
- sigmoid
- tanh

Test Plan: Imported from OSS

Differential Revision: D21559811

fbshipit-source-id: 26f3c9c3389dea4f07b350172e2974fac8c5c470
2020-05-14 16:36:06 -07:00
Jerry Zhang
eb66dd0bc8 [quant][graphmode][refactor] Refactor propagateQuantizationOps (#38276)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38276

Test Plan: Imported from OSS

Differential Revision: D21559814

fbshipit-source-id: 31331415c30f59cde0af478cfad5e890e994ef71
2020-05-13 19:07:38 -07:00
Jerry Zhang
7ce733d218 [quant][graphmode] Move leaky_relu to general value op map (#38166)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38166

Test Plan: Imported from OSS

Differential Revision: D21559813

fbshipit-source-id: 8521f7ad2b0fcd6f87090fb40517d5d92c37ba54
2020-05-13 17:51:14 -07:00
Jerry Zhang
16696186e1 [quant][graphmode] Move elu to general value ops map (#38165)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38165

Test Plan: Imported from OSS

Differential Revision: D21559812

fbshipit-source-id: 55bc28d71d0b8a1c33e05bce20a802db1015ea0b
2020-05-13 17:51:09 -07:00
Jerry Zhang
98d78a7f20 [quant][graphmode] Move hardtanh to general value ops map (#38164)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38164

Test Plan: Imported from OSS

Differential Revision: D21559808

fbshipit-source-id: 7b00e40cfa58806ce8675a61073778c4d77f8a8b
2020-05-13 17:51:03 -07:00
Jerry Zhang
1fde373f2f [quant][graphmode] Move clamp to general value ops map (#38163)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38163

Test Plan: Imported from OSS

Differential Revision: D21559805

fbshipit-source-id: db02bd17fbc6d1335fe021265955d02d52d139e6
2020-05-13 17:50:57 -07:00
Jerry Zhang
e988b4fbb1 [quant][graphmode] Move interpolate to general value ops (#38162)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38162

Test Plan: Imported from OSS

Differential Revision: D21559810

fbshipit-source-id: 2d975fc71f73c18f594108172850dfcfdb0cb9a0
2020-05-13 17:49:08 -07:00
Supriya Rao
7d7d73655d [quant][graphmode] Add quantizedconv1d to graphmode (#38341)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38341

Test Plan:
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_quantized_conv1d

Imported from OSS

Differential Revision: D21554256

fbshipit-source-id: baf78c7788a38acd9362204990f0b22c21263dfb
2020-05-13 16:59:24 -07:00
Jerry Zhang
d403b85c00 [quant][graphmode] Move aten::mean to general value ops (#38160)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38160

Test Plan: Imported from OSS

Differential Revision: D21512971

fbshipit-source-id: 98cb1cc0eec5e7b140dcdf4e756bdbcd724b98f3
2020-05-13 11:39:22 -07:00
Jerry Zhang
f2c6346ebe [quant][graphmode] Move avg_pool/adaptive_avg_pool to general value ops (#38330)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/38330

Test Plan:
python test/test_quantization.py TestQuantizeScriptPTSQOps.test_quantize_general_value_ops

Imported from OSS

Differential Revision: D21533452

fbshipit-source-id: 56928d93624f7c3d5c61f2627a19c5d3bb595202
2020-05-13 09:22:24 -07:00
Jerry Zhang
0ed7fc581c [quant][graphmode][refactor] Split quantization.cpp (#37975)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/37975

Test Plan:
.

Imported from OSS

Differential Revision: D21468497

fbshipit-source-id: 35cbf98a344ca6e4094d616a4040eacf017fd2de
2020-05-08 12:24:50 -07:00