Skip to content

Commit 3344dba

Browse files
author
Svetlana Karslioglu
authored
Merge branch 'main' into arrow-key
2 parents c857fa1 + e5176b6 commit 3344dba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+493
-158
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ pytorch_tutorial_build_defaults: &pytorch_tutorial_build_defaults
142142
143143
pytorch_tutorial_build_worker_defaults: &pytorch_tutorial_build_worker_defaults
144144
environment:
145-
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.6-cudnn8-py3-gcc7"
145+
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.7-cudnn8-py3-gcc7"
146146
CUDA_VERSION: "9"
147147
resource_class: gpu.nvidia.small
148148
<<: *pytorch_tutorial_build_defaults
149149

150150
pytorch_tutorial_build_manager_defaults: &pytorch_tutorial_build_manager_defaults
151151
environment:
152-
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.6-cudnn8-py3-gcc7"
152+
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.7-cudnn8-py3-gcc7"
153153
resource_class: medium
154154
<<: *pytorch_tutorial_build_defaults
155155

.circleci/config.yml.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ pytorch_tutorial_build_defaults: &pytorch_tutorial_build_defaults
142142

143143
pytorch_tutorial_build_worker_defaults: &pytorch_tutorial_build_worker_defaults
144144
environment:
145-
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.6-cudnn8-py3-gcc7"
145+
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.7-cudnn8-py3-gcc7"
146146
CUDA_VERSION: "9"
147147
resource_class: gpu.nvidia.small
148148
<<: *pytorch_tutorial_build_defaults
149149

150150
pytorch_tutorial_build_manager_defaults: &pytorch_tutorial_build_manager_defaults
151151
environment:
152-
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.6-cudnn8-py3-gcc7"
152+
DOCKER_IMAGE: "308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda11.7-cudnn8-py3-gcc7"
153153
resource_class: medium
154154
<<: *pytorch_tutorial_build_defaults
155155
{% raw %}

.jenkins/get_docker_tag.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
}
66

77
if __name__ == "__main__":
8-
url = "https://api.github.com/repos/pytorch/pytorch/contents/.circleci"
8+
url = "https://api.github.com/repos/pytorch/pytorch/contents/.ci"
99

1010
response = requests.get(url, headers=REQUEST_HEADERS)
11-
for file in response.json():
12-
if file["name"] == "docker":
13-
print(file["sha"])
11+
docker_sha = None
12+
for finfo in response.json():
13+
if finfo["name"] == "docker":
14+
docker_sha = finfo["sha"]
15+
break
16+
if docker_sha is None:
17+
raise RuntimeError("Can't find sha sum of docker folder")
18+
print(docker_sha)

.jenkins/validate_tutorials_built.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"recipes/timer_quick_start",
5050
"recipes/amp_recipe",
5151
"recipes/Captum_Recipe",
52-
"hyperparameter_tuning_tutorial",
5352
"flask_rest_api_tutorial",
5453
"text_to_speech_with_torchaudio",
5554
]

CONTRIBUTING.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ We welcome your pull requests (PR) for updates and fixes.
4848
1. If you haven't already, complete the Contributor License Agreement
4949
("CLA").
5050
1. Fork the repo and create a branch from
51-
[`master`](https://github.com/pytorch/tutorials).
51+
[`main`](https://github.com/pytorch/tutorials).
5252
1. Test your code.
5353
1. Lint your code with a tool such as
5454
[Pylint](https://pylint.pycqa.org/en/latest/).
@@ -88,7 +88,7 @@ commonly-used storage service, such as Amazon S3, and instructing your
8888
users to download the data at the beginning of your tutorial.
8989

9090
The
91-
[Makefile](https://github.com/pytorch/tutorials/blob/master/Makefile)
91+
[Makefile](https://github.com/pytorch/tutorials/blob/main/Makefile)
9292
that we use to build the tutorials contains automation that downloads
9393
required data files.
9494

@@ -248,14 +248,14 @@ For Python files, our CI system runs your code during each build.
248248
[https://github.com/pytorch/tutorials](https://github.com/pytorch/tutorials)
249249

250250
1. Put the tutorial in one of the
251-
[`beginner_source`](https://github.com/pytorch/tutorials/tree/master/beginner_source),
252-
[`intermediate_source`](https://github.com/pytorch/tutorials/tree/master/intermediate_source),
253-
[`advanced_source`](https://github.com/pytorch/tutorials/tree/master/advanced_source)
251+
[`beginner_source`](https://github.com/pytorch/tutorials/tree/main/beginner_source),
252+
[`intermediate_source`](https://github.com/pytorch/tutorials/tree/main/intermediate_source),
253+
[`advanced_source`](https://github.com/pytorch/tutorials/tree/main/advanced_source)
254254
based on the technical level of the content. For recipes, put the
255255
recipe in
256-
[`recipes_source`](https://github.com/pytorch/tutorials/tree/master/recipes_source).
256+
[`recipes_source`](https://github.com/pytorch/tutorials/tree/main/recipes_source).
257257
In addition, for recipes, add the recipe in the recipes
258-
[README.txt](https://github.com/pytorch/tutorials/blob/master/recipes_source/recipes/README.txt)
258+
[README.txt](https://github.com/pytorch/tutorials/blob/main/recipes_source/recipes/README.txt)
259259
file.
260260

261261

@@ -266,9 +266,9 @@ search, you need to include it in `index.rst`, or for recipes, in
266266
`recipes_index.rst`.
267267

268268
1. Open the relevant file
269-
[`index.rst`](https://github.com/pytorch/tutorials/blob/master/index.rst)
269+
[`index.rst`](https://github.com/pytorch/tutorials/blob/main/index.rst)
270270
or
271-
[`recipes_index.rst`](https://github.com/pytorch/tutorials/blob/master/recipes_source/recipes_index.rst)
271+
[`recipes_index.rst`](https://github.com/pytorch/tutorials/blob/main/recipes_source/recipes_index.rst)
272272
1. Add a _card_ in reStructuredText format similar to the following:
273273

274274
```
@@ -300,10 +300,10 @@ might fail to build, and the cards will not display properly.
300300
### Image ###
301301

302302
Add a thumbnail to the
303-
[`_static/img/thumbnails/cropped`](https://github.com/pytorch/tutorials/tree/master/_static/img/thumbnails/cropped)
303+
[`_static/img/thumbnails/cropped`](https://github.com/pytorch/tutorials/tree/main/_static/img/thumbnails/cropped)
304304
directory. Images that render the best are square--that is, they have
305305
equal `x` and `y` dimensions--and also have high resolution. [Here is an
306-
example](https://github.com/pytorch/tutorials/blob/master/_static/img/thumbnails/cropped/loading-data.PNG).
306+
example](https://github.com/pytorch/tutorials/blob/main/_static/img/thumbnails/cropped/loading-data.PNG).
307307

308308
## `toctree` ##
309309

@@ -344,7 +344,7 @@ test your tutorial when you submit your PR.
344344
NOTE: Please do not use [ghstack](https://github.com/ezyang/ghstack). We
345345
do not support ghstack in the [`pytorch/tutorials`](https://github.com/pytorch/tutorials) repo.
346346

347-
Submit the changes as a PR to the master branch of
347+
Submit the changes as a PR to the main branch of
348348
[`pytorch/tutorials`](https://github.com/pytorch/tutorials).
349349

350350
1. Add your changes, commit, and push:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Here is how you can create a new tutorial (for a detailed description, see [CONT
1616
1. Create a Python file. If you want it executed while inserted into documentation, save the file with the suffix `tutorial` so that the file name is `your_tutorial.py`.
1717
2. Put it in one of the `beginner_source`, `intermediate_source`, `advanced_source` directory based on the level of difficulty. If it is a recipe, add it to `recipes_source`. For tutorials demonstrating unstable prototype features, add to the `prototype_source`.
1818
2. For Tutorials (except if it is a prototype feature), include it in the `toctree` directive and create a `customcarditem` in [index.rst](./index.rst).
19-
3. For Tutorials (except if it is a prototype feature), create a thumbnail in the [index.rst file](https://github.com/pytorch/tutorials/blob/master/index.rst) using a command like `.. customcarditem:: beginner/your_tutorial.html`. For Recipes, create a thumbnail in the [recipes_index.rst](https://github.com/pytorch/tutorials/blob/master/recipes_source/recipes_index.rst)
19+
3. For Tutorials (except if it is a prototype feature), create a thumbnail in the [index.rst file](https://github.com/pytorch/tutorials/blob/main/index.rst) using a command like `.. customcarditem:: beginner/your_tutorial.html`. For Recipes, create a thumbnail in the [recipes_index.rst](https://github.com/pytorch/tutorials/blob/main/recipes_source/recipes_index.rst)
2020

2121
If you are starting off with a Jupyter notebook, you can use [this script](https://gist.github.com/chsasank/7218ca16f8d022e02a9c0deb94a310fe) to convert the notebook to Python file. After conversion and addition to the project, please make sure that section headings and other things are in logical order.
2222

_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/8-inference?WT.mc_id=aiml-7486-cxa";
4949
}
5050

51-
$(".pytorch-call-to-action-links").children().first().before("<a href="+url+' data-behavior="call-to-action-event" data-response="Run in Microsoft Learn" target="_blank"><div id="microsoft-learn-link" style="padding-bottom: 0.625rem;border-bottom: 1px solid #f3f4f7;padding-right: 2.5rem;display: -webkit-box; display: -ms-flexbox; isplay: flex; -webkit-box-align: center;-ms-flex-align: center;align-items: center;"><img class="call-to-action-img" src="../../_static/images/microsoft-logo.svg"/><div class="call-to-action-desktop-view">Run in Microsoft Learn</div><div class="call-to-action-mobile-view">Learn</div></div></a>')
51+
$(".pytorch-call-to-action-links").children().first().before("<a href="+url+' data-behavior="call-to-action-event" data-response="Run in Microsoft Learn" target="_blank"><div id="microsoft-learn-link" style="padding-bottom: 0.625rem;border-bottom: 1px solid #f3f4f7;padding-right: 2.5rem;display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center;-ms-flex-align: center;align-items: center;"><img class="call-to-action-img" src="../../_static/images/microsoft-logo.svg"/><div class="call-to-action-desktop-view">Run in Microsoft Learn</div><div class="call-to-action-mobile-view">Learn</div></div></a>')
5252
}
5353

5454
!function(f,b,e,v,n,t,s)

advanced_source/generic_join.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Distributed Training with Uneven Inputs Using the Join Context Manager
44
**Author**\ : `Andrew Gu <https://github.com/andwgu>`_
55

66
.. note::
7-
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/master/advanced_source/generic_join.rst>`__.
7+
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/main/advanced_source/generic_join.rst>`__.
88

99
.. note:: ``Join`` is introduced in PyTorch 1.10 as a prototype feature. This
1010
API is subject to change.

advanced_source/rpc_ddp_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Combining Distributed DataParallel with Distributed RPC Framework
33
**Authors**: `Pritam Damania <https://github.com/pritamdamania87>`_ and `Yi Wang <https://github.com/SciPioneer>`_
44

55
.. note::
6-
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/master/advanced_source/rpc_ddp_tutorial.rst>`__.
6+
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/main/advanced_source/rpc_ddp_tutorial.rst>`__.
77

88
This tutorial uses a simple example to demonstrate how you can combine
99
`DistributedDataParallel <https://pytorch.org/docs/stable/nn.html#torch.nn.parallel.DistributedDataParallel>`__ (DDP)

beginner_source/basics/optimization_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def train_loop(dataloader, model, loss_fn, optimizer):
160160
optimizer.step()
161161

162162
if batch % 100 == 0:
163-
loss, current = loss.item(), batch * len(X)
163+
loss, current = loss.item(), (batch + 1) * len(X)
164164
print(f"loss: {loss:>7f} [{current:>5d}/{size:>5d}]")
165165

166166

beginner_source/basics/quickstart_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
# operations in the neural network, we move it to the GPU if available.
8888

8989
# Get cpu or gpu device for training.
90-
device = "cuda" if torch.cuda.is_available() else "cpu"
90+
device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
9191
print(f"Using {device} device")
9292

9393
# Define model
@@ -151,7 +151,7 @@ def train(dataloader, model, loss_fn, optimizer):
151151
optimizer.step()
152152

153153
if batch % 100 == 0:
154-
loss, current = loss.item(), batch * len(X)
154+
loss, current = loss.item(), (batch + 1) * len(X)
155155
print(f"loss: {loss:>7f} [{current:>5d}/{size:>5d}]")
156156

157157
##############################################################################

beginner_source/bettertransformer_tutorial.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ been updated to use the core library modules to benefit from fastpath accelerati
1818

1919
Better Transformer offers two types of acceleration:
2020

21-
* Native multihead attention implementation for CPU and GPU to improvee overall execution efficiency.
21+
* Native multihead attention (MHA) implementation for CPU and GPU to improve overall execution efficiency.
2222
* Exploiting sparsity in NLP inference. Because of variable input lengths, input
2323
tokens may contain a large number of padding tokens for which processing may be
2424
skipped, delivering significant speedups.
@@ -124,6 +124,7 @@ Finally, we set the benchmark iteration count:
124124
2.1 Run and benchmark inference on CPU with and without BT fastpath (native MHA only)
125125

126126
We run the model on CPU, and collect profile information:
127+
127128
* The first run uses traditional ("slow path") execution.
128129
* The second run enables BT fastpath execution by putting the model in inference mode using `model.eval()` and disables gradient collection with `torch.no_grad()`.
129130

@@ -167,6 +168,7 @@ We disable the BT sparsity:
167168
168169
169170
We run the model on DEVICE, and collect profile information for native MHA execution on DEVICE:
171+
170172
* The first run uses traditional ("slow path") execution.
171173
* The second run enables BT fastpath execution by putting the model in inference mode using `model.eval()`
172174
and disables gradient collection with `torch.no_grad()`.

beginner_source/blitz/neural_networks_tutorial.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ def forward(self, x):
219219
# The simplest update rule used in practice is the Stochastic Gradient
220220
# Descent (SGD):
221221
#
222-
# ``weight = weight - learning_rate * gradient``
222+
# .. code:: python
223+
#
224+
# weight = weight - learning_rate * gradient
223225
#
224226
# We can implement this using simple Python code:
225227
#
@@ -233,18 +235,21 @@ def forward(self, x):
233235
# update rules such as SGD, Nesterov-SGD, Adam, RMSProp, etc.
234236
# To enable this, we built a small package: ``torch.optim`` that
235237
# implements all these methods. Using it is very simple:
236-
237-
import torch.optim as optim
238-
239-
# create your optimizer
240-
optimizer = optim.SGD(net.parameters(), lr=0.01)
241-
242-
# in your training loop:
243-
optimizer.zero_grad() # zero the gradient buffers
244-
output = net(input)
245-
loss = criterion(output, target)
246-
loss.backward()
247-
optimizer.step() # Does the update
238+
#
239+
# .. code:: python
240+
#
241+
# import torch.optim as optim
242+
#
243+
# # create your optimizer
244+
# optimizer = optim.SGD(net.parameters(), lr=0.01)
245+
#
246+
# # in your training loop:
247+
# optimizer.zero_grad() # zero the gradient buffers
248+
# output = net(input)
249+
# loss = criterion(output, target)
250+
# loss.backward()
251+
# optimizer.step() # Does the update
252+
#
248253

249254

250255
###############################################################

beginner_source/ddp_series_fault_tolerance.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Follow along with the video below or on `youtube <https://www.youtube.com/watch/
4242

4343
In distributed training, a single process failure can
4444
disrupt the entire training job. Since the susceptibility for failure can be higher here, making your training
45-
script robust is particularly important here. You might also prefer your training job to be *elastic* i.e.
46-
45+
script robust is particularly important here. You might also prefer your training job to be *elastic*, for example,
46+
compute resources can join and leave dynamically over the course of the job.
4747

4848
PyTorch offers a utility called ``torchrun`` that provides fault-tolerance and
4949
elastic training. When a failure occurs, ``torchrun`` logs the errors and
@@ -60,7 +60,7 @@ Why use ``torchrun``
6060
``torchrun`` handles the minutiae of distributed training so that you
6161
don't need to. For instance,
6262

63-
- You don't need to set environment variables or explicitly pass the ``rank`` and ``world_size``; torchrun assigns this along with several other `environment variables <https://pytorch.org/docs/stable/elastic/run.html#environment-variables>`__.
63+
- You don't need to set environment variables or explicitly pass the ``rank`` and ``world_size``; ``torchrun`` assigns this along with several other `environment variables <https://pytorch.org/docs/stable/elastic/run.html#environment-variables>`__.
6464
- No need to call ``mp.spawn`` in your script; you only need a generic ``main()`` entrypoint, and launch the script with ``torchrun``. This way the same script can be run in non-distributed as well as single-node and multinode setups.
6565
- Gracefully restarting training from the last saved training snapshot
6666

beginner_source/ddp_series_multigpu.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ In this tutorial, we start with a single-GPU training script and migrate that to
4141
Along the way, we will talk through important concepts in distributed training while implementing them in our code.
4242

4343
.. note::
44-
If your model contains any ``BatchNorm`` layer, it needs to be converted to ``SyncBatchNorm`` to sync the running stats of ``BatchNorm``
44+
If your model contains any ``BatchNorm`` layers, it needs to be converted to ``SyncBatchNorm`` to sync the running stats of ``BatchNorm``
4545
layers across replicas.
4646

4747
Use the helper function
@@ -57,7 +57,7 @@ Imports
5757
~~~~~~~
5858
- ``torch.multiprocessing`` is a PyTorch wrapper around Python's native
5959
multiprocessing
60-
- The dsitributed process group contains all the processes that can
60+
- The distributed process group contains all the processes that can
6161
communicate and synchronize with each other.
6262

6363
.. code:: diff

beginner_source/ddp_series_theory.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ DDP improves upon the architecture in a few ways:
5454
| | machines |
5555
+---------------------------------------+------------------------------+
5656
| Slower; uses multithreading on a | Faster (no GIL contention) |
57-
| single process and runs into GIL | because it uses |
58-
| contention | multiprocessing |
57+
| single process and runs into Global | because it uses |
58+
| Interpreter Lock (GIL) contention | multiprocessing |
5959
+---------------------------------------+------------------------------+
6060

6161
Further Reading

beginner_source/dist_overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PyTorch Distributed Overview
33
**Author**: `Shen Li <https://mrshenli.github.io/>`_
44

55
.. note::
6-
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/master/beginner_source/dist_overview.rst>`__.
6+
|edit| View and edit this tutorial in `github <https://github.com/pytorch/tutorials/blob/main/beginner_source/dist_overview.rst>`__.
77

88
This is the overview page for the ``torch.distributed`` package. The goal of
99
this page is to categorize documents into different topics and briefly

beginner_source/former_torchies/parallelism_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def forward(self, x):
132132
# - `Discuss PyTorch on the Forums`_
133133
# - `Chat with other users on Slack`_
134134
#
135-
# .. _`Deep Learning with PyTorch: a 60-minute blitz`: https://github.com/pytorch/tutorials/blob/master/Deep%20Learning%20with%20PyTorch.ipynb
135+
# .. _`Deep Learning with PyTorch: a 60-minute blitz`: https://github.com/pytorch/tutorials/blob/main/Deep%20Learning%20with%20PyTorch.ipynb
136136
# .. _Train a state-of-the-art ResNet network on imagenet: https://github.com/pytorch/examples/tree/master/imagenet
137137
# .. _Train a face generator using Generative Adversarial Networks: https://github.com/pytorch/examples/tree/master/dcgan
138138
# .. _Train a word-level language model using Recurrent LSTM networks: https://github.com/pytorch/examples/tree/master/word_language_model

beginner_source/hyperparameter_tuning_tutorial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ def main(num_samples=10, max_num_epochs=10, gpus_per_trial=2):
424424

425425

426426
if __name__ == "__main__":
427+
# sphinx_gallery_start_ignore
428+
# Fixes AttributeError: '_LoggingTee' object has no attribute 'fileno'.
429+
# This is only needed to run with sphinx-build.
430+
import sys
431+
sys.stdout.fileno = lambda: False
432+
# sphinx_gallery_end_ignore
427433
# You can change the number of GPUs per trial here:
428434
main(num_samples=10, max_num_epochs=10, gpus_per_trial=0)
429435

0 commit comments

Comments
 (0)