Possible Memory Leak

Hello,

I’m trying to run a customized version of the seq2seq tutorial. The relevant snippets are included in the following gist:

I’ve tracked it down to the nn.gru calls in encoder and decoder, where a torch.cuda.FloatTensor of size 4509000 keeps getting added everytime forward is called, eventually running out of memory. Far as I understand, the trouble happens after the GRU call. I’m not very familiar with internals, so:

        {torch.Size([3, 383, 500]): [4, 2, 2, 2, 2],
         torch.Size([383, 10, 500]): [4, 2, 2, 2, 2],
         torch.Size([1500]): [24, 24, 24, 24, 24],
         torch.Size([1500, 500]): [24, 24, 24, 24, 24],
         torch.Size([3085]): [2, 2, 2, 2, 2],
         torch.Size([3085, 500]): [4, 4, 4, 4, 4],
         torch.Size([3258]): [2, 2, 2, 2, 2],
         torch.Size([3258, 500]): [4, 4, 4, 4, 4],
         **torch.Size([4509000]): [1, 2, 3, 4, 5],**
         torch.Size([153200000]): [1, 1, 1, 1, 1]})

What could I do further to isolate where this is happening and fix it?