Remove channels_last requirement for pool ops via explicit permutes (#21796) - #21796
Remove channels_last requirement for pool ops via explicit permutes (#21796)#21796mcremon-meta wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21796
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit 75262bb with merge base 43f89fb ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@mcremon-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113943678. |
This PR needs a
|
|
@AdrianLundell do you mind taking a look when you're back and get a chance? :) |
…21796) Summary: Changes the cortex_m pool ops (avg_pool2d, max_pool2d) from the "logical-NCHW-shape + NHWC-physical (channels_last dim_order)" contract to a "logical-NHWC-shape, plain contiguous" contract, bridged to the surrounding NCHW graph by explicit aten.permute_copy nodes. This lets the pool ops run when the graph is contiguous (e.g. _skip_dim_order=True or channels_last not propagated), which previously failed at runtime with: cortex_m_ops_common.h: quantized_avg_pool2d_out: tensors must use channels_last dimension order The CMSIS pool kernels already treat the data pointer as physically NHWC; the physical bytes are identical in both contracts, so the kernel change is only how dims are read (NHWC positions) plus dropping the channels_last check. Changes (mirrored fbcode + xplat, DirSync-identical): - ops/cortex_m_ops_common.h (prepare_cmsis_pool2d_config): read dims from NHWC positions (size(1)=H, size(2)=W, size(3)=C), compare batch/channels at size(0)/size(3), and drop the require_channels_last parameter/check. - ops/op_quantized_avg_pool2d.cpp: update call site; NHWC-consistent. - ops/operators.py: pool fake-metas use NHWC-shaped I/O; the avg_pool2d and max_pool2d reference impls permute NHWC<->NCHW around F.*_pool2d and return NHWC-shaped output (consistent with the NHWC kernel contract). - passes/aten_to_cortex_m_pass.py: pool replacements insert explicit permute_copy (NCHW->NHWC before, NHWC->NCHW after); pad reworked for NHWC; qparams preserved. - passes/scratch_buffer_sizes.py: pool scratch sizing uses NHWC-shaped I/O. Differential Revision: D113943678
0ad9c82 to
2a56c36
Compare
…21796) Summary: Changes the cortex_m pool ops (avg_pool2d, max_pool2d) from the "logical-NCHW-shape + NHWC-physical (channels_last dim_order)" contract to a "logical-NHWC-shape, plain contiguous" contract, bridged to the surrounding NCHW graph by explicit aten.permute_copy nodes. This lets the pool ops run when the graph is contiguous (e.g. _skip_dim_order=True or channels_last not propagated), which previously failed at runtime with: cortex_m_ops_common.h: quantized_avg_pool2d_out: tensors must use channels_last dimension order The CMSIS pool kernels already treat the data pointer as physically NHWC; the physical bytes are identical in both contracts, so the kernel change is only how dims are read (NHWC positions) plus dropping the channels_last check. Changes (mirrored fbcode + xplat, DirSync-identical): - ops/cortex_m_ops_common.h (prepare_cmsis_pool2d_config): read dims from NHWC positions (size(1)=H, size(2)=W, size(3)=C), compare batch/channels at size(0)/size(3), and drop the require_channels_last parameter/check. - ops/op_quantized_avg_pool2d.cpp: update call site; NHWC-consistent. - ops/operators.py: pool fake-metas use NHWC-shaped I/O; the avg_pool2d and max_pool2d reference impls permute NHWC<->NCHW around F.*_pool2d and return NHWC-shaped output (consistent with the NHWC kernel contract). - passes/aten_to_cortex_m_pass.py: pool replacements insert explicit permute_copy (NCHW->NHWC before, NHWC->NCHW after); pad reworked for NHWC; qparams preserved. - passes/scratch_buffer_sizes.py: pool scratch sizing uses NHWC-shaped I/O. Differential Revision: D113943678
2a56c36 to
75262bb
Compare
Summary:
Changes the cortex_m pool ops (avg_pool2d, max_pool2d) from the
"logical-NCHW-shape + NHWC-physical (channels_last dim_order)" contract to a
"logical-NHWC-shape, plain contiguous" contract, bridged to the surrounding NCHW
graph by explicit aten.permute_copy nodes. This lets the pool ops run when the
graph is contiguous (e.g. _skip_dim_order=True or channels_last not propagated),
which previously failed at runtime with:
cortex_m_ops_common.h: quantized_avg_pool2d_out: tensors must use channels_last
dimension order
The CMSIS pool kernels already treat the data pointer as physically NHWC; the
physical bytes are identical in both contracts, so the kernel change is only how
dims are read (NHWC positions) plus dropping the channels_last check.
Changes (mirrored fbcode + xplat, DirSync-identical):
positions (size(1)=H, size(2)=W, size(3)=C), compare batch/channels at
size(0)/size(3), and drop the require_channels_last parameter/check.
max_pool2d reference impls permute NHWC<->NCHW around F.*_pool2d and return
NHWC-shaped output (consistent with the NHWC kernel contract).
permute_copy (NCHW->NHWC before, NHWC->NCHW after); pad reworked for NHWC;
qparams preserved.
Differential Revision: D113943678