I have a model and I want to disable some of the weights, so I flatten the weights of the model in order to iterate through them and turn off requires_grad for a subset:
params = torch.cat([param.flatten() for param in model.parameters()])
for i, param in enumerate(params):
     if should_be_disabled[i]:
           param.requires_grad_(False)

This returns error that requires_grad can only be changed for leaves.