MCPcopy Create free account
hub / github.com/AMAP-ML/EMF / make

Function make

tok/models.py:16–31  ·  view source on GitHub ↗
(model_spec, args=None, load_sd=False)

Source from the content-addressed store, hash-verified

14
15
16def make(model_spec, args=None, load_sd=False) -> torch.nn.Module:
17 if args is not None:
18 model_args = copy.deepcopy(model_spec['args'])
19 model_args.update(args)
20 else:
21 model_args = model_spec['args']
22 model_params = inspect.signature(models[model_spec['name']]).parameters
23 if 'kwargs' not in model_params:
24 model_args = {k: v for k, v in model_args.items() if k in model_params}
25 model = models[model_spec['name']](**model_args)
26 if load_sd:
27 if ('abs_pe' in model_spec['sd']) and hasattr(model, 'abs_pe') and model_spec['sd']['abs_pe'].shape != model.abs_pe.shape:
28 del model_spec['sd']['abs_pe']
29 msg = model.load_state_dict(model_spec['sd'], strict=False)
30 print(msg)
31 return model

Callers

nothing calls this directly

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected