Your loop is wrong, you are not changing f and t before running the backward() step again (or at least that’s more or less what that error means).
Comment out the backward() and step() and debug f and t and see what they are doing.