def upsample_kernel_size_solver(
    in_size, out_size, stride=1, padding=0, output_padding=0, dilation=1,
):
    """
    Returns kernel size needed to upsample a tensor of some input size to
    a desired output size.

    The implementation solves for kernel size in the equation described the
    the "Shape" section of the pytorch docs:
    https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose1d.html
    """
    x = out_size - 1 - output_padding - (in_size - 1) * stride + 2 * padding
    x = int(x / dilation + 1)
    return (x, )