MCPcopy Create free account
hub / github.com/togethercomputer/OpenChatKit / from_pretrained

Method from_pretrained

training/modules/hf_opt_modules.py:463–474  ·  view source on GitHub ↗
(cls, model_path, config=None)

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 2

from_pretrainedMethod · 0.45
load_state_dictMethod · 0.45

Tested by

no test coverage detected