code: def init_torch_distributed(self):
      if self.distributed:
          # See:
          # https://docs.nvidia.com/deeplearning/sdk/nccl-developer-guide/docs/env.html
          os.environ.setdefault("NCCL_DEBUG", "INFO")
  
          # See:
          # https://pytorch.org/docs/stable/distributed.html#torch.distributed.init_process_group
          os.environ.setdefault("NCCL_BLOCKING_WAIT", "1")
  
          torch.distributed.init_process_group(
              backend=self.dist_backend,
              init_method=self.dist_init_method,
              world_size=self.dist_world_size,
              rank=self.dist_rank,
          )
  
          # About distributed model:
          # if self.local_rank is not None and ngpu == 1
          #    => Distributed with n-Process and n-GPU
          # if self.local_rank is None and ngpu >= 1
          #    => Distributed with 1-Process and n-GPU
          if self.local_rank is not None and self.ngpu > 0:
              torch.cuda.set_device(self.local_rank)
  
imports: import dataclasses
  import os
  import socket
  from typing import Optional
  import torch
  import torch.distributed
label_desc: Use image node_id 2 for calling the DistributedOption obj's underlying member method code with example usage: obj.init_torch_distributed() without return types