Customized load.
(self, state_dict, strict=True)
| 728 | return state_dict_ |
| 729 | |
| 730 | def load_state_dict(self, state_dict, strict=True): |
| 731 | """Customized load.""" |
| 732 | |
| 733 | # Word embedding. |
| 734 | if self._word_embeddings_key in state_dict: |
| 735 | state_dict_ = state_dict[self._word_embeddings_key] |
| 736 | else: |
| 737 | # for backward compatibility. |
| 738 | state_dict_ = {} |
| 739 | for key in state_dict.keys(): |
| 740 | if 'word_embeddings' in key: |
| 741 | state_dict_[key.split('word_embeddings.')[1]] \ |
| 742 | = state_dict[key] |
| 743 | state_dict_["weight"] = state_dict_["weight"][:self.vocab_size] |
| 744 | self.word_embeddings.load_state_dict(state_dict_, strict=strict) |
| 745 | |
| 746 | # Position embedding. |
| 747 | if self._position_embeddings_key in state_dict: |
| 748 | state_dict_ = state_dict[self._position_embeddings_key] |
| 749 | else: |
| 750 | # for backward compatibility. |
| 751 | state_dict_ = {} |
| 752 | for key in state_dict.keys(): |
| 753 | if 'position_embeddings' in key: |
| 754 | state_dict_[key.split('position_embeddings.')[1]] \ |
| 755 | = state_dict[key] |
| 756 | self.position_embeddings.load_state_dict(state_dict_, strict=strict) |
| 757 | |
| 758 | |
| 759 | class QueryEmbedding(torch.nn.Module): |
no outgoing calls