Solved by tom in post #2 
              
              
                Cool, will you submit it to TorchVision for its C++ interface? 
I think you need AnyModule, look at what nn::Sequential does. 
Best regards 
Thomas