(cls, model_path, config=None, layer_index=None)
| 360 | |
| 361 | @classmethod |
| 362 | def from_pretrained(cls, model_path, config=None, layer_index=None): |
| 363 | assert layer_index is not None |
| 364 | if config is None: |
| 365 | config = GPTConfig.from_pretrained(model_path) |
| 366 | # module = cls(config).eval() |
| 367 | # module = cls(config).eval() |
| 368 | module = torch.nn.utils.skip_init(cls, config).eval() # fast init |
| 369 | try: |
| 370 | module.load_state_dict(torch.load(os.path.join( |
| 371 | model_path, f'pytorch_{layer_index}.pt', |
| 372 | ))) |
| 373 | except: |
| 374 | print('Cannot load from <model_name>. The model is randomly initialized.') |
| 375 | return module |
| 376 | |
| 377 | def forward(self, x: torch.Tensor, layer_past=None, mask=None, *args, **kargs) -> torch.Tensor: |
| 378 |
no test coverage detected