def test_training_starts_with_seed(tmp_path, seed_once):
    """Test the behavior of seed_everything on subsequent Trainer runs in combination with different settings of
    num_sanity_val_steps (which must not affect the random state)."""

    class SeededModel(BoringModel):
        def __init__(self):
            super().__init__()
            self.seen_batches = []

        def training_step(self, batch, batch_idx):
            self.seen_batches.append(batch.view(-1))
            return super().training_step(batch, batch_idx)

    def run_training(**trainer_kwargs):
        model = SeededModel()
        trainer = Trainer(**trainer_kwargs)
        trainer.fit(model)
        return torch.cat(model.seen_batches)

    if seed_once:
        seed_everything(123)
        sequence0 = run_training(default_root_dir=tmp_path, max_steps=2, num_sanity_val_steps=0)
        sequence1 = run_training(default_root_dir=tmp_path, max_steps=2, num_sanity_val_steps=2)
        assert not torch.allclose(sequence0, sequence1)
    else:
        seed_everything(123)
        sequence0 = run_training(default_root_dir=tmp_path, max_steps=2, num_sanity_val_steps=0)
        seed_everything(123)
        sequence1 = run_training(default_root_dir=tmp_path, max_steps=2, num_sanity_val_steps=2)
        assert torch.allclose(sequence0, sequence1)
Test the behavior of seed_everything on subsequent Trainer runs in combination with different settings of
    num_sanity_val_steps (which must not affect the random state).
tests/tests_pytorch/loops/test_training_loop.py