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: Gather ``stuff`` to the local chief and broadcast all of it back to the local workers.
  
  ``allgather_local()`` is not a replacement for the allgather functionality of your
  distributed training framework.
docstr_tok: ["Gather","``","stuff","``","to","the","local","chief","and","broadcast","all","of","it","back","to","the","local","workers",".","``","allgather_local","(",")","``","is","not","a","replacement","for","the","allgather","functionality","of","your","distributed","training","framework","."]
code: def allgather_local(self, stuff: Any) -> List:
      """
      Gather ``stuff`` to the local chief and broadcast all of it back to the local workers.
  
      ``allgather_local()`` is not a replacement for the allgather functionality of your
      distributed training framework.
      """
      if self.local_size < 2:
          return [stuff]
      logger.debug(
          f"Worker {self.get_rank()} beginning zmq local allgather."
      )
      if self._is_local_chief:
          worker_stuff_ranked = self._local_chief_zmq.gather()
          worker_stuff = [
              value for _, value in sorted(worker_stuff_ranked)
          ]
          all_stuff = [stuff, *worker_stuff]
          self._local_chief_zmq.broadcast(all_stuff)
      else:
          self._local_worker_zmq.send((self.get_local_rank(), stuff))
          all_stuff = self._local_worker_zmq.recv()
      logger.debug(
          f"Worker {self.get_rank()} finished zmq local allgather."
      )
      return all_stuff
  
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 14 for calling the DistributedContext obj's underlying member method code with example usage: obj.allgather_local(stuff) and returns: all_stuff, list