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

Method from_pretrained

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

Source from the content-addressed store, hash-verified

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

Callers 12

prepare.pyFile · 0.45
prepare.pyFile · 0.45
__init__Method · 0.45
mainFunction · 0.45
mainFunction · 0.45
build_tokenizerFunction · 0.45
build_gpt2_tokenizerFunction · 0.45
build_deberta_tokenizerFunction · 0.45
from_pretrainedMethod · 0.45
from_pretrainedMethod · 0.45
__init__Method · 0.45

Calls 1

load_state_dictMethod · 0.45

Tested by

no test coverage detected