I meant to create your own Dataset class and then do a transform to pad to a given length.  An example of a custom dataset class below.  The idea would be to add a transform to that which pads to tensors so that upon every call of getitem() the tensors are padded and thus the batch is all padded tensors.  You could also have the getitem() function return a third value, which is the original length of the tensor so you can do masking.

  
      github.com
  
  
    pytorch/vision/blob/master/torchvision/datasets/mnist.py 2.1k
from __future__ import print_function
import torch.utils.data as data
from PIL import Image
import os
import os.path
import errno
import numpy as np
import torch
import codecs


class MNIST(data.Dataset):
    """`MNIST <http://yann.lecun.com/exdb/mnist/>`_ Dataset.

    Args:
        root (string): Root directory of dataset where ``processed/training.pt``
            and  ``processed/test.pt`` exist.
        train (bool, optional): If True, creates dataset from ``training.pt``,
            otherwise from ``test.pt``.
        download (bool, optional): If true, downloads the dataset from the internet and


  This file has been truncated. show original