Hii, I forgot posting my code after replying earlier
This is the relavant code
         data, target = data.to(device), target.to(device)
         optimizer.zero_grad()
         output = model1(data)
         finalOutput = model2(data - factor*output)
         loss = F.nll_loss(finalOutput, target)
         loss.backward()
         print(output.grad)
         print(finalOutput.grad)
         optimizer.step()

None is being printed!!