Universal way to loop through parameters of a model

Is the following the universal pytorch way to loop through model params:

for name, W in net.named_parameters():
    do(name,W)

are there other ways or thats the universal way to do it? Are all models most commonly just a net object instance?

Hi,

This will return all the nn.Parameter() stored in you model (and all it’s “child” nn.Module). This is the right way to go through all the parameters (with net.parameters()).
Yes most models are a single nn.Module that will contain many other nn.Modules.