Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 6d49b01

Browse files
committed
Followup CR
1 parent 210b165 commit 6d49b01

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/api/python/autograd/autograd.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ The pattern to calculate higher order gradients is the following:
100100
```python
101101
from mxnet import ndarray as nd
102102
from mxnet import autograd as ag
103-
x=nd.array([1,2,3])
103+
x = nd.array([1,2,3])
104104
x.attach_grad()
105105
def f(x):
106-
# A function which supports higher oder gradients
106+
# Any function which supports higher oder gradient
107107
return nd.log(x)
108108
```
109109

@@ -117,28 +117,28 @@ Using mxnet.autograd.grad multiple times:
117117
```python
118118
with ag.record():
119119
y = f(x)
120-
x_grad = ag.grad(y, x, create_graph=True, retain_graph=True)[0]
121-
x_grad_grad = ag.grad(x_grad, x, create_graph=False, retain_graph=True)[0]
122-
print(f"dy/dx: {x_grad}")
123-
print(f"d2y/dx2: {x_grad_grad}")
120+
x_grad = ag.grad(heads=y, variables=x, create_graph=True, retain_graph=True)[0]
121+
x_grad_grad = ag.grad(heads=x_grad, variables=x, create_graph=False, retain_graph=False)[0]
122+
print(f"dL/dx: {x_grad}")
123+
print(f"d2L/dx2: {x_grad_grad}")
124124
```
125125

126126
Running backward on the backward graph:
127127

128128
```python
129129
with ag.record():
130130
y = f(x)
131-
x_grad = ag.grad(y, x, create_graph=True, retain_graph=True)[0]
131+
x_grad = ag.grad(heads=y, variables=x, create_graph=True, retain_graph=True)[0]
132132
x_grad.backward()
133133
x_grad_grad = x.grad
134-
print(f"dy/dx: {x_grad}")
135-
print(f"d2y/dx2: {x_grad_grad}")
134+
print(f"dL/dx: {x_grad}")
135+
print(f"d2L/dx2: {x_grad_grad}")
136136

137137
```
138138

139139
Both methods are equivalent, except that in the second case, retain_graph on running backward is set
140140
to False by default. But both calls are running a backward pass as on the graph as usual to get the
141-
gradient of the first gradient `y_grad` with respect to `x` evaluated at the value of `x`.
141+
gradient of the first gradient `x_grad` with respect to `x` evaluated at the value of `x`.
142142

143143

144144

0 commit comments

Comments
 (0)