[Mlir-commits] [mlir] Sub-channel quantized type implementation (PR #120172)
Kevin Gleason
llvmlistbot at llvm.org
Tue Feb 11 14:55:22 PST 2025
================
@@ -228,38 +365,44 @@ static Type parseUniformType(DialectAsmParser &parser) {
return nullptr;
}
- // Optionally parse quantized dimension for per-axis quantization.
+ // Optionally parse quantized dimension for per-axis or sub-channel
+ // quantization.
if (succeeded(parser.parseOptionalColon())) {
- if (parser.parseInteger(quantizedDimension))
- return nullptr;
- isPerAxis = true;
+ if (succeeded(parser.parseOptionalLBrace())) {
+ isSubChannel = true;
+ if (parseBlockSizeInfoUntilRBrace(parser, quantizedDimensions,
+ blockSizes)) {
+ return nullptr;
+ }
+ } else {
+ isPerAxis = true;
+ quantizedDimensions.resize(1);
+ if (parser.parseInteger(quantizedDimensions.back())) {
+ return nullptr;
+ }
+ }
}
// Comma leading into range_spec.
if (parser.parseComma()) {
return nullptr;
}
- // Parameter specification.
- // For per-axis, ranges are in a {} delimitted list.
- if (isPerAxis) {
- if (parser.parseLBrace()) {
- return nullptr;
- }
- }
-
- // Parse scales/zeroPoints.
- SMLoc scaleZPLoc = parser.getCurrentLocation();
- do {
- scales.resize(scales.size() + 1);
+ // Quantization parameter (scales/zeroPoints) specification.
+ bool isPerTensor = !isPerAxis && !isSubChannel;
+ SmallVector<int64_t> dims;
+ if (isPerTensor) {
zeroPoints.resize(zeroPoints.size() + 1);
- if (parseQuantParams(parser, scales.back(), zeroPoints.back())) {
+ scales.resize(scales.size() + 1);
+ if (parseQuantParams(parser, expressedType, scales.back(),
+ zeroPoints.back())) {
return nullptr;
}
- } while (isPerAxis && succeeded(parser.parseOptionalComma()));
- if (isPerAxis) {
- if (parser.parseRBrace()) {
+ } else {
+ if (parser.parseLBrace() ||
+ parseQuantParamListUntilRBrace(parser, expressedType, scales,
----------------
GleasonK wrote:
Same here, use one of the other parsecomma functions with an explicit delim
https://github.com/llvm/llvm-project/pull/120172
More information about the Mlir-commits
mailing list