def test_replace_sampler_with_multiprocessing_context(tmpdir):
    """
    This test verifies that replace_sampler conserves multiprocessing context
    """
    train = RandomDataset(32, 64)
    context = 'spawn'
    train = DataLoader(train,
                       batch_size=32,
                       num_workers=2,
                       multiprocessing_context=context,
                       shuffle=True)

    class ExtendedBoringModel(BoringModel):
        def train_dataloader(self):
            return train

    trainer = Trainer(
        max_epochs=1,
        progress_bar_refresh_rate=20,
        overfit_batches=5,
    )

    new_data_loader = trainer.replace_sampler(train,
                                              SequentialSampler(train.dataset))
    assert (new_data_loader.multiprocessing_context ==
            train.multiprocessing_context)
Beispiel #2
0
 def test_dataloader(self):
     return torch.utils.data.DataLoader(RandomDataset(32, 64))
 def val_dataloader(self):
     dl1 = torch.utils.data.DataLoader(RandomDataset(32, 64))
     dl2 = torch.utils.data.DataLoader(RandomDataset(32, 64))
     return [dl1, dl2]
Beispiel #4
0
 def train_dataloader(self):
     seed_everything(42)
     return torch.utils.data.DataLoader(RandomDataset(32, 64))
 def test_dataloader(self):
     return [torch.utils.data.DataLoader(RandomDataset(32, 64)) for _ in range(num_dataloaders)]
Beispiel #6
0
 def val_dataloader(self):
     return [
         torch.utils.data.DataLoader(RandomDataset(32, 64)),
         torch.utils.data.DataLoader(RandomDataset(32, 64))
     ]
Beispiel #7
0
 def test_dataloader(self):
     return DataLoader(RandomDataset(32, 64), batch_size=4)