Torch::nn in iOS C++ is unavailable

I started from the HelloWorld example on iOS and everything worked until i tried to add nn functionality like

auto loss = torch::nn::MSELoss(); // Error: No member named 'nn' in namespace 'torch'

Is there a way to include torch::nn and torch::nn::functional API in iOS?

Hi @dnnagy the APIs under nn namespace are being used to support eager mode in Python. Since we’re using torchscript on mobile, we didn’t compile that part of code in our binary. However, I think you can manually enable it by changing the NO_API value to OFF in the root CMakeLists.txt and rebuild the libraries. However, I personally haven’t tried, so not sure if they’ll work or not.