(
state_dict,
model_state_dict,
loaded_keys,
ignore_mismatched_sizes,
)
| 450 | |
| 451 | |
| 452 | def _find_mismatched_keys( |
| 453 | state_dict, |
| 454 | model_state_dict, |
| 455 | loaded_keys, |
| 456 | ignore_mismatched_sizes, |
| 457 | ): |
| 458 | mismatched_keys = [] |
| 459 | if ignore_mismatched_sizes: |
| 460 | for checkpoint_key in loaded_keys: |
| 461 | model_key = checkpoint_key |
| 462 | # If the checkpoint is sharded, we may not have the key here. |
| 463 | if checkpoint_key not in state_dict: |
| 464 | continue |
| 465 | |
| 466 | if model_key in model_state_dict and state_dict[checkpoint_key].shape != model_state_dict[model_key].shape: |
| 467 | mismatched_keys.append( |
| 468 | (checkpoint_key, state_dict[checkpoint_key].shape, model_state_dict[model_key].shape) |
| 469 | ) |
| 470 | del state_dict[checkpoint_key] |
| 471 | return mismatched_keys |
| 472 | |
| 473 | |
| 474 | def _load_state_dict_into_model( |
no outgoing calls
no test coverage detected
searching dependent graphs…