I ran into a strange problem. I am trying out a GRU with pytorch. My forward function goes like this: def forward(self, ids, lengths, masks, labels): … Everything works fine until it gets a batch containing only 1 element. I inserted a print for debugging at the very beginning of the forward function: print(“FORW”, masks, lengths), and the output is FORW tensor([8]) tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]). I.e. lenghts refers to masks and masks refers to lengths? Any idea why this happens?