Skip to content
masterclass Buddy

PyTorch · Function

backward

Function.backward defines the reverse-mode gradient rule for a custom PyTorch operation. It receives output gradients and returns matching input gradients.

Last updated

Syntax

static Function.backward(ctx, *grad_outputs)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • torch.autograd.Function
  • torch.autograd.function.BackwardCFunction
  • ctx.needs_input_grad
  • ctx.saved_tensors

Source: torch.autograd.Function.backward — PyTorch 2.14 documentation. Checked 2026-11-03.