You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: beginner_source/examples_autograd/polynomial_custom_function.py
+17-9Lines changed: 17 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -29,19 +29,24 @@ class LegendrePolynomial3(torch.autograd.Function):
29
29
"""
30
30
31
31
@staticmethod
32
-
defforward(ctx, input):
32
+
defforward(input):
33
33
"""
34
34
In the forward pass we receive a Tensor containing the input and return
35
-
a Tensor containing the output. ctx is a context object that can be used
36
-
to stash information for backward computation. You can cache tensors for
37
-
use in the backward pass using the ``ctx.save_for_backward`` method. Other
38
-
objects can be stored directly as attributes on the ctx object, such as
39
-
``ctx.my_object = my_object``. Check out `Extending torch.autograd <https://docs.pytorch.org/docs/stable/notes/extending.html#extending-torch-autograd>`_
35
+
a Tensor containing the output. Check out `Extending torch.autograd <https://docs.pytorch.org/docs/stable/notes/extending.html#extending-torch-autograd>`_
40
36
for further details.
41
37
"""
42
-
ctx.save_for_backward(input)
43
38
return0.5* (5*input**3-3*input)
44
39
40
+
@staticmethod
41
+
defsetup_context(ctx, inputs, output):
42
+
"""
43
+
Store input for use in the backward pass using ``ctx.save_for_backward``.
44
+
Other objects can be stored directly as attributes on the ctx object,
0 commit comments