Thanks ptrblck.
Actually In was confused about the error. Let me explain you. In training phase I am giving the output of my network to a function lets say f1() which the  tensor as input  and giving a scalar output and then output of f1() is going into this loss function. So it is some what like
 output = net(input)
 out1 = f1(output)
 Loss = my_Loss(out1,X)
 Loss.backward()

And then all the gradients of parameters are None. So may be the problem was at function f1(). That I will attach later.