How to use AOTInductor output models in non-Python environments

username: prm-james-hill
cooked: <p>I’m trying to follow <a href="https://pytorch.org/docs/stable/torch.compiler_aot_inductor.html" class="inline-onebox" rel="noopener nofollow ugc">AOTInductor: Ahead-Of-Time Compilation for Torch.Export-ed Models — PyTorch 2.5 documentation</a> to export a model from Python and then deploy it in an environment that just uses C++.</p>
<p>If I follow the example, the model.so which is output from Python has dynamic linkage to the libtorch.so, etc., which come as part of <code>pip install torch</code>. I can repro the example if I let the C++ executable link to those same pip artifacts, but I would count this as needing Python in the end environment. I’ve tried linking to the shared libs from the equivalent version of LibTorch but have been unsuccessful.</p>
<p>What is the intended way of working around this dynamic linkage in a non-Python environment?</p>

username: bdhirsh
cooked: <p>cc <a class="mention" href="/u/desertfire">@desertfire</a> for AOTInductor</p>
<p>It’s worth calling out though that <code>libtorch.so</code> is python free: as long as you have it installed, you can use it in a C++ only runtime (and dynamically link to it) without needing python in the environment.</p>

username: prm-james-hill
cooked: <p>Is that the intended way of doing this then? (e.g. just pip install and then rip out the torch/ package dir for use elsewhere?) I noticed that the <code>libtorch.so</code> instances in the precompiled LibTorch 2.5.1+CPU and PyTorch 2.5.1+CPU (for example) are not equivalent, so I didn’t know if this could cause weird issues later</p>
<p>(Edit, tangential but for posterity: the pip installation comes with libs that use the pre-cxx11 ABI. Seems like building from source is the only way around this for now. More context in <a href="https://github.com/pytorch/pytorch/issues/51039" class="inline-onebox" rel="noopener nofollow ugc">Status of pip wheels with _GLIBCXX_USE_CXX11_ABI=1 · Issue #51039 · pytorch/pytorch · GitHub</a>)</p>

username: Xavier31
cooked: <p>I am also very confused by this, especially since the tutorial explicitly states to link against the libtorch library, which I assumed was C++ libtorch.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/2/a2952e4d899f68a9a2cd821ba982e956ba1c30ba.png" data-download-href="https://discuss.pytorch.org/uploads/default/a2952e4d899f68a9a2cd821ba982e956ba1c30ba" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/2/a2952e4d899f68a9a2cd821ba982e956ba1c30ba_2_690x92.png" alt="image" data-base62-sha1="ncgY3TcGRG1VRuHPRopVTv0vs7M" width="690" height="92" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/2/a2952e4d899f68a9a2cd821ba982e956ba1c30ba_2_690x92.png, https://discuss.pytorch.org/uploads/default/original/3X/a/2/a2952e4d899f68a9a2cd821ba982e956ba1c30ba.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/2/a2952e4d899f68a9a2cd821ba982e956ba1c30ba.png 2x" data-dominant-color="EFEFF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">901×121 22.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Does that mean we can use the full range of the C++ API without any need of Libtorch C++ ?</p>