def regroup_if_changed(group, op_list, name=None):
  """Creates a new group for op_list if it has changed.

  Args:
    group: The current group. It is returned if op_list is unchanged.
    op_list: The list of operations to check.
    name: The name to use if a new group is created.
  Returns:
    Either group or a new group (or if op_list is empty then no_op).
  """
  has_deltas = isinstance(op_list, sequence_with_deltas.SequenceWithDeltas)
  if (group is None or len(group.control_inputs) != len(op_list) or
      (has_deltas and op_list.has_changed())):
    if has_deltas:
      op_list.mark()
    if op_list:
      return tf.group(*op_list, name=name)
    else:
      return tf.no_op(name=name)
  else:
    return group