[Mlir-commits] [mlir] [mlir][quant] Fix quantization example. (PR #151518)
Javed Absar
llvmlistbot at llvm.org
Thu Jul 31 06:23:17 PDT 2025
https://github.com/javedabsar1 created https://github.com/llvm/llvm-project/pull/151518
None
>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] [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());
}
More information about the Mlir-commits
mailing list