Repository navigation
Description
Problem
With --iree-global-opt-use-im2col-for-convs, most convolutions in QDQ-quantized models are lowered as f32 matmuls instead of integer matmuls.
The issue is pass ordering. ConvertQDQToIntegerMath expects a zero-initialized contraction with operands coming directly from iree_linalg_ext.dequantize_affine. Currently, biased convolutions don't match either of the two places where this pass runs.
This matters because most exported models have biased convolutions (e.g., from batch norm folding).
Why the current ordering doesn't work
The relevant part of the pipeline is:
PropagateAffineQuantization + ConvertQDQToIntegerMath (early)
ConvertConv2DToImg2Col
DetachElementwiseFromNamedOps
...
GeneralizeLinalgNamedOps
FoldUnitExtentDims
DemoteContractionInputs
ConvertBatchMatmulToMatmul
PropagateLinalgTranspose
PropagateAffineQuantization + ConvertQDQToIntegerMath (late)
There are two problems:
- Early QDQ conversion: Biased convolutions still have
linalg.broadcast %biasas their accumulator instead of a zero fill. The bias is detached later byDetachElementwiseFromNamedOps, so these convolutions cannot be converted yet. - Late QDQ conversion: im2col has already turned the convolution into a gather + matmul. The matmul now consumes the im2col result rather than a dequantize directly, so the conversion doesn't match either.
For example, a QDQ-quantized yolov8n model has 72 convolutions, all biased. The early conversion only eliminates 2 of 247 dequantize ops, and with im2col enabled only 1 convolution ends up using integer math.
Proposed change
Move im2col after the late QDQ conversion and remove the early QDQ conversion.
This lets the existing canonicalization and generalization passes detach the bias and normalize the contractions before attempting integer conversion. im2col then operates on the converted integer convolutions.
The early QDQ conversion was originally needed because later passes could introduce reshapes, pads or transposes between the dequantize and contraction. Since #24906, PropagateAffineQuantization can propagate dequantization through these operations before conversion, so the early slot should no longer be necessary.
I tested removing it, and all GlobalOptimization and LinalgExt lit tests pass, including the unit-batch-dimension pipeline tests that originally motivated the early slot.
DemoteContractionInputs should also move after QDQ conversion, since it can insert arith.truncf between the dequantize and contraction. This part is based on code inspection and hasn't been tested yet.
The change depends on #25011, which allows im2col to handle generic convolutions, since GeneralizeLinalgNamedOps runs before the new im2col position.
Results
Tested with QDQ-quantized yolov8n on llvm-cpu (znver5), using:
--iree-opt-data-tiling
--iree-llvmcpu-enable-ukernels=all
--iree-global-opt-use-im2col-for-convs
| Configuration | Integer convs | Median latency |
|---|---|---|
| Current ordering, named im2col | 1 / 72 | 25.0 |
| Single QDQ conversion, generic im2col | 72 / 72 | 15.8 |
Assisted by: Claude
Activity
ziereis commentedon Oct 19, 2026
once llvm/torch-mlir#4833 lands and we bump torch-mlir again basically all onnx model will hit the new path. This should for sure be done before 3.13 release.
CC @Manewing.
[GlobalOptimization] change pass ordering so img2col convolutions in …