docstr: Construct a class holding the parameters required to properly setup
  PyTorch distributed (with the default env:// initialization method).
  
  Examples
  --------
  >>> dist_env = TorchDistributedEnvironment().export()
  >>> torch.distributed.init_process_group(backend="nccl")
  >>> print(f"master: {dist_env.master_addr}:{dist_env.master_port}")
docstr_tok: ["Construct","a","class","holding","the","parameters","required","to","properly","setup","PyTorch","distributed","(","with","the","default","env",":","\/\/","initialization","method",")",".","Examples","--","--","--","--",">",">",">","dist_env","=","TorchDistributedEnvironment","(",")",".export","(",")",">",">",">","torch.distributed.init_process_group","(","backend=","''","nccl","''",")",">",">",">","print","(","f","''","master",":","{","dist_env.master_addr","}",":","{","dist_env.master_port","}","''",")"]
code: def __init__(self) -> None:
      """Construct a class holding the parameters required to properly setup
      PyTorch distributed (with the default env:// initialization method).
  
      Examples
      --------
      >>> dist_env = TorchDistributedEnvironment().export()
      >>> torch.distributed.init_process_group(backend="nccl")
      >>> print(f"master: {dist_env.master_addr}:{dist_env.master_port}")
      """
      self._job_env = JobEnvironment()
      self.master_addr = self._job_env.hostnames[0]
      self.master_port = self._get_master_port()
      self.rank = self._job_env.global_rank
      self.world_size = self._job_env.num_tasks
      self.local_rank = self._job_env.local_rank
      self.local_world_size = (
          self._job_env.num_tasks // self._job_env.num_nodes
      )
  
imports: import collections
  import contextlib
  import datetime
  import itertools
  import os
  import random
  import shutil
  import subprocess
  import tempfile
  import time
  import typing
  from pathlib import Path
  from .core import core
  from .core.job_environment import JobEnvironment
  from .core.utils import CommandFunction
  from .core.utils import DelayedSubmission
  from .core.utils import environment_variables
label_desc: Use image node_id 1 to create a new TorchDistributedEnvironment object  with example: obj = TorchDistributedEnvironment()