Hi,
I have seen a method to scale model, in PySyft, and I had some guesses, but I would appreciate it if you could please explain what is happening in here.
I mention my questions in the code as comments.
def scale_model(model, scale):
"""Scale the parameters of a model.
Args:
model (torch.nn.Module): the models whose parameters will be scaled.
scale (float): the scaling factor.
Returns:
torch.nn.Module: the module with scaled parameters.
"""
params = model.named_parameters()
# in here, does params have references of model parameters? It only makes sense
# for me only in this, way, but how a method return a pointer?
dict_params = dict(params)
# I was assuming that casting params as a dictionary, would change the pointer
# assignments, but it seems that it still has its references
with torch.no_grad():
for name, param in dict_params.items():
dict_params[name].set_(dict_params[name].data * scale)
# I am seeing that in the line above, the scale is applying to each layer separately. Is it
# correct? and then we have modified the parameters, and the data is changing in the
# model, as well
return model