Skip to content
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

Check quantized-storage-type to be a signless integer #2054

Merged
Merged
Show file tree
Hide file tree
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
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 @illegal_storage_type_for_quantized_element_type(%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>
}
Loading