Whilst not being an answer to your question, this post is directly related: Pytorch 2 and the c++ interface - #6 by ezyang