MCPcopy Create free account
hub / github.com/modelscope/modelscope / build_model

Method build_model

modelscope/trainers/trainer.py:811–825  ·  view source on GitHub ↗

Instantiate a pytorch model and return. By default, we will create a model using config from configuration file. You can override this method in a subclass.

(self)

Source from the content-addressed store, hash-verified

809 return self._metric_values
810
811 def build_model(self) -> Union[nn.Module, TorchModel]:
812 """ Instantiate a pytorch model and return.
813
814 By default, we will create a model using config from configuration file. You can
815 override this method in a subclass.
816
817 """
818 model = Model.from_pretrained(
819 self.model_dir,
820 cfg_dict=self.cfg,
821 trust_remote_code=self.trust_remote_code)
822 if not isinstance(model, nn.Module) and hasattr(model, 'model'):
823 return model.model
824 elif isinstance(model, nn.Module):
825 return model
826
827 def to_parallel(self, model) -> Union[nn.Module, TorchModel]:
828 # config format to reserve custom ddp

Callers 1

__init__Method · 0.95

Calls 1

from_pretrainedMethod · 0.45

Tested by

no test coverage detected