LIBTORCH/C++ and Unreal Engine 4 Runtime error: Variable is optimized away and not avaible

Hi, sadly Libtorch and ue4 have several integration problems. Strictly, I have not been able to resolve the integration, but I can share my progress with you if it is helpful.

  1. I first tried to directly integrate Libtorch and ue4. I get the memory error in the forward function, however if I ignore the exception I can continue normally, this may be useful if you want to do a demo or proof of concept. For example, my demo is this: Question Answering: BERT(Bidirectional Encoder Representation with Transformers) with LibTorch & UE4 - YouTube. The link where I describe the steps is here: How to properly integrate Libtorch (Pytorch) and Unreal Engine 4? - AI (Artificial Intelliegence) - Unreal Engine Forums

  2. Later, I tried to do it through DLLs, but it didn’t work. However, with DLLs it is possible to catch the exception and learn a little more about the problem. The link where I describe the problem is here: Integrate Libtorch into Unreal Engine 4: _ivalue_INTERNAL ASSERT FAILED · Issue #69425 · pytorch/pytorch · GitHub

  3. The next step I will try is to try a more elaborate solution which is to integrate libtorch as a plugin. For example: GitHub - NeuralVFX/basic-unreal-libtorch-plugin: A "Hello World" for running LibTorch inside Unreal Engine or UE4 Plugin to execute trained PyTorch modules | BestOfCpp.

In case of success, I will gladly share it here :).

1 Like