This is my training iteration. I need to check the gradient. I incorporated what you suggested.
I am getting this error.
grad_output = grad_output.data**
atributeError: ‘NoneType’ object has no attribute ‘data’**
The code snippet:
for i,batch in enumerate(train_loader):
if (i%100)==0:
print(epoch,i,len(train_loader))
print(i,batch)
          #Clear the GRADIENT
          optimizer.zero_grad()
          #INPUT
          imgs,ques,ans = batch
          #imgs,ques,ans = imgs.cuda(),ques.cuda(),ans.cuda()
          imgs,ques,ans = imgs.to(device),ques.to(device),ans.to(device)
          #FORWARD PASS
          #OUTPUT
          
          ansout,queryout = net(imgs,ques,ans)
          
          #LOSS CALCULATED
          #Here answer is my target thus ".data" is used
          queryloss = loss(queryout, ansout.data)
          #Here query is my target 
          ansloss = loss(ansout, queryout.data)
          get_dot = check_grad.register_hooks(ansloss)
          #MSE Added
          #print(ansloss)
          sum_ans_train += ansloss.item()
          queryloss.backward(retain_graph=True)
        
          #BACKPROPAGATION
          ansloss.backward()
          dot = get_dot()
          dot.save('/home/Abhishek/plots/tmp.dot')