fix: use int8_t for GGUF bool array loading instead of platform-dependent bool (#1648)

Upstream: llama.cpp#21428. GGUF stores bools as 1-byte int8_t but the
loader was casting through (const bool*) which has implementation-defined
sizeof. Use explicit int8_t cast with != 0 normalization.

Co-authored-by: Mark Alonzo <mark.alonzo@outlook.com>
This commit is contained in:
markaalonzo 2026-04-17 01:25:07 -04:00 committed by GitHub
parent eaf83865a1
commit a42f898d35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -724,8 +724,8 @@ bool llama_model_loader::get_arr(const std::string & key, std::vector<T> & resul
result.resize(arr_info.length);
if (arr_info.gt == GGUF_TYPE_BOOL) {
std::transform((const bool *)arr_info.data, (const bool *)arr_info.data + arr_info.length, result.begin(),
[] (bool x) { return static_cast<T>(x); });
std::transform((const int8_t *)arr_info.data, (const int8_t *)arr_info.data + arr_info.length, result.begin(),
[] (int8_t x) { return static_cast<T>(x != 0); });
} else {
result.assign((const T*)arr_info.data, (const T *)arr_info.data + arr_info.length);
@ -762,8 +762,8 @@ bool llama_model_loader::get_arr(const std::string & key, std::array<T, N_MAX> &
}
if (arr_info.gt == GGUF_TYPE_BOOL) {
std::transform((const bool *)arr_info.data, (const bool *)arr_info.data + arr_info.length, result.begin(),
[] (bool x) { return static_cast<T>(x); });
std::transform((const int8_t *)arr_info.data, (const int8_t *)arr_info.data + arr_info.length, result.begin(),
[] (int8_t x) { return static_cast<T>(x != 0); });
} else {
std::copy((const T*)arr_info.data, (const T *)arr_info.data + arr_info.length, result.begin());
}