Skip to content

Commit

Permalink
Cleanup: Remove duplicate quantization checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sdasgup3 committed Oct 2, 2024
1 parent 7b13f60 commit 2f34420
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions stablehlo/dialect/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,23 +751,6 @@ bool isValidStablehloQuantizedElementType(Type elementType) {
quantizedPerAxisElementType.getScales().end());
}

// quantized_type_c6
auto maxPosFiniteNum =
APFloat::getLargest(
cast<FloatType>(quantizedElementType.getExpressedType())
.getFloatSemantics())
.convertToDouble();
auto minPosFiniteNum =
APFloat::getSmallest(
cast<FloatType>(quantizedElementType.getExpressedType())
.getFloatSemantics())
.convertToDouble();
if (llvm::any_of(scales, [&](double scale) {
return scale < minPosFiniteNum || scale > maxPosFiniteNum;
})) {
return false;
}

// quantized_type_c7, quantized_type_c8
if (llvm::any_of(zeroPoints, [&](int64_t zeroPoint) {
return storageTypeMin > zeroPoint || zeroPoint > storageTypeMax;
Expand All @@ -788,11 +771,11 @@ bool isValidQuantizedDimension(Type type) {

if (!quantizedPerAxisElementType) return true;

// quantized_type_c11, quantized_type_c12, quantized_type_c13
// quantized_type_c12, quantized_type_c13
int64_t quantDim = quantizedPerAxisElementType.getQuantizedDimension();
int64_t numScales =
static_cast<int64_t>(quantizedPerAxisElementType.getScales().size());
return quantDim >= 0 && quantDim < rankedType.getRank() &&
return quantDim < rankedType.getRank() &&
(!rankedType.isDynamicDim(quantDim) &&
numScales == rankedType.getDimSize(quantDim));
}
Expand Down

0 comments on commit 2f34420

Please sign in to comment.