A similar example using exclusively the C++ interface of the same pytorch version works without problems (.backward() does not hang).
It would already be interesting to know whether the above issue occurs for anyone else or if it runs for someone.