import torch


def pad_inputs(inputs: list, max_length: int, pad_value, dtype, device):
    """
    Pad the inputs to a fixed size. The entries in the batch must be shorter than max_length.

    :param inputs: to pad to max_length (not just to the longest in the batch)
    :param max_length: the length upto which padding is applied
    :param pad_value: the value to use for padding
    :param dtype: of the padded inputs
    :param device: of the padded inputs

    :return: the padded inputs
    """
    max_size = inputs[0].size()
    trailing_dims = max_size[1:]
    out_dims = (len(inputs), max_length) + trailing_dims
    inputs_padded = torch.full(size=out_dims, fill_value=pad_value, dtype=dtype, device=device)
    # We need to iterate here, because each tensor has individual length
    for idx, tensor in enumerate(inputs):
        length = len(tensor)
        inputs_padded[idx, :length, ...] = tensor
    return inputs_padded