Loading traced pytorch model to C++

Will be grateful for any help :frowning:

I’m having a problem with using pytorch 2.2.1+cpu pretrained model in C++ via TorchLib 2.2.2 (cpu version). I’m also using Visual Studio 2022. I’ve added Torchlib to Cmake and it successfully downloads the model and works until line:

`at::Tensor output = module.forward(inputs).toTensor();`

After this line it crushes with the error: INTEL MKL ERROR: The specified module could not be found. mkl_avx2.1.dll. Intel MKL FATAL ERROR: Cannot load mkl_avx2.1.dll or mkl_def.1.dll. and I didn't figured out what is wrong with TorchLib here.

The whole code is here:

`#include <torch/script.h>
...
    string path = "traced_energynn_model.pt";
    torch::jit::script::Module module;
    try {
        // Deserialize the ScriptModule from a file using torch::jit::load().
        module = torch::jit::load(path);
    }
    catch (const c10::Error& e) {
        std::cerr << "error loading the model\n";
        return -1;
    }
    std::cout << "Model traced_energynn_model loaded fine\n";

    // Create a vector of inputs.
    std::vector<torch::jit::IValue> inputs;
    inputs.push_back(torch::randn({ 1, 2 }));

    // Execute the model and turn its output into a tensor.
    at::Tensor output = module.forward(inputs).toTensor();
    std::cout << output << "\n";`

Seems like the problem is with some part of the lib related to python, but it’s strange because the model loads to C++ by LibTorch successfully.

Could you create a GitHub issue so the code owners could take a look at it, please?

Sure, here it is Loading traced pytorch model to C++ · Issue #124009 · pytorch/pytorch · GitHub, thank you!