Skip to content
Snippets Groups Projects

Moved code to lightning

Merged Daniel CARRON requested to merge move-to-lightning into main
1 unresolved thread
6 files
+ 44
2
Compare changes
  • Side-by-side
  • Inline
Files
6
  • 507a6207
    Move criterion to selected device · 507a6207
    Daniel CARRON authored
    As the criterion is not part of the model but instead a hyperparameter
    due to the use of configuration files, it is not moved to the GPU if
    selected as a device. We therefore manually move the criterion to the proper
    device, which is bad practice when using lightning but works.
@@ -60,6 +60,8 @@ class Alexnet(pl.LightningModule):
# Forward pass on the network
outputs = self(images)
# Manually move criterion to selected device, since not part of the model.
self.hparams.criterion = self.hparams.criterion.to(self.device)
training_loss = self.hparams.criterion(outputs, labels.float())
return {"loss": training_loss}
@@ -75,6 +77,11 @@ class Alexnet(pl.LightningModule):
# data forwarding on the existing network
outputs = self(images)
# Manually move criterion to selected device, since not part of the model.
self.hparams.criterion_valid = self.hparams.criterion_valid.to(
self.device
)
validation_loss = self.hparams.criterion_valid(outputs, labels.float())
return {"validation_loss": validation_loss}
Loading