# Calculate the loss
  loss = F.nll_loss(output, target)
  # Zero all existing gradients
  model.zero_grad()
  # Calculate gradients of model in backward pass
  loss.backward()
  # Collect datagrad
  data_grad = data.grad.data

I implemented the pytorch tutorial on adversarial examples, which works fine with fc layers on MNIST, but when I use a convnet on CIFAR10, I get the error message: ‘NoneType’ object has no attribute ‘data’. It seems that gradients are not calculated.