Building Torchlib with nn namespace for iOS

I’m trying to utilize torch::nn::functional::pad however it appears that nn namespace is in not included in the build for ios (as i’ve read here). I’ve tried to include nn into the build by setting the NO_API property in the root CMakeLists.txt to OFF as suggested. However, when building with this changed property the build fails…

torch/csrc/api/src/nn/module.cpp:5:10: fatal error: 'torch/csrc/autograd/generated/VariableType.h' file not found
#include <torch/csrc/autograd/generated/VariableType.h>

Found a post where someone ran into this issue and apparently found a solution here… however their explanation is unclear about what was done to resolve it.

How does one ensure that VariableType.h is generated?

Ok, so looking into this a bit further… VariableType.h is generated by tools/autograd/gen_variable_type.py. Which is utilized the caffe2 CMakeList.txt.

Reading through the caffe2/CMakeList.txt, it appears that for VariableType.h to be generated the Build_Mobile_Autograd must be set ON. (An in development option)

With the NO_API set OFF and BUILD_MOBILE_AUTOGRAD set ON VariableTypes.h is generated and the build succeeds… however the nn namespace is still not included… and now have new errors when trying to use the built library…

Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, bool, bool)
Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&, std::__1::function<unsigned long (void const*, unsigned long)> const&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, bool, bool)
Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, bool, bool)

Anybody have any thoughts on this?