(self, pretrained=None)
| 37 | # self.text_projection = nn.Linear(transformer_width, embed_dim) |
| 38 | |
| 39 | def init_weights(self, pretrained=None): |
| 40 | pretrained = pretrained or self.pretrained |
| 41 | if isinstance(pretrained, str): |
| 42 | checkpoint = torch.jit.load(pretrained, map_location='cpu').float().state_dict() |
| 43 | # checkpoint = torch.load(pretrained)['model'] |
| 44 | |
| 45 | state_dict = {} |
| 46 | |
| 47 | for k in checkpoint.keys(): |
| 48 | if k.startswith('transformer.'): |
| 49 | # if k.startswith('module.encode_text.transformer.'): |
| 50 | # new_k = k.replace('module.encode_text.', '') |
| 51 | # state_dict[new_k] = checkpoint[k].float() |
| 52 | state_dict[k] = checkpoint[k].float() |
| 53 | |
| 54 | if k == 'positional_embedding' or k == 'text_projection' or k.startswith('token_embedding') or k.startswith('ln_final'): |
| 55 | # if k == 'module.encode_text.positional_embedding' or k.startswith('module.encode_text.text_projection') or k.startswith('module.encode_text.token_embedding') or k.startswith('module.encode_text.ln_final'): |
| 56 | # new_k = k.replace('module.encode_text.', '') |
| 57 | # if new_k == 'positional_embedding' and checkpoint[k].size(0) > self.context_length: |
| 58 | if k == 'positional_embedding' and checkpoint[k].size(0) > self.context_length: |
| 59 | checkpoint[k] = checkpoint[k][:self.context_length] |
| 60 | print('positional_embedding is tuncated from 77 to', self.context_length) |
| 61 | # state_dict[new_k] = checkpoint[k] |
| 62 | state_dict[k] = checkpoint[k] |
| 63 | |
| 64 | u, w = self.load_state_dict(state_dict, False) |
| 65 | if u != [] or w != [] : |
| 66 | print(u, w, 'are misaligned params in text encoder') |
| 67 | |
| 68 | |
| 69 | def build_attention_mask(self): |
nothing calls this directly
no outgoing calls
no test coverage detected