def multi_process_spawn(fn=None, args=None):
        """
        Use torch.multiprocessing to spawn N (world_size) processes.
        """
        with tempfile.NamedTemporaryFile() as file:
            os.environ["INIT_FILE"] = "file://{}".format(file.name)
        proc = torch.multiprocessing.get_context("spawn").Process

        processes = []
        pid_to_pipe = {}
        world_size = len(torch.xpu.getDeviceIdListForCard())
        for rank in range(world_size):
            parent_conn, child_conn = torch.multiprocessing.Pipe()
            child_env = os.environ.copy()
            child_env["PMI_SIZE"] = str(world_size)
            child_env["PMI_RANK"] = str(rank)

            os.environ["RANK"] = child_env["PMI_RANK"]
            os.environ["WORLD_SIZE"] = child_env["PMI_SIZE"]
            process = proc(target=fn, name="process " + str(rank), args=args)

            process.start()
            print(f"Start process {rank} with pid {process.pid}")
            pid_to_pipe[process.pid] = parent_conn
            processes.append(process)
        for process in processes:
            process.join()
            return process.exitcode

        Use torch.multiprocessing to spawn N (world_size) processes.
        
intel_extension_for_pytorch/xpu/single_card.py