mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
fix: move layers added by build() to same device as the rest of the model
This commit is contained in:
1 parent
2d06c1a0e1
commit
79804315a0
1 file changed
+8
-3
@@ -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__,
|
||||
|
||||
Reference in new issue
Block a user