MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / convert_state_dict_keys_to_single_str

Function convert_state_dict_keys_to_single_str

models/transformer/utils.py:210–223  ·  view source on GitHub ↗
(state_dict, with_shape=True)

Source from the content-addressed store, hash-verified

208 return hashlib.md5(keys_str).hexdigest()
209
210def convert_state_dict_keys_to_single_str(state_dict, with_shape=True):
211 keys = []
212 for key, value in state_dict.items():
213 if isinstance(key, str):
214 if isinstance(value, torch.Tensor):
215 if with_shape:
216 shape = "_".join(map(str, list(value.shape)))
217 keys.append(key + ":" + shape)
218 keys.append(key)
219 elif isinstance(value, dict):
220 keys.append(key + "|" + convert_state_dict_keys_to_single_str(value, with_shape=with_shape))
221 keys.sort()
222 keys_str = ",".join(keys)
223 return keys_str

Callers 1

hash_state_dict_keysFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected