The behavior of model.parameters()


I am writing a pytorch model by myself and use model.parameters() and model.named_parameters() to access the parameters.

As one can see, both of them are iterators. When we use them to get a list of parameter tensors,

  1. Do they follow the same order?
  2. If I save/load the model again, is the order identical to the original order.

Thanks very much~

  1. Yes, in fact model.parameters just yield values from named_parameters
  2. It depends on the code rather than the weights, if the code is the same, the order is the same.
1 Like