code: def test_trainer_reset_correctly(tmpdir, trainer_fn):
      """Check that model and all trainer parameters are reset correctly after scaling batch size."""
      model = BatchSizeModel(batch_size=2)
      before_state_dict = deepcopy(model.state_dict())
  
      # logger file to get meta
      trainer = Trainer(default_root_dir=tmpdir, max_epochs=1)
      tuner = Tuner(trainer)
  
      changed_attributes = [
          "loggers",
          "callbacks",
          "global_step",
          "max_steps",
          "limit_train_batches",
          "limit_val_batches",
          "limit_test_batches",
          "limit_predict_batches",
      ]
  
      expected = {ca: getattr(trainer, ca) for ca in changed_attributes}
      expected_loop_state_dict = trainer.fit_loop.state_dict()
  
      with no_warning_call(
          UserWarning, match="Please add the following callbacks"
      ):
          tuner.scale_batch_size(
              model, max_trials=64, method=trainer_fn
          )
  
      actual = {ca: getattr(trainer, ca) for ca in changed_attributes}
      actual_loop_state_dict = trainer.fit_loop.state_dict()
      assert expected_loop_state_dict == actual_loop_state_dict
      assert actual == expected
  
      after_state_dict = model.state_dict()
      for key in before_state_dict:
          assert torch.all(
              torch.eq(before_state_dict[key], after_state_dict[key])
          ), "Model was not reset correctly after scaling batch size"
  
      assert not any(
          f
          for f in os.listdir(tmpdir)
          if f.startswith(".scale_batch_size_temp_model")
      )
  
imports: import logging
  import os
  from copy import deepcopy
  from unittest.mock import patch
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder
  from lightning.pytorch.demos.boring_classes import BoringDataModule, BoringModel, RandomDataset
  from lightning.pytorch.tuner.tuning import Tuner
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning_utilities.test.warning import no_warning_call
  from torch.utils.data import DataLoader
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: test_trainer_reset_correctly(tmpdir, trainer_fn) without return types