I’m using MSVS 2022, UE 5.3.2, and libtorch - debug-2.2.2+cu121.
I created a simple UE FPS project, added a code into a GameMode class, that loads libtorch.
Added a code like:
torch::jit::script::Module module_pt;
module_pt = torch::jit::load(“C:/src/model_weights.pt”);
This code compiled, linked, and I started the UEditor from MSVS. The UEditor has crashed on torch::jit::load with a runtime exception, going deep into the C runtime
ucrtbased.dll!00007ffb27daa053() | Unknown | No symbols loaded. | |
---|---|---|---|
ucrtbased.dll!00007ffb27daa627() | Unknown | No symbols loaded. | |
msvcp140d.dll!00007ffb27f46c12() | Unknown | No symbols loaded. | |
msvcp140d.dll!00007ffb27f469e4() | Unknown | No symbols loaded. | |
msvcp140d.dll!00007ffb27f46b75() | Unknown | No symbols loaded. | |
torch_cpu.dll!std::basic_filebuf<char,std::char_traits>::open(const char * _Filename, int _Mode, int _Prot) Line 277 | C++ | Symbols loaded. | |
torch_cpu.dll!std::basic_ifstream<char,std::char_traits>::basic_ifstream<char,std::char_traits>(const char * _Filename, int _Mode, int _Prot) Line 808 | C++ | Symbols loaded. | |
torch_cpu.dll!std::basic_ifstream<char,std::char_traits>::basic_ifstream<char,std::char_traits>(const std::string & _Str, int _Mode, int _Prot) Line 815 | C++ | Symbols loaded. | |
torch_cpu.dll!torch::jit::getFileFormat(const std::string & filename) Line 113 | C++ | Symbols loaded. | |
torch_cpu.dll!torch::jit::import_ir_module(std::shared_ptrtorch::jit::CompilationUnit cu, const std::string & filename, std::optionalc10::Device device, std::unordered_map<std::string,std::string,std::hashstd::string,std::equal_tostd::string,std::allocator<std::pair<std::string const ,std::string>>> & extra_files, bool load_debug_files, bool restore_shapes) Line 429 | C++ | Symbols loaded. | |
torch_cpu.dll!torch::jit::import_ir_module(std::shared_ptrtorch::jit::CompilationUnit cu, const std::string & filename, std::optionalc10::Device device, bool load_debug_files) Line 416 | C++ | Symbols loaded. | |
> | torch_cpu.dll!torch::jit::load(const std::string & filename, std::optionalc10::Device device, bool load_debug_files) Line 498 | C++ | Symbols loaded. |
UnrealEditor-RASample.dll!ARASampleGameMode::InitPytorch() Line 84 | C++ | Symbols loaded. | |
UnrealEditor-RASample.dll!ARASampleGameMode::ARASampleGameMode() Line 48 | C++ | Symbols loaded. |
After debugging I figured out that the torch::jit::load is not receiving the string value, that I’ve passed, but receives NULL.
My C string value is converted to std::string on my side, but inside torch::jit::load it crosses dll boundary, and gets converted to NULL, probably because of different versions of std::string being used on my machine and machine used to build the libtorch distribution.
What could be done in this case?
Build libtorch locally from sources?