Add Variables of different sizes

My computation has an intermediate variable-length list of 3-D PyTorch Variables of different sizes (say [32x32x3, 16x2x36, 18x6x12]). What would be the easiest way to add up all the Variables after the necessary padding? For the example I’ve given, the final output would have size 32x32x36. Note that this addition needs to be done in a way that gradients can flow backwards.

Just resurfacing the topic in case anyone missed it. :slight_smile:

  • create output Variable of size 32x32x36 and fill with zeros
  • slice Variable to dimension of each Variable in your list and add the input Variable.

This will correctly compute gradients too.