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