[Mlir-commits] [mlir] [mlir][quant] Fix quantization example. (PR #151518)
Javed Absar
llvmlistbot at llvm.org
Sat Aug 2 01:13:37 PDT 2025
https://github.com/javedabsar1 updated https://github.com/llvm/llvm-project/pull/151518
>From 33cc2a1665be433bfd369ca1bfab01d179159caf Mon Sep 17 00:00:00 2001
From: Javed Absar <javed.absar at gmail.com>
Date: Thu, 31 Jul 2025 09:20:54 -0400
Subject: [PATCH 1/2] [mlir][quant] Fix example/documentation.
---
mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h | 2 ++
mlir/lib/Dialect/Quant/IR/QuantTypes.cpp | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)
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());
}
>From add9b1e02b77c6e3073ce0b652d4ed17546c92bd Mon Sep 17 00:00:00 2001
From: Javed Absar <javed.absar at gmail.com>
Date: Sat, 2 Aug 2025 04:12:35 -0400
Subject: [PATCH 2/2] address review comment
---
mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h b/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
index 32cdd25c7433d..34f47a15395c9 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
@@ -147,7 +147,7 @@ class QuantizedType : public 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>`.
+ /// 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
More information about the Mlir-commits
mailing list