From 673a1dd09f772077d3a80fe586559da79075257e Mon Sep 17 00:00:00 2001 From: Max Klein Date: Wed, 13 May 2026 14:06:42 -0400 Subject: [PATCH 1/3] fix description of equation in polynomial_autograd.py example The equation that a + b*x + c*x^2 + d*x^3 converges to changed in a recent commit, from y=sin(x) to y=e^x. However, they didn't change the text description of the equation. This commit fixes that --- beginner_source/examples_autograd/polynomial_autograd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beginner_source/examples_autograd/polynomial_autograd.py b/beginner_source/examples_autograd/polynomial_autograd.py index d33ca8bcb90..185f0bc7791 100755 --- a/beginner_source/examples_autograd/polynomial_autograd.py +++ b/beginner_source/examples_autograd/polynomial_autograd.py @@ -2,8 +2,8 @@ PyTorch: Tensors and autograd ------------------------------- -A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`\pi` by minimizing squared Euclidean distance. +A third order polynomial, trained to predict :math:`y=e^x` from :math:`-1` +to :math:`1` by minimizing squared Euclidean distance. This implementation computes the forward pass using operations on PyTorch Tensors, and uses PyTorch autograd to compute gradients. From b6df7d2a92c66c3e39bc1b899bed04b21ffa3dbc Mon Sep 17 00:00:00 2001 From: Max Klein Date: Sat, 16 May 2026 00:12:08 -0400 Subject: [PATCH 2/3] Removed unused lines of code --- beginner_source/examples_autograd/polynomial_autograd.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/beginner_source/examples_autograd/polynomial_autograd.py b/beginner_source/examples_autograd/polynomial_autograd.py index 185f0bc7791..d94e4ed5d55 100755 --- a/beginner_source/examples_autograd/polynomial_autograd.py +++ b/beginner_source/examples_autograd/polynomial_autograd.py @@ -14,7 +14,6 @@ holding the gradient of ``x`` with respect to some scalar value. """ import torch -import math # We want to be able to train our model on an `accelerator `__ # such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU. @@ -39,7 +38,6 @@ c = torch.randn((), dtype=dtype, requires_grad=True) d = torch.randn((), dtype=dtype, requires_grad=True) -initial_loss = 1. learning_rate = 1e-5 for t in range(5000): # Forward pass: compute predicted y using operations on Tensors. From 852040a0ab93a53cfa2ffb3480e90a05ad02b947 Mon Sep 17 00:00:00 2001 From: Max Klein Date: Sat, 16 May 2026 00:17:21 -0400 Subject: [PATCH 3/3] fix typo --- beginner_source/examples_autograd/polynomial_autograd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_source/examples_autograd/polynomial_autograd.py b/beginner_source/examples_autograd/polynomial_autograd.py index d94e4ed5d55..b8353fc598e 100755 --- a/beginner_source/examples_autograd/polynomial_autograd.py +++ b/beginner_source/examples_autograd/polynomial_autograd.py @@ -48,7 +48,7 @@ # loss.item() gets the scalar value held in the loss. loss = (y_pred - y).pow(2).sum() - # Calculare initial loss, so we can report loss relative to it + # Calculate initial loss, so we can report loss relative to it if t==0: initial_loss=loss.item()