Tim-Salzmann / l4casadi

Use PyTorch Models with CasADi for data-driven optimization or learning-based optimal control. Supports Acados.
MIT License
350 stars 23 forks source link

Symbol Lookup Error with torch-2.1.0+cpu.cxx11.abi #15

Closed merdan-9 closed 11 months ago

merdan-9 commented 11 months ago

Hi Tim,

I encountered a symbol lookup error when attempting to run an example after successfully building with torch with cxxabi.

Details:

Error Message: symbol lookup error: _l4c_generated/libl4casadi_f.so: undefined symbol: _ZN8L4CasADiC1ESsSsbSsbb

Torch Version: torch-2.1.0+cpu.cxx11.abi-cp39-cp39-linux_x86_64.whl

I'd appreciate any guidance or assistance in resolving this. Thank you!

Tim-Salzmann commented 11 months ago

Hi,

Could you elaborate on why cxxabi is preferable for you? This would help me decide if I should support this by default.

My guess is that the following line is leading to the problem:

https://github.com/Tim-Salzmann/l4casadi/blob/7b773a141ef108b322cacb7aeb67c8e3991f5220/l4casadi/l4casadi.py#L146

Could you try setting -D_GLIBCXX_USE_CXX11_ABI=1?

Best Tim

merdan-9 commented 11 months ago

Hi Tim,

Firstly, I'd like to integrate this as a control algorithm into my larger project, which consists of various other control algorithms. My main project is linked to cxx11 abi, so it won't run as expected with the standard installation method.

I tried the -D_GLIBCXX_USE_CXX11_ABI=1 as you suggested. It works fine on the x86 architecture. However, in the later stages, I need to perform embedded control on the ARM architecture. The challenge is that there isn't a torch version for the ARM architecture with cxx11 abi, so it doesn't seem like a complete solution.

Given that the generated C code doesn't have torch doing much, would it be possible to directly export the network weights into a C file and decouple the torch-related portions?

Best regards, Merdan

Tim-Salzmann commented 11 months ago

Hi Merdan,

Firstly, I'd like to integrate this as a control algorithm into my larger project, which consists of various other control algorithms. My main project is linked to cxx11 abi, so it won't run as expected with the standard installation method.

I see the problem!

I tried the -D_GLIBCXX_USE_CXX11_ABI=1 as you suggested. It works fine on the x86 architecture. However, in the later stages, I need to perform embedded control on the ARM architecture. The challenge is that there isn't a torch version for the ARM architecture with cxx11 abi, so it doesn't seem like a complete solution.

I imagine you could build torchlib from source with cxx11 abi.

Given that the generated C code doesn't have torch doing much, would it be possible to directly export the network weights into a C file and decouple the torch-related portions?

This is certainly possible. But this would not scale to anything more complicated than simple MultiLayerPerceptrons. For simple MLPs you could also check out the old naive implementation within ml-casadi [1]. Please keep in mind that this can become slow for larger MLPs.

Hope this helps Tim

[1] https://github.com/TUM-AAS/ml-casadi#naive

Tim-Salzmann commented 11 months ago

Quick update on this: With the latest commit L4CasADi will automatically detect if torch was compiled with CXX11 ABI or not.

merdan-9 commented 11 months ago

Hi Tim,

Your suggestions were incredibly helpful, and I appreciate the depth of detail you provided!

Have a good day. Merdan