Skip to content

Update introyt tutorial to torchvision v2 APIs#3865

Open
saurabhkthakur wants to merge 1 commit intopytorch:mainfrom
saurabhkthakur:fix-introyt-v2-transforms
Open

Update introyt tutorial to torchvision v2 APIs#3865
saurabhkthakur wants to merge 1 commit intopytorch:mainfrom
saurabhkthakur:fix-introyt-v2-transforms

Conversation

@saurabhkthakur
Copy link
Copy Markdown

@saurabhkthakur saurabhkthakur commented May 5, 2026

Fixes #3858

Description

Updates the Training with PyTorch tutorial by:

  • replacing deprecated torchvision transforms with v2 APIs
  • replacing ToTensor() with ToImage() and ToDtype(...)
  • updating Python 2-style super() usage
  • converting .format() calls to f-strings
image

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/3865

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

✅ No Failures

As of commit fe8a6a1 with merge base 5efb99a (image):
💚 Looks good so far! There are no failures yet. 💚

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

@svekars
Copy link
Copy Markdown
Contributor

svekars commented May 5, 2026

@claude

@claude
Copy link
Copy Markdown

claude Bot commented May 5, 2026

Claude finished @svekars's task in 1m 20s —— View job


Review of PR #3865

  • Gather context and read the changed file
  • Review the diff against origin/main
  • Post review feedback

Summary

This PR correctly migrates from the deprecated torchvision.transforms to the torchvision.transforms.v2 API, modernizes super() calls, and converts .format() to f-strings. The changes are straightforward and the screenshot confirms successful execution.

Issues Found

1. Stale docstring reference (line 60)

The tutorial prose still says:

We use ``torchvision.transforms.Normalize()`` to
zero-center and normalize the distribution of the image tile content,

Since the code now uses v2.ToImage(), v2.ToDtype(), and v2.Normalize(), this description should be updated to reflect the new transform pipeline. A suggested replacement:

We use ``torchvision.transforms.v2`` to convert images to tensors,
normalize the distribution of the image tile content,

Fix this →

Looks Good

  • v2.ToImage() + v2.ToDtype(torch.float32, scale=True) is the correct replacement for the deprecated ToTensor() per the torchvision migration guide.
  • v2.Normalize((0.5,), (0.5,)) is unchanged in behavior.
  • super().__init__() is the modern Python 3 style — correct.
  • f-string conversions are all equivalent to the original .format() calls.

Verdict

Approve with one minor nit: update the tutorial prose at line 60 to not reference the old torchvision.transforms.Normalize() API. Otherwise LGTM.


@svekars
Copy link
Copy Markdown
Contributor

svekars commented May 5, 2026

@saurabhkthakur can you update the above comment?

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.

Update Intro YouTube Training with PyTorch tutorial — v2 transforms, super(), formatting

2 participants