Skip to content

Commit 4227799

Browse files
authored
Merge branch 'main' into RC-TEST-2.9
2 parents 4d0eae2 + 7a6978b commit 4227799

20 files changed

+104
-1661
lines changed

advanced_source/semi_structured_sparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
# - A NVIDIA GPU with semi-structured sparsity support (Compute
4444
# Capability 8.0+).
4545
#
46+
# .. note:: This tutorial is tested on an NVIDIA A100 80GB GPU. You may not see similar speedups on newer GPU architectures, For the latest information on semi-structured sparsity support, please refer to the README `here <https://github.com/pytorch/ao/tree/main/torchao/sparsity#torchao-sparsity>
47+
#
4648
# This tutorial is designed for beginners to semi-structured sparsity and
4749
# sparsity in general. For users with existing 2:4 sparse models,
4850
# accelerating ``nn.Linear`` layers for inference with
@@ -52,7 +54,6 @@
5254
import torch
5355
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
5456
from torch.utils.benchmark import Timer
55-
SparseSemiStructuredTensor._FORCE_CUTLASS = True
5657

5758
# mask Linear weight to be 2:4 sparse
5859
mask = torch.Tensor([0, 0, 1, 1]).tile((3072, 2560)).cuda().bool()
@@ -207,7 +208,6 @@
207208
import transformers
208209

209210
# force CUTLASS use if ``cuSPARSELt`` is not available
210-
SparseSemiStructuredTensor._FORCE_CUTLASS = True
211211
torch.manual_seed(100)
212212

213213
# Set default device to "cuda:0"

beginner_source/blitz/autograd_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
loss.backward() # backward pass
6868

6969
############################################################
70-
# Next, we load an optimizer, in this case SGD with a learning rate of 0.01 and `momentum <https://towardsdatascience.com/stochastic-gradient-descent-with-momentum-a84097641a5d>`__ of 0.9.
70+
# Next, we load an optimizer, in this case SGD with a learning rate of 0.01 and `momentum <https://medium.com/data-science/stochastic-gradient-descent-with-momentum-a84097641a5d>`__ of 0.9.
7171
# We register all the parameters of the model in the optimizer.
7272
#
7373

beginner_source/blitz/cifar10_tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565

6666
########################################################################
6767
# .. note::
68-
# If running on Windows and you get a BrokenPipeError, try setting
68+
# If you are running this tutorial on Windows or MacOS and encounter a
69+
# BrokenPipeError or RuntimeError related to multiprocessing, try setting
6970
# the num_worker of torch.utils.data.DataLoader() to 0.
7071

7172
transform = transforms.Compose(

beginner_source/examples_autograd/polynomial_autograd.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
PyTorch: Tensors and autograd
33
-------------------------------
44
@@ -27,8 +27,8 @@
2727
# Create Tensors to hold input and outputs.
2828
# By default, requires_grad=False, which indicates that we do not need to
2929
# compute gradients with respect to these Tensors during the backward pass.
30-
x = torch.linspace(-math.pi, math.pi, 2000, dtype=dtype)
31-
y = torch.sin(x)
30+
x = torch.linspace(-1, 1, 2000, dtype=dtype)
31+
y = torch.exp(x) # A Taylor expansion would be 1 + x + (1/2) x**2 + (1/3!) x**3 + ...
3232

3333
# Create random Tensors for weights. For a third order polynomial, we need
3434
# 4 weights: y = a + b x + c x^2 + d x^3
@@ -39,17 +39,23 @@
3939
c = torch.randn((), dtype=dtype, requires_grad=True)
4040
d = torch.randn((), dtype=dtype, requires_grad=True)
4141

42-
learning_rate = 1e-6
43-
for t in range(2000):
42+
initial_loss = 1.
43+
learning_rate = 1e-5
44+
for t in range(5000):
4445
# Forward pass: compute predicted y using operations on Tensors.
4546
y_pred = a + b * x + c * x ** 2 + d * x ** 3
4647

4748
# Compute and print loss using operations on Tensors.
4849
# Now loss is a Tensor of shape (1,)
4950
# loss.item() gets the scalar value held in the loss.
5051
loss = (y_pred - y).pow(2).sum()
52+
53+
# Calculare initial loss, so we can report loss relative to it
54+
if t==0:
55+
initial_loss=loss.item()
56+
5157
if t % 100 == 99:
52-
print(t, loss.item())
58+
print(f'Iteration t = {t:4d} loss(t)/loss(0) = {round(loss.item()/initial_loss, 6):10.6f} a = {a.item():10.6f} b = {b.item():10.6f} c = {c.item():10.6f} d = {d.item():10.6f}')
5359

5460
# Use autograd to compute the backward pass. This call will compute the
5561
# gradient of loss with respect to all Tensors with requires_grad=True.

beginner_source/examples_nn/polynomial_nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-----------
55
66
A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi`
7-
to :math:`pi` by minimizing squared Euclidean distance.
7+
to :math:`\pi` by minimizing squared Euclidean distance.
88
99
This implementation uses the nn package from PyTorch to build the network.
1010
PyTorch autograd makes it easy to define computational graphs and take gradients,

beginner_source/examples_nn/polynomial_optim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
--------------
55
66
A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi`
7-
to :math:`pi` by minimizing squared Euclidean distance.
7+
to :math:`\pi` by minimizing squared Euclidean distance.
88
99
This implementation uses the nn package from PyTorch to build the network.
1010

beginner_source/examples_tensor/polynomial_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
--------------
55
66
A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi`
7-
to :math:`pi` by minimizing squared Euclidean distance.
7+
to :math:`\pi` by minimizing squared Euclidean distance.
88
99
This implementation uses numpy to manually compute the forward pass, loss, and
1010
backward pass.

beginner_source/examples_tensor/polynomial_tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
----------------
55
66
A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi`
7-
to :math:`pi` by minimizing squared Euclidean distance.
7+
to :math:`\pi` by minimizing squared Euclidean distance.
88
99
This implementation uses PyTorch tensors to manually compute the forward pass,
1010
loss, and backward pass.

beginner_source/hybrid_frontend/README.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)