Hi, I am trying to get the gradients when I train Resnet50 model provided by DeepLearningExamples. And the problem is successfully solved by calling this function “print(self.model.module.conv1.weight.grad)”. But I found there are too many ‘…’ in gradients. Although I set “np.set_printoptions(threshold=sys.maxsize)”, this problem is still not solved. In addition to this, I found self.model.module.conv1.weight.grad is a NoneType object and I can’t use some torch functions.
So how can I get the whole gradients?
Using np.set_printoptions
won’t change the behavior of PyTorch and you should use torch.set_printoptions(threshold=...)
instead.
The .grad
attributes are None
if they were not computed and will be filled during the backward
call assuming the corresponding parameter was used to calculate the model output.
Thank you very much! I figure it out by setting torch.set_printoptions(threshold=sys.maxsize)