import torch


def pad_tensor(tensor, seq_len):
    """Pad tensor with last element along 0 dimension."""
    sz = list(tensor.size())
    sz[0] = seq_len - tensor.size()[0] % seq_len

    tail = tensor[-1].clone().expand(sz).to(tensor.device)
    tensor = torch.cat((tensor, tail))
    return tensor