Fix nn.PixelUnshuffle wrong channel ordering (replace SpaceToDepth with Reshape→Transpose→Reshape)#2892
Open
Fix nn.PixelUnshuffle wrong channel ordering (replace SpaceToDepth with Reshape→Transpose→Reshape)#2892
Conversation
…paceToDepth SpaceToDepth only supports DCR channel ordering, but PixelUnshuffle (inverse of PixelShuffle) requires CRD ordering. Implement via: 1. Reshape [..., C, H*r, W*r] -> [batch, C, H, r, W, r] 2. Transpose with perm [0, 1, 3, 5, 2, 4] (inverse of CRD DepthToSpace perm) 3. Reshape to [batch, C*r*r, H, W] Agent-Logs-Url: https://github.com/microsoft/onnxscript/sessions/44a370bd-6b05-4d23-b35a-f6a6c1df1d23 Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix nn.PixelUnshuffle wrongfully exported as SpaceToDepth
Fix nn.PixelUnshuffle wrong channel ordering (replace SpaceToDepth with Reshape→Transpose→Reshape)
Apr 17, 2026
justinchuby
approved these changes
Apr 17, 2026
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nn.PixelUnshufflewas exported asSpaceToDepth, which only supports DCR channel ordering — butPixelUnshuffleis the inverse ofPixelShuffle, which usesDepthToSpacewithmode="CRD". This mismatch produced incorrect output channel order.Changes
aten_pixel_unshuffle: Replaceop.SpaceToDepthwith an explicit Reshape→Transpose→Reshape sequence that correctly implements the inverse of CRDDepthToSpace:[..., C, H×r, W×r]→[batch, C, H, r, W, r]perm=[0, 1, 3, 5, 2, 4]→[batch, C, r, r, H, W](inverse of CRD perm[0, 1, 4, 2, 5, 3])[batch, C×r², H, W]if len(self.shape) == 4special case.This satisfies PyTorch's
PixelUnshufflesemantics:output[n, c·r²+r_h·r+r_w, h, w] = input[n, c, h·r+r_h, w·r+r_w].Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
download-r2.pytorch.org/usr/bin/pip pip install torch onnx onnxruntime --index-url REDACTED -q(dns block)If you need me to access, download, or install something from one of these locations, you can either: