'Args:
config(TrainConfig): Must contain \'model\' and \'data\'.
server (tf.train.Server): the server object with ps and workers'

def __init__(self, config, server):

    assert ((config.data is not None) and (config.model is not None))
    self.server = server
    server_def = server.server_def
    self.cluster = tf.train.ClusterSpec(server_def.cluster)
    self.job_name = server_def.job_name
    self.task_index = server_def.task_index
    assert (self.job_name in ['ps', 'worker']), self.job_name
    assert tf.test.is_gpu_available
    self._input_source = config.data
    self.is_chief = ((self.task_index == 0) and (self.job_name == 'worker'))
    worker_prefix = ('/job:worker/task:%s' % self.task_index)
    self.param_server_device = tf.train.replica_device_setter(worker_device=(worker_prefix + '/cpu:0'), cluster=self.cluster)
    self.num_ps = self.cluster.num_tasks('ps')
    self.num_worker = self.cluster.num_tasks('worker')
    self.nr_gpu = config.nr_tower
    self.cpu_device = ('%s/cpu:0' % worker_prefix)
    self.raw_devices = [('%s/%s:%i' % (worker_prefix, 'gpu', i)) for i in range(self.nr_gpu)]
    self.sync_queue_devices = [('/job:ps/task:%s/cpu:0' % i) for i in range(self.num_ps)]
    self.sync_queue_counter = 0
    super(DistributedTrainerReplicated, self).__init__(config)
