Skip to content

Commit

Permalink
Fix pytorch lightning test. (#1019)
Browse files Browse the repository at this point in the history
In 1.3.x, trainer.fit(...) returns None.

Asserting on trainer.logged_metrics instead.

http:https://b/188429515
  • Loading branch information
rosbo committed May 25, 2021
1 parent 597bc2a commit 97ab4b8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/test_pytorch_lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def setup(self, stage=None):
self.valid_ds = TensorDataset(X_valid, y_valid)

def train_dataloader(self):
return DataLoader(self.train_ds, batch_size=self.batch_size, shuffle=True)
return DataLoader(self.train_ds, batch_size=self.batch_size, shuffle=True, num_workers=1)

def val_dataloader(self):
return DataLoader(self.valid_ds, batch_size=self.batch_size, shuffle=False)
return DataLoader(self.valid_ds, batch_size=self.batch_size, shuffle=False, num_workers=1)


class LitClassifier(pl.LightningModule):
Expand Down Expand Up @@ -54,7 +54,6 @@ def validation_step(self, batch, batch_idx):
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=1e-2)


class TestPytorchLightning(unittest.TestCase):

def test_version(self):
Expand All @@ -64,5 +63,8 @@ def test_mnist(self):
dm = LitDataModule()
model = LitClassifier()
trainer = pl.Trainer(gpus=None, max_epochs=1)
result = trainer.fit(model, datamodule=dm)
self.assertTrue(result)
trainer.fit(model, datamodule=dm)

self.assertIn("train_loss", trainer.logged_metrics)
self.assertIn("val_loss", trainer.logged_metrics)

0 comments on commit 97ab4b8

Please sign in to comment.