Fix JPEG transform for non-contiguous batches - #9615
Merged
NicolasHug merged 3 commits intoAug 24, 2026
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9615
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 6 PendingAs of commit 85ac26e with merge base c7ef957 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
tandede
marked this pull request as ready for review
August 19, 2026 03:52
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
Problem
transforms.v2.JPEGdocuments tensor inputs as[..., C, H, W], with an arbitrary number of leading dimensions. The kernel flattened those dimensions withview(), which rejects valid non-contiguous layouts such as tensors with transposed batch axes before JPEG encoding is reached.Fix
Use
reshape()to flatten the leading dimensions. This remains a view when the layout is compatible and materializes the logical tensor order only when required, so the existing contiguous path is unchanged while valid non-contiguous inputs are supported. The decoded images are then restored to the original shape as before.Testing
python -m pytest test/test_transforms_v2.py::TestJPEG -q(78 passed)python -m pytest test/test_transforms_v2.py -q(6690 passed, 2936 skipped, 348 xfailed)pre-commit run --files torchvision/transforms/v2/functional/_augment.py test/test_transforms_v2.pycc @vfdev-5