MCPcopy Create free account
hub / github.com/chenhaoxing/HDNet / copy_state_dict

Function copy_state_dict

util/util.py:105–123  ·  view source on GitHub ↗
(cur_state_dict, pre_state_dict, prefix='', load_name=None)

Source from the content-addressed store, hash-verified

103 os.makedirs(path)
104
105def copy_state_dict(cur_state_dict, pre_state_dict, prefix='', load_name=None):
106 def _get_params(key):
107 key = prefix + key
108 if key in pre_state_dict:
109 return pre_state_dict[key]
110 return None
111 for k in cur_state_dict.keys():
112 if load_name is not None:
113 if load_name not in k:
114 continue
115 v = _get_params(k)
116 try:
117 if v is None:
118 # print('parameter {} not found'.format(k))
119 continue
120 cur_state_dict[k].copy_(v)
121 except:
122 # print('copy param {} failed'.format(k))
123 continue

Callers

nothing calls this directly

Calls 1

_get_paramsFunction · 0.85

Tested by

no test coverage detected