You are detaching the losses from the computation graph by wrapping them into a new tensor.
Setting requires_grad = True on this new tensor will then hide the expected error message.
You can verify it by checking the .grad attributes of all parameters after the backward() op and would see that they are None.
To fix this sum the losses directly without using torch.tensor(err...).
PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier.