Padding/masking are sometimes used. Eventually we’ll have support for nested tensors. There’s some discussion of the problem here with some of the workarounds typically employed:

  
      github.com/pytorch/pytorch
  
  
    
  
	  
  

  
    
      [RFC] NestedTensor - 0.0.1 10
    

    
      
        opened 
        
          
        
        Jun 25, 2019
      
      


      
        
          
          cpuhrsch
        
      
    
  



  Motivation
Many fields manipulate collections of Tensors of different shapes. For example, paragraphs of text, images of different sizes or audio files...



    topic: batching
    triaged


  
  
    
    
  
  


Also:

  
    
    
    Nested list of variable length to a tensor 
  
  
    I might be a bit late to the party, but after realizing that pytorch won’t spoonfeed me anymore, I ended up writing my own function to pad a list of tensors. 
The following function takes a nested list of integers and converts it into a padded tensor. 
def ints_to_tensor(ints):
    """
    Converts a nested list of integers to a padded tensor.
    """
    if isinstance(ints, torch.Tensor):
        return ints
    if isinstance(ints, list):
        if isinstance(ints[0], int):
            return …