Skip to content

Instantly share code, notes, and snippets.

View andrewnc's full-sized avatar

Andrew Carr andrewnc

View GitHub Profile
andrewnc /
Created April 21, 2022 15:43
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
def get_GPU_usage():
cmd = "nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits"
result = subprocess.check_output(cmd, shell=True).decode('utf-8')
usages = list(map(int, result.strip().split('\n')))
return usages