Building Torchlib with nn namespace for iOS

username: JP-Lisn
cooked: <p>I’m trying to utilize <code>torch::nn::functional::pad</code> however it appears that nn namespace is in not included in the build for ios (as i’ve read <a href="https://discuss.pytorch.org/t/torch-nn-in-ios-c-is-unavailable/69420">here</a>). I’ve tried to include nn into the build by setting the <code>NO_API</code> property in the root CMakeLists.txt to <code>OFF</code> as suggested. However, when building with this changed property the build fails…</p>
<pre><code class="lang-auto">torch/csrc/api/src/nn/module.cpp:5:10: fatal error: 'torch/csrc/autograd/generated/VariableType.h' file not found
#include &lt;torch/csrc/autograd/generated/VariableType.h&gt;
</code></pre>
<p>Found a post where someone ran into this issue and apparently found a solution <a href="https://discuss.pytorch.org/t/where-does-the-torch-csrc-autograd-generated-variabletype-h-file-move-to/40136">here</a>… however their explanation is unclear about what was done to resolve it.</p>
<p>How does one ensure that <code>VariableType.h</code> is generated?</p>

username: JP-Lisn
cooked: <p>Ok, so looking into this a bit further… VariableType.h is generated by <code>tools/autograd/gen_variable_type.py</code>. Which is utilized the caffe2 CMakeList.txt.</p>
<p>Reading through the <code>caffe2/CMakeList.txt</code>, it appears that for <code>VariableType.h</code> to be generated the <code>Build_Mobile_Autograd</code> must be set <code>ON</code>. (An in development option)</p>
<p>With the <code>NO_API</code> set <code>OFF</code> and <code>BUILD_MOBILE_AUTOGRAD</code> set <code>ON</code> <code>VariableTypes.h</code> is generated and the build succeeds… however the <code>nn</code> namespace is still not included… and now have new errors when trying to use the built library…</p>
<pre><code class="lang-auto">Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::unordered_map&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::hash&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::equal_to&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::allocator&lt;std::__1::pair&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt; &gt; const&amp;, bool, bool)
Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&amp;, std::__1::function&lt;unsigned long (void const*, unsigned long)&gt; const&amp;, std::__1::unordered_map&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::hash&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::equal_to&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::allocator&lt;std::__1::pair&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt; &gt; const&amp;, bool, bool)
Undefined symbol: torch::jit::ExportModule(torch::jit::Module const&amp;, std::__1::basic_ostream&lt;char, std::__1::char_traits&lt;char&gt; &gt;&amp;, std::__1::unordered_map&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::hash&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::equal_to&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;, std::__1::allocator&lt;std::__1::pair&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt; &gt; const&amp;, bool, bool)
</code></pre>
<p>Anybody have any thoughts on this?</p>