I came into the same problem when using loss.backward(), when I swithed torch to Preview(Nightly) version, it worked.