import tensorflow as tf


    Args:
      config: A `DeploymentConfig` object.
      model_fn: A callable. Called as `model_fn(*args, **kwargs)`
      args: Optional list of arguments to pass to `model_fn`.
      kwargs: Optional list of keyword arguments to pass to `model_fn`.
      optimizer: Optional `Optimizer` object.  If passed the model is deployed
          for training with that optimizer.
      summarize_gradients: Whether or not add summaries to the gradients.

    Returns:
      A `DeployedModel` namedtuple.

    """
    # Gather initial summaries.
    summaries = set(tf.get_collection(tf.GraphKeys.SUMMARIES))

    # Create Clones.
    clones = create_clones(config, model_fn, args, kwargs)
    first_clone = clones[0]

    # Gather update_ops from the first clone. These contain, for example,
    # the updates for the batch_norm variables created by model_fn.
    update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS, first_clone.scope)

    train_op = None
    total_loss = None
    with tf.device(config.optimizer_device()):
        if optimizer:
            # Place the global step on the device storing the variables.
