Open DJW220207 opened 7 months ago
You can use the following code to change the original code
def on_validation_epoch_end(self):
# val
avg_loss = torch.stack(self.validation_step_outputs).mean()
val_loss = torch.mean(self.all_gather(avg_loss))
self.log(
"lr",
self.optimizer.param_groups[0]["lr"],
on_epoch=True,
prog_bar=True,
sync_dist=True,
)
self.logger.experiment.log(
{"learning_rate": self.optimizer.param_groups[0]["lr"], "epoch": self.current_epoch}
)
self.logger.experiment.log(
{"val_pit_sisnr": -val_loss, "epoch": self.current_epoch}
)
# test
if (self.trainer.current_epoch) % 10 == 0:
avg_loss = torch.stack(self.test_step_outputs).mean()
test_loss = torch.mean(self.all_gather(avg_loss))
self.logger.experiment.log(
{"test_pit_sisnr": -test_loss, "epoch": self.current_epoch}
)
self.validation_step_outputs.clear() # free memory
self.test_step_outputs.clear() # free memory
You can use the following code to change the original code
def on_validation_epoch_end(self): # val avg_loss = torch.stack(self.validation_step_outputs).mean() val_loss = torch.mean(self.all_gather(avg_loss)) self.log( "lr", self.optimizer.param_groups[0]["lr"], on_epoch=True, prog_bar=True, sync_dist=True, ) self.logger.experiment.log( {"learning_rate": self.optimizer.param_groups[0]["lr"], "epoch": self.current_epoch} ) self.logger.experiment.log( {"val_pit_sisnr": -val_loss, "epoch": self.current_epoch} ) # test if (self.trainer.current_epoch) % 10 == 0: avg_loss = torch.stack(self.test_step_outputs).mean() test_loss = torch.mean(self.all_gather(avg_loss)) self.logger.experiment.log( {"test_pit_sisnr": -test_loss, "epoch": self.current_epoch} ) self.validation_step_outputs.clear() # free memory self.test_step_outputs.clear() # free memory
Hello, I have changed the code, but there is a new error at this time. AttributeError: 'System' object has no attribute 'validation_step_outputs'
add the validation_step_outputs in def init
Hello, when I want to train the model, it has an error that The
LightningModule.on_epoch_end
hook was removed in v1.8. How can I useLightningModule.on_<train/validation/test>_epoch_end
instead?