Hi,
Note that we have hardsignmoid (https://pytorch.org/docs/master/nn.functional.html#torch.nn.functional.hardsigmoid 65) if you’re using the nightly builds or similar functions like hardtanh.
If you want to use your custom function:

If you want the “true” gradient to be used, then just implement the function you want and autograd will get the gradient for you.
If you want the backward to compute something else than the gradient of your function, you can see this doc 11 that explains how to do that with a custom autograd Function where you will have to specify the backward to use.