I am trying to assign a ndarray of zeros to the grad of the model parameters, but I am getting the error in the title.
I was just trying to see if I can assign a numpy array to the param.grad. But in my project I won’t be assigning zeros actually.
for param in model.parameters():
            #print(param.grad)
            param.grad = torch.from_numpy(np.zeros(param.grad.shape)).type(param.grad.dtype)

I am trying to do this step after loss.backward() step.
I want to know what is causing this error and how to solve it.
Kindly help!