Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions beginner_source/examples_autograd/polynomial_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <https://pytorch.org/docs/stable/torch.html#accelerators>`__
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
Expand All @@ -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.
Expand All @@ -50,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()

Expand Down