code: def _ensure_initialized():
      if "RANK" not in os.environ:
          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"
          )
      if not dist.is_initialized():
          dist.init_process_group(backend="nccl")
  
file_path: smart-moe/tests/test_ddp.py
imports: import json
  import random
  import os
  import sys
  from typing import Dict
  import random
  import pytest
  import torch
  import torch.distributed
  from test_numerical import test_fmoe
  from test_numerical import test_fmoe_linear
  from test_numerical import _test_fmoe_local_ddp
label_desc: Use image node_id 1 for calling a global function with example usage: _ensure_initialized() without return types