Skip to content

Fix generic im2row NHWC layout to match Python reference#20708

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
ethansfng:export-D110508326
Jul 3, 2026
Merged

Fix generic im2row NHWC layout to match Python reference#20708
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
ethansfng:export-D110508326

Conversation

@ethansfng

Copy link
Copy Markdown
Contributor

Summary:
The generic Cadence im2row kernel wrote its NHWC (channel_last=True) output in kernel-position-major order [kp][c], but the operator contract — defined by the Python reference in ref_implementations.py via torch.nn.functional.unfold — is channel-major [c][kp], i.e. column index c*(kH*kW) + kh*kW + kw. The conv-lowering pass ReplaceConvWithIm2RowAndLinear packs the matmul weights in the same [c][kp] order (permute [OC,kH,kW,IC] -> [OC,IC,kH,kW] -> [OC,K]), so the generic kernel's [kp][c] output was transposed relative to the weights.

This rewrites the generic NHWC branch to write [c][kp] (per-channel scatter data_col[i_col*channels_col + c*num_kp + kp])

Differential Revision: D110508326

Summary:
The generic Cadence `im2row` kernel wrote its NHWC (`channel_last=True`) output in kernel-position-major order `[kp][c]`, but the operator contract — defined by the Python reference in `ref_implementations.py` via `torch.nn.functional.unfold` — is channel-major `[c][kp]`, i.e. column index `c*(kH*kW) + kh*kW + kw`. The conv-lowering pass `ReplaceConvWithIm2RowAndLinear` packs the matmul weights in the same `[c][kp]` order (permute `[OC,kH,kW,IC]` -> `[OC,IC,kH,kW]` -> `[OC,K]`), so the generic kernel's `[kp][c]` output was transposed relative to the weights.


This rewrites the generic NHWC branch to write `[c][kp]` (per-channel scatter `data_col[i_col*channels_col + c*num_kp + kp]`)

Differential Revision: D110508326
@pytorch-bot

pytorch-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20708

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 2312458 with merge base 8965e51 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 3, 2026
@meta-codesync

meta-codesync Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@ethansfng has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110508326.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync Bot merged commit 124b677 into pytorch:main Jul 3, 2026
196 of 201 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants