class_docstr: Used to perform in-graph replication on a computational graph.
  
  That is, Replicator is used to create _n_ replicas of a `tf.Graph`,
  with all replicas being stored in a new `tf.Graph` and delineated
  with name scopes.
  
  This also handles ControlFlowContexts, updating variable and gradient
  information, etc.
class_docstr_tok: ["Used","to","perform","in-graph","replication","on","a","computational","graph",".","That","is",",","Replicator","is","used","to","create","_n_","replicas","of","a","`","tf.Graph","`",",","with","all","replicas","being","stored","in","a","new","`","tf.Graph","`","and","delineated","with","name","scopes",".","This","also","handles","ControlFlowContexts",",","updating","variable","and","gradient","information",",","etc","."]
code: def __init__(self, key, graph_item, config, cluster):
      super().__init__(key)
      self._graph_item = graph_item
      self._cluster = cluster
  
      self._replica_devices = {
          device_spec.DeviceSpecV2.from_string(s) for s in config
      }
  
      self._local_canonical_replica_devices = sorted(
          {
              d.to_string()
              for d in self._replica_devices
              if self._cluster.get_local_address()
              == cluster.get_address_from_task(d.job, d.task)
          }
      )
      logging.debug(
          "Local replica devices: {}".format(
              self._local_canonical_replica_devices
          )
      )
      self._num_local_replicas = len(
          self._local_canonical_replica_devices
      )
  
      self._local_worker_id = (
          self._cluster.get_local_worker_task_index()
      )
      self._local_worker_device = "/job:worker/task:{}".format(
          self._local_worker_id
      )
  
file_path: autodist/autodist/kernel/replicator.py
imports: from tensorflow.python import ops, import_graph_def
  from tensorflow.python.framework import device_spec, kernels
  from tensorflow.python.framework.device_spec import DeviceSpecV2
  from tensorflow.python.ops.control_flow_ops import WhileContext
  from tensorflow.python.ops.control_flow_util import GetWhileContext
  from tensorflow.python.ops.resource_variable_ops import _from_proto_fn
  from autodist.graph_item import GraphItem
  from autodist.kernel.common.utils import replica_prefix
  from autodist.kernel.kernel import Kernel
  from autodist.checkpoint.saver import Saver
  from autodist.utils import logging
label_desc: Use image node_id 1 to create a new Replicator object from inherited base classes: Kernel with example: obj = Replicator(key, graph_item, config, cluster)