code: def _pipeline_parallel_pre_init(cfg: DistributedTrainingConfig):
      from fairseq import utils
  
      balance_exists = (
          cfg.pipeline_balance is not None
          or cfg.pipeline_encoder_balance is not None
          or cfg.pipeline_decoder_balance is not None
      )
      devices_exist = (
          cfg.pipeline_devices is not None
          or cfg.pipeline_encoder_devices is not None
          or cfg.pipeline_decoder_devices is not None
      )
      if not balance_exists:
          raise ValueError(
              "--pipeline-balance is currently required for pipeline model parallelism"
          )
      if not devices_exist:
          raise ValueError(
              "--pipeline-devices is currently required for pipeline model parallelism"
          )
  
      cfg.pipeline_balance = utils.eval_str_list(
          cfg.pipeline_balance, type=int
      )
      if cfg.pipeline_devices is not None:
          cfg.pipeline_devices = utils.eval_str_list(
              cfg.pipeline_devices, type=int
          )
          num_pipeline_devices = len(set(cfg.pipeline_devices))
      else:
          cfg.pipeline_encoder_devices = utils.eval_str_list(
              cfg.pipeline_encoder_devices, type=int
          )
          cfg.pipeline_decoder_devices = utils.eval_str_list(
              cfg.pipeline_decoder_devices, type=int
          )
          num_pipeline_devices = len(
              set(
                  cfg.pipeline_encoder_devices
                  + cfg.pipeline_decoder_devices
              )
          )
      gpus_per_node = torch.cuda.device_count()
      assert (
          gpus_per_node >= num_pipeline_devices
          and gpus_per_node % num_pipeline_devices == 0
      ), (
          "the number of unique device IDs in --pipeline-devices must evenly divide "
          "the number of GPUs per node (multi-node pipelining is not yet supported)"
      )
      num_pipelines_per_node = gpus_per_node // num_pipeline_devices
      return num_pipeline_devices, num_pipelines_per_node
  
imports: import io
  import logging
  import os
  import pickle
  import random
  import socket
  import struct
  import subprocess
  import warnings
  from argparse import Namespace
  from collections import OrderedDict
  from dataclasses import dataclass
  from typing import Any, Dict, List, Mapping, Optional
  import torch
  import torch.distributed
  from fairseq.dataclass.configs import DistributedTrainingConfig, FairseqConfig
  from omegaconf import open_dict
label_desc: Use image node_id 6 for calling a global function with example usage: _pipeline_parallel_pre_init(cfg) and returns: num_pipeline_devices,  num_pipelines_per_node