[Mlir-commits] [mlir] [mlir][quant] Fix quantization example. (PR #151518)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 31 06:23:49 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-quant
Author: Javed Absar (javedabsar1)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/151518.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h (+2)
- (modified) mlir/lib/Dialect/Quant/IR/QuantTypes.cpp (+3-3)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h b/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
index 44062fe376ec0..32cdd25c7433d 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
@@ -143,9 +143,11 @@ class QuantizedType : public Type {
/// Casts from a type based on the storageType to a corresponding type based
/// on this type (returns nullptr if the cast is not valid).
/// Examples:
+ /// `candidate type` -> `return type`
/// i8 -> !quant.uniform<i8:f32, 1.0>
/// tensor<4xi8> -> tensor<4x!quant.uniform<i8:f32, 1.0}>>
/// vector<4xi8> -> vector<4x!quant.uniform<i8:f32, 1.0>>
+ //. It is assumed above that this type's quantization is `<i8:f32, 1.0>`.
Type castFromStorageType(Type candidateType);
/// Casts from a type based on a QuantizedType to a corresponding type based
diff --git a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
index 8122c4db684e5..b2227792f32ca 100644
--- a/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
+++ b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
@@ -127,7 +127,7 @@ QuantizedType::getQuantizedElementType(Type primitiveOrContainerType) {
Type QuantizedType::castFromStorageType(Type candidateType) {
if (candidateType == getStorageType()) {
- // i.e. i32 -> quant<"uniform[i8:f32]{1.0}">
+ // i.e. i8 -> quant<"uniform[i8:f32]{1.0}">
return *this;
}
if (llvm::isa<RankedTensorType>(candidateType)) {
@@ -137,11 +137,11 @@ Type QuantizedType::castFromStorageType(Type candidateType) {
getStorageType());
}
if (llvm::isa<UnrankedTensorType>(candidateType)) {
- // i.e. tensor<i8> -> tensor<!quant<"uniform[i8:f32]{1.0}">>
+ // i.e. tensor<xi8> -> tensor<x!quant<"uniform[i8:f32]{1.0}">>
return UnrankedTensorType::get(getStorageType());
}
if (llvm::isa<VectorType>(candidateType)) {
- // i.e. tensor<4xi8> -> tensor<4x!quant<"uniform[i8:f32]{1.0}">>
+ // i.e. vector<4xi8> -> vector<4x!quant<"uniform[i8:f32]{1.0}">>
return VectorType::get(llvm::cast<VectorType>(candidateType).getShape(),
getStorageType());
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/151518
More information about the Mlir-commits
mailing list