-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Remove redundant checks related to quantized type #110604
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
Conversation
@llvm/pr-subscribers-mlir Author: Sandeep Dasgupta (sdasgup3) ChangesAPFloat::getSmallest (and similarly
return the positive number when the default value for the second argument is used. With that being said, the check QuantTypes.cpp#L325 if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
return emitError() << "illegal scale: " << scale; is already covered by the check which follows QuantTypes.cpp#L327 if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]"; given that range I propose to remove the redundant check. Any suggestion for improving the error message is welcome. Full diff: https://github.com/llvm/llvm-project/pull/110604.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
index ac01b37a553077..7c0d3696486515 100644
--- a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
+++ b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
@@ -322,8 +322,6 @@ LogicalResult UniformQuantizedType::verifyInvariants(
// Verify scale.
double minScale = getMinScale(expressedType);
double maxScale = getMaxScale(expressedType);
- if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
- return emitError() << "illegal scale: " << scale;
if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]";
@@ -388,8 +386,6 @@ LogicalResult UniformQuantizedPerAxisType::verifyInvariants(
double minScale = getMinScale(expressedType);
double maxScale = getMaxScale(expressedType);
for (double scale : scales) {
- if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
- return emitError() << "illegal scale: " << scale;
if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]";
diff --git a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
index 7613a344cf2b8f..4528d2826a850c 100644
--- a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
+++ b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
@@ -107,7 +107,7 @@
// -----
// Illegal scale: negative
-// expected-error@+1 {{illegal scale: -1.000000}}
+// expected-error@+1 {{scale out of expressed type range}}
!qalias = !quant.uniform<i8<-4:3>:f32, -1.0:127>
// -----
|
@llvm/pr-subscribers-mlir-quant Author: Sandeep Dasgupta (sdasgup3) ChangesAPFloat::getSmallest (and similarly
return the positive number when the default value for the second argument is used. With that being said, the check QuantTypes.cpp#L325 if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
return emitError() << "illegal scale: " << scale; is already covered by the check which follows QuantTypes.cpp#L327 if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]"; given that range I propose to remove the redundant check. Any suggestion for improving the error message is welcome. Full diff: https://github.com/llvm/llvm-project/pull/110604.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
index ac01b37a553077..7c0d3696486515 100644
--- a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
+++ b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
@@ -322,8 +322,6 @@ LogicalResult UniformQuantizedType::verifyInvariants(
// Verify scale.
double minScale = getMinScale(expressedType);
double maxScale = getMaxScale(expressedType);
- if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
- return emitError() << "illegal scale: " << scale;
if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]";
@@ -388,8 +386,6 @@ LogicalResult UniformQuantizedPerAxisType::verifyInvariants(
double minScale = getMinScale(expressedType);
double maxScale = getMaxScale(expressedType);
for (double scale : scales) {
- if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
- return emitError() << "illegal scale: " << scale;
if (scale < minScale || scale > maxScale)
return emitError() << "scale out of expressed type range [" << minScale
<< ", " << maxScale << "]";
diff --git a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
index 7613a344cf2b8f..4528d2826a850c 100644
--- a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
+++ b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
@@ -107,7 +107,7 @@
// -----
// Illegal scale: negative
-// expected-error@+1 {{illegal scale: -1.000000}}
+// expected-error@+1 {{scale out of expressed type range}}
!qalias = !quant.uniform<i8<-4:3>:f32, -1.0:127>
// -----
|
Hi Rafael (@rafaelubalmw), |
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
a5365a2
to
2461430
Compare
@rafaelubalmw Can you please merge this? Sorry I do not have the merge access. |
APFloat::getSmallest (and similarly
APFloat:getLargest
)return the positive number when the default value for the second argument is used.
With that being said, the check QuantTypes.cpp#L325
is already covered by the check which follows QuantTypes.cpp#L327
given that range
[positive-smallest-finite-number, positive-largest-finite-number]
does not includeinf
andnan
s.I propose to remove the redundant check. Any suggestion for improving the error message is welcome.