Hi,
The print(output) and loss.backward() you mention above are the ones in the last lines of your code sample right?
If you don’t set any breakpoint, is the code working fine?
If the structure of your code is:
    for i, input_str in enumerate(MyDataLoader, 0):
        output = model(input_str)
        print(output)
        loss = sentence_loss(output)
        loss.backward()

I don’t see how the last line can be called twice without the print being called.
Or you have other calls to .backward() in your code?