MCPcopy Index your code
hub / github.com/modelscope/modelscope / weight_diff

Function weight_diff

tools/weight_diff.py:107–140  ·  view source on GitHub ↗

Make the weight diff. This function is given to present full transparency of how the weight diff was created.

(path_raw: str,
                path_convert: str,
                path_to_save: str,
                make_diff_or_recover,
                device='cpu')

Source from the content-addressed store, hash-verified

105
106@torch.inference_mode()
107def weight_diff(path_raw: str,
108 path_convert: str,
109 path_to_save: str,
110 make_diff_or_recover,
111 device='cpu'):
112 """Make the weight diff.
113
114 This function is given to present full transparency of how the weight diff was created.
115 """
116 if not os.path.exists(path_raw):
117 logger.info(
118 f'Path `{path_raw}` not found. Try to load from cache or remote.')
119 path_raw = snapshot_download(path_raw)
120 if not os.path.exists(path_convert):
121 logger.info(
122 f'Path `{path_convert}` not found. Try to load from cache or remote.'
123 )
124 path_convert = snapshot_download(path_convert)
125
126 model_raw = Model.from_pretrained(path_raw, device=device)
127 model_convert = Model.from_pretrained(path_convert, device=device)
128
129 tokenizer_raw: transformers.PreTrainedTokenizer = transformers.AutoTokenizer.from_pretrained(
130 path_raw)
131 tokenizer_convert: transformers.PreTrainedTokenizer = transformers.AutoTokenizer.from_pretrained(
132 path_convert)
133
134 return _weight_diff(
135 model_raw,
136 model_convert,
137 tokenizer_raw,
138 tokenizer_convert,
139 path_to_save=path_to_save,
140 make_diff_or_recover=make_diff_or_recover)
141
142
143if __name__ == '__main__':

Callers 1

weight_diff.pyFile · 0.85

Calls 5

snapshot_downloadFunction · 0.90
_weight_diffFunction · 0.85
infoMethod · 0.80
existsMethod · 0.45
from_pretrainedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…