Description
The PyTorch TensorBoard Support tutorial uses deprecated torchvision transforms, non-idiomatic train/eval toggling, and contains stale workaround comments.
Note: Check the status of PR #3128 — the Oct 2024 Tutorial Audit decided to deprecate all TensorBoard tutorials. If that deprecation is proceeding, this issue may be superseded.
Changes needed
Deprecated APIs
transforms.ToTensor() → v2.ToImage() + v2.ToDtype(torch.float32, scale=True): ToTensor() is deprecated since torchvision 0.18 and lives in torchvision.transforms._deprecated.py. Update Compose and Normalize to v2 namespace as well.
Outdated patterns
net.train(False) / net.train(True) → net.eval() / net.train(): While functionally equivalent, model.eval() and model.train() are the idiomatic forms used in all current PyTorch tutorials.
- Python 2-style
super(Net, self).__init__() → super().__init__()
.format() → f-strings: e.g., 'Batch {}'.format(i + 1) → f'Batch {i + 1}'
- Remove stale TensorFlow workaround comment (lines ~75-77): This was a workaround for an
add_embedding bug in environments with TensorFlow installed. The bug was fixed long ago; the comment is confusing for readers.
Files
cc @subramen
Description
The PyTorch TensorBoard Support tutorial uses deprecated torchvision transforms, non-idiomatic train/eval toggling, and contains stale workaround comments.
Changes needed
Deprecated APIs
transforms.ToTensor()→v2.ToImage() + v2.ToDtype(torch.float32, scale=True):ToTensor()is deprecated since torchvision 0.18 and lives intorchvision.transforms._deprecated.py. UpdateComposeandNormalizeto v2 namespace as well.Outdated patterns
net.train(False)/net.train(True)→net.eval()/net.train(): While functionally equivalent,model.eval()andmodel.train()are the idiomatic forms used in all current PyTorch tutorials.super(Net, self).__init__()→super().__init__().format()→ f-strings: e.g.,'Batch {}'.format(i + 1)→f'Batch {i + 1}'add_embeddingbug in environments with TensorFlow installed. The bug was fixed long ago; the comment is confusing for readers.Files
beginner_source/introyt/tensorboardyt_tutorial.pycc @subramen