Skip to content

Commit 58190cc

Browse files
authored
llama : correct platform-independent loading of BOOL metadata (ggml-org#21428)
* model-loader : fix GGUF bool array conversion * model-loader : fix remaining GGUF bool pointer uses
1 parent af76639 commit 58190cc

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/llama-impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static std::string gguf_data_to_str(enum gguf_type type, const void * data, int
128128
case GGUF_TYPE_INT64: return std::to_string(((const int64_t *)data)[i]);
129129
case GGUF_TYPE_FLOAT32: return std::to_string(((const float *)data)[i]);
130130
case GGUF_TYPE_FLOAT64: return std::to_string(((const double *)data)[i]);
131-
case GGUF_TYPE_BOOL: return ((const bool *)data)[i] ? "true" : "false";
131+
case GGUF_TYPE_BOOL: return ((const int8_t *)data)[i] != 0 ? "true" : "false";
132132
default: return format("unknown type %d", type);
133133
}
134134
}

src/llama-model-loader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ namespace GGUFMeta {
374374
}
375375
} else {
376376
if (arr_info.gt == GGUF_TYPE_BOOL) {
377-
std::transform((const bool *)arr_info.data, (const bool *)arr_info.data + arr_info.length, result.begin(), [](bool x) {
378-
return static_cast<T>(x);
377+
const int8_t * values = (const int8_t *) arr_info.data;
378+
std::transform(values, values + arr_info.length, result.begin(), [](int8_t x) {
379+
return static_cast<T>(x != 0);
379380
});
380381
} else {
381382
std::copy((const T*)arr_info.data, (const T *)arr_info.data + arr_info.length, result.begin());

tools/mtmd/clip-impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ static std::string gguf_data_to_str(enum gguf_type type, const void * data, int
522522
case GGUF_TYPE_INT64: return std::to_string(((const int64_t *)data)[i]);
523523
case GGUF_TYPE_FLOAT32: return std::to_string(((const float *)data)[i]);
524524
case GGUF_TYPE_FLOAT64: return std::to_string(((const double *)data)[i]);
525-
case GGUF_TYPE_BOOL: return ((const bool *)data)[i] ? "true" : "false";
525+
case GGUF_TYPE_BOOL: return ((const int8_t *)data)[i] != 0 ? "true" : "false";
526526
default: return string_format("unknown type %d", type);
527527
}
528528
}

0 commit comments

Comments
 (0)