code: def test_scale_batch_size_method_with_model_or_datamodule(
      tmpdir, model_bs, dm_bs
  ):
      """Test the tuner method `Tuner.scale_batch_size` with a datamodule."""
      trainer = Trainer(
          default_root_dir=tmpdir,
          limit_train_batches=1,
          limit_val_batches=0,
          max_epochs=1,
      )
  
      model = BatchSizeModel(model_bs)
      datamodule = BatchSizeDataModule(dm_bs) if dm_bs != -1 else None
  
      tuner = Tuner(trainer)
      new_batch_size = tuner.scale_batch_size(
          model,
          mode="binsearch",
          init_val=4,
          max_trials=2,
          datamodule=datamodule,
      )
      assert new_batch_size == 16
  
      if model_bs is not None:
          assert model.batch_size == new_batch_size
          if dm_bs == -1:
              # datamodule batch size takes precedence
              assert (
                  trainer.train_dataloader.batch_size == new_batch_size
              )
      if dm_bs not in (-1, None):
          assert datamodule.batch_size == new_batch_size
          assert trainer.train_dataloader.batch_size == new_batch_size
  
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 1 for calling a global function with example usage: test_scale_batch_size_method_with_model_or_datamodule(tmpdir, model_bs, dm_bs) without return types