Skip to content

Commit b27175e

Browse files
committed
Update tests
1 parent dba6fa6 commit b27175e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+149
-641
lines changed

tests/tests_pytorch/accelerators/test_ipu.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ def validation_step(self, batch, batch_idx):
4747
def test_step(self, batch, batch_idx):
4848
return self.step(batch)
4949

50-
def training_epoch_end(self, outputs) -> None:
51-
pass
52-
53-
def validation_epoch_end(self, outputs) -> None:
54-
pass
55-
56-
def test_epoch_end(self, outputs) -> None:
57-
pass
58-
5950

6051
class IPUClassificationModel(ClassificationModel):
6152
def training_step(self, batch, batch_idx):

tests/tests_pytorch/accelerators/test_tpu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def on_train_end(self):
155155
model = ManualOptimizationModel()
156156
model_copy = deepcopy(model)
157157
model.training_step_end = None
158-
model.training_epoch_end = None
159158

160159
trainer = Trainer(
161160
max_epochs=1,

tests/tests_pytorch/callbacks/progress/test_tqdm_progress_bar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ def predict_step(self, batch, batch_idx, dataloader_idx=None):
136136
return
137137

138138
model = CustomModel()
139-
model.validation_epoch_end = None
140-
model.test_epoch_end = None
141139

142140
# check the sanity dataloaders
143141
num_sanity_val_steps = 4

tests/tests_pytorch/callbacks/test_callback_hook_outputs.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ def on_validation_batch_end(self, outputs, batch, batch_idx: int, dataloader_idx
4141
def on_test_batch_end(self, outputs, batch, batch_idx: int, dataloader_idx: int) -> None:
4242
assert "x" in outputs
4343

44-
def training_epoch_end(self, outputs) -> None:
45-
assert len(outputs) == self.trainer.num_training_batches
46-
4744
model = TestModel()
4845

4946
trainer = Trainer(
@@ -59,22 +56,3 @@ def training_epoch_end(self, outputs) -> None:
5956
assert any(isinstance(c, CB) for c in trainer.callbacks)
6057

6158
trainer.fit(model)
62-
63-
64-
def test_free_memory_on_eval_outputs(tmpdir):
65-
class CB(Callback):
66-
def on_train_epoch_end(self, trainer, pl_module):
67-
assert not trainer._evaluation_loop._outputs
68-
69-
model = BoringModel()
70-
71-
trainer = Trainer(
72-
callbacks=CB(),
73-
default_root_dir=tmpdir,
74-
limit_train_batches=2,
75-
limit_val_batches=2,
76-
max_epochs=1,
77-
enable_model_summary=False,
78-
)
79-
80-
trainer.fit(model)

tests/tests_pytorch/callbacks/test_early_stopping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_early_stopping_patience(tmpdir, loss_values: list, patience: int, expec
134134
class ModelOverrideValidationReturn(BoringModel):
135135
validation_return_values = torch.tensor(loss_values)
136136

137-
def validation_epoch_end(self, outputs):
137+
def on_validation_epoch_end(self):
138138
loss = self.validation_return_values[self.current_epoch]
139139
self.log("test_val_loss", loss)
140140

@@ -164,7 +164,7 @@ def test_early_stopping_patience_train(
164164
class ModelOverrideTrainReturn(BoringModel):
165165
train_return_values = torch.tensor(loss_values)
166166

167-
def training_epoch_end(self, outputs):
167+
def on_train_epoch_end(self):
168168
loss = self.train_return_values[self.current_epoch]
169169
self.log("train_loss", loss)
170170

@@ -226,7 +226,7 @@ def test_early_stopping_no_val_step(tmpdir):
226226
)
227227
def test_early_stopping_thresholds(tmpdir, stopping_threshold, divergence_threshold, losses, expected_epoch):
228228
class CurrentModel(BoringModel):
229-
def validation_epoch_end(self, outputs):
229+
def on_validation_epoch_end(self):
230230
val_loss = losses[self.current_epoch]
231231
self.log("abc", val_loss)
232232

@@ -252,7 +252,7 @@ def test_early_stopping_on_non_finite_monitor(tmpdir, stop_value):
252252
expected_stop_epoch = 2
253253

254254
class CurrentModel(BoringModel):
255-
def validation_epoch_end(self, outputs):
255+
def on_validation_epoch_end(self):
256256
val_loss = losses[self.current_epoch]
257257
self.log("val_loss", val_loss)
258258

@@ -352,12 +352,12 @@ def _epoch_end(self) -> None:
352352
self.log("abc", torch.tensor(loss))
353353
self.log("cba", torch.tensor(0))
354354

355-
def training_epoch_end(self, outputs):
355+
def on_train_epoch_end(self):
356356
if not self.early_stop_on_train:
357357
return
358358
self._epoch_end()
359359

360-
def validation_epoch_end(self, outputs):
360+
def on_validation_epoch_end(self):
361361
if self.early_stop_on_train:
362362
return
363363
self._epoch_end()

tests/tests_pytorch/callbacks/test_lr_monitor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ def configure_optimizers(self):
248248
return [optimizer1, optimizer2], [lr_scheduler1, lr_scheduler2]
249249

250250
model = CustomBoringModel()
251-
model.training_epoch_end = None
252251

253252
lr_monitor = LearningRateMonitor(logging_interval=logging_interval)
254253
log_every_n_steps = 2
@@ -306,7 +305,6 @@ def configure_optimizers(self):
306305
return [optimizer1, optimizer2]
307306

308307
model = CustomBoringModel()
309-
model.training_epoch_end = None
310308

311309
lr_monitor = LearningRateMonitor(logging_interval=logging_interval)
312310
log_every_n_steps = 2
@@ -563,7 +561,6 @@ def finetune_function(self, pl_module, epoch: int, optimizer, opt_idx: int):
563561
enable_checkpointing=False,
564562
)
565563
model = TestModel()
566-
model.training_epoch_end = None
567564
trainer.fit(model)
568565

569566
expected = [0.1, 0.1, 0.1, 0.1, 0.1]

tests/tests_pytorch/checkpointing/test_checkpoint_callback_frequency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def training_step(self, batch, batch_idx):
9696
self.log("my_loss", batch_idx * (1 + local_rank), on_epoch=True)
9797
return super().training_step(batch, batch_idx)
9898

99-
def training_epoch_end(self, outputs) -> None:
99+
def on_train_epoch_end(self):
100100
local_rank = int(os.getenv("LOCAL_RANK"))
101101
if self.trainer.is_global_zero:
102102
self.log("my_loss_2", (1 + local_rank), on_epoch=True, rank_zero_only=True)

tests/tests_pytorch/checkpointing/test_model_checkpoint.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ def training_step(self, batch, batch_idx):
5959
self.log("early_stop_on", out["loss"])
6060
return out
6161

62-
def validation_epoch_end(self, outputs):
63-
outs = torch.stack([x["x"] for x in outputs]).mean()
64-
self.log("val_acc", outs)
62+
def on_validation_epoch_end(self):
63+
self.log("val_acc", torch.tensor(1.23))
6564

6665

6766
def mock_training_epoch_loop(trainer):
@@ -214,9 +213,8 @@ def validation_step(self, batch, batch_idx):
214213
self.log("val_log", log_value)
215214
return super().validation_step(batch, batch_idx)
216215

217-
def validation_epoch_end(self, outputs):
216+
def on_validation_epoch_end(self):
218217
self.val_loop_count += 1
219-
super().validation_epoch_end(outputs)
220218
self.scores.append(self.trainer.logged_metrics[monitor])
221219

222220
def configure_optimizers(self):
@@ -829,7 +827,7 @@ def test_checkpointing_with_nan_as_first(tmpdir, mode):
829827
monitor += [5, 7, 8] if mode == "max" else [8, 7, 5]
830828

831829
class CurrentModel(LogInTwoMethods):
832-
def validation_epoch_end(self, outputs):
830+
def on_validation_epoch_end(self):
833831
val_loss = monitor[self.current_epoch]
834832
self.log("abc", val_loss)
835833

@@ -863,7 +861,6 @@ def validation_step(self, batch, batch_idx):
863861
self.log("val_loss", loss)
864862

865863
model = ExtendedBoringModel()
866-
model.validation_epoch_end = None
867864
trainer_kwargs = {
868865
"max_epochs": 1,
869866
"limit_train_batches": 2,
@@ -901,9 +898,6 @@ def validation_step(self, batch, batch_idx):
901898
self.log("val_loss", loss)
902899
return {"val_loss": loss}
903900

904-
def validation_epoch_end(self, *_):
905-
...
906-
907901
def assert_trainer_init(trainer):
908902
assert trainer.global_step == 0
909903
assert trainer.current_epoch == 0

tests/tests_pytorch/checkpointing/test_trainer_checkpoint.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def validation_step(self, batch, batch_idx):
4141
self.log("val_loss", loss, on_epoch=True, prog_bar=True)
4242

4343
model = ExtendedBoringModel()
44-
model.validation_epoch_end = None
4544
trainer = Trainer(
4645
default_root_dir=tmpdir,
4746
max_epochs=1,

tests/tests_pytorch/core/test_datamodules.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ def test_train_loop_only(tmpdir):
163163

164164
model.validation_step = None
165165
model.validation_step_end = None
166-
model.validation_epoch_end = None
167166
model.test_step = None
168167
model.test_step_end = None
169-
model.test_epoch_end = None
170168

171169
trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, enable_model_summary=False)
172170

@@ -185,7 +183,6 @@ def test_train_val_loop_only(tmpdir):
185183

186184
model.validation_step = None
187185
model.validation_step_end = None
188-
model.validation_epoch_end = None
189186

190187
trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, enable_model_summary=False)
191188

@@ -278,10 +275,8 @@ def train_dataloader(self):
278275

279276
model.validation_step = None
280277
model.validation_step_end = None
281-
model.validation_epoch_end = None
282278
model.test_step = None
283279
model.test_step_end = None
284-
model.test_epoch_end = None
285280

286281
trainer = Trainer(default_root_dir=tmpdir, max_epochs=3, limit_train_batches=2, reload_dataloaders_every_n_epochs=2)
287282
trainer.fit(model, dm)

0 commit comments

Comments
 (0)