MCPcopy Index your code
hub / github.com/zai-org/CodeGeeX / load_state_dict

Method load_state_dict

codegeex/torch/codegeex_model.py:912–945  ·  view source on GitHub ↗

Customized load.

(self, state_dict, strict=True)

Source from the content-addressed store, hash-verified

910 return state_dict_
911
912 def load_state_dict(self, state_dict, strict=True):
913 """Customized load."""
914
915 # Embedding.
916 if self._embedding_key in state_dict:
917 state_dict_ = state_dict[self._embedding_key]
918 else:
919 # for backward compatibility.
920 state_dict_ = {}
921 for key in state_dict.keys():
922 if '_embeddings' in key:
923 state_dict_[key] = state_dict[key]
924 self.embedding.load_state_dict(state_dict_, strict=strict)
925
926 if self._topQueryEmbedding_key in state_dict:
927 state_dict_ = state_dict[self._topQueryEmbedding_key]
928 else:
929 # for backward compatibility.
930 state_dict_ = {}
931 for key in state_dict.keys():
932 if '_embeddings' in key:
933 state_dict_[key] = state_dict[key]
934 self.topQueryEmbedding.load_state_dict(state_dict_, strict=strict)
935
936 # Transformer.
937 if self._transformer_key in state_dict:
938 state_dict_ = state_dict[self._transformer_key]
939 else:
940 # for backward compatibility.
941 state_dict_ = {}
942 for key in state_dict.keys():
943 if 'transformer.' in key:
944 state_dict_[key.split('transformer.')[1]] = state_dict[key]
945 self.transformer.load_state_dict(state_dict_, strict=strict)
946
947
948class CodeGeeXModel(torch.nn.Module):

Callers

nothing calls this directly

Calls 1

load_state_dictMethod · 0.45

Tested by

no test coverage detected