From f6cd0101433897441240e682b95245eb54f7f0c5 Mon Sep 17 00:00:00 2001 From: harshaljanjani Date: Tue, 3 Jun 2025 23:04:18 +0400 Subject: [PATCH 1/4] docs: Fix incorrect usage description of ctx.save_for_backward --- .../examples_autograd/polynomial_custom_function.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/beginner_source/examples_autograd/polynomial_custom_function.py b/beginner_source/examples_autograd/polynomial_custom_function.py index eea1c4ca9ee..f7535c25962 100755 --- a/beginner_source/examples_autograd/polynomial_custom_function.py +++ b/beginner_source/examples_autograd/polynomial_custom_function.py @@ -33,8 +33,10 @@ def forward(ctx, input): """ In the forward pass we receive a Tensor containing the input and return a Tensor containing the output. ctx is a context object that can be used - to stash information for backward computation. You can cache arbitrary - objects for use in the backward pass using the ctx.save_for_backward method. + to stash information for backward computation. You can cache tensors for + use in the backward pass using the ctx.save_for_backward method. Other + objects can be stored directly as attributes on the ctx object, such as + ctx.my_object = my_object. """ ctx.save_for_backward(input) return 0.5 * (5 * input ** 3 - 3 * input) From dfb4f9ee1bf34026cee26e248cbaac3781250e89 Mon Sep 17 00:00:00 2001 From: Harshal Janjani <75426551+harshaljanjani@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:47:04 +0400 Subject: [PATCH 2/4] Update polynomial_custom_function.py Co-authored-by: Svetlana Karslioglu --- beginner_source/examples_autograd/polynomial_custom_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_source/examples_autograd/polynomial_custom_function.py b/beginner_source/examples_autograd/polynomial_custom_function.py index f7535c25962..e0f2c732fce 100755 --- a/beginner_source/examples_autograd/polynomial_custom_function.py +++ b/beginner_source/examples_autograd/polynomial_custom_function.py @@ -34,7 +34,7 @@ def forward(ctx, input): In the forward pass we receive a Tensor containing the input and return a Tensor containing the output. ctx is a context object that can be used to stash information for backward computation. You can cache tensors for - use in the backward pass using the ctx.save_for_backward method. Other + use in the backward pass using the ``ctx.save_for_backward`` method. Other objects can be stored directly as attributes on the ctx object, such as ctx.my_object = my_object. """ From ed7e50998d9d5aab701063bc5d75c162917a7ed0 Mon Sep 17 00:00:00 2001 From: harshaljanjani Date: Wed, 4 Jun 2025 12:30:00 +0400 Subject: [PATCH 3/4] docs: Update docstring to include link for extending torch.autograd --- .../examples_autograd/polynomial_custom_function.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beginner_source/examples_autograd/polynomial_custom_function.py b/beginner_source/examples_autograd/polynomial_custom_function.py index e0f2c732fce..6a84226a684 100755 --- a/beginner_source/examples_autograd/polynomial_custom_function.py +++ b/beginner_source/examples_autograd/polynomial_custom_function.py @@ -35,8 +35,9 @@ def forward(ctx, input): a Tensor containing the output. ctx is a context object that can be used to stash information for backward computation. You can cache tensors for use in the backward pass using the ``ctx.save_for_backward`` method. Other - objects can be stored directly as attributes on the ctx object, such as - ctx.my_object = my_object. + objects can be stored directly as attributes on the ctx object, such as + ctx.my_object = my_object. Check out `Extending torch.autograd `_ + for further details. """ ctx.save_for_backward(input) return 0.5 * (5 * input ** 3 - 3 * input) From 6549007bd68c322d925a61c7d93d4de45fb188ca Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Wed, 4 Jun 2025 10:41:52 -0700 Subject: [PATCH 4/4] Update beginner_source/examples_autograd/polynomial_custom_function.py --- beginner_source/examples_autograd/polynomial_custom_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_source/examples_autograd/polynomial_custom_function.py b/beginner_source/examples_autograd/polynomial_custom_function.py index 6a84226a684..39057c8fd7a 100755 --- a/beginner_source/examples_autograd/polynomial_custom_function.py +++ b/beginner_source/examples_autograd/polynomial_custom_function.py @@ -36,7 +36,7 @@ def forward(ctx, input): to stash information for backward computation. You can cache tensors for use in the backward pass using the ``ctx.save_for_backward`` method. Other objects can be stored directly as attributes on the ctx object, such as - ctx.my_object = my_object. Check out `Extending torch.autograd `_ + ``ctx.my_object = my_object``. Check out `Extending torch.autograd `_ for further details. """ ctx.save_for_backward(input)