Skip to content

Instantly share code, notes, and snippets.

@andrewnc
Created April 21, 2022 15:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewnc/c744607028123d273d68b7c0f31d3ade to your computer and use it in GitHub Desktop.
Save andrewnc/c744607028123d273d68b7c0f31d3ade to your computer and use it in GitHub Desktop.
Code to soup two models in pytorch
def soup_two_models(model, second_model):
souped_model = copy.deepcopy(model)
for param in souped_model.named_parameters():
name = param[0]
param[1].data = (model.state_dict()[name] + second_model.state_dict()[name]) / 2
return souped_model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment