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", weights_only=True)
    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"
Test that the default `map_location` provided by Lightning moves parameters to CPU if the accelerator is not
    available at the time of loading.
tests/tests_pytorch/core/test_saving.py