Skip to content

Fix JPEG transform for non-contiguous batches - #9615

Merged
NicolasHug merged 3 commits into
pytorch:mainfrom
tandede:fix/jpeg-noncontiguous-leading-dims
Aug 24, 2026
Merged

NicolasHug merged 3 commits into
pytorch:mainfrom
tandede:fix/jpeg-noncontiguous-leading-dims

Conversation

@tandede

@tandede tandede commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • allow the v2 JPEG kernel to process non-contiguous tensors with multiple leading batch dimensions
  • add regression coverage that compares a transposed batch layout with its contiguous equivalent

Problem

transforms.v2.JPEG documents tensor inputs as [..., C, H, W], with an arbitrary number of leading dimensions. The kernel flattened those dimensions with view(), 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.py

cc @vfdev-5

@pytorch-bot

pytorch-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🔗 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 Pending

As of commit 85ac26e with merge base c7ef957 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the cla signed label Aug 19, 2026
@tandede
tandede marked this pull request as ready for review August 19, 2026 03:52

@NicolasHug NicolasHug left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @tandede

@NicolasHug
NicolasHug merged commit 50237ca into pytorch:main Aug 24, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants