import torch


def pack_sequence_for_linear(inputs, lengths):
    """
    :param inputs: [B, T, D]
    :param lengths:  [B]
    :return:    [sum(batch lengths), D]
    """
    batch_list = []
    for i, l in enumerate(lengths.tolist()):
        batch_list.append(inputs[i, :l])
    packed_sequence = torch.cat(batch_list, 0)

    return packed_sequence