Repository navigation
Cortex-M: Don't replace channels-first conv with channels-last kernel - #23943
rahimuddin140 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23943
Note: Links to docs will display an error until the docs builds have been completed.
|
|
Hi @rahimuddin140! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
This PR needs a
|
Erik-Lundell
left a comment
There was a problem hiding this comment.
Thanks for the fix! Could you include the tests I attached (preferably the ones that don't require adding more kernels to the test runner). The fix additionally targets transposed and normal convolution, so please add tests for those as well.
I also dug more into the issue. It is actually a bit hard to recover here than it looks, since the FoldAndAnnotateQParamsPass has folded away quantization nodes. This means that the existing fp kernel will break if it is left as is. That pass is not specific to the Cortex-M backend, so it is tricky to modify.
I think a proper solution actually needs to insert a layout op. Otherwise, raising early with a good error message could be the easy way out. What do you think?
/Erik
@rahimuddin140 gentle ping to address these, thanks |
Fixes #23812. _get_convolution_replacement replaced any batch-1 depthwise (or regular) quantized conv with cortex_m::quantized_depthwise_conv2d / quantized_conv2d without verifying the input layout, but those kernels require channels-last input and output (checked at runtime). A channels-first input — e.g. from x.contiguous() or mean(dim=2) — produced a graph that exported fine (the fake unconditionally reports a channels-last output) and then failed at runtime with 'input and output must be channels_last'. Now the pass checks the input's dim order with the existing is_channels_last() util and leaves non-channels-last convs un-replaced so they fall back to portable ops. The explicit-NHWC pipeline is unaffected (uses the _nhwc kernels). Test plan: new dialect tests covering a channels-first depthwise conv (via .contiguous() and via mean-pooling) asserting no replacement, and a channels-last control asserting replacement still happens.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani @nil-is-all @psiddh @AdrianLundell