import torch


def process_sequence_wise(cell, x, h=None):
    """
    Process the entire sequence through an GRUCell.
    Args:
         cell (DistillerGRUCell): the cell.
         x (torch.Tensor): the input
         h (tuple of torch.Tensor-s): the hidden states of the GRUCell.
    Returns:
         y (torch.Tensor): the output
         h (tuple of torch.Tensor-s): the new hidden states of the GRUCell.
    """
    results = []
    for step in x:
        y, h = cell(step, h)
        results.append(y)
        h = (y, h)
    return torch.stack(results), h