From 79804315a0dd7b6de4982daaa6fbc673d8835c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20BREDIN?= Date: Wed, 17 Feb 2021 10:49:27 +0100 Subject: [PATCH] fix: move layers added by build() to same device as the rest of the model --- pyannote/audio/core/model.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pyannote/audio/core/model.py b/pyannote/audio/core/model.py index fd403452..9c9ddefa 100644 --- a/pyannote/audio/core/model.py +++ b/pyannote/audio/core/model.py @@ -364,10 +364,15 @@ class Model(pl.LightningModule): # list of layers before adding task-dependent layers before = set((name, id(module)) for name, module in self.named_modules()) - + # add layers that depends on task specs (e.g. final classification layer) self.build() + # move layers that were added by build() to same device as the rest of the model + for name, module in self.named_modules(): + if (name, id(module)) not in before: + module.to(self.device) + # add (trainable) loss function (e.g. ArcFace has its own set of trainable weights) if stage == "fit": # let task know about the model @@ -387,8 +392,8 @@ class Model(pl.LightningModule): def on_save_checkpoint(self, checkpoint): - #  put everything pyannote.audio-specific under pyannote.audio - #  to avoid any future conflicts with pytorch-lightning updates + # put everything pyannote.audio-specific under pyannote.audio + # to avoid any future conflicts with pytorch-lightning updates checkpoint["pyannote.audio"] = { "versions": { "torch": torch.__version__,