Solved by albanD in post #2 
              
              
                Hi, 
loss is a Tensor at this line: 
loss['model'].backward()

So you should not try to get the 'model' attribute from it. 
loss.backward() should work though