Backward for operations in torch.nn.functional

The “torch.nn.grad” package ( contains functions to manually compute backwards through a convolution operation. It is unclear why it has this name but only contains this for convolutions; I was not able to find documentation for this package or these functions. My question is, is there any similar Python interface for other operations, for instance F.max_pool2d? (It is quite simple to compute the gradient backward through max pooling. But I believe I remember finding this exact backward function somewhere in PyTorch just a few days ago, but I cannot for the life of me remember where, which is why I ask about this specifically.)

1 Like


There is a max_pool2d_with_indices_backward in L5188 of native_functions.yaml
and L1145 & L1282 of derivatives.yaml

“Life of a Tensor” pytorch wiki seems to imply that all the functions listed in native_functions.yaml could be used as python functions:

I have no idea how to directly call max_pool2d_with_indices_backward via pytorch’s python frontend though.

How can I call max_pool2d_with_indices_backward (and all the other *_backward functions) via pytorch’s python frontend (without using torch.Tensor.backward or torch.autograd.backward)?