Fix dim_order derivation for channels-last tensors with size-1 dims - #22745
Fix dim_order derivation for channels-last tensors with size-1 dims#22745JakeStevens wants to merge 2 commits into
Conversation
A channels-last tensor with a size-1 channel (e.g. the (1, 1, 49, 10) input of MLPerf Tiny keyword spotting) has strides whose stable sort is the non-canonical dim order (0, 2, 1, 3). dim_order_from_stride now takes the tensor sizes and returns the canonical dim order when the strides exactly match a contiguous or channels-last layout, which portable kernels require. The canonical order describes the identical physical layout, and genuinely non-canonical layouts still fall back to sorting. Fixes pytorch#22520
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22745
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 66bd993 with merge base a3ae329 ( BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
| edge_prog.to_executorch() | ||
|
|
||
| def test_channels_last_single_channel_conv_dim_order(self) -> None: | ||
| # Regression test for https://github.com/pytorch/executorch/issues/22520: |
There was a problem hiding this comment.
do not reference the issue in a comment.
in general, comment too verbose
| dim_order_from_stride((u0, 0, 1)) | ||
|
|
||
| def test_dim_order_from_stride_with_sizes(self) -> None: | ||
| # Regression test for https://github.com/pytorch/executorch/issues/22520: |
Reuse PyTorch stride calculation while keeping existing default orders and preserve_format inference. Cover singleton-layout regressions and symbolic sizes, and restore portable NXP KWS comparisons with finite tolerances. Authored with AI assistance (Codex).
Fixes #22520. Stride sorting can give a channels-last tensor with a size-1 channel an unsupported dimension order, such as
(0, 2, 1, 3)for the KWS input(1, 1, 49, 10). Pass sizes through tensor specs, weight emission, and serialization so these orders can be corrected when strides exactly match channels-last. Preserve existing default orders, which keeps physically equivalent singleton layouts compatible with portable kernels. Reuse PyTorch's stride calculation; memory-format pass behavior is unchanged.Add coverage for the convolution export, mixed-format addition, 5D ReLU, and symbolic sizes. Re-enable the NXP channels-last PTQ/QAT cases with the portable C++ reference and the comparator's standard finite MSE tolerance (
3.5e-4).Validation: 287 tests passed across tensor, dim-order, passes, native serialization, EXIR serialization, and layout transforms; 49 skipped and 1 expected failure. The unrelated
test_to_out_variant_none_outputfailure was confirmed with pre-PR stride inference. Lintrunner is clean on all touched files. Portable runtime probes match Python for addition, 5D ReLU, and PTQ/QAT convolution and DSCNN KWS models (XNNPACK PT2E quantization, no delegation). The full NXP simulator suite requires CI and was not run locally.This PR was authored with AI assistance (Muse Code and Codex).