Skip to content

Commit 0422bf5

Browse files
authored
Merge pull request #279 from MannLabs/memorize_device
persist device in model initialization
2 parents 3c95269 + b2a5a23 commit 0422bf5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

peptdeep/pretrained_models.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,17 @@ def __init__(
346346
"""
347347
_download_models(get_model_zip_file_path())
348348

349+
self._device = device
349350
self._train_psm_logging = True
350351

351352
self.ms2_model: pDeepModel = pDeepModel(
352-
mask_modloss=mask_modloss, device=device
353+
mask_modloss=mask_modloss, device=self._device
353354
)
354-
self.rt_model: AlphaRTModel = AlphaRTModel(device=device)
355-
self.ccs_model: AlphaCCSModel = AlphaCCSModel(device=device)
355+
self.rt_model: AlphaRTModel = AlphaRTModel(device=self._device)
356+
self.ccs_model: AlphaCCSModel = AlphaCCSModel(device=self._device)
356357

357358
self.charge_model: ChargeModelForModAASeq = ChargeModelForModAASeq(
358-
device=device
359+
device=self._device
359360
)
360361

361362
self.load_installed_models()
@@ -373,7 +374,16 @@ def reinitialize_ms2_model(self, charged_frag_types: typing.List[str], **kwargs)
373374
kwargs : dict
374375
Other keyword arguments for `pDeepModel`.
375376
"""
376-
self.ms2_model = pDeepModel(charged_frag_types=charged_frag_types, **kwargs)
377+
device = kwargs.pop("device", self._device)
378+
if device != self._device:
379+
logging.warning(
380+
f"Overwriting MS2 model device from '{self._device}' to '{device}'"
381+
)
382+
self.ms2_model = pDeepModel(
383+
charged_frag_types=charged_frag_types,
384+
device=device,
385+
**kwargs,
386+
)
377387

378388
def reset_by_global_settings(
379389
self,

0 commit comments

Comments
 (0)