Skip to content

Commit 3a9bec9

Browse files
committed
fix segfault on multipart gguf load
2 parents f57ea5f + 5fa2334 commit 3a9bec9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/llama-model-loader.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,16 @@ void llama_model_loader::get_mapping_range(size_t * first, size_t * last, void *
918918

919919
#ifdef GGML_NUMA_MIRROR
920920
// Check if this is a unified mapping (mapping[0] exists but others are null)
921-
bool is_unified_mapping = mappings.size() > 1 && mappings[0] && !mappings[1];
921+
bool is_unified_mapping = mappings.size() > 1 && mappings[0];
922+
// Verify it's truly unified by checking that all other mappings are null
923+
if (is_unified_mapping) {
924+
for (size_t i = 1; i < mappings.size(); ++i) {
925+
if (mappings[i]) {
926+
is_unified_mapping = false;
927+
break;
928+
}
929+
}
930+
}
922931

923932
if (is_unified_mapping) {
924933
// For unified mapping, use the first (and only real) mapping
@@ -978,7 +987,16 @@ void llama_model_loader::load_data_for(struct ggml_tensor * cur) const {
978987
if (use_mmap) {
979988
#ifdef GGML_NUMA_MIRROR
980989
// Check if this is a unified mapping (mapping[0] exists but others are null)
981-
bool is_unified_mapping = mappings.size() > 1 && mappings[0] && !mappings[1];
990+
bool is_unified_mapping = mappings.size() > 1 && mappings[0];
991+
// Verify it's truly unified by checking that all other mappings are null
992+
if (is_unified_mapping) {
993+
for (size_t i = 1; i < mappings.size(); ++i) {
994+
if (mappings[i]) {
995+
is_unified_mapping = false;
996+
break;
997+
}
998+
}
999+
}
9821000

9831001
if (is_unified_mapping) {
9841002
// For unified mapping, calculate offset within the unified mapping

0 commit comments

Comments
 (0)