code: def _setup_graph(self, input, get_cost_fn, get_opt_fn):
      assert isinstance(input, FeedfreeInput), input
      (
          self.train_op,
          initial_sync_op,
          model_sync_op,
      ) = self._builder.build(
          self._make_get_grad_fn(input, get_cost_fn, get_opt_fn),
          get_opt_fn,
      )
  
      callbacks = []
      # Initial syncing vars from PS
      cb = RunOp(
          lambda: initial_sync_op,
          run_before=True,
          run_as_trigger=False,
          verbose=True,
      )
      cb.chief_only = False
      callbacks.append(cb)
  
      # Sync model_variables to PS, only chief needs to do this
      if model_sync_op:
          cb = RunOp(
              lambda: model_sync_op,
              run_before=False,
              run_as_trigger=True,
              verbose=True,
          )
          logger.warn(
              "For efficiency, local MODEL_VARIABLES are only synced to PS once "
              "every epoch. Be careful if you save the model more frequently than this."
          )
          callbacks.append(cb)
      return callbacks
  
imports: import multiprocessing
  import os
  import sys
  import tensorflow
  from tensorpack.compat import tfv1
  from ..callbacks import CallbackFactory, RunOp
  from ..graph_builder.distributed import DistributedParameterServerBuilder, DistributedReplicatedBuilder
  from ..graph_builder.training import AsyncMultiGPUBuilder, SyncMultiGPUParameterServerBuilder, SyncMultiGPUReplicatedBuilder
  from ..graph_builder.utils import override_to_local_variable
  from ..input_source import FeedfreeInput, QueueInput
  from ..tfutils import get_global_step_var
  from ..tfutils.common import get_tf_version_tuple
  from ..tfutils.distributed import get_distributed_session_creator
  from ..tfutils.sesscreate import NewSessionCreator
  from ..tfutils.tower import TrainTowerContext
  from ..utils import logger
  from ..utils.argtools import map_arg
  from ..utils.develop import HIDE_DOC, deprecated
  from .tower import SingleCostTrainer
label_desc: Use image node_id 3 for calling the DistributedTrainerReplicated obj's underlying member method code with example usage: obj._setup_graph(input, get_cost_fn, get_opt_fn) and returns: callbacks