code: def spawn_launch(fn, parallel_devices):
      """Copied from ``tests_pytorch.core.test_results.spawn_launch``"""
      # TODO: the accelerator and cluster_environment should be optional to just launch processes, but this requires lazy
      # initialization to be implemented
      device_to_accelerator = {
          "cuda": CUDAAccelerator,
          "mps": MPSAccelerator,
          "cpu": CPUAccelerator,
      }
      accelerator_cls = device_to_accelerator[parallel_devices[0].type]
      strategy = DDPStrategy(
          accelerator=accelerator_cls(),
          parallel_devices=parallel_devices,
          cluster_environment=LightningEnvironment(),
          start_method="spawn",
      )
      launcher = _MultiProcessingLauncher(strategy=strategy)
      wrapped = partial(wrap_launch_function, fn, strategy)
      return launcher.launch(wrapped, strategy)
  
imports: import functools
  import os
  from functools import partial
  from pathlib import Path
  from unittest import mock
  import pytest
  import torch
  from lightning.fabric.accelerators import CPUAccelerator, CUDAAccelerator, MPSAccelerator
  from lightning.fabric.plugins.environments import LightningEnvironment
  from lightning.fabric.strategies import DDPStrategy, SingleDeviceStrategy
  from lightning.fabric.strategies.launchers.multiprocessing import _MultiProcessingLauncher
  from lightning.fabric.utilities.distributed import _gather_all_tensors, _set_num_threads_if_needed, _suggested_max_num_threads, _sync_ddp, is_shared_filesystem
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: spawn_launch(fn, parallel_devices) and returns: launcher