Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit 1b55378

Browse files
authored
Remove *_step_end from LitModular (#170)
Merge train/validation/test_step_end into train/validation/test_step.
1 parent 4185b3d commit 1b55378

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

‎mart/models/modular.py‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,15 @@ def training_step(self, batch, batch_idx):
134134
for log_name, output_key in self.training_step_log.items():
135135
self.log(f"training/{log_name}", output[output_key])
136136

137-
assert "loss" in output
138-
return output
139-
140-
def training_step_end(self, output):
141137
if self.training_metrics is not None:
142138
# Some models only return loss in the training mode.
143139
if self.output_preds_key not in output or self.output_target_key not in output:
144140
raise ValueError(
145141
f"You have specified training_metrics, but the model does not return {self.output_preds_key} or {self.output_target_key} during training. You can either nullify training_metrics or configure the model to return {self.output_preds_key} and {self.output_target_key} in the training output."
146142
)
147143
self.training_metrics(output[self.output_preds_key], output[self.output_target_key])
148-
loss = output.pop(self.output_loss_key)
149-
return loss
144+
145+
return output[self.output_loss_key]
150146

151147
def training_epoch_end(self, outputs):
152148
if self.training_metrics is not None:
@@ -168,13 +164,9 @@ def validation_step(self, batch, batch_idx):
168164
for log_name, output_key in self.validation_step_log.items():
169165
self.log(f"validation/{log_name}", output[output_key])
170166

171-
return output
172-
173-
def validation_step_end(self, output):
174167
self.validation_metrics(output[self.output_preds_key], output[self.output_target_key])
175168

176-
# I don't know why this is required to prevent CUDA memory leak in validaiton and test. (Not required in training.)
177-
output.clear()
169+
return None
178170

179171
def validation_epoch_end(self, outputs):
180172
metrics = self.validation_metrics.compute()
@@ -194,13 +186,9 @@ def test_step(self, batch, batch_idx):
194186
for log_name, output_key in self.test_step_log.items():
195187
self.log(f"test/{log_name}", output[output_key])
196188

197-
return output
198-
199-
def test_step_end(self, output):
200189
self.test_metrics(output[self.output_preds_key], output[self.output_target_key])
201190

202-
# I don't know why this is required to prevent CUDA memory leak in validaiton and test. (Not required in training.)
203-
output.clear()
191+
return None
204192

205193
def test_epoch_end(self, outputs):
206194
metrics = self.test_metrics.compute()

0 commit comments

Comments
 (0)