fmassa:

params1 = model1.named_parameters() params2 = model2.named_parameters()


Is there a better way to copy layer parameters from one model to another in 2020 (when trying to transfer a trained encoder or something else)?
I created this helper function per the discussion above but it doesn’t seem to be working as expected!
def copyParams(module_src, module_dest):
    params_src = module_src.named_parameters()
    params_dest = module_dest.named_parameters()

    dict_dest = dict(params_dest)

    for name, param in params_src:
        if name in dict_dest:
            dict_dest[name].data.copy_(param.data)