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')
| 105 | |
| 106 | @torch.inference_mode() |
| 107 | def 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 | |
| 143 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…