Skip to content

Commit 3fdb299

Browse files
authored
Merge branch 'main' into remove-tensorboard-profiler-tutorial
2 parents ddbacf1 + 45a5b17 commit 3fdb299

30 files changed

Lines changed: 1287 additions & 524 deletions

.ci/docker/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pandocfilters==1.5.1
1616
markdown==3.8.2
1717

1818
# PyTorch Theme
19-
pytorch_sphinx_theme2==0.4.6
19+
pytorch_sphinx_theme2==0.4.9
2020

2121
# Tutorial dependencies
2222
tqdm==4.66.1
@@ -25,7 +25,7 @@ pydantic>=2.10
2525
fastapi
2626
matplotlib
2727
librosa
28-
torch==2.11
28+
torch==2.12
2929
torchvision
3030
torchdata
3131
networkx
@@ -34,10 +34,10 @@ bs4
3434
awscliv2==2.1.1
3535
flask
3636
spacy==3.7.1 # Keep this version consistent with the model version in .jenkins/build.sh
37-
ray[serve,train,tune]==2.54.0
37+
ray[serve,train,tune]==2.55.0
3838
tiktoken
3939
tensorboard
40-
jinja2==3.1.3
40+
jinja2==3.1.6
4141
pytorch-lightning
4242
torchx
4343
torchrl==0.10.1

.github/workflows/docathon-assign.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
repo: context.repo.repo,
2929
issue_number: issueNumber
3030
});
31-
const hasLabel = issue.labels.some(label => label.name === 'docathon-h1-2025');
31+
const hasLabel = issue.labels.some(label => label.name === 'docathon-2026');
3232
if (hasLabel) {
3333
if (issue.assignee !== null) {
3434
await github.rest.issues.createComment({
3535
owner: context.repo.owner,
3636
repo: context.repo.repo,
3737
issue_number: issueNumber,
38-
body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-h1-2025 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2025)."
38+
body: "The issue is already assigned. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)."
3939
});
4040
} else {
4141
await github.rest.issues.addAssignees({
@@ -46,7 +46,7 @@ jobs:
4646
});
4747
}
4848
} else {
49-
const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-h1-2025 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-h1-2025)."
49+
const commmentMessage = "This issue does not have the correct label. Please pick an opened and unnasigned issue with the [docathon-2026 label](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3Adocathon-2026)."
5050
await github.rest.issues.createComment({
5151
owner: context.repo.owner,
5252
repo: context.repo.repo,

.jenkins/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ sudo apt-get install -y pandoc
3030
# Install PyTorch Nightly for test.
3131
if [ "${USE_NIGHTLY:-0}" -eq 1 ]; then
3232
sudo pip uninstall -y torch torchvision torchaudio
33-
pip3 install torch==2.11.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu130
33+
pip3 install torch==2.12.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu130
3434
pip show torch
3535
fi
3636

3737
# Nightly - pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
38-
# Install 2.11 to merge all 2.11 PRs - uncomment to install nightly binaries (update the version as needed).
38+
# Install 2.12 to merge all 2.12 PRs - uncomment to install nightly binaries (update the version as needed).
3939
# sudo pip uninstall -y torch torchvision torchaudio torchtext torchdata
40-
# pip3 install torch==2.11.0 torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu130
40+
# pip3 install torch==2.12.0 torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu130
4141
# Install two language tokenizers for Translation with TorchText tutorial
4242
# Note: keep this version consistent with the spacy version in requirements.txt
4343
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl

advanced_source/privateuseone.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Facilitating New Backend Integration by PrivateUse1
44
In this tutorial we will walk through some necessary steps to integrate a new backend
55
living outside ``pytorch/pytorch`` repo by ``PrivateUse1``. Note that this tutorial assumes that
66
you already have a basic understanding of PyTorch.
7-
you are an advanced user of PyTorch.
87

98
.. note::
109

beginner_source/basics/data_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@
4848
import torch
4949
from torch.utils.data import Dataset
5050
from torchvision import datasets
51-
from torchvision.transforms import ToTensor
51+
from torchvision.transforms import v2
5252
import matplotlib.pyplot as plt
5353

5454

5555
training_data = datasets.FashionMNIST(
5656
root="data",
5757
train=True,
5858
download=True,
59-
transform=ToTensor()
59+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
6060
)
6161

6262
test_data = datasets.FashionMNIST(
6363
root="data",
6464
train=False,
6565
download=True,
66-
transform=ToTensor()
66+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
6767
)
6868

6969

beginner_source/basics/optimization_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
from torch import nn
2929
from torch.utils.data import DataLoader
3030
from torchvision import datasets
31-
from torchvision.transforms import ToTensor
31+
from torchvision.transforms import v2
3232

3333
training_data = datasets.FashionMNIST(
3434
root="data",
3535
train=True,
3636
download=True,
37-
transform=ToTensor()
37+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
3838
)
3939

4040
test_data = datasets.FashionMNIST(
4141
root="data",
4242
train=False,
4343
download=True,
44-
transform=ToTensor()
44+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
4545
)
4646

4747
train_dataloader = DataLoader(training_data, batch_size=64)

beginner_source/basics/quickstart_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from torch import nn
2727
from torch.utils.data import DataLoader
2828
from torchvision import datasets
29-
from torchvision.transforms import ToTensor
29+
from torchvision.transforms import v2
3030

3131
######################################################################
3232
# PyTorch offers domain-specific libraries such as `TorchText <https://pytorch.org/text/stable/index.html>`_,
@@ -43,15 +43,15 @@
4343
root="data",
4444
train=True,
4545
download=True,
46-
transform=ToTensor(),
46+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]),
4747
)
4848

4949
# Download test data from open datasets.
5050
test_data = datasets.FashionMNIST(
5151
root="data",
5252
train=False,
5353
download=True,
54-
transform=ToTensor(),
54+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]),
5555
)
5656

5757
######################################################################

beginner_source/basics/tensorqs_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#
6464
# ``shape`` is a tuple of tensor dimensions. In the functions below, it determines the dimensionality of the output tensor.
6565

66-
shape = (2,3,)
66+
shape = (2,3)
6767
rand_tensor = torch.rand(shape)
6868
ones_tensor = torch.ones(shape)
6969
zeros_tensor = torch.zeros(shape)

beginner_source/basics/transforms_tutorial.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,47 @@
2323
2424
The FashionMNIST features are in PIL Image format, and the labels are integers.
2525
For training, we need the features as normalized tensors, and the labels as one-hot encoded tensors.
26-
To make these transformations, we use ``ToTensor`` and ``Lambda``.
26+
To make these transformations, we use the ``torchvision.transforms.v2`` API along with ``torch.nn.functional.one_hot``.
2727
"""
2828

2929
import torch
30+
import torch.nn.functional as F
3031
from torchvision import datasets
31-
from torchvision.transforms import ToTensor, Lambda
32+
from torchvision.transforms import v2
3233

3334
ds = datasets.FashionMNIST(
3435
root="data",
3536
train=True,
3637
download=True,
37-
transform=ToTensor(),
38-
target_transform=Lambda(lambda y: torch.zeros(10, dtype=torch.float).scatter_(0, torch.tensor(y), value=1))
38+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]),
39+
target_transform=v2.Lambda(
40+
lambda y: F.one_hot(torch.tensor(y), num_classes=10).float()
41+
),
3942
)
4043

4144
#################################################
42-
# ToTensor()
45+
# ToImage() and ToDtype()
4346
# -------------------------------
4447
#
45-
# `ToTensor <https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.ToTensor>`_
46-
# converts a PIL image or NumPy ``ndarray`` into a ``FloatTensor``. and scales
47-
# the image's pixel intensity values in the range [0., 1.]
48+
# The ``torchvision.transforms.v2`` API replaces the legacy ``ToTensor`` transform with a two-step pipeline.
49+
# `v2.ToImage <https://pytorch.org/vision/stable/generated/torchvision.transforms.v2.ToImage.html>`_
50+
# converts a PIL image or NumPy ``ndarray`` into a ``torchvision.tv_tensors.Image`` tensor, and
51+
# `v2.ToDtype <https://pytorch.org/vision/stable/generated/torchvision.transforms.v2.ToDtype.html>`_
52+
# with ``scale=True`` casts it to ``float32`` and scales the pixel intensity values to the range [0., 1.].
4853
#
4954

5055
##############################################
5156
# Lambda Transforms
5257
# -------------------------------
5358
#
54-
# Lambda transforms apply any user-defined lambda function. Here, we define a function
55-
# to turn the integer into a one-hot encoded tensor.
56-
# It first creates a zero tensor of size 10 (the number of labels in our dataset) and calls
57-
# `scatter_ <https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_.html>`_ which assigns a
58-
# ``value=1`` on the index as given by the label ``y``.
59+
# Lambda transforms apply any user-defined lambda function. Here, we use
60+
# `torch.nn.functional.one_hot <https://pytorch.org/docs/stable/generated/torch.nn.functional.one_hot.html>`_
61+
# to turn the integer label into a one-hot encoded tensor of size 10 (the number of labels in our dataset),
62+
# then cast it to ``float`` to match the expected dtype.
5963

60-
target_transform = Lambda(lambda y: torch.zeros(
61-
10, dtype=torch.float).scatter_(dim=0, index=torch.tensor(y), value=1))
64+
target_transform = v2.Lambda(
65+
lambda y: F.one_hot(torch.tensor(y), num_classes=10).float()
66+
)
6267

6368
######################################################################
6469
# --------------
@@ -67,4 +72,5 @@
6772
#################################################################
6873
# Further Reading
6974
# ~~~~~~~~~~~~~~~~~
70-
# - `torchvision.transforms API <https://pytorch.org/vision/stable/transforms.html>`_
75+
# - `Getting started with transforms v2 <https://pytorch.org/vision/stable/auto_examples/transforms/plot_transforms_getting_started.html>`_
76+
# - `torchvision.transforms.v2 API <https://pytorch.org/vision/stable/transforms.html#v2-api-reference-recommended>`_

beginner_source/blitz/cifar10_tutorial.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"""
5858
import torch
5959
import torchvision
60-
import torchvision.transforms as transforms
60+
from torchvision.transforms import v2
6161

6262
########################################################################
6363
# The output of torchvision datasets are PILImage images of range [0, 1].
@@ -69,9 +69,10 @@
6969
# BrokenPipeError or RuntimeError related to multiprocessing, try setting
7070
# the num_worker of torch.utils.data.DataLoader() to 0.
7171

72-
transform = transforms.Compose(
73-
[transforms.ToTensor(),
74-
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
72+
transform = v2.Compose([
73+
v2.ToImage(),
74+
v2.ToDtype(torch.float32, scale=True),
75+
v2.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
7576

7677
batch_size = 4
7778

@@ -191,7 +192,7 @@ def forward(self, x):
191192
########################################################################
192193
# Let's quickly save our trained model:
193194

194-
PATH = './cifar_net.pth'
195+
PATH = './cifar_net.pt'
195196
torch.save(net.state_dict(), PATH)
196197

197198
########################################################################
@@ -302,7 +303,7 @@ def forward(self, x):
302303
# Let's first define our device as the first visible cuda device if we have
303304
# CUDA available:
304305

305-
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
306+
device = torch.device(torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else 'cpu')
306307

307308
# Assuming that we are on a CUDA machine, this should print a CUDA device:
308309

@@ -355,9 +356,9 @@ def forward(self, x):
355356
# - `Discuss PyTorch on the Forums`_
356357
# - `Chat with other users on Slack`_
357358
#
358-
# .. _Train a state-of-the-art ResNet network on imagenet: https://github.com/pytorch/examples/tree/master/imagenet
359-
# .. _Train a face generator using Generative Adversarial Networks: https://github.com/pytorch/examples/tree/master/dcgan
360-
# .. _Train a word-level language model using Recurrent LSTM networks: https://github.com/pytorch/examples/tree/master/word_language_model
359+
# .. _Train a state-of-the-art ResNet network on imagenet: https://github.com/pytorch/examples/tree/main/imagenet
360+
# .. _Train a face generator using Generative Adversarial Networks: https://github.com/pytorch/examples/tree/main/dcgan
361+
# .. _Train a word-level language model using Recurrent LSTM networks: https://github.com/pytorch/examples/tree/main/word_language_model
361362
# .. _More examples: https://github.com/pytorch/examples
362363
# .. _More tutorials: https://github.com/pytorch/tutorials
363364
# .. _Discuss PyTorch on the Forums: https://discuss.pytorch.org/

0 commit comments

Comments
 (0)