Passing models, optimizers and schedulers to functions

Hi!

Bit confused about passing models, optimizers and schedulers to functions.

I have a function called train_epoch(model, optimizer, scheduler, …). Should the model in the calling function get updated by this function without me returning the model and reassigning it?

My (imperfect) understanding of python is that the function would create an instance of the objects and changes would only effect this scope (not the calling function). However my code currently does not return the model ect and training does appear to progress as expected.

Any insights much appreciated!

Try writing a function that accepts a list as argument and changes some elements of this list. Now initialize a list and pass it to this function. Print the list after the function returns. What do you observe?

1 Like

Ah yes, make sense now! Thank you :slight_smile:

1 Like