Skip to content

Commit 22b15c8

Browse files
Relax negative scales conditions in Quant Dialect (#61)
* relax negative scale conditions * adapt tests now handling negative scales
1 parent b526d14 commit 22b15c8

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

mlir/lib/Dialect/Quant/IR/QuantTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ LogicalResult UniformQuantizedType::verify(
299299
return emitError() << "expressed type must be floating point";
300300

301301
// Verify scale.
302-
if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
302+
if (std::isinf(scale) || std::isnan(scale))
303303
return emitError() << "illegal scale: " << scale;
304304

305305
return success();
@@ -364,7 +364,7 @@ LogicalResult UniformQuantizedPerAxisType::verify(
364364

365365
// Verify scale.
366366
for (double scale : scales) {
367-
if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
367+
if (std::isinf(scale) || std::isnan(scale))
368368
return emitError() << "illegal scale: " << scale;
369369
}
370370

mlir/test/Dialect/Quant/parse-quantile-invalid.mlir

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ func.func @parse() -> !qalias {
142142
// expected-error@+1 {{expected non-function type}}
143143
!qalias = !quant.quantile<i8<-4:3>:f16:f33, {-1.0,1.0}:0.99872:127>
144144

145-
// -----
146-
// Illegal scale: negative
147-
// expected-error@+1 {{illegal scale: -1.000000}}
148-
!qalias = !quant.quantile<i8<-4:3>:f16:f32, {-1.0,1.0}:-1.0:127>
149-
150145
// -----
151146
// Illegal uniform params: missing quantized dimension
152147
// expected-error@+1 {{expected integer value}}

mlir/test/Dialect/Quant/parse-quantile.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,21 @@ func.func @parse() -> !qalias {
163163
%0 = "foo"() : () -> !qalias
164164
return %0 : !qalias
165165
}
166+
167+
// -----
168+
// Negative scale checking
169+
// CHECK: !quant.quantile<i4:f16:f32, {-1.000000e+00,-8.667000e-01,-7.333000e-01,-6.000000e-01,-4.667000e-01,-3.333000e-01,-2.000000e-01,-0.066699999999999995,0.066699999999999995,2.000000e-01,3.333000e-01,4.667000e-01,6.000000e-01,7.333000e-01,8.667000e-01,1.000000e+00}:-2.000000e+02>
170+
!qalias = !quant.quantile<i4:f16:f32, {-1.0000,-0.8667,-0.7333,-0.6000,-0.4667,-0.3333,-0.2000,-0.0667,0.0667,0.2000,0.3333,0.4667,0.6000,0.7333,0.8667,1.0000}:-2.0e+2>
171+
func.func @parse() -> !qalias {
172+
%0 = "foo"() : () -> !qalias
173+
return %0 : !qalias
174+
}
175+
176+
// -----
177+
// Per-axis negative scale checking
178+
// CHECK: !quant.quantile<i4:f16:f32:1, {-1.000000e+00,-8.667000e-01,-7.333000e-01,-6.000000e-01,-4.667000e-01,-3.333000e-01,-2.000000e-01,-0.066699999999999995,0.066699999999999995,2.000000e-01,3.333000e-01,4.667000e-01,6.000000e-01,7.333000e-01,8.667000e-01,1.000000e+00}:{-2.000000e+02,-9.987200e-01:120}>
179+
!qalias = !quant.quantile<i4:f16:f32:1, {-1.0000,-0.8667,-0.7333,-0.6000,-0.4667,-0.3333,-0.2000,-0.0667,0.0667,0.2000,0.3333,0.4667,0.6000,0.7333,0.8667,1.0000}:{-2.0e+2,-0.99872:120}>
180+
func.func @parse() -> !qalias {
181+
%0 = "foo"() : () -> !qalias
182+
return %0 : !qalias
183+
}

mlir/test/Dialect/Quant/parse-uniform-invalid.mlir

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@
125125
// expected-error@+1 {{expected non-function type}}
126126
!qalias = !quant.uniform<i8<-4:3>:f33, 0.99872:127>
127127

128-
// -----
129-
// Illegal scale: negative
130-
// expected-error@+1 {{illegal scale: -1.000000}}
131-
!qalias = !quant.uniform<i8<-4:3>:f32, -1.0:127>
132-
133128
// -----
134129
// Illegal uniform params: missing quantized dimension
135130
// expected-error@+1 {{expected integer value}}

mlir/test/Dialect/Quant/parse-uniform.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,21 @@ func.func @parse() -> !qalias {
199199
%0 = "foo"() : () -> !qalias
200200
return %0 : !qalias
201201
}
202+
203+
// -----
204+
// Negative scale checking
205+
// CHECK: !quant.uniform<i8:f32, -2.000000e+02>
206+
!qalias = !quant.uniform<i8:f32, -2.0e+2>
207+
func.func @parse() -> !qalias {
208+
%0 = "foo"() : () -> !qalias
209+
return %0 : !qalias
210+
}
211+
212+
// -----
213+
// Per axis negative scale checking
214+
// CHECK: !quant.uniform<i8:f32:1, {-2.000000e+02,-9.987200e-01:120}>
215+
!qalias = !quant.uniform<i8:f32:1, {-2.0e+2,-0.99872:120}>
216+
func.func @parse() -> !qalias {
217+
%0 = "foo"() : () -> !qalias
218+
return %0 : !qalias
219+
}

0 commit comments

Comments
 (0)