MCPcopy Create free account
hub / github.com/devinxzhang/MFuser / init_weights

Method init_weights

models/backbones/clip/models.py:466–485  ·  view source on GitHub ↗
(self, pretrained=None)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected