code: def _ensure_initialized():
      if not dist.is_initialized():
          os.environ["RANK"] = os.environ.get(
              "OMPI_COMM_WORLD_RANK", "0"
          )
          os.environ["WORLD_SIZE"] = os.environ.get(
              "OMPI_COMM_WORLD_SIZE", "1"
          )
          os.environ["CUDA_VISIBLE_DEVICES"] = os.environ["RANK"]
          os.environ["MASTER_ADDR"] = os.environ.get(
              "MASTER_ADDR", "localhost"
          )
          os.environ["MASTER_PORT"] = os.environ.get(
              "MASTER_PORT", "12211"
          )
          dist.init_process_group(backend="nccl")
  
file_path: thu-pacman-faster-moe/tests/test_gates.py
imports: import pytest
  import os
  import sys
  import json
  import math
  import torch
  import torch.distributed
  import torch.nn.functional
  from fmoe.gates import GShardGate, SwitchGate, BaseLayerGate
  from test_ddp import _run_distributed
label_desc: Use image node_id 1 for calling a global function with example usage: _ensure_initialized() without return types