fix(MemoryFormatOpsPass): preserve input dim_order for clone/to_copy with no memory_format kwarg#17611
Open
nefainl wants to merge 1 commit intopytorch:mainfrom
Open
Conversation
…with no memory_format kwarg Issue pytorch#16032: clone() and _to_copy operations with no explicit memory_format kwarg were defaulting to contiguous dim_order, causing runtime assertion failures when cloning channels-last tensors. Changes: - Default memory_format to torch.preserve_format instead of torch.contiguous_format - When preserve_format, derive dim_order from input tensor's dim_order() - Simplify type annotation: dim_order is always assigned, no Optional needed Tests: - test_clone_no_kwarg_preserves_channels_last_dim_order: core repro case - test_clone_contiguous_format_kwarg_stays_contiguous: regression guard - test_to_copy_no_kwarg_preserves_channels_last_dim_order: _to_copy path
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/17611
Note: Links to docs will display an error until the docs builds have been completed.
|
Author
|
@pytorchbot label "release notes: exir" |
Author
|
Request to the reviewers: Could you please add @GregoryComer as well? I have received very helpful advice from him in the other PR and it makes sense to have him also here so he can edit if needed. Note that some of the other changes will still be handled in another PR (where it also makes sense to have him review). |
4 tasks
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.
Summary
Fixes #16032
This PR fixes
MemoryFormatOpsPassto correctly handletorch.preserve_formatsemantics forclone()and_to_copy.defaultoperations.Root cause: When
clone()or_to_copyis called without an explicitmemory_formatkwarg, the pass was defaulting totorch.contiguous_format, causing the outputdim_orderto be[0,1,2,3](contiguous) even when the input was channels-last[0,2,3,1]. This caused runtime assertion failures:Fix: Change the default from
torch.contiguous_formattotorch.preserve_format, and derivedim_orderfrom the input tensor'sdim_order()when preserve_format is used.This is a minimal, focused fix following the guidance from @GregoryComer in the discussion on PR #17463.
Changes
exir/passes/memory_format_ops_pass.py(+29/-5 lines):memory_formattotorch.preserve_formatinstead oftorch.contiguous_formatdim_orderfrominput_tensor.dim_order()empty())exir/tests/test_passes.py(+130 lines):test_clone_no_kwarg_preserves_channels_last_dim_order: Core repro case for Dim Order Validation Inconsistency for Edge / Ambiguous Cases #16032test_clone_contiguous_format_kwarg_stays_contiguous: Regression guardtest_to_copy_no_kwarg_preserves_channels_last_dim_order: Verifies_to_copy.defaultpathStandalone Reproduction
Test Plan
Related