Back propagation problem

I am new to Pytorch. When I try to create my own module with Pytorch. I meet some problem.First, I want to write a backward() function in python,but I can not use nn.SpatialAdaptiveMaxPooling().backwrad().Then how can i get the gradinput?Thank you for your help.

You don’t need to write your own backward function. You just need to write your forward function and your backward function will be generated automatically via autograd. See http://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html for an example.

Thank you for your replay, I am sorry that I did not express meaning correctly. Actually,I want to write a new layer,not a module, then how to write the backward function?

See http://pytorch.org/docs/notes/extending.html