code: def run_parity_test(
      accelerator: str = "cpu",
      devices: int = 2,
      tolerance: float = 0.02,
  ):
      cuda_reset()
  
      # Launch processes with Fabric and re-use them for the PyTorch training for convenience
      fabric = Fabric(
          accelerator=accelerator, strategy="ddp", devices=devices
      )
      fabric.launch()
  
      # Train with Fabric
      (
          state_dict_fabric,
          timings_fabric,
          memory_fabric,
      ) = train_fabric_ddp(fabric)
  
      fabric.barrier()
      cuda_reset()
      torch.distributed.destroy_process_group()
      # sleep for a bit to avoid race conditions, since the very first call in `train_torch_ddp`
      # is initializing a new process group
      time.sleep(3)
  
      # Train with raw PyTorch
      state_dict_torch, timings_torch, memory_torch = train_torch_ddp(
          rank=fabric.global_rank,
          world_size=fabric.world_size,
          device=fabric.device,
          backend=fabric.strategy._process_group_backend,
      )
  
      # Compare the final weights
      assert all(
          fabric.all_gather(
              is_state_dict_equal(state_dict_torch, state_dict_fabric)
          )
      )
  
      # Compare the time per iteration
      assert all(
          fabric.all_gather(
              is_timing_close(
                  timings_torch,
                  timings_fabric,
                  rtol=tolerance,
                  atol=tolerance,
              )
          )
      )
  
      # Compare memory usage
      if accelerator == "cuda":
          assert all(
              fabric.all_gather(
                  is_cuda_memory_close(
                      memory_torch["start"], memory_fabric["start"]
                  )
              )
          )
          assert all(
              fabric.all_gather(
                  is_cuda_memory_close(
                      memory_torch["end"], memory_fabric["end"]
                  )
              )
          )
  
file_path: pytorch-lightning/tests/parity_fabric/test_parity_ddp.py
imports: import os
  import time
  from copy import deepcopy
  import torch
  import torch.distributed
  import torch.nn.functional
  from lightning.fabric.fabric import Fabric
  from torch.nn.parallel.distributed import DistributedDataParallel
  from torch.utils.data import DataLoader
  from torch.utils.data.distributed import DistributedSampler
  from parity_fabric.models import ConvNet
  from parity_fabric.utils import cuda_reset, is_cuda_memory_close, is_state_dict_equal, is_timing_close, make_deterministic
label_desc: Use image node_id 3 for calling a global function with example usage: run_parity_test(accelerator, devices, tolerance) without return types