nn.Sequential modules will add the index to the parameter names, such as 0.weight, 1.weight etc.



 veritas:

The reason for extracting only the weight and bias values is that .modules() returns all modules, including modules that contain other modules, whereas .named_parameters() only returns the parameters at the very end of the recursion.


I might misunderstand the use case, but I thought that’s exactly what you need: the actual parameters at the most inner level.