Grad is None after backward() is called, and required_grad is True(!)

Please see this post for an answer Why cant I see .grad of an intermediate variable?

In your case, note that since you call .cuda(), the variable that you store in X_var is not the leaf Variable.
Either do
X_var = Variable(X.cuda(), requires_grad=True)
or

X_var = Variable(X, requires_grad=True)
X_var_cuda = X_var.cuda()
scores = model(X_var_cuda)
5 Likes