Grad is a 'NoneType' Object

Hi all,

I am trying to zero out some gradients. While trying to access these gradients, I am getting an error saying that grad is a ‘NoneType’ object. I am trying to access grads in the following way:
x.grad[:,6:] = 0.

Although I can print out the grads, as shown in the following. Can someone please clarify what I am doing wrong? Instead what I should be doing? I would like to zero out some of the grads. The parameters are SMPL model’s parameters, if that information is critical. I have checked that requires_grad is set to True.

I am using PyTorch version 1.7.1.

x grads: tensor([[-0.0270, -0.0827, 0.1278, -0.0646, 0.0180, 0.1799, -0.0155, -0.0112,
-0.0456, -0.0226, -0.0908, -0.0457, 0.0180, -0.0526, 0.0139, 0.0440,

0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]])

Thank you very much.