Skip to content

Commit 8008f90

Browse files
authored
Merge branch 'main' into main
2 parents 9b3c476 + 23a9aa0 commit 8008f90

14 files changed

+146
-18
lines changed

.ci/docker/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pyopengl
6464
gymnasium[mujoco]==0.27.0
6565
timm
6666
iopath
67-
pygame==2.1.2
67+
pygame==2.6.0
6868
pycocotools
6969
semilearn==0.3.2
7070
torchao==0.0.3

.gitmodules

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
[submodule "src/pytorch-sphinx-theme"]
2-
path = src/pytorch-sphinx-theme
3-
url = https://github.com/pytorch/pytorch_sphinx_theme
1+

beginner_source/deeplabv3_on_android.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Image Segmentation DeepLabV3 on Android
55

66
**Reviewed by**: `Jeremiah Chung <https://github.com/jeremiahschung>`_
77

8+
.. warning::
9+
PyTorch Mobile is no longer actively supported. Please check out `ExecuTorch <https://pytorch.org/executorch-overview>`_, PyTorch’s all-new on-device inference library. You can also review our `end-to-end workflows <https://github.com/pytorch/executorch/tree/main/examples/portable#readme>`_ and review the `source code for DeepLabV3 <https://github.com/pytorch/executorch/tree/main/examples/models/deeplab_v3>`_.
10+
11+
812
Introduction
913
------------
1014

beginner_source/onnx/intro_onnx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
4040
- `ONNX <https://onnx.ai>`_ standard library
4141
- `ONNX Script <https://onnxscript.ai>`_ library that enables developers to author ONNX operators,
42-
functions and models using a subset of Python in an expressive, and yet simple fashion.
42+
functions and models using a subset of Python in an expressive, and yet simple fashion
43+
- `ONNX Runtime <https://onnxruntime.ai>`_ accelerated machine learning library.
4344
4445
They can be installed through `pip <https://pypi.org/project/pip/>`_:
4546
4647
.. code-block:: bash
4748
48-
pip install --upgrade onnx onnxscript
49+
pip install --upgrade onnx onnxscript onnxruntime
4950
5051
To validate the installation, run the following commands:
5152

conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
#
6868
# needs_sphinx = '1.0'
6969

70+
html_meta = {
71+
'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!',
72+
'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI',
73+
'author': 'PyTorch Contributors'
74+
}
75+
7076
# Add any Sphinx extension module names here, as strings. They can be
7177
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
7278
# ones.

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Welcome to PyTorch Tutorials
33

44
**What's new in PyTorch tutorials?**
55

6+
* `torch.export AOTInductor Tutorial for Python runtime (Beta) <https://pytorch.org/tutorials/recipes/torch_export_aoti_python.html>`__
67
* `A guide on good usage of non_blocking and pin_memory() in PyTorch <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__
78
* `Introduction to Distributed Pipeline Parallelism <https://pytorch.org/tutorials/intermediate/pipelining_tutorial.html>`__
89
* `Introduction to Libuv TCPStore Backend <https://pytorch.org/tutorials/intermediate/TCPStore_libuv_backend.html>`__

intermediate_source/torch_compile_tutorial.py

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,21 @@ def foo(x, y):
7373

7474
######################################################################
7575
# Alternatively, we can decorate the function.
76+
t1 = torch.randn(10, 10)
77+
t2 = torch.randn(10, 10)
7678

7779
@torch.compile
7880
def opt_foo2(x, y):
7981
a = torch.sin(x)
8082
b = torch.cos(y)
8183
return a + b
82-
print(opt_foo2(torch.randn(10, 10), torch.randn(10, 10)))
84+
print(opt_foo2(t1, t2))
8385

8486
######################################################################
8587
# We can also optimize ``torch.nn.Module`` instances.
8688

89+
t = torch.randn(10, 100)
90+
8791
class MyModule(torch.nn.Module):
8892
def __init__(self):
8993
super().__init__()
@@ -94,7 +98,101 @@ def forward(self, x):
9498

9599
mod = MyModule()
96100
opt_mod = torch.compile(mod)
97-
print(opt_mod(torch.randn(10, 100)))
101+
print(opt_mod(t))
102+
103+
######################################################################
104+
# torch.compile and Nested Calls
105+
# ------------------------------
106+
# Nested function calls within the decorated function will also be compiled.
107+
108+
def nested_function(x):
109+
return torch.sin(x)
110+
111+
@torch.compile
112+
def outer_function(x, y):
113+
a = nested_function(x)
114+
b = torch.cos(y)
115+
return a + b
116+
117+
print(outer_function(t1, t2))
118+
119+
######################################################################
120+
# In the same fashion, when compiling a module all sub-modules and methods
121+
# within it, that are not in a skip list, are also compiled.
122+
123+
class OuterModule(torch.nn.Module):
124+
def __init__(self):
125+
super().__init__()
126+
self.inner_module = MyModule()
127+
self.outer_lin = torch.nn.Linear(10, 2)
128+
129+
def forward(self, x):
130+
x = self.inner_module(x)
131+
return torch.nn.functional.relu(self.outer_lin(x))
132+
133+
outer_mod = OuterModule()
134+
opt_outer_mod = torch.compile(outer_mod)
135+
print(opt_outer_mod(t))
136+
137+
######################################################################
138+
# We can also disable some functions from being compiled by using
139+
# ``torch.compiler.disable``. Suppose you want to disable the tracing on just
140+
# the ``complex_function`` function, but want to continue the tracing back in
141+
# ``complex_conjugate``. In this case, you can use
142+
# ``torch.compiler.disable(recursive=False)`` option. Otherwise, the default is
143+
# ``recursive=True``.
144+
145+
def complex_conjugate(z):
146+
return torch.conj(z)
147+
148+
@torch.compiler.disable(recursive=False)
149+
def complex_function(real, imag):
150+
# Assuming this function cause problems in the compilation
151+
z = torch.complex(real, imag)
152+
return complex_conjugate(z)
153+
154+
def outer_function():
155+
real = torch.tensor([2, 3], dtype=torch.float32)
156+
imag = torch.tensor([4, 5], dtype=torch.float32)
157+
z = complex_function(real, imag)
158+
return torch.abs(z)
159+
160+
# Try to compile the outer_function
161+
try:
162+
opt_outer_function = torch.compile(outer_function)
163+
print(opt_outer_function())
164+
except Exception as e:
165+
print("Compilation of outer_function failed:", e)
166+
167+
######################################################################
168+
# Best Practices and Recommendations
169+
# ----------------------------------
170+
#
171+
# Behavior of ``torch.compile`` with Nested Modules and Function Calls
172+
#
173+
# When you use ``torch.compile``, the compiler will try to recursively compile
174+
# every function call inside the target function or module inside the target
175+
# function or module that is not in a skip list (such as built-ins, some functions in
176+
# the torch.* namespace).
177+
#
178+
# **Best Practices:**
179+
#
180+
# 1. **Top-Level Compilation:** One approach is to compile at the highest level
181+
# possible (i.e., when the top-level module is initialized/called) and
182+
# selectively disable compilation when encountering excessive graph breaks or
183+
# errors. If there are still many compile issues, compile individual
184+
# subcomponents instead.
185+
#
186+
# 2. **Modular Testing:** Test individual functions and modules with ``torch.compile``
187+
# before integrating them into larger models to isolate potential issues.
188+
#
189+
# 3. **Disable Compilation Selectively:** If certain functions or sub-modules
190+
# cannot be handled by `torch.compile`, use the `torch.compiler.disable` context
191+
# managers to recursively exclude them from compilation.
192+
#
193+
# 4. **Compile Leaf Functions First:** In complex models with multiple nested
194+
# functions and modules, start by compiling the leaf functions or modules first.
195+
# For more information see `TorchDynamo APIs for fine-grained tracing <https://pytorch.org/docs/stable/torch.compiler_fine_grain_apis.html>`__.
98196

99197
######################################################################
100198
# Demonstrating Speedups

prototype_source/gpu_quantization_torchao_tutorial.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@
3535
#
3636
# Segment Anything Model checkpoint setup:
3737
#
38-
# 1. Go to the `segment-anything repo <checkpoint https://github.com/facebookresearch/segment-anything/tree/main#model-checkpoints>`_ and download the ``vit_h`` checkpoint. Alternatively, you can just use ``wget``: `wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth --directory-prefix=<path>
38+
# 1. Go to the `segment-anything repo checkpoint <https://github.com/facebookresearch/segment-anything/tree/main#model-checkpoints>`_ and download the ``vit_h`` checkpoint. Alternatively, you can use ``wget`` (for example, ``wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth --directory-prefix=<path>``).
3939
# 2. Pass in that directory by editing the code below to say:
4040
#
41-
# .. code-block::
42-
#
43-
# {sam_checkpoint_base_path}=<path>
41+
# .. code-block:: bash
4442
#
45-
# This was run on an A100-PG509-200 power limited to 330.00 W
43+
# {sam_checkpoint_base_path}=<path>
4644
#
4745

4846
import torch
@@ -297,7 +295,7 @@ def get_sam_model(only_one_block=False, batchsize=1):
297295
# -----------------
298296
# In this tutorial, we have learned about the quantization and optimization techniques
299297
# on the example of the segment anything model.
300-
298+
#
301299
# In the end, we achieved a full-model apples to apples quantization speedup
302300
# of about 7.7% on batch size 16 (677.28ms to 729.65ms). We can push this a
303301
# bit further by increasing the batch size and optimizing other parts of

prototype_source/lite_interpreter.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(Prototype) Introduce lite interpreter workflow in Android and iOS
2+
=======================
3+
4+
This tutorial has been moved to https://pytorch.org/tutorials/recipes/mobile_interpreter.html
5+
6+
7+
.. raw:: html
8+
9+
<meta http-equiv="Refresh" content="0; url='https://pytorch.org/tutorials/recipes/mobile_interpreter.html'" />

recipes_source/distributed_checkpoint_recipe.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ the intent is to save or load in "non-distributed" style, meaning entirely in th
289289
import os
290290
291291
import torch
292-
import torch.distributed.checkpoint as DCP
292+
import torch.distributed.checkpoint as dcp
293293
import torch.nn as nn
294294
295295

recipes_source/mobile_interpreter.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
**Author**: `Chen Lai <https://github.com/cccclai>`_, `Martin Yuan <https://github.com/iseeyuan>`_
55

6+
.. warning::
7+
PyTorch Mobile is no longer actively supported. Please check out `ExecuTorch <https://pytorch.org/executorch-overview>`_, PyTorch’s all-new on-device inference library. You can also review our new documentation to learn more about how to build `iOS <https://pytorch.org/executorch/stable/demo-apps-ios.html>`_ and `Android <https://pytorch.org/executorch/stable/demo-apps-android.html>`_ apps with ExecuTorch.
8+
69
Introduction
710
------------
811

recipes_source/mobile_perf.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Pytorch Mobile Performance Recipes
22
==================================
33

4+
.. warning::
5+
PyTorch Mobile is no longer actively supported. Please check out `ExecuTorch <https://pytorch.org/executorch-overview>`_, PyTorch’s all-new on-device inference library. You can also learn more about `quantization <https://pytorch.org/executorch/stable/quantization-overview.html>`_, `Hardware acceleration (op fusion using hw) <https://pytorch.org/executorch/stable/examples-end-to-end-to-lower-model-to-delegate.html>`_, and `benchmarking <https://pytorch.org/executorch/stable/sdk-profiling.html>`_ on ExecuTorch’s documentation pages.
6+
47
Introduction
58
----------------
69
Performance (aka latency) is crucial to most, if not all,
@@ -245,7 +248,7 @@ For example, using ResNet-50 and running the following script:
245248

246249

247250

248-
you would get the following result:
251+
you would get the following result:
249252

250253
::
251254

recipes_source/ptmobile_recipes_summary.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Summary of PyTorch Mobile Recipes
22
=====================================
33

4+
.. warning::
5+
Note: PyTorch Mobile is no longer actively supported. Please check out `ExecuTorch <https://pytorch.org/executorch-overview>`_, PyTorch’s all-new on-device inference library. You can also review these `ExecuTorch examples <https://github.com/pytorch/executorch/tree/main/examples#readme>`_.
6+
47
This summary provides a top level overview of recipes for PyTorch Mobile to help developers choose which recipes to follow for their PyTorch-powered mobile app development.
58

69
Introduction

recipes_source/torch_export_aoti_python.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
(Beta) ``torch.export`` AOTInductor Tutorial for Python runtime
4+
.. meta::
5+
:description: An end-to-end example of how to use AOTInductor for Python runtime.
6+
:keywords: torch.export, AOTInductor, torch._inductor.aot_compile, torch._export.aot_load
7+
8+
``torch.export`` AOTInductor Tutorial for Python runtime (Beta)
59
===============================================================
610
**Author:** Ankith Gunapal, Bin Bao, Angela Yi
711
"""
@@ -18,7 +22,7 @@
1822
# a shared library that can be run in a non-Python environment.
1923
#
2024
#
21-
# In this tutorial, you will learn an end-to-end example of how to use AOTInductor for python runtime.
25+
# In this tutorial, you will learn an end-to-end example of how to use AOTInductor for Python runtime.
2226
# We will look at how to use :func:`torch._inductor.aot_compile` along with :func:`torch.export.export` to generate a
2327
# shared library. Additionally, we will examine how to execute the shared library in Python runtime using :func:`torch._export.aot_load`.
2428
# You will learn about the speed up seen in the first inference time using AOTInductor, especially when using

0 commit comments

Comments
 (0)