Parameters() and children() methods guaranteed to return paramters in same order?

Can I count on the parameters() method of my neural network to always return parameters (and, therefore, their weights/gradients) in the same order throughout the life of the network?

Would the same go for how the children are returned in the named_children() method?

I don’t see this explicitly addressed in documentation or in forums.

Thank you in advance.

nn.Module stores the modules using an OrderedDict, so both the order of the parameters as well as the modules should be fixed during runtime

1 Like