Skip to content

Commit

Permalink
Quantized storage type required to be signless
Browse files Browse the repository at this point in the history
  • Loading branch information
sdasgup3 committed Feb 28, 2024
1 parent 9bbf6d8 commit e727c62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stablehlo/dialect/Base.td
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StableHLO_UniformQuantizedSignedInt<int width>
CPred<"$_self.cast<mlir::quant::UniformQuantizedType>()" #
".getStorageTypeIntegralWidth() == " # width>,
CPred<"$_self.cast<mlir::quant::UniformQuantizedType>()" #
".isSigned()">]>,
".getStorageType().cast<mlir::IntegerType>().isSignless()">]>,
"QI" # width # " type"> {
string name = "UniformQuantizedSignedInt";
int bitwidth = width;
Expand All @@ -68,7 +68,7 @@ class StableHLO_UniformQuantizedPerAxisSignedInt<int width>
CPred<"$_self.cast<mlir::quant::UniformQuantizedPerAxisType>()" #
".getStorageTypeIntegralWidth() == " # width>,
CPred<"$_self.cast<mlir::quant::UniformQuantizedPerAxisType>()" #
".isSigned()">]>,
".getStorageType().cast<mlir::IntegerType>().isSignless()">]>,
"QI" # width # " type"> {
string name = "UniformQuantizedPerAxisSignedInt";
int bitwidth = width;
Expand Down
8 changes: 8 additions & 0 deletions stablehlo/tests/ops_stablehlo_quantized.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,11 @@ func.func @negative_select_and_scatter_quantization(%arg0: tensor<10x24x24x64x!q
} : (tensor<10x24x24x64x!quant.uniform<i8:f32:0, {0.1:-30}>>, tensor<10x23x23x64x!quant.uniform<i8:f32:0, {0.1:-30}>>, tensor<!quant.uniform<i8:f32:0, {0.1:-30}>>) -> tensor<10x24x24x64x!quant.uniform<i8:f32:0, {0.1:-30}>>
func.return %0 : tensor<10x24x24x64x!quant.uniform<i8:f32:0, {0.1:-30}>>
}

// -----

func.func @main(%arg0: tensor<4x!quant.uniform<si8:f32, 1.000000e+00>>) -> tensor<4xf32> {
// expected-error@+1 {{operand #0 must be tensor of 4/8/16/32-bit uniform quantized signed integer or 4/8/16/32-bit uniform quantized unsigned integer or 4/8/16/32-bit uniform quantized per axis signed integer or 4/8/16/32-bit uniform quantized per axis unsigned integer values, but got 'tensor<4x!quant.uniform<i8:f32, 1.000000e+00>>}}
%0 = "stablehlo.uniform_dequantize"(%arg0) : (tensor<4x!quant.uniform<si8:f32, 1.000000e+00>>) -> tensor<4xf32>
func.return %0 : tensor<4xf32>
}

0 comments on commit e727c62

Please sign in to comment.