Jerry Zhang
c98896b76f
[quant][pt2e] Add more precise representation for quantized add ( #104130 )
...
Summary:
The planned e2e for quantization in pytorch 2.0 export is the following:
float_model -> prepare_pt2e -> calibration -> convert_pt2e -> ...
inside convert_pt2e, we will first produce a q/dq representation of the quantized model, similar to the previous output of
convert_to_reference_fx in fx grah mode quantization:
```
torch.ops.quantized_decomposed.dequantize_per_tensor -> torch.ops.aten.add -> torch.ops.quantized_decomopsed.quantize_per_tensor
torch.ops.quantized_decomposed.dequantize_per_tensor /
```
Then we'll rewrite the above to a more precise representation that express the intention in a more precise manner, since
here we actually want to do int8 addition, instead of simulating the int8 addition with fp32 operations, the representation for
quantized add is:
```
def quantized_add(x_i8, x_scale, x_zero_point, y_i8, y_scale, y_zero_point, out_scale, out_zero_point):
x = (x_scale / out_scale) * x_i8
y = (y_scale / out_scale) * y_i8
out = x + y
out -= (x_zero_point * x_scale - y_zero_point * y_scale) / out_scale
out += out_zero_point
return out
```
Test Plan:
```
buck2 test caffe2/test:quantization_pt2e -- --exact 'caffe2/test:quantization_pt2e - test_representation_add (quantization.pt2e.test_quantize_pt2e.TestQuantizePT2E)'
```
Reviewed By: kimishpatel
Differential Revision: D45628032
Pull Request resolved: https://github.com/pytorch/pytorch/pull/104130
Approved by: https://github.com/kimishpatel
2023-06-27 20:11:30 +00:00
..
2023-03-01 19:01:18 +00:00
2023-05-23 02:20:10 +00:00
2023-02-23 11:38:27 +00:00
2023-03-07 01:19:46 +00:00
2023-04-26 21:10:55 +00:00
2023-02-12 22:20:53 +00:00
2023-06-27 00:37:26 +00:00
2023-03-20 00:56:57 +00:00
2023-06-23 11:01:44 +00:00
2023-02-12 22:20:53 +00:00
2023-03-16 16:18:08 +00:00
2023-06-27 19:00:25 +00:00
2023-06-15 16:16:50 +00:00
2023-06-26 23:05:03 +00:00
2023-06-27 09:53:20 +00:00
2023-06-26 23:05:03 +00:00
2023-06-27 18:14:29 +00:00
2023-06-26 23:05:03 +00:00
2023-06-23 14:38:50 +00:00
2023-05-16 14:08:44 +00:00
2023-06-27 20:08:40 +00:00
2023-06-27 03:43:06 +00:00
2022-12-08 02:27:48 +00:00
2023-05-02 18:32:36 +00:00
2023-02-12 22:20:53 +00:00
2023-06-22 18:05:10 +00:00
2023-06-23 22:50:17 +00:00
2023-02-12 22:20:53 +00:00
2023-06-23 03:53:15 +00:00
2023-05-17 17:08:48 +00:00
2023-06-22 19:41:54 +00:00
2023-06-27 20:11:30 +00:00
2023-04-23 23:09:51 +00:00
2023-05-18 20:29:08 +00:00
2023-02-07 18:27:01 +00:00
2023-05-27 12:10:36 +00:00
2023-03-08 21:01:27 +00:00
2023-03-08 21:01:27 +00:00
2023-02-12 22:20:53 +00:00
2022-12-29 05:32:42 +00:00
2023-06-27 15:54:34 +00:00
2023-04-01 01:43:33 +00:00
2023-04-15 00:37:45 +00:00
2023-06-22 15:38:45 +00:00
2023-06-22 21:52:35 +00:00
2023-05-25 21:21:30 +00:00
2023-02-12 01:01:25 +00:00
2023-03-22 19:09:08 +00:00
2023-04-12 03:02:06 +00:00
2023-04-14 02:02:16 +00:00
2023-05-05 05:25:03 +00:00
2022-08-05 16:12:08 +00:00
2023-06-07 17:28:31 +00:00
2023-06-23 11:01:44 +00:00
2023-06-14 01:43:21 +00:00
2023-04-17 23:46:08 +00:00
2023-06-27 05:32:05 +00:00
2023-03-07 18:30:27 +00:00
2023-06-22 00:07:44 +00:00
2023-03-07 18:30:27 +00:00
2023-03-07 18:30:27 +00:00
2023-06-27 05:32:05 +00:00
2023-06-16 16:55:51 +00:00
2023-05-18 00:57:12 +00:00
2023-05-19 22:50:18 +00:00
2023-05-24 02:22:58 +00:00
2023-02-07 21:10:56 +00:00
2022-09-26 15:35:47 +00:00
2023-05-27 02:36:16 +00:00
2023-06-10 01:59:55 +00:00
2023-06-15 02:33:12 +00:00
2023-06-16 16:55:51 +00:00
2023-06-20 19:34:02 +00:00
2023-06-21 09:26:33 +00:00
2023-01-12 01:26:50 +00:00
2023-02-07 21:10:56 +00:00
2023-04-28 02:20:13 +00:00
2023-06-21 22:04:30 +00:00
2023-05-24 07:05:30 +00:00
2023-04-23 05:13:40 +00:00
2023-05-05 23:20:17 +00:00
2022-12-22 19:41:53 +00:00
2023-06-26 06:59:48 +00:00
2023-04-11 12:44:25 +00:00
2023-06-14 05:41:43 +00:00
2023-02-12 22:20:53 +00:00
2023-04-25 15:02:13 +00:00
2023-03-01 19:01:18 +00:00
2023-02-12 22:20:53 +00:00
2023-02-09 20:16:49 +00:00
2023-04-23 23:09:51 +00:00
2023-02-12 22:20:53 +00:00
2023-02-09 20:16:49 +00:00
2023-06-10 05:17:17 +00:00
2023-02-09 20:16:49 +00:00
2023-02-09 20:16:49 +00:00
2023-05-10 15:46:45 +00:00
2023-04-17 16:05:16 +00:00
2023-06-08 06:51:10 +00:00
2023-06-24 18:36:45 +00:00
2023-01-04 21:08:32 +00:00
2023-05-24 05:37:51 +00:00
2023-04-18 06:19:30 +00:00
2023-06-22 11:18:05 +00:00
2023-02-12 22:20:53 +00:00
2023-06-10 05:17:17 +00:00
2023-06-10 05:17:17 +00:00
2023-02-12 22:20:53 +00:00
2023-02-10 18:02:50 +00:00
2023-03-10 03:51:41 +00:00
2023-06-25 00:36:10 +00:00
2023-06-15 15:51:03 +00:00
2023-02-07 21:10:56 +00:00
2023-04-17 23:46:08 +00:00
2022-12-02 21:36:13 +00:00
2023-05-18 16:15:34 +00:00
2023-05-11 03:10:23 +00:00
2022-10-31 04:06:31 +00:00
2023-05-03 02:27:08 +00:00
2023-06-26 21:47:22 +00:00
2023-04-28 20:47:00 +00:00
2023-03-01 19:01:18 +00:00
2023-03-01 19:01:18 +00:00
2022-11-22 00:13:38 +00:00
2023-05-23 18:31:29 +00:00
2023-04-25 15:02:13 +00:00
2023-06-22 03:01:43 +00:00
2023-05-12 16:41:44 +00:00
2023-04-06 19:42:26 +00:00
2023-03-10 19:10:43 +00:00
2022-08-09 18:53:19 +00:00
2023-06-21 22:04:30 +00:00
2023-06-22 11:18:05 +00:00
2023-03-22 19:09:08 +00:00
2023-06-23 19:46:42 +00:00
2023-06-21 22:04:30 +00:00
2023-06-23 10:53:15 +00:00
2023-06-17 06:10:23 +00:00
2023-02-20 04:59:11 +00:00
2023-05-03 23:52:58 +00:00
2023-04-27 20:12:42 +00:00
2023-04-23 01:59:45 +00:00
2023-06-23 03:53:15 +00:00
2023-02-21 17:13:38 +00:00
2023-06-02 07:41:28 +00:00
2023-06-26 16:45:04 +00:00
2023-06-27 19:21:06 +00:00
2023-06-23 18:40:15 +00:00
2023-04-19 17:23:40 +00:00
2023-05-08 23:36:57 +00:00
2023-02-12 22:20:53 +00:00
2022-09-26 20:07:13 +00:00
2023-05-04 12:31:55 +00:00
2023-05-12 16:18:22 +00:00
2023-04-25 15:02:13 +00:00
2023-02-15 01:21:10 +00:00
2023-04-27 15:10:50 +00:00
2023-02-12 22:20:53 +00:00
2023-06-21 02:53:22 +00:00
2023-06-26 23:05:03 +00:00
2023-03-30 14:34:24 +00:00
2023-03-30 14:34:24 +00:00
add Half support for logsigmoid, threshold, elu, gelu, hardtanh, hardsigmoid, hardswish, hardshrink, softshrink, leakyrelu, softplus, glu, silu, mish, and prelu on CPU ( #98745 )
2023-05-27 16:20:21 +00:00
2023-05-31 22:08:04 +00:00
2023-04-09 01:30:55 +00:00
2023-02-12 22:20:53 +00:00
2023-02-07 21:10:56 +00:00
2023-02-12 22:20:53 +00:00