[Mlir-commits] [mlir] Sub-channel quantized type implementation (PR #120172)
Sandeep Dasgupta
llvmlistbot at llvm.org
Wed Mar 12 19:15:22 PDT 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,
----------------
sdasgup3 wrote:
That is a good point!
>> parseCommaSeparatedListUntil
I could not find `` defined in `DialectAsmParser` ([ref](https://github.com/llvm/llvm-project/blob/12fe5ae88cce0e3a8de47ed766425cbf8505ab87/mlir/include/mlir/IR/DialectImplementation.h#L56) and [ref](https://github.com/llvm/llvm-project/blob/12fe5ae88cce0e3a8de47ed766425cbf8505ab87/mlir/include/mlir/IR/OpImplementation.h#L805)
>> parseCommaSeparatedList
The problem with just using this one is if we pass on a explicitly specified delimiter, then empty list is allowed. But the sub-channel types expects the block-info to be non-empty. To mitigate the above two limitations, we have implemented our own version of `parseCommaSeparatedListUntil` as follows using the second API you suggested.
```
static ParseResult
parseBlockSizeInfoUntilRBrace(DialectAsmParser &parser,
SmallVectorImpl<int32_t> &quantizedDimensions,
SmallVectorImpl<int64_t> &blockSizes) {
// Empty block-sizes info.
if (succeeded(parser.parseOptionalRBrace())) {
return success();
}
auto parseBlockSizeElements = [&]() -> ParseResult {
quantizedDimensions.resize(quantizedDimensions.size() + 1);
blockSizes.resize(blockSizes.size() + 1);
if (parser.parseInteger(quantizedDimensions.back()) ||
parser.parseColon() || parser.parseInteger(blockSizes.back()))
return failure();
return success();
};
if (parser.parseCommaSeparatedList(parseBlockSizeElements) ||
parser.parseRBrace()) {
return failure();
}
return success();
}
```
https://github.com/llvm/llvm-project/pull/120172
More information about the Mlir-commits
mailing list