Can a PyTorch Model Built in Debug Mode Be Used in Release Mode? TorchScript Model Load Error in Release Mode but Works in Debug Mode

I’m encountering an issue when trying to load a TorchScript model in my C++ application using LibTorch. The model loads and works fine in debug mode, but I get an exception when switching to release mode.Here is a minimal reproducible example of the code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <torch/script.h> // Include necessary headers
#include <iostream>
int main() {
try {
std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct
torch::jit::script::Module model;
model = torch::jit::load(model_path); // This is where the error occurs
std::cout << "Model loaded successfully!" << std::endl;
} catch (const c10::Error& e) {
std::cerr << "Error loading the model: " << e.what() << std::endl;
return -1;
}
return 0;
}
</code>
<code>#include <torch/script.h> // Include necessary headers #include <iostream> int main() { try { std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct torch::jit::script::Module model; model = torch::jit::load(model_path); // This is where the error occurs std::cout << "Model loaded successfully!" << std::endl; } catch (const c10::Error& e) { std::cerr << "Error loading the model: " << e.what() << std::endl; return -1; } return 0; } </code>
#include <torch/script.h> // Include necessary headers
#include <iostream>

int main() {
    try {
        std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct
        torch::jit::script::Module model;
        model = torch::jit::load(model_path); // This is where the error occurs
        std::cout << "Model loaded successfully!" << std::endl;
    } catch (const c10::Error& e) {
        std::cerr << "Error loading the model: " << e.what() << std::endl;
        return -1;
    }
    return 0;
}

this code is supposed to load a PyTorch model using torch::jit::load(model_path);. However, I encounter the following error: Unhandled exception at 0x00007FFA25F5B699 in myApp.exe: Microsoft C++ exception: c10::Error at memory location 0x000000D4C29DE3F0. I am using libtorch (Stable 2.5.1,Windows,C++/java, CPU), Visual Studio, on Windows 10 Pro

Sanitized stack trace

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>KernelBase.dll!00007ffcc7e7b699() Unknown
00007ffcc7e7b699()
00007ffc3a79bbf1()
c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &)
caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &)
caffe2::serialize::FileAdapter::FileAdapter(const std::string &)
std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &)
caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &)
std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool)
torch::jit::load(const std::string &, std::optional<c10::Device>, bool)
processImage(int, const std::string &, const std::string &, const std::string &)
main()
</code>
<code>KernelBase.dll!00007ffcc7e7b699() Unknown 00007ffcc7e7b699() 00007ffc3a79bbf1() c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &) caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &) caffe2::serialize::FileAdapter::FileAdapter(const std::string &) std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &) caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &) std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &) torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool) torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool) torch::jit::load(const std::string &, std::optional<c10::Device>, bool) processImage(int, const std::string &, const std::string &, const std::string &) main() </code>
KernelBase.dll!00007ffcc7e7b699()   Unknown
00007ffcc7e7b699()
00007ffc3a79bbf1()
c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &)
caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &)
caffe2::serialize::FileAdapter::FileAdapter(const std::string &)
std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &)
caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &)
std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool)
torch::jit::load(const std::string &, std::optional<c10::Device>, bool)
processImage(int, const std::string &, const std::string &, const std::string &)
main()

The model was provided to me by another company, and I suspect it was built in debug mode. Since I cannot modify or rebuild the model, I need to determine if this discrepancy (debug vs. release) is causing the issue. My task is to inspect the compatibility of this model with our company’s application in both debug and release modes. I need to make sure before asking them for the release mode.

I have checked that the model file path is correct and accessible also there are no linker errors and ensured all necessary libraries are correctly linked in both debug and release configurations.
Also verified the file path and access permissions

New contributor

Nimasha Konara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

I have noticed this document says

On Windows, debug and release builds are not ABI-compatible. If you plan to build your project in debug mode, please try the debug version of LibTorch. Also, make sure you specify the correct configuration in the cmake –build . line above.

Based on my understanding, i think if you plan to build your project in debug mode, you should use the debug version of LibTorch. For release mode, you should use the release version of LibTorch.

Try to download Release version:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Download here (Release version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip
Download here (Debug version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip
</code>
<code>Download here (Release version): https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip Download here (Debug version): https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip </code>
Download here (Release version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip
Download here (Debug version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Can a PyTorch Model Built in Debug Mode Be Used in Release Mode? TorchScript Model Load Error in Release Mode but Works in Debug Mode

I’m encountering an issue when trying to load a TorchScript model in my C++ application using LibTorch. The model loads and works fine in debug mode, but I get an exception when switching to release mode.Here is a minimal reproducible example of the code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <torch/script.h> // Include necessary headers
#include <iostream>
int main() {
try {
std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct
torch::jit::script::Module model;
model = torch::jit::load(model_path); // This is where the error occurs
std::cout << "Model loaded successfully!" << std::endl;
} catch (const c10::Error& e) {
std::cerr << "Error loading the model: " << e.what() << std::endl;
return -1;
}
return 0;
}
</code>
<code>#include <torch/script.h> // Include necessary headers #include <iostream> int main() { try { std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct torch::jit::script::Module model; model = torch::jit::load(model_path); // This is where the error occurs std::cout << "Model loaded successfully!" << std::endl; } catch (const c10::Error& e) { std::cerr << "Error loading the model: " << e.what() << std::endl; return -1; } return 0; } </code>
#include <torch/script.h> // Include necessary headers
#include <iostream>

int main() {
    try {
        std::string model_path = "path/to/your/model.pt"; // make sure that this path is correct
        torch::jit::script::Module model;
        model = torch::jit::load(model_path); // This is where the error occurs
        std::cout << "Model loaded successfully!" << std::endl;
    } catch (const c10::Error& e) {
        std::cerr << "Error loading the model: " << e.what() << std::endl;
        return -1;
    }
    return 0;
}

this code is supposed to load a PyTorch model using torch::jit::load(model_path);. However, I encounter the following error: Unhandled exception at 0x00007FFA25F5B699 in myApp.exe: Microsoft C++ exception: c10::Error at memory location 0x000000D4C29DE3F0. I am using libtorch (Stable 2.5.1,Windows,C++/java, CPU), Visual Studio, on Windows 10 Pro

Sanitized stack trace

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>KernelBase.dll!00007ffcc7e7b699() Unknown
00007ffcc7e7b699()
00007ffc3a79bbf1()
c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &)
caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &)
caffe2::serialize::FileAdapter::FileAdapter(const std::string &)
std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &)
caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &)
std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool)
torch::jit::load(const std::string &, std::optional<c10::Device>, bool)
processImage(int, const std::string &, const std::string &, const std::string &)
main()
</code>
<code>KernelBase.dll!00007ffcc7e7b699() Unknown 00007ffcc7e7b699() 00007ffc3a79bbf1() c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &) caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &) caffe2::serialize::FileAdapter::FileAdapter(const std::string &) std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &) caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &) std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &) torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool) torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool) torch::jit::load(const std::string &, std::optional<c10::Device>, bool) processImage(int, const std::string &, const std::string &, const std::string &) main() </code>
KernelBase.dll!00007ffcc7e7b699()   Unknown
00007ffcc7e7b699()
00007ffc3a79bbf1()
c10::detail::torchCheckFail(const char *, const char *, unsigned int, const std::string &)
caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(const std::string &)
caffe2::serialize::FileAdapter::FileAdapter(const std::string &)
std::make_unique<caffe2::serialize::FileAdapter,std::string const &,0>(const std::string &)
caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(const std::string &)
std::make_unique<caffe2::serialize::PyTorchStreamReader,std::string const &,0>(const std::string &)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, std::unordered_map<std::string,std::string,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,std::string>>> &, bool, bool)
torch::jit::import_ir_module(std::shared_ptr<torch::jit::CompilationUnit>, const std::string &, std::optional<c10::Device>, bool)
torch::jit::load(const std::string &, std::optional<c10::Device>, bool)
processImage(int, const std::string &, const std::string &, const std::string &)
main()

The model was provided to me by another company, and I suspect it was built in debug mode. Since I cannot modify or rebuild the model, I need to determine if this discrepancy (debug vs. release) is causing the issue. My task is to inspect the compatibility of this model with our company’s application in both debug and release modes. I need to make sure before asking them for the release mode.

I have checked that the model file path is correct and accessible also there are no linker errors and ensured all necessary libraries are correctly linked in both debug and release configurations.
Also verified the file path and access permissions

New contributor

Nimasha Konara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

I have noticed this document says

On Windows, debug and release builds are not ABI-compatible. If you plan to build your project in debug mode, please try the debug version of LibTorch. Also, make sure you specify the correct configuration in the cmake –build . line above.

Based on my understanding, i think if you plan to build your project in debug mode, you should use the debug version of LibTorch. For release mode, you should use the release version of LibTorch.

Try to download Release version:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Download here (Release version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip
Download here (Debug version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip
</code>
<code>Download here (Release version): https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip Download here (Debug version): https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip </code>
Download here (Release version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-latest.zip
Download here (Debug version):
https://download.pytorch.org/libtorch/nightly/cu118/libtorch-win-shared-with-deps-debug-latest.zip

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật