You are detaching the loss tensor by wrapping it into the deprecated Variable, so remove this line of code.
PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier