class_docstr: DistributedContext provides useful methods for effective distributed training.
  
  A DistributedContext has the following required args:
   - rank: the index of this worker in the entire job
   - size: the number of workers in the entire job
   - local_rank: the index of this worker on this machine
   - local_size: the number of workers on this machine
   - cross_rank: the index of this machine in the entire job
   - cross_size: the number of machines in the entire job
  
  Additionally, any time that cross_size > 1, you must also provide:
   - chief_ip: the ip address to reach the chief worker (where rank==0)
  
  .. note::
  
     DistributedContext has ``.allgather()``, ``.gather()``, and ``.broadcast()`` methods, which
     are easy to use and which can be useful for coordinating work across workers, but it is not a
     replacement for the allgather/gather/broadcast operations in your particular distributed
     training framework.
class_docstr_tok: ["DistributedContext","provides","useful","methods","for","effective","distributed","training",".","A","DistributedContext","has","the","following","required","args",":","-","rank",":","the","index","of","this","worker","in","the","entire","job","-","size",":","the","number","of","workers","in","the","entire","job","-","local_rank",":","the","index","of","this","worker","on","this","machine","-","local_size",":","the","number","of","workers","on","this","machine","-","cross_rank",":","the","index","of","this","machine","in","the","entire","job","-","cross_size",":","the","number","of","machines","in","the","entire","job","Additionally",",","any","time","that","cross_size",">","1",",","you","must","also","provide",":","-","chief_ip",":","the","ip","address","to","reach","the","chief","worker","(","where","rank==0",")","..","note",":",":","DistributedContext","has","``",".allgather","(",")","``",",","``",".gather","(",")","``",",","and","``",".broadcast","(",")","``","methods",",","which","are","easy","to","use","and","which","can","be","useful","for","coordinating","work","across","workers",",","but","it","is","not","a","replacement","for","the","allgather\/gather\/broadcast","operations","in","your","particular","distributed","training","framework","."]
docstr: Create a ``DistributedContext`` using the provided ``hvd`` module to determine rank
  information.
  
  Example:
  
  .. code:: python
  
     import horovod.torch as hvd
     hvd.init()
     distributed = DistributedContext.from_horovod(hvd)
  
  The IP address for the chief worker is required whenever ``hvd.cross_size() > 1``. The value
  may be provided using the ``chief_ip`` argument or the ``DET_CHIEF_IP`` environment
  variable.
docstr_tok: ["Create","a","``","DistributedContext","``","using","the","provided","``","hvd","``","module","to","determine","rank","information",".","Example",":","..","code",":",":","python","import","horovod.torch","as","hvd","hvd.init","(",")","distributed","=","DistributedContext.from_horovod","(","hvd",")","The","IP","address","for","the","chief","worker","is","required","whenever","``","hvd.cross_size","(",")",">","1","``",".","The","value","may","be","provided","using","the","``","chief_ip","``","argument","or","the","``","DET_CHIEF_IP","``","environment","variable","."]
code: def from_horovod(
      cls, hvd: Any, chief_ip: Optional[str] = None
  ) -> "DistributedContext":
      """
      Create a ``DistributedContext`` using the provided ``hvd`` module to determine rank
      information.
  
      Example:
  
      .. code:: python
  
         import horovod.torch as hvd
         hvd.init()
         distributed = DistributedContext.from_horovod(hvd)
  
      The IP address for the chief worker is required whenever ``hvd.cross_size() > 1``. The value
      may be provided using the ``chief_ip`` argument or the ``DET_CHIEF_IP`` environment
      variable.
      """
  
      return cls(
          rank=hvd.rank(),
          size=hvd.size(),
          local_rank=hvd.local_rank(),
          local_size=hvd.local_size(),
          cross_rank=hvd.cross_rank(),
          cross_size=hvd.cross_size(),
          chief_ip=chief_ip or os.environ.get("DET_CHIEF_IP"),
      )
  
imports: import logging
  import os
  import socket
  import tempfile
  from typing import Any, List, Optional
  from determined import constants, ipc, util
label_desc: Use image node_id 3 for calling the DistributedContext obj's underlying member method code with example usage: obj.from_horovod(cls, hvd, chief_ip) and returns: cls