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

Function convert_single_pth

tools/convert_ckpt.py:9–19  ·  view source on GitHub ↗
(fullname)

Source from the content-addressed store, hash-verified

7
8
9def convert_single_pth(fullname):
10 filename, ext = os.path.splitext(fullname)
11 checkpoint = torch.load(fullname, map_location='cpu', weights_only=True)
12 only_module = 'state_dict' not in checkpoint
13 state_dict = checkpoint if only_module else checkpoint['state_dict']
14 torch.save(state_dict, fullname)
15
16 if not only_module:
17 checkpoint.pop('state_dict')
18 fullname_trainer = filename + '_trainer_state' + ext
19 torch.save(checkpoint, fullname_trainer)
20
21
22# This script is used to split pth files which generated before version 1.3.1 into two files.

Callers 1

convert_ckpt.pyFile · 0.85

Calls 2

loadMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…