Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the
qunt-to-math
pass limitation of Dot/Conv op result type (#…
…2462) [ParentPR](#2461) `quant-to-math` pass [assumes](https://github.com/openxla/stablehlo/blob/eba821aa1c54a21d70331d7926dfc8b929f988f3/stablehlo/transforms/StablehloLegalizeQuantToInt.cpp#L984) that the return type of quantized dot_general or convolution is always having `i32` as storage type. With that the following program with the result storage type of `i8`fail to materialize all the intermediate converted values. ``` func.func @dot_general_per_tensor_quantization(%arg0: tensor<2x3x4x!quant.uniform<i8:f32, 1.0:17>>, %arg1: tensor<2x3x5x!quant.uniform<i8:f32, 1.0:0>>) -> tensor<2x4x5x!quant.uniform<i8:f32, 1.0:17>> { // expected-error@+1 {{failed to legalize operation 'stablehlo.dot_general' that was explicitly marked illegal}} %0 = "stablehlo.dot_general"(%arg0, %arg1) { dot_dimension_numbers = #stablehlo.dot< lhs_batching_dimensions = [0], rhs_batching_dimensions = [0], lhs_contracting_dimensions = [1], rhs_contracting_dimensions = [1] > } : (tensor<2x3x4x!quant.uniform<i8:f32, 1.0:17>>, tensor<2x3x5x!quant.uniform<i8:f32, 1.0:0>>) -> tensor<2x4x5x!quant.uniform<i8:f32, 1.0:17>> func.return %0 : tensor<2x4x5x!quant.uniform<i8:f32, 1.0:17>> } ``` One option to fix this to provode source/target materialization [link](https://mlir.llvm.org/docs/DialectConversion/#type-converter), but we found that for other Ops [e.g.](https://github.com/openxla/stablehlo/blob/eba821aa1c54a21d70331d7926dfc8b929f988f3/stablehlo/transforms/StablehloLegalizeQuantToInt.cpp#L510), there is a precedent on how to convert the math computed in `i32` is converted back to result type. The PR implements the missing conversion. Note to the reviewers: To may just focus on the very last commit of the chain. The rest is coming from parent PR.
- Loading branch information