I’m not sure if you will encounter this error, but if you want to call backward sequentially for your losses, you might want to specify retain_graph=True in the .backward() call, as the intermediate variables will be cleared otherwise.