There are plenty of small bugs in your code. If you replace the functions by
affine = torch.mm
tanh = torch.tanh
squere_loss = torch.nn.MSELoss()

and one at a time change to your function, you will have better error messages.
A few points by the way in Gn_Tanh:

in your case, most of the time you want to do def backward(self, grad_output) instead of def backward(self, *grad_output)

you should unpack the saved tensors (it is a tuple, not a tensor), so x, = self.saved_tensors

you are getting the size of grad_input.size()[1], but then using it to index the 0th dimension. Is that right?

It’s interesting though that the error messages get lost when everything is put together,