Skip to content

Commit 9687d01

Browse files
committed
Formatting
1 parent 674edc3 commit 9687d01

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

intermediate_source/forward_ad_tutorial.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
This tutorial demonstrates how to use forward-mode AD to compute
77
directional derivatives (or equivalently, Jacobian-vector products).
88
9-
"""
9+
Basic Usage
10+
--------------------------------------------------------------------
11+
Unlike reverse-mode AD, forward-mode AD computes gradients eagerly
12+
alongside the forward pass. We can use forward-mode AD to compute a
13+
directional derivative by performing the forward pass as before,
14+
except we first associate with our input with another tensor representing
15+
the direction of the directional derivative (or equivalently, the ``v``
16+
in a Jacobian-vector product). When a input, which we call "primal", is
17+
associated with a "direction" tensor, which we call "tangent", the
18+
resultant new tensor object is called a "dual tensor" for its connection
19+
to dual numbers[0].
20+
21+
As the forward pass is performed, if any input tensors are dual tensors,
22+
extra computation is performed to propogate this "sensitivity" of the
23+
function.
24+
25+
[0] https://en.wikipedia.org/wiki/Dual_number
1026
11-
######################################################################
12-
# Basic Usage
13-
# --------------------------------------------------------------------
14-
# Unlike reverse-mode AD, forward-mode AD computes gradients eagerly
15-
# alongside the forward pass. We can use forward-mode AD to compute a
16-
# directional derivative by performing the forward pass as before,
17-
# except we first associate with our input with another tensor representing
18-
# the direction of the directional derivative (or equivalently, the ``v``
19-
# in a Jacobian-vector product). When a input, which we call "primal", is
20-
# associated with a "direction" tensor, which we call "tangent", the
21-
# resultant new tensor object is called a "dual tensor" for its connection
22-
# to dual numbers[0].
23-
#
24-
# As the forward pass is performed, if any input tensors are dual tensors,
25-
# extra computation is performed to propogate this "sensitivity" of the
26-
# function.
27-
#
28-
# [0] https://en.wikipedia.org/wiki/Dual_number
27+
"""
2928

3029
import torch
3130
import torch.autograd.forward_ad as fwAD

0 commit comments

Comments
 (0)