Skip to content

Cleanup: Remove duplicate quantization checks #2566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to a TD file? Or somewhere else for searchability?

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
Loading