I have a ModuleList, with Linear and Batchnorm layers. I wanted to call named named_parameters() and only get the grads of the linear layers as follows:
for name, param in model.named_parameters():
            if(isinstance(param, nn.Linear)):            
                  grads[name] = param.grad

This doesn’t work since type(param) always returns torch.nn.parameter.Parameter. Also if "weight" in name: doesn’t work since batchnorm layers also have “weight” in their name.
Are there any workarounds to this? I also looked at giving custom names to modules in the ModuleList, but I couldn’t find how.