Skip to content

[GlobalOpt] Support Img2Col Transformation for Conv2D Including Quantized Types#23278

Merged
hanhanW merged 5 commits intoiree-org:mainfrom
phoebesv:enable_conv_img2col
Mar 6, 2026
Merged

[GlobalOpt] Support Img2Col Transformation for Conv2D Including Quantized Types#23278
hanhanW merged 5 commits intoiree-org:mainfrom
phoebesv:enable_conv_img2col

Conversation

@phoebesv
Copy link
Copy Markdown
Contributor

@phoebesv phoebesv commented Jan 26, 2026

Move the Conv2D to Img2Col transformation pass from Preprocessing to GlobalOptimization phase. This allows the pass to run after LinalgQuantizedConvToConvPass, enabling quantized convolutions to benefit from the img2col transformation.

Copy link
Copy Markdown
Collaborator

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but we cannot have the global optimization depend on preprocessing pass pipelines. Adding Global optimization to run some pre-processing pass pipeline is an inversion of dependencies. Could you describe what you are trying to see if there is a different way to approach this. In general using im2col at this level is not the best way to handle convs.

@phoebesv
Copy link
Copy Markdown
Contributor Author

@MaheshRavishankar Thanks for the clarification. We observed that ConvertConv2DToImg2ColPass only handles a limited set of conv ops, so quantized models using QuantizedConv are not covered. While QuantizedConvToConvPass can handle this, it currently resides in GlobalOptimization.

Our goal is to understand the intended lowering path for QuantizedConv and whether there is a more appropriate place to handle this without introducing dependency inversion. We’re open to alternative approaches and would appreciate guidance on the recommended direction.

@MaheshRavishankar
Copy link
Copy Markdown
Collaborator

@MaheshRavishankar Thanks for the clarification. We observed that ConvertConv2DToImg2ColPass only handles a limited set of conv ops, so quantized models using QuantizedConv are not covered. While QuantizedConvToConvPass can handle this, it currently resides in GlobalOptimization.

Our goal is to understand the intended lowering path for QuantizedConv and whether there is a more appropriate place to handle this without introducing dependency inversion. We’re open to alternative approaches and would appreciate guidance on the recommended direction.

I think one option here is to use the iree-preprocessing-pass-pipeline option to stitch together the exact sequence of passes that you want to call before the iree-compile pass pipeline kicks in. This should be able to call any passes registered in IREE.

Broadly if you have a proposal for moving some of the pre-processing pass pipelines into IREE global optimization phase we can definitely iterate on that. In this particular case, converting a convolution using im2col this early is typically seen as an anti-pattern due to the high replication this entails. We would prefer to try to handle the convolutions more natively and fix the backend code-generator to handle that better. That is a lot of work, so if you want to use the im2col approach as a stop-gap then I think the iree-preprocessing-pass-pipeline should get you what you need.

@phoebesv
Copy link
Copy Markdown
Contributor Author

I think one option here is to use the iree-preprocessing-pass-pipeline option to stitch together the exact sequence of passes that you want to call before the iree-compile pass pipeline kicks in. This should be able to call any passes registered in IREE.

Broadly if you have a proposal for moving some of the pre-processing pass pipelines into IREE global optimization phase we can definitely iterate on that. In this particular case, converting a convolution using im2col this early is typically seen as an anti-pattern due to the high replication this entails. We would prefer to try to handle the convolutions more natively and fix the backend code-generator to handle that better. That is a lot of work, so if you want to use the im2col approach as a stop-gap then I think the iree-preprocessing-pass-pipeline should get you what you need.

@MaheshRavishankar Thank you for the suggestion. We agree that iree-preprocessing-pass-pipeline is useful for experimentation and prototyping.
While exploring this approach, we found that using it as a permanent solution has some practical limitations:

  • Users must manually configure the pass sequence and understand internal dependencies
  • The pipeline is fragile to changes in IREE's internal pass ordering
  • It doesn't solve the ordering issue with LinalgQuantizedConvToConvPass (which runs in GlobalOptimization)

We're thinking that moving the im2col pass to GlobalOptimization with an opt-in flag could be a good fit for our scenario while avoiding the anti-pattern concern for backends that don't need it.

We'll prepare a proposal with more details and rationale. Happy to iterate based on your feedback.

@phoebesv phoebesv force-pushed the enable_conv_img2col branch 4 times, most recently from 5292a97 to 9ea4d0b Compare February 13, 2026 05:29
@phoebesv phoebesv changed the title [GlobalOptimization] Add Conv2D to Img2Col conversion options [GlobalOpt] Support Img2Col Transformation for Conv2D Including Quantized Types Feb 13, 2026
Comment thread compiler/src/iree/compiler/GlobalOptimization/Passes.h Outdated
Comment thread compiler/src/iree/compiler/Pipelines/Options.cpp
@phoebesv
Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to review! @MaheshRavishankar @benvanik @qedawkins @IanWood1 Please feel free to let me know if there's anything I can do to help with the next steps.

@phoebesv phoebesv force-pushed the enable_conv_img2col branch from 2444d8a to 6706448 Compare March 3, 2026 04:13
@phoebesv
Copy link
Copy Markdown
Contributor Author

phoebesv commented Mar 3, 2026

Rebased only.

@rednoah91
Copy link
Copy Markdown
Contributor

@MaheshRavishankar Could anyone help merge this PR : )?

@MaheshRavishankar
Copy link
Copy Markdown
Collaborator

Ok, let me check if CI passes. cc @hanhanW as well to merge if everything passes.

Copy link
Copy Markdown
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can help trigger CI and merge it, please fix the failures.

@phoebesv
Copy link
Copy Markdown
Contributor Author

phoebesv commented Mar 6, 2026

Hi @hanhanW, the pre-commit workflow failure seems to be caused by a temporary GitHub Actions service issue during the setup phase.

Getting action download info
Failed to resolve action download info. Error: Service Unavailable
Retrying in 21.442 seconds
Failed to resolve action download info. Error: Service Unavailable
Retrying in 21.695 seconds
Error: Failed to resolve action download info.
Error: Failed to resolve action download info.

Re-running the workflow might resolve the problem.

@hanhanW
Copy link
Copy Markdown
Contributor

hanhanW commented Mar 6, 2026

Hi @hanhanW, the pre-commit workflow failure seems to be caused by a temporary GitHub Actions service issue during the setup phase.

Getting action download info
Failed to resolve action download info. Error: Service Unavailable
Retrying in 21.442 seconds
Failed to resolve action download info. Error: Service Unavailable
Retrying in 21.695 seconds
Error: Failed to resolve action download info.
Error: Failed to resolve action download info.

Re-running the workflow might resolve the problem.

ooops, it ran for 2 mins, so I did not click into the link. Re-running the jobs now.

@hanhanW
Copy link
Copy Markdown
Contributor

hanhanW commented Mar 6, 2026

Here is the new log from lint: https://github.com/iree-org/iree/actions/runs/22607978256/job/65965929632?pr=23278

You can run build_tools/bazel_to_cmake/bazel_to_cmake.py to fix cmake files.

phoebesv added 3 commits March 5, 2026 19:30
Move the Conv2D to Img2Col transformation pass from Preprocessing to
GlobalOptimization phase. This allows the pass to run after
LinalgQuantizedConvToConvPass, enabling quantized convolutions to
benefit from the img2col transformation.

Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com>
…tion

Add --iree-global-opt-enable-conv2d-to-img2col flag to enable the
transformation. The pass is disabled by default and runs after
LinalgQuantizedConvToConvPass in the global optimization pipeline.

Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com>
Move test file from Preprocessing to GlobalOptimization and update
preprocessing_flags.mlir to remove references to the moved pass.

Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com>
phoebesv added 2 commits March 5, 2026 19:30
- Rename option from enableConv2DToImg2Col to useIm2colForConvs
- Update CLI flag from enable-conv2d-to-img2col to use-im2col-for-convs
- Update pipeline flag from iree-global-opt-enable-conv2d-to-img2col to
  iree-global-opt-use-im2col-for-convs

Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com>
Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com>
@phoebesv phoebesv force-pushed the enable_conv_img2col branch from 0d06a72 to 52a4579 Compare March 6, 2026 03:30
@phoebesv
Copy link
Copy Markdown
Contributor Author

phoebesv commented Mar 6, 2026

Here is the new log from lint: https://github.com/iree-org/iree/actions/runs/22607978256/job/65965929632?pr=23278

You can run build_tools/bazel_to_cmake/bazel_to_cmake.py to fix cmake files.

@hanhanW Formatting fix applied. Thanks!

@hanhanW hanhanW merged commit 80d70d6 into iree-org:main Mar 6, 2026
54 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants