code: def test_training_starts_with_seed(tmpdir, 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=tmpdir,
              max_steps=2,
              num_sanity_val_steps=0,
          )
          sequence1 = run_training(
              default_root_dir=tmpdir,
              max_steps=2,
              num_sanity_val_steps=2,
          )
          assert not torch.allclose(sequence0, sequence1)
      else:
          seed_everything(123)
          sequence0 = run_training(
              default_root_dir=tmpdir,
              max_steps=2,
              num_sanity_val_steps=0,
          )
          seed_everything(123)
          sequence1 = run_training(
              default_root_dir=tmpdir,
              max_steps=2,
              num_sanity_val_steps=2,
          )
          assert torch.allclose(sequence0, sequence1)
  
file_path: pytorch-lightning/tests/tests_pytorch/loops/test_training_loop.py
imports: import logging
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import Trainer, seed_everything
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loops import _FitLoop
label_desc: Use image node_id 2 for calling a global function with example usage: test_training_starts_with_seed(tmpdir, seed_once) and returns: torch, super