def unpack(variables):
    """ remove first dimension and zero padding from each variable

      variables is a list with one tensor per variable
      a tensor [3, 5, 4] may be unpacked to [[5, 4], [2, 4], [1, 4]]
    """
    all_unpacked = []
    for v in variables:
        # note on gpu sorted; on cpu not unless specified
        unpacked = [item[item.ne(0).nonzero()[:, 0].unique(sorted=True)] for item in v]
        all_unpacked.append(unpacked)
    return all_unpacked