(model_raw: Model, model_convert: Model, tokenizer_raw,
tokenizer_convert)
| 52 | |
| 53 | |
| 54 | def make_same_shape(model_raw: Model, model_convert: Model, tokenizer_raw, |
| 55 | tokenizer_convert): |
| 56 | if model_raw.__class__ != model_convert.__class__: |
| 57 | logger.error( |
| 58 | f'weight diff: These two models should be of the same class. model_raw:' |
| 59 | f'{model_raw.__class__} vs model_convert: {model_convert.__class__}.' |
| 60 | ) |
| 61 | |
| 62 | special_tokens = {} |
| 63 | for k, v in tokenizer_convert.special_tokens_map_extended.items(): |
| 64 | if k not in tokenizer_raw.special_tokens_map_extended: |
| 65 | special_tokens[k] = v |
| 66 | |
| 67 | smart_tokenizer_and_embedding_resize( |
| 68 | special_tokens_dict=special_tokens, |
| 69 | model=model_raw, |
| 70 | tokenizer=tokenizer_raw, |
| 71 | ) |
| 72 | |
| 73 | state_dict_tuned = model_convert.state_dict() |
| 74 | state_dict_raw = model_raw.state_dict() |
| 75 | for key in tqdm.tqdm(state_dict_tuned): |
| 76 | if state_dict_tuned[key].shape != state_dict_raw[key].shape: |
| 77 | logger.error( |
| 78 | f'weight diff: shape mismatch. {key}, model_raw shape: {state_dict_raw[key].shape}' |
| 79 | f' vs model_convert shape: {state_dict_tuned[key].shape}.') |
| 80 | |
| 81 | |
| 82 | def _weight_diff(model_raw, |
no test coverage detected
searching dependent graphs…