-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge qdq and quant-to-int passes (#2458)
This PR does the followings: 1. Merges `stablehlo-legalize-quantized-op-to-qdq` into `stablehlo-legalize-quant-to-int`. 1. Rename `stablehlo-legalize-quant-to-int` to `stablehlo-legalize-quant-to-math`. This is to clarify for scenario when the fallback `qdq` is used and sull integer quantized program cannot be generated. 1. Removes `stablehlo-legalize-quantized-op-to-qdq` pass and replace its uses with `stablehlo-legalize-quant-to-math`. 1. Remove QDQ lit checks from `stablehlo/tests/ops_stablehlo_quantized.mlir` and merges the tests added for qdq pass in `stablehlo/tests/stablehlo_legalize_quant_to_int.mlir` 1. Updates the tests in `stablehlo/tests/stablehlo_legalize_quant_to_int.mlir` updating __only__ negatives tests, which are previously unhanded by `stablehlo-legalize-quant-to-int`. The current `stablehlo-legalize-quant-to-math` uses the fallback to handle these cases. 1. About the pass `stablehlo-legalize-quant-to-math` - It uses `Patternbenefit` to assign highest priority (`benefit=10`) to pattern which has specialized handling in `stablehlo-legalize-quant-to-int`. Next in priority (`benefit=0`) are the QDQ patterns. With that the following program, which `stablehlo-legalize-quant-to-int` has specialized handling, will avoid the fallback path. ``` func.func @max_per_tensor_same_quant_parameters( %arg0: tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>> ) -> tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>> { %0 = "stablehlo.maximum"(%arg0, %arg0) : ( tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>>, tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>> ) -> tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>> return %0 : tensor<1x2x!quant.uniform<i8:f32, 2.000000e+00:3>> } ``` whereas the following, which is not supported in `stablehlo-legalize-quant-to-int` will choose the fallback path. ``` func.func @max_per_tensor_diff_quant_parameters(%arg0: tensor<!quant.uniform<i8:f32,1.0:0>>, %arg1: tensor<!quant.uniform<i8:f32,2.0:1>>) -> tensor<!quant.uniform<i8:f32,3.0:2>> { %0 = "stablehlo.maximum"(%arg0, %arg1) : (tensor<!quant.uniform<i8:f32,1.0:0>>, tensor<!quant.uniform<i8:f32,2.0:1>>) -> tensor<!quant.uniform<i8:f32,3.0:2>> func.return %0 : tensor<!quant.uniform<i8:f32,3.0:2>> } ``` - Currently handles qdq fallback for AddOp and a bunch of `GenericOps` op [cs](https://github.com/openxla/stablehlo/blob/eba821aa1c54a21d70331d7926dfc8b929f988f3/stablehlo/transforms/StablehloLegalizeQuantToInt.cpp#L1239). qdq fallback for `dot_general` and `convolution` will be handled in a follow up PR. What this means is we will still see quantized dot_gneral/convolution program, which are currently unsupported by `stablehlo-legalize-quant-to-int`, error out. [childPR](#2459)
- Loading branch information
Showing
11 changed files
with
1,189 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
592 changes: 592 additions & 0 deletions
592
stablehlo/tests/stablehlo_legalize_quantized_op_to_qdq.mlir
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters