code: def test_load_from_checkpoint_map_location_automatic(
      accelerator, tmp_path, monkeypatch
  ):
      """Test that the default `map_location` provided by Lightning moves parameters to CPU if the accelerator is not
      available at the time of loading."""
      create_boring_checkpoint(
          tmp_path, BoringModel(), accelerator=accelerator
      )
  
      # The checkpoint contains tensors with storage tag on the accelerator
      checkpoint = torch.load(f"{tmp_path}/checkpoint.ckpt")
      assert checkpoint["state_dict"][
          "layer.weight"
      ].device.type.startswith(accelerator)
  
      # Pretend that the accelerator is not available
      mock_cuda_count(monkeypatch, 0)
      mock_mps_count(monkeypatch, 0)
  
      model = BoringModel.load_from_checkpoint(
          f"{tmp_path}/checkpoint.ckpt"
      )
      _ = BoringDataModule.load_from_checkpoint(
          f"{tmp_path}/checkpoint.ckpt"
      )
      assert model.device.type == "cpu"
      assert model.layer.weight.device.type == "cpu"
  
file_path: pytorch-lightning/tests/tests_pytorch/core/test_saving.py
imports: import lightning.pytorch
  import pytest
  import torch
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringDataModule, BoringModel
  from tests_pytorch.conftest import mock_cuda_count, mock_mps_count
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: test_load_from_checkpoint_map_location_automatic(accelerator, tmp_path, monkeypatch) without return types