[Mlir-commits] [mlir] 69aa6a0 - [mlir][quant] Fix quantization example. (#151518)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Aug 2 01:39:06 PDT 2025


Author: Javed Absar
Date: 2025-08-02T09:39:03+01:00
New Revision: 69aa6a0bdd5adb2d48d3cfbea1a50135d68e0453

URL: https://github.com/llvm/llvm-project/commit/69aa6a0bdd5adb2d48d3cfbea1a50135d68e0453
DIFF: https://github.com/llvm/llvm-project/commit/69aa6a0bdd5adb2d48d3cfbea1a50135d68e0453.diff

LOG: [mlir][quant] Fix quantization example. (#151518)

Fix and improve code example

quic_mabsar at quicinc.com

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
    mlir/lib/Dialect/Quant/IR/QuantTypes.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h b/mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
index 44062fe376ec0..34f47a15395c9 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