def gnmt_residual_fn(inputs, outputs):
  """Residual function that handles different inputs and outputs inner dims.

  Args:
    inputs: A potentially nested structure of <tensor> [..., input_dim] that
      represents cell inputs.
    outputs: A potentially nested structure of <tensor> [..., output_dim] that
      represents cell outputs. Must have the same structure and number of
      dimensions as inputs and output_dim >= input_dim must hold.

  Returns:
    outputs + actual_inputs where actual_inputs are a nested structure of slices
    of the inputs along the last dimension up to the output_dim.
  """
  def split_input(inp, out):
    out_dim = out.get_shape().as_list()[-1]
    inp_dim = inp.get_shape().as_list()[-1]
    return tf.split(inp, [out_dim, inp_dim - out_dim], axis=-1)

  actual_inputs, _ = contrib_framework.nest.map_structure(
      split_input, inputs, outputs)
  def assert_shape_match(inp, out):
    inp.get_shape().assert_is_compatible_with(out.get_shape())

  contrib_framework.nest.assert_same_structure(actual_inputs, outputs)
  contrib_framework.nest.map_structure(assert_shape_match, actual_inputs,
                                       outputs)
  return contrib_framework.nest.map_structure(lambda inp, out: inp + out,
                                              actual_inputs, outputs)
Residual function that handles different inputs and outputs inner dims.

  Args:
    inputs: A potentially nested structure of <tensor> [..., input_dim] that
      represents cell inputs.
    outputs: A potentially nested structure of <tensor> [..., output_dim] that
      represents cell outputs. Must have the same structure and number of
      dimensions as inputs and output_dim >= input_dim must hold.

  Returns:
    outputs + actual_inputs where actual_inputs are a nested structure of slices
    of the inputs along the last dimension up to the output_dim.
  
language/labs/consistent_zero_shot_nmt/utils/model_utils.py