|
6 | 6 | This tutorial demonstrates how to use forward-mode AD to compute
|
7 | 7 | directional derivatives (or equivalently, Jacobian-vector products).
|
8 | 8 |
|
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 |
10 | 26 |
|
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 | +""" |
29 | 28 |
|
30 | 29 | import torch
|
31 | 30 | import torch.autograd.forward_ad as fwAD
|
|
0 commit comments