MCPcopy Create free account
hub / github.com/modelscope/modelscope / weights_to_cpu

Function weights_to_cpu

modelscope/utils/checkpoint.py:30–44  ·  view source on GitHub ↗

Copy a model state_dict to cpu. Args: state_dict (OrderedDict): Model weights on GPU. Returns: OrderedDict: Model weights on GPU.

(state_dict)

Source from the content-addressed store, hash-verified

28
29
30def weights_to_cpu(state_dict):
31 """Copy a model state_dict to cpu.
32
33 Args:
34 state_dict (OrderedDict): Model weights on GPU.
35
36 Returns:
37 OrderedDict: Model weights on GPU.
38 """
39 state_dict_cpu = OrderedDict()
40 for key, val in state_dict.items():
41 state_dict_cpu[key] = val.cpu()
42 # Keep metadata in state_dict
43 state_dict_cpu._metadata = getattr(state_dict, '_metadata', OrderedDict())
44 return state_dict_cpu
45
46
47def save_checkpoint(model: torch.nn.Module,

Callers 1

save_checkpointFunction · 0.70

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…