Skip to content

Commit a23262d

Browse files
authored
fix: added a clean exit in ModelLoader::load_tensors if OOM (#1097)
1 parent e687913 commit a23262d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

examples/common/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static bool is_absolute_path(const std::string& p) {
862862

863863
struct SDGenerationParams {
864864
std::string prompt;
865-
std::string prompt_with_lora; // for metadata record only
865+
std::string prompt_with_lora; // for metadata record only
866866
std::string negative_prompt;
867867
int clip_skip = -1; // <= 0 represents unspecified
868868
int width = 512;

model.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,11 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, int n_thread
15201520
i64_to_i32_vec((int64_t*)read_buf, (int32_t*)target_buf, tensor_storage.nelements());
15211521
}
15221522
if (tensor_storage.type != dst_tensor->type) {
1523+
if (convert_buf == nullptr) {
1524+
LOG_ERROR("read tensor data failed: too less memory for conversion");
1525+
failed = true;
1526+
return;
1527+
}
15231528
convert_tensor((void*)target_buf,
15241529
tensor_storage.type,
15251530
convert_buf,

0 commit comments

Comments
 (0)