(cls, model_path, config=None)
| 461 | |
| 462 | @classmethod |
| 463 | def from_pretrained(cls, model_path, config=None): |
| 464 | if config is None: |
| 465 | config = GPTConfig.from_pretrained(model_path) |
| 466 | # module = cls(config).eval() |
| 467 | module = torch.nn.utils.skip_init(cls, config).eval() # fast init |
| 468 | try: |
| 469 | module.load_state_dict(torch.load(os.path.join( |
| 470 | model_path, 'pytorch_lm_head.pt', |
| 471 | ))) |
| 472 | except: |
| 473 | print('Cannot load from <model_name>. The model is randomly initialized.') |
| 474 | return module |
| 475 | |
| 476 | def forward(self, x, input_ids=None, *args, **kargs): |
| 477 | if self.final_layer_norm is not None: |
nothing calls this directly
no test coverage detected