I want to have gradient but I dont know how to return the second gradient tensor For example:
def forward(self, input,N_bits):
self.save_for_backward(input,N_bits)
ttanh = (torch.tanh(input))
abss = torch.abs(ttanh)
maxx = torch.max(abss)
Func = ttanh / (maxx * 2) + 0.5
#Func = Func * 2 - 1
output = (Func * (2 ** N_bits - 1)).round() / (2 ** N_bits - 1)
output = output * 2 - 1
return output

def backward(self, grad_output):
# saved tensors - tuple of tensors with one element
grad_input = grad_output.clone()
input,N_bits, = self.saved_tensors
grad_input[input.ge(1)] = 0
grad_input[input.le(-1)] = 0
return grad_input, (??)
I am not sure about ?? that part