Skip to content

Commit c495957

Browse files
authored
Cleanup: Remove duplicate quantization checks (#2566)
The recent upstream [change](llvm/llvm-project#100667) have introduced quantization checks that are already present in the StableHLO core library. This commit removes these duplicate checks to avoid redundancy and potential inconsistencies. |Checks proposed to be removed| StableHLO Code | Upstream MLIR | |-|-|-| | `channel-axis >= 0`| [cs](https://github.com/openxla/stablehlo/blob/1c0547f391dff5ac71d36dc20a916260afa78c61/stablehlo/dialect/Base.cpp#L795) | [cs](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp#L399) | | scale within smallest and largest finite numbers determined by `expressed_type`| [cs](https://github.com/openxla/stablehlo/blob/1c0547f391dff5ac71d36dc20a916260afa78c61/stablehlo/dialect/Base.cpp#L765) | [cs1](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp#L327) [cs2](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp#L393C9-L393C45) | Note that StableHLO has checks like `quantization_dimension < rank(self)` and `dim(self, quantization_dimension) = size(scales)` implemented at [cs](https://github.com/openxla/stablehlo/blob/1c0547f391dff5ac71d36dc20a916260afa78c61/stablehlo/dialect/Base.cpp#L795). In upstream MLIR similar checks [cs](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantOps.cpp#L51) are encoded as part of [dcast](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantOps.cpp#L110) and [qcast](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantOps.cpp#L139) ops and hence cannot be claimed as duplicate. related upstream clean-up llvm/llvm-project#110604
1 parent 8dd667a commit c495957

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

stablehlo/dialect/Base.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -751,23 +751,6 @@ bool isValidStablehloQuantizedElementType(Type elementType) {
751751
quantizedPerAxisElementType.getScales().end());
752752
}
753753

754-
// quantized_type_c6
755-
auto maxPosFiniteNum =
756-
APFloat::getLargest(
757-
cast<FloatType>(quantizedElementType.getExpressedType())
758-
.getFloatSemantics())
759-
.convertToDouble();
760-
auto minPosFiniteNum =
761-
APFloat::getSmallest(
762-
cast<FloatType>(quantizedElementType.getExpressedType())
763-
.getFloatSemantics())
764-
.convertToDouble();
765-
if (llvm::any_of(scales, [&](double scale) {
766-
return scale < minPosFiniteNum || scale > maxPosFiniteNum;
767-
})) {
768-
return false;
769-
}
770-
771754
// quantized_type_c7, quantized_type_c8
772755
if (llvm::any_of(zeroPoints, [&](int64_t zeroPoint) {
773756
return storageTypeMin > zeroPoint || zeroPoint > storageTypeMax;
@@ -788,11 +771,11 @@ bool isValidQuantizedDimension(Type type) {
788771

789772
if (!quantizedPerAxisElementType) return true;
790773

791-
// quantized_type_c11, quantized_type_c12, quantized_type_c13
774+
// quantized_type_c12, quantized_type_c13
792775
int64_t quantDim = quantizedPerAxisElementType.getQuantizedDimension();
793776
int64_t numScales =
794777
static_cast<int64_t>(quantizedPerAxisElementType.getScales().size());
795-
return quantDim >= 0 && quantDim < rankedType.getRank() &&
778+
return quantDim < rankedType.getRank() &&
796779
(!rankedType.isDynamicDim(quantDim) &&
797780
numScales == rankedType.getDimSize(quantDim));
798781
}

0 commit comments

Comments
 (0)