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

Method to_parallel

modelscope/trainers/trainer.py:827–842  ·  view source on GitHub ↗
(self, model)

Source from the content-addressed store, hash-verified

825 return model
826
827 def to_parallel(self, model) -> Union[nn.Module, TorchModel]:
828 # config format to reserve custom ddp
829 if self.cfg.get('parallel', None) is not None:
830 dp_cfg = deepcopy(self.cfg['parallel'])
831 dp_cfg.update(
832 dict(module=model, device_ids=[torch.cuda.current_device()]))
833 return build_parallel(dp_cfg)
834
835 dp_cfg = dict(
836 type='DistributedDataParallel',
837 module=model,
838 find_unused_parameters=True,
839 device_ids=[torch.cuda.current_device()],
840 process_group=self.dp_group)
841
842 return build_parallel(dp_cfg)
843
844 def unwrap_module(self, model) -> Union[nn.Module, TorchModel]:
845 """Unwrap the model until it's a naked nn.Module.

Callers 1

place_modelMethod · 0.95

Calls 3

build_parallelFunction · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected