(state_dict, with_shape=True)
| 208 | return hashlib.md5(keys_str).hexdigest() |
| 209 | |
| 210 | def 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 |
no outgoing calls
no test coverage detected