(self, pretrained=None)
| 464 | self.text_projection = nn.Parameter(torch.empty(transformer_width, embed_dim)) |
| 465 | |
| 466 | def init_weights(self, pretrained=None): |
| 467 | pretrained = pretrained or self.pretrained |
| 468 | print("text_encoder:", pretrained) |
| 469 | if isinstance(pretrained, str): |
| 470 | checkpoint = torch.jit.load(pretrained, map_location='cpu').float().state_dict() |
| 471 | |
| 472 | state_dict = {} |
| 473 | |
| 474 | for k in checkpoint.keys(): |
| 475 | if k.startswith('transformer.'): |
| 476 | state_dict[k] = checkpoint[k] |
| 477 | |
| 478 | if k == 'positional_embedding' or k == 'text_projection' or k.startswith('token_embedding') or k.startswith('ln_final'): |
| 479 | if k == 'positional_embedding' and checkpoint[k].size(0) > self.context_length: |
| 480 | checkpoint[k] = checkpoint[k][:self.context_length] |
| 481 | print('positional_embedding is tuncated from 77 to', self.context_length) |
| 482 | state_dict[k] = checkpoint[k] |
| 483 | |
| 484 | u, w = self.load_state_dict(state_dict, False) |
| 485 | print(u, w, 'are misaligned params in text encoder') |
| 486 | |
| 487 | |
| 488 | def build_attention_mask(self): |
nothing calls this directly
no outgoing calls
no test coverage detected