From 2fa24b6c79cae4f14bce56fe8e7bbba7928957e2 Mon Sep 17 00:00:00 2001 From: akleine Date: Mon, 15 Dec 2025 16:20:00 +0100 Subject: [PATCH 1/2] fix: added a clean exit in ModelLoader::load_tensors if OOM at convert_tensor() call --- model.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/model.cpp b/model.cpp index 0480efefb..c42ee2760 100644 --- a/model.cpp +++ b/model.cpp @@ -1520,6 +1520,11 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, int n_thread i64_to_i32_vec((int64_t*)read_buf, (int32_t*)target_buf, tensor_storage.nelements()); } if (tensor_storage.type != dst_tensor->type) { + if (convert_buf==nullptr) { + LOG_ERROR("read tensor data failed: too less memory for conversion"); + failed = true; + return; + } convert_tensor((void*)target_buf, tensor_storage.type, convert_buf, From b4c4f3dc5713f74819718c5c81680679be3ba2bf Mon Sep 17 00:00:00 2001 From: leejet Date: Tue, 16 Dec 2025 00:12:10 +0800 Subject: [PATCH 2/2] format code --- examples/common/common.hpp | 2 +- model.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/common/common.hpp b/examples/common/common.hpp index bf38379d2..b9ac7edc1 100644 --- a/examples/common/common.hpp +++ b/examples/common/common.hpp @@ -863,7 +863,7 @@ static bool is_absolute_path(const std::string& p) { struct SDGenerationParams { std::string prompt; - std::string prompt_with_lora; // for metadata record only + std::string prompt_with_lora; // for metadata record only std::string negative_prompt; int clip_skip = -1; // <= 0 represents unspecified int width = 512; diff --git a/model.cpp b/model.cpp index c42ee2760..01a8c45de 100644 --- a/model.cpp +++ b/model.cpp @@ -1520,7 +1520,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, int n_thread i64_to_i32_vec((int64_t*)read_buf, (int32_t*)target_buf, tensor_storage.nelements()); } if (tensor_storage.type != dst_tensor->type) { - if (convert_buf==nullptr) { + if (convert_buf == nullptr) { LOG_ERROR("read tensor data failed: too less memory for conversion"); failed = true; return;