Skip to content

Conversation

justinchuby
Copy link
Collaborator

Simplify the graph when input rank is 4, in which case we don't need to do any shape manipulation.

Fix pytorch/pytorch#162061

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the pixel_shuffle and pixel_unshuffle operations in the torch library by adding fast paths for 4D inputs and improving shape handling for higher-dimensional tensors.

  • Adds early return optimization for 4D tensors that can directly use ONNX DepthToSpace/SpaceToDepth operations
  • Replaces tensor slicing with explicit op.Slice calls for better shape manipulation
  • Adds trace_only=True parameter to both function decorators

Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 28.57143% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.93%. Comparing base (54de741) to head (908ca91).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 28.57% 8 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2537      +/-   ##
==========================================
- Coverage   69.93%   69.93%   -0.01%     
==========================================
  Files         216      216              
  Lines       26048    26052       +4     
  Branches     2614     2616       +2     
==========================================
+ Hits        18217    18219       +2     
  Misses       6931     6931              
- Partials      900      902       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

justinchuby and others added 2 commits September 3, 2025 12:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@justinchuby justinchuby added this to the 0.4.1 milestone Sep 3, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in ONNX Script Review Board Sep 3, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby enabled auto-merge (squash) September 3, 2025 20:03
@justinchuby justinchuby disabled auto-merge September 3, 2025 20:15
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby enabled auto-merge (squash) September 3, 2025 22:28
@justinchuby justinchuby merged commit a925acc into main Sep 3, 2025
32 checks passed
@justinchuby justinchuby deleted the justinchu/pixel-shuffle branch September 3, 2025 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: torchlib Related to the torch/aten function lib in development
Projects
Development

Successfully merging this pull request may close these issues.

Dynamo-based ONNX exporter adds seemingly unnecessary operations to the graph
2 participants