Question about Optimizer in 03_minibach_trainning

In the notebook, we pass the model parameters to the optimizer as shown below:

Then we update the parameters in the optimizer:

I thought that since we passed on the model parameters to the optimizer and save them in self.params, changing self.params will not affect the values of the model parameters. I don’t understand why updating self.params will also update the parameter values of the model.

Would you please help me understand this? Thank you very much!

I think you may be confusing “pass by value” and “pass by reference”. The parameters are stored as a references to objects in Python, the same objects as in the model.

HTH, Malcolm

Thank you for your help!