Actually I found the real reason behind this. In between these two lines:

output = net(input for first case)
second_output = net(output from the first call as the input)

I actually have several extra simple operations over the output tensor in the middle. Strangely enough, with that back-propagation does not work properly. My solution is to wrap these extra operations into a nn.module. With this it works normally again.
That is it. I hope my experience is useful to someone.