Customized load.
(self, state_dict, strict=True)
| 404 | return state_dict_ |
| 405 | |
| 406 | def load_state_dict(self, state_dict, strict=True): |
| 407 | """Customized load.""" |
| 408 | |
| 409 | # Position embedding. |
| 410 | if self._top_query_embeddings_key in state_dict: |
| 411 | state_dict_ = state_dict[self._top_query_embeddings_key] |
| 412 | else: |
| 413 | # for backward compatibility. |
| 414 | state_dict_ = {} |
| 415 | for key in state_dict.keys(): |
| 416 | if 'top_query_embeddings' in key: |
| 417 | state_dict_[key.split('top_query_embeddings.')[1]] \ |
| 418 | = state_dict[key] |
| 419 | pos_len = state_dict_['weight'].shape[0] |
| 420 | max_seq_len = self.max_sequence_length // get_tensor_model_parallel_world_size() |
| 421 | if pos_len < max_seq_len: |
| 422 | print_rank_0(f"Top query embedding padded {pos_len} -> {max_seq_len}.") |
| 423 | top_query_embeddings_padded = torch.nn.Embedding( |
| 424 | max_seq_len - pos_len, self.hidden_size).half() |
| 425 | self.init_method(top_query_embeddings_padded.weight) |
| 426 | state_dict_['weight'] = torch.cat([state_dict_['weight'], top_query_embeddings_padded.weight], dim=0) |
| 427 | self.top_query_embeddings.load_state_dict(state_dict_, strict=strict) |
| 428 | |
| 429 | # Tokentype embedding. |
| 430 | if self.num_tokentypes > 0: |
| 431 | state_dict_ = {} |
| 432 | if self._tokentype_embeddings_key in state_dict: |
| 433 | state_dict_ = state_dict[self._tokentype_embeddings_key] |
| 434 | else: |
| 435 | # for backward compatibility. |
| 436 | for key in state_dict.keys(): |
| 437 | if 'tokentype_embeddings' in key: |
| 438 | state_dict_[key.split('tokentype_embeddings.')[1]] \ |
| 439 | = state_dict[key] |
| 440 | if len(state_dict_.keys()) > 0: |
| 441 | self.tokentype_embeddings.load_state_dict(state_dict_, |
| 442 | strict=strict) |
| 443 | else: |
| 444 | print('***WARNING*** expected tokentype embeddings in the ' |
| 445 | 'checkpoint but could not find it', flush=True) |
| 446 | |
| 447 | |
| 448 | class QueryEmbeddingPipe(QueryEmbedding): |
nothing calls this directly
no test coverage detected