title: Pytorch: how to mask flexible size of input for average pooling?
body: <p><strong>Backgroud</strong>: I would like to apply convolutions and average pooling to sequences for sequence classification task.</p>
  
  <p><strong>Problem</strong>: without mask for inputs, the calculation of mini-batch and one-by-one will be different. 
  For example:</p>
  
  <pre><code># Two sequences.
  s1 = torch.range(start=1, end=6).view(-1, 1)
  s2 = torch.range(start=1, end=3).view(-1, 1)
  
  ##########################################
  # one-by-one
  
  # Convolutions.
  kernels = torch.ones(1, 1, 2)
  h1 = F.conv1d(s1.view(1, 1, -1), kernels) #h1=[[[3, 5, 7, 9, 11]]]
  h2 = F.conv1d(s2.view(1, 1, -1), kernels) #h2=[[[3, 5]]]
  
  # Average pooling.
  h1 = h1.mean(-1) #h1=[[7]]
  h2 = h2.mean(-1) #h2=[[4]]
  
  ##########################################
  # mini-batch
  s = torch.nn.utils.rnn.pad_sequence([s1, s2], batch_first=True)
  s = s.permute(0, 2, 1)
  h = torch.mean(F.conv1d(s, kernels), dim=-1) #h=[[7], [2.2]]
  </code></pre>
  
  <p>As you can see, the <code>h</code> is different from <code>[h1, h2]</code>.</p>
  
  <p><strong>Questions</strong>:</p>
  
  <ol>
  <li>In order to make mini-batch the same as one-by-one, what is the normal way to employ?</li>
  <li>Is there a given pytorch api?</li>
  <li>If not, how to implement that?</li>
  </ol>