Spaces:
Running
Running
ggml: check if non-native endian model is being loaded (llama/13943)
Browse files* gguf: prevent non-native endian models from being loaded
Signed-off-by: Aaron Teo <[email protected]>
* gguf: update error message
Signed-off-by: Aaron Teo <[email protected]>
* gguf: make the non-native endian check more verbose
Signed-off-by: Aaron Teo <[email protected]>
* ggml: move ggml_assert location
Signed-off-by: Aaron Teo <[email protected]>
* ggml: reword the endianness check error message
Signed-off-by: Aaron Teo <[email protected]>
---------
Signed-off-by: Aaron Teo <[email protected]>
- ggml/src/gguf.cpp +14 -0
ggml/src/gguf.cpp
CHANGED
|
@@ -347,6 +347,20 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
|
|
| 347 |
int64_t n_tensors = 0;
|
| 348 |
|
| 349 |
if (ok && gr.read(ctx->version)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
if (ctx->version == 1) {
|
| 351 |
GGML_LOG_ERROR("%s: GGUFv1 is no longer supported, please use a more up-to-date version\n", __func__);
|
| 352 |
ok = false;
|
|
|
|
| 347 |
int64_t n_tensors = 0;
|
| 348 |
|
| 349 |
if (ok && gr.read(ctx->version)) {
|
| 350 |
+
/*
|
| 351 |
+
* bit layout is different when reading non-native endian models.
|
| 352 |
+
* assuming that the GGUF version is 3, the non-native endian model
|
| 353 |
+
* would read it as 0x30000000. we can use the AND operation against
|
| 354 |
+
* the last 4 hexadecimal digits to check if the model is the same
|
| 355 |
+
* endianness as the host system.
|
| 356 |
+
*/
|
| 357 |
+
if ((ctx->version & 0x0000FFFF) == 0x00000000) {
|
| 358 |
+
GGML_LOG_ERROR("%s: failed to load model: this GGUF file version %" PRIu32 " is extremely large, is there a mismatch between the host and model endianness?\n", __func__, ctx->version);
|
| 359 |
+
gguf_free(ctx);
|
| 360 |
+
return nullptr;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
GGML_ASSERT(ctx->version > 0 && ctx->version <= 65535);
|
| 364 |
if (ctx->version == 1) {
|
| 365 |
GGML_LOG_ERROR("%s: GGUFv1 is no longer supported, please use a more up-to-date version\n", __func__);
|
| 366 |
ok = false;
|