Skip to content

Conversation

@phoebesv
Copy link
Contributor

This change adds support for converting Conv2D operations to Img2Col + Matmul form, enabling better optimization opportunities for convolution operations.

Two new flags are introduced:

  • --iree-preprocessing-enable-conv2d-to-img2col: Enable Conv2D to Img2Col conversion in the preprocessing pipeline
  • --iree-preprocessing-enable-conv2d-to-img2col-after-quantized-conv: Enable Conv2D to Img2Col conversion specifically after QuantizedConvToConvPass in the global optimization pipeline

The separate flag for post-quantization conversion allows isolating the impact to only quantized models when explicitly enabled, avoiding affecting other model types that don't need this transformation.

This change adds support for converting Conv2D operations to Img2Col + Matmul
form, enabling better optimization opportunities for convolution operations.

Two new flags are introduced:
- --iree-preprocessing-enable-conv2d-to-img2col: Enable Conv2D to Img2Col
  conversion in the preprocessing pipeline
- --iree-preprocessing-enable-conv2d-to-img2col-after-quantized-conv: Enable
  Conv2D to Img2Col conversion specifically after QuantizedConvToConvPass in
  the global optimization pipeline

The separate flag for post-quantization conversion allows isolating the impact
to only quantized models when explicitly enabled, avoiding affecting other
model types that don't need this transformation.

Signed-off-by: Phoebe Chen <[email protected]>
Copy link
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
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
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.

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.

2 participants