def pack_range(key, packing, grad_vars, rng):
    'Form the concatenation of a specified range of gradient tensors.\n\n  Args:\n    key: Value under which to store meta-data in packing that will be used\n      later to restore the grad_var list structure.\n    packing: Dict holding data describing packed ranges of small tensors.\n    grad_vars: List of (grad, var) pairs for one replica.\n    rng: A pair of integers giving the first, last indices of a consecutive\n      range of tensors to be packed.\n\n  Returns:\n    A tensor that is the concatenation of all the specified small tensors.\n  '
    to_pack = grad_vars[rng[0]:(rng[1] + 1)]
    members = []
    variables = []
    restore_shapes = []
    with ops.name_scope('pack'):
        for (g, v) in to_pack:
            variables.append(v)
            restore_shapes.append(g.shape)
            with ops.device(g.device):
                members.append(array_ops.reshape(g, [(- 1)]))
        packing[key] = GradPackTuple(indices=range(rng[0], (rng[1] + 1)), vars=variables, shapes=restore_shapes)
        with ops.device(members[0].device):
            return array_ops.concat(members, 0)
Form the concatenation of a specified range of gradient tensors.

Args:
  key: Value under which to store meta-data in packing that will be used
    later to restore the grad_var list structure.
  packing: Dict holding data describing packed ranges of small tensors.
  grad_vars: List of (grad, var) pairs for one replica.
  rng: A pair of integers giving the first, last indices of a consecutive
    range of tensors to be packed.

Returns:
  A tensor that is the concatenation of all the specified small tensors.
def pack_range(key, packing, grad_vars, rng):
    'Form the concatenation of a specified range of gradient tensors.\n\n  Args:\n    key: Value under which to store meta-data in packing that will be used\n      later to restore the grad_var list structure.\n    packing: Dict holding data describing packed ranges of small tensors.\n    grad_vars: List of (grad, var) pairs for one replica.\n    rng: A pair of integers giving the first, last indices of a consecutive\n      range of tensors to be packed.\n\n  Returns:\n    A tensor that is the concatenation of all the specified small tensors.\n  '
    to_pack = grad_vars[rng[0]:(rng[1] + 1)]
    members = []
    variables = []
    restore_shapes = []
    with ops.name_scope('pack'):
        for (g, v) in to_pack:
            variables.append(v)
            restore_shapes.append(g.shape)
            with ops.device(g.device):
                members.append(array_ops.reshape(g, [(- 1)]))
        packing[key] = GradPackTuple(indices=range(rng[0], (rng[1] + 1)), vars=variables, shapes=restore_shapes)
        with ops.device(members[0].device):
            return array_ops.concat(members, 0)