Skip to content

Modernize data tutorial to torchvision v2 API#3863

Open
omkar-334 wants to merge 3 commits intopytorch:mainfrom
omkar-334:fix/3852-data-tutorial-v2
Open

Modernize data tutorial to torchvision v2 API#3863
omkar-334 wants to merge 3 commits intopytorch:mainfrom
omkar-334:fix/3852-data-tutorial-v2

Conversation

@omkar-334
Copy link
Copy Markdown

@omkar-334 omkar-334 commented May 5, 2026

Fixes ##3852

Description

Replace deprecated ToTensor() with v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]) in both the training and test FashionMNIST splits, and switch the import to the v2 namespace.

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER")
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

cc @subramen

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 5, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3863

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 2 Pending

As of commit 8710778 with merge base 08435cc (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 May 5, 2026
@sekyondaMeta
Copy link
Copy Markdown
Contributor

@claude

@claude
Copy link
Copy Markdown

claude Bot commented May 6, 2026

Claude finished @sekyondaMeta's task in 1m 7s —— View job


PR Review: Modernize data tutorial to torchvision v2 API

  • Gather context and review changes
  • Provide review feedback

Summary: This is a clean, minimal change that correctly replaces the deprecated ToTensor() with the v2 transforms API. The pattern used (v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])) is the recommended replacement per the torchvision docs and is consistent with the identical change already merged in PR #3869 for the quickstart tutorial.

Review: LGTM

The changes are correct and well-scoped:

  1. Import (line 51): from torchvision.transforms import ToTensorfrom torchvision.transforms import v2 — correct namespace switch.
  2. Training transform (line 59): ToTensor()v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]) — functionally equivalent replacement.
  3. Test transform (line 66): Same replacement applied consistently.

No issues found. The change is minimal, addresses only the deprecation, and doesn't introduce unnecessary refactoring.


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.

3 participants