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

Conversation

sdasgup3
Copy link
Member

Current StablehLO quantized signed int cs uses mlir::quant::QuantizedType::isSIgned to decide on the signed-ness of the storage type.

StableHLO, as bootstrapped from MHLO, inherits signless integers (added in MHLO for some legacy reasons) to be treated as signed integer. This is not captured by the check mlir::quant::QuantizedType::isSigned because of the following reason.

Based on this, mlir::quant::QuantizedType::isSIgned() is true if the associated bit in flag is 1. Here are a few ways to set that flag as true.

 auto signed_flag_bit = storage_type.cast<mlir::IntegerType>().isSignless();
... mlir::quant::UniformQuantizedPerAxisType::get(
     is_signed, storage_type, expressed_type, scales, zero_points,
     quantization_dimension, storage_min, storage_max);

or

 auto signed_flag_bit = storage_type.cast<mlir::IntegerType>().isSigned();
... mlir::quant::UniformQuantizedPerAxisType::get(
     is_signed, storage_type, expressed_type, scales, zero_points,
     quantization_dimension, storage_min, storage_max);

In other words, It is on the producers of mlir::quant::QuantizedType to set that bit based on their interpretation of signedness, which in case of StableHLO is signedless. That means the a true value of mlir::quant::QuantizedType::isSIgned() is not enough to ensure that the desired signed-ness of storage type.

Suggested change

Replace

CPred<"$_self.cast<mlir::quant::UniformQuantizedType>()" #
                 ".isSigned()">]>,

with

           CPred<"$_self.cast<mlir::quant::UniformQuantizedType>()" #
                 ".getStorageType().cast<mlir::IntegerType>().isSignless()">]>,

IMO, we can skip the check mlir::quant::UniformQuantizedType::isSigned() altogether as is it not sufficient nor necessary.

Context: #1812 (comment)

@sdasgup3 sdasgup3 force-pushed the require-quant-storage-type-to-be-signless branch from eacd2fe to e727c62 Compare February 28, 2024 01:48
@sdasgup3 sdasgup3 force-pushed the require-quant-storage-type-to-be-signless branch from e727c62 to 5f85d02 Compare February 28, 2024 01:49
@GleasonK GleasonK merged commit 1d304fc into openxla:main Feb 28, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants