//  [python]
def setup(self, is_training=True, reuse=False):
        """Sets up the module.

        This usually involves creating the actual tensorflow graph. It is expected to be called after the input module
        is set up and shared resources, such as the vocab, config, etc., are prepared already at this point.
        """
        old_train_variables = tf.trainable_variables()
        old_variables = tf.global_variables()

        with tf.variable_scope(self.shared_resources.config.get("name", "jtreader"),
                               initializer=tf.contrib.layers.xavier_initializer(), reuse=reuse):
            self._tensors = {p: p.create_tf_placeholder() for p in self.input_ports}
            output_tensors = self.create_output(
                self.shared_resources, {port: self._tensors[port] for port in self.input_ports})

            self._placeholders = dict(self._tensors)
            self._tensors.update(output_tensors)

            if is_training:
                self._placeholders.update((p, p.create_tf_placeholder()) for p in self.training_input_ports
                                          if p not in self._placeholders and p not in self._tensors)
                self._tensors.update(self._placeholders)
                input_target_tensors = {p: self._tensors.get(p, None) for p in self.training_input_ports}
                training_output_tensors = self.create_training_output(
                    self.shared_resources, {port: input_target_tensors[port] for port in self.training_input_ports})
                self._tensors.update(training_output_tensors)
        self._training_variables = [v for v in tf.trainable_variables() if v not in old_train_variables]
        self._saver = tf.train.Saver(self._training_variables, max_to_keep=1)
        self._variables = [v for v in tf.global_variables() if v not in old_variables]
        self.tf_session.run([v.initializer for v in self.variables])

        for var in tf.global_variables():
            is_trainable = var in tf.trainable_variables()
            logger.debug('Variable: {} (Trainable: {})'.format(var, is_trainable))

        # Sometimes we want to initialize (partially) with a pre-trained model
        load_dir = self.shared_resources.config.get('load_dir')
        if is_training and load_dir is not None:
            if not load_dir.endswith('model_module'):
                # path to a reader was provided
                load_dir = os.path.join(load_dir, 'model_module')
            # get all variables in the checkpoint file
            from tensorflow.python import pywrap_tensorflow
            reader = pywrap_tensorflow.NewCheckpointReader(load_dir)
            init_vars = []
            for n in reader.get_variable_to_shape_map().keys():
                found = False
                for v in self.variables:
                    if v.op.name == n:
                        found = True
                        init_vars.append(v)
                        break
                if not found:
                    logger.warn("Could not find variable %s in computation graph to restore from pretrained model." % n)

            saver = tf.train.Saver(init_vars)
            saver.restore(self.tf_session, load_dir)