[Mlir-commits] [mlir] Sub-channel quantized type implementation (PR #120172)
Kevin Gleason
llvmlistbot at llvm.org
Tue Feb 11 14:55:22 PST 2025
================
@@ -405,6 +572,74 @@ static void printUniformQuantizedPerAxisType(UniformQuantizedPerAxisType type,
out << "}>";
}
+/// Prints quantization parameters as a nested list of `scale`[:`zero_point`]
+/// elements. The nesting corresponds to the `shape` dimensions.
+///
+/// Elements are delimited by commas, and the inner dimensions are enclosed in
+/// braces. `zero_point` is only printed if it is non-zero. For example:
+///
+/// printDenseQuantizationParameters(scales=[1.0, 2.0, 3.0, 4.0],
+/// zeroPoints=[0, 0, 1, 9],
+/// shape=[2, 2])
+///
+/// would print:
+///
+/// {{1.0, 2.0}, {3.0:1, 4.0:9}}
+void printDenseQuantizationParameters(ArrayRef<APFloat> scales,
+ ArrayRef<APInt> zeroPoints,
+ ArrayRef<int64_t> shape,
+ DialectAsmPrinter &out) {
+ int64_t rank = shape.size();
+ SmallVector<unsigned, 4> counter(rank, 0);
+ unsigned openBrackets = 0;
+
+ auto bumpCounter = [&]() {
----------------
GleasonK wrote:
Can we give this a more precise name, `bumpCounter` doesn't help understand what's going on in this function. This function is fairly difficult to properly read as it is
https://github.com/llvm/llvm-project/pull/120172
More information about the Mlir-commits
mailing list