cui-llama.rn 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/CMakeLists.txt +6 -0
- package/android/src/main/java/com/rnllama/LlamaContext.java +38 -5
- package/android/src/main/java/com/rnllama/RNLlama.java +139 -4
- package/android/src/main/jni.cpp +153 -14
- package/android/src/main/jniLibs/arm64-v8a/librnllama.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnllama_v8.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_dotprod.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnllama_v8_2_i8mm.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnllama.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnllama_x86_64.so +0 -0
- package/android/src/newarch/java/com/rnllama/RNLlamaModule.java +24 -4
- package/android/src/oldarch/java/com/rnllama/RNLlamaModule.java +22 -2
- package/cpp/chat.cpp +128 -106
- package/cpp/chat.h +2 -0
- package/cpp/common.cpp +41 -76
- package/cpp/common.h +23 -19
- package/cpp/ggml-backend.cpp +9 -5
- package/cpp/ggml-backend.h +4 -4
- package/cpp/ggml-cpu/ggml-cpu-aarch64.cpp +0 -2
- package/cpp/ggml-cpu/ggml-cpu-quants.c +306 -6
- package/cpp/ggml-cpu/ggml-cpu.c +5 -13
- package/cpp/ggml-cpu/ggml-cpu.cpp +29 -16
- package/cpp/ggml-cpu/ops.cpp +107 -13
- package/cpp/ggml-cpu/vec.cpp +0 -6
- package/cpp/ggml-cpu/vec.h +16 -0
- package/cpp/ggml-llama-sim.metallib +0 -0
- package/cpp/ggml-llama.metallib +0 -0
- package/cpp/ggml-metal-impl.h +36 -11
- package/cpp/ggml-metal.m +321 -132
- package/cpp/ggml-opt.cpp +373 -190
- package/cpp/ggml-opt.h +49 -28
- package/cpp/ggml-quants.c +0 -6
- package/cpp/ggml.c +93 -38
- package/cpp/ggml.h +21 -7
- package/cpp/gguf.cpp +33 -33
- package/cpp/llama-adapter.cpp +6 -0
- package/cpp/llama-arch.cpp +3 -0
- package/cpp/llama-batch.cpp +3 -1
- package/cpp/llama-chat.cpp +8 -6
- package/cpp/llama-chat.h +1 -0
- package/cpp/llama-context.cpp +349 -135
- package/cpp/llama-context.h +30 -3
- package/cpp/llama-cparams.h +1 -0
- package/cpp/llama-graph.cpp +150 -234
- package/cpp/llama-graph.h +52 -7
- package/cpp/llama-hparams.cpp +17 -1
- package/cpp/llama-hparams.h +34 -5
- package/cpp/llama-kv-cache.cpp +662 -321
- package/cpp/llama-kv-cache.h +203 -93
- package/cpp/llama-memory.h +3 -2
- package/cpp/llama-model-loader.cpp +24 -15
- package/cpp/llama-model-saver.cpp +281 -0
- package/cpp/llama-model-saver.h +37 -0
- package/cpp/llama-model.cpp +536 -132
- package/cpp/llama-model.h +7 -1
- package/cpp/llama-sampling.cpp +18 -6
- package/cpp/llama-vocab.cpp +46 -8
- package/cpp/llama-vocab.h +6 -0
- package/cpp/llama.cpp +14 -0
- package/cpp/llama.h +72 -131
- package/cpp/minja/chat-template.hpp +9 -5
- package/cpp/minja/minja.hpp +69 -36
- package/cpp/rn-llama.cpp +611 -47
- package/cpp/rn-llama.h +33 -3
- package/cpp/sampling.cpp +57 -50
- package/cpp/tools/mtmd/clip-impl.h +462 -0
- package/cpp/tools/mtmd/clip.cpp +4024 -0
- package/cpp/tools/mtmd/clip.h +101 -0
- package/cpp/tools/mtmd/miniaudio.h +93468 -0
- package/cpp/tools/mtmd/mtmd-audio.cpp +855 -0
- package/cpp/tools/mtmd/mtmd-audio.h +62 -0
- package/cpp/tools/mtmd/mtmd-helper.cpp +297 -0
- package/cpp/tools/mtmd/mtmd.cpp +942 -0
- package/cpp/tools/mtmd/mtmd.h +362 -0
- package/cpp/tools/mtmd/stb_image.h +7988 -0
- package/ios/CMakeLists.txt +7 -0
- package/ios/RNLlama.mm +77 -3
- package/ios/RNLlamaContext.h +5 -1
- package/ios/RNLlamaContext.mm +105 -10
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/chat.h +2 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/common.h +23 -19
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/ggml-backend.h +4 -4
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/ggml-metal-impl.h +36 -11
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/ggml-opt.h +49 -28
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/ggml.h +21 -7
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-chat.h +1 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-context.h +30 -3
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-cparams.h +1 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-graph.h +52 -7
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-hparams.h +34 -5
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-kv-cache.h +203 -93
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-memory.h +3 -2
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-model-saver.h +37 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-model.h +7 -1
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama-vocab.h +6 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/llama.h +72 -131
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/minja/chat-template.hpp +9 -5
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/minja/minja.hpp +69 -36
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Headers/rn-llama.h +33 -3
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/Info.plist +0 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/ggml-llama.metallib +0 -0
- package/ios/rnllama.xcframework/ios-arm64/rnllama.framework/rnllama +0 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/chat.h +2 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/common.h +23 -19
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-backend.h +4 -4
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-metal-impl.h +36 -11
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-opt.h +49 -28
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/ggml.h +21 -7
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-chat.h +1 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-context.h +30 -3
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-cparams.h +1 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-graph.h +52 -7
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-hparams.h +34 -5
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-kv-cache.h +203 -93
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-memory.h +3 -2
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-model-saver.h +37 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-model.h +7 -1
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama-vocab.h +6 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/llama.h +72 -131
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/minja/chat-template.hpp +9 -5
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/minja/minja.hpp +69 -36
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Headers/rn-llama.h +33 -3
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/Info.plist +0 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/_CodeSignature/CodeResources +1 -1
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/ggml-llama-sim.metallib +0 -0
- package/ios/rnllama.xcframework/ios-arm64_x86_64-simulator/rnllama.framework/rnllama +0 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/chat.h +2 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/common.h +23 -19
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/ggml-backend.h +4 -4
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/ggml-metal-impl.h +36 -11
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/ggml-opt.h +49 -28
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/ggml.h +21 -7
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-chat.h +1 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-context.h +30 -3
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-cparams.h +1 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-graph.h +52 -7
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-hparams.h +34 -5
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-kv-cache.h +203 -93
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-memory.h +3 -2
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-model-saver.h +37 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-model.h +7 -1
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama-vocab.h +6 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/llama.h +72 -131
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/minja/chat-template.hpp +9 -5
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/minja/minja.hpp +69 -36
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Headers/rn-llama.h +33 -3
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/Info.plist +0 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/ggml-llama.metallib +0 -0
- package/ios/rnllama.xcframework/tvos-arm64/rnllama.framework/rnllama +0 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/chat.h +2 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/common.h +23 -19
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-backend.h +4 -4
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-metal-impl.h +36 -11
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/ggml-opt.h +49 -28
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/ggml.h +21 -7
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-chat.h +1 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-context.h +30 -3
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-cparams.h +1 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-graph.h +52 -7
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-hparams.h +34 -5
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-kv-cache.h +203 -93
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-memory.h +3 -2
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-model-saver.h +37 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-model.h +7 -1
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama-vocab.h +6 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/llama.h +72 -131
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/minja/chat-template.hpp +9 -5
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/minja/minja.hpp +69 -36
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Headers/rn-llama.h +33 -3
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/Info.plist +0 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/_CodeSignature/CodeResources +1 -1
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/ggml-llama-sim.metallib +0 -0
- package/ios/rnllama.xcframework/tvos-arm64_x86_64-simulator/rnllama.framework/rnllama +0 -0
- package/jest/mock.js +33 -7
- package/lib/commonjs/NativeRNLlama.js.map +1 -1
- package/lib/commonjs/index.js +153 -21
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRNLlama.js.map +1 -1
- package/lib/module/index.js +152 -20
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRNLlama.d.ts +50 -4
- package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +72 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeRNLlama.ts +67 -4
- package/src/index.ts +212 -38
- package/lib/commonjs/chat.js +0 -37
- package/lib/commonjs/chat.js.map +0 -1
- package/lib/module/chat.js +0 -33
- package/lib/module/chat.js.map +0 -1
- package/lib/typescript/chat.d.ts +0 -10
- package/lib/typescript/chat.d.ts.map +0 -1
- package/src/chat.ts +0 -44
package/cpp/gguf.cpp
CHANGED
@@ -299,10 +299,10 @@ bool lm_gguf_read_emplace_helper(const struct lm_gguf_reader & gr, std::vector<s
|
|
299
299
|
return false;
|
300
300
|
}
|
301
301
|
} catch (std::length_error &) {
|
302
|
-
|
302
|
+
LM_GGML_LOG_ERROR("%s: encountered length_error while reading value for key '%s'\n", __func__, key.c_str());
|
303
303
|
return false;
|
304
304
|
} catch (std::bad_alloc &) {
|
305
|
-
|
305
|
+
LM_GGML_LOG_ERROR("%s: encountered bad_alloc error while reading value for key '%s'\n", __func__, key.c_str());
|
306
306
|
return false;
|
307
307
|
}
|
308
308
|
kv.emplace_back(key, value);
|
@@ -328,14 +328,14 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
328
328
|
ok = ok && gr.read(magic, 4);
|
329
329
|
|
330
330
|
if (!ok) {
|
331
|
-
|
331
|
+
LM_GGML_LOG_ERROR("%s: failed to read magic\n", __func__);
|
332
332
|
lm_gguf_free(ctx);
|
333
333
|
return nullptr;
|
334
334
|
}
|
335
335
|
|
336
336
|
for (uint32_t i = 0; i < magic.size(); i++) {
|
337
337
|
if (magic[i] != LM_GGUF_MAGIC[i]) {
|
338
|
-
|
338
|
+
LM_GGML_LOG_ERROR("%s: invalid magic characters: '%c%c%c%c', expected 'GGUF'\n", __func__, magic[0], magic[1], magic[2], magic[3]);
|
339
339
|
lm_gguf_free(ctx);
|
340
340
|
return nullptr;
|
341
341
|
}
|
@@ -348,11 +348,11 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
348
348
|
|
349
349
|
if (ok && gr.read(ctx->version)) {
|
350
350
|
if (ctx->version == 1) {
|
351
|
-
|
351
|
+
LM_GGML_LOG_ERROR("%s: GGUFv1 is no longer supported, please use a more up-to-date version\n", __func__);
|
352
352
|
ok = false;
|
353
353
|
}
|
354
354
|
if (ctx->version > LM_GGUF_VERSION) {
|
355
|
-
|
355
|
+
LM_GGML_LOG_ERROR("%s: this GGUF file is version %" PRIu32 " but this software only supports up to version %d\n",
|
356
356
|
__func__, ctx->version, LM_GGUF_VERSION);
|
357
357
|
ok = false;
|
358
358
|
}
|
@@ -363,7 +363,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
363
363
|
if (ok && gr.read(n_tensors)) {
|
364
364
|
static_assert(sizeof(size_t) <= 8 && sizeof(lm_gguf_tensor_info) >= 2, "int64_t insufficient for indexing");
|
365
365
|
if (n_tensors < 0 || n_tensors > int64_t(SIZE_MAX/sizeof(lm_gguf_tensor_info))) {
|
366
|
-
|
366
|
+
LM_GGML_LOG_ERROR("%s: number of tensors is %" PRIi64 " but must be in [0, %zu]\n",
|
367
367
|
__func__, n_tensors, SIZE_MAX/sizeof(lm_gguf_tensor_info));
|
368
368
|
ok = false;
|
369
369
|
}
|
@@ -374,7 +374,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
374
374
|
if (ok && gr.read(n_kv)) {
|
375
375
|
static_assert(sizeof(size_t) <= 8 && sizeof(lm_gguf_tensor_info) >= 2, "int64_t insufficient for indexing");
|
376
376
|
if (n_kv < 0 || n_kv > int64_t(SIZE_MAX/sizeof(lm_gguf_kv))) {
|
377
|
-
|
377
|
+
LM_GGML_LOG_ERROR("%s: number of key value pairs is %" PRIi64 " but must be in [0, %zu]\n",
|
378
378
|
__func__, n_kv, SIZE_MAX/sizeof(lm_gguf_kv));
|
379
379
|
ok = false;
|
380
380
|
}
|
@@ -383,7 +383,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
383
383
|
}
|
384
384
|
|
385
385
|
if (!ok) {
|
386
|
-
|
386
|
+
LM_GGML_LOG_ERROR("%s: failed to read header\n", __func__);
|
387
387
|
lm_gguf_free(ctx);
|
388
388
|
return nullptr;
|
389
389
|
}
|
@@ -399,15 +399,15 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
399
399
|
try {
|
400
400
|
ok = ok && gr.read(key);
|
401
401
|
} catch (std::length_error &) {
|
402
|
-
|
402
|
+
LM_GGML_LOG_ERROR("%s: encountered length_error while reading key %" PRIi64 "\n", __func__, i);
|
403
403
|
ok = false;
|
404
404
|
} catch (std::bad_alloc &) {
|
405
|
-
|
405
|
+
LM_GGML_LOG_ERROR("%s: encountered bad_alloc error while reading key %" PRIi64 "\n", __func__, i);
|
406
406
|
ok = false;
|
407
407
|
}
|
408
408
|
for (size_t j = 0; ok && j < ctx->kv.size(); ++j) {
|
409
409
|
if (key == ctx->kv[j].key) {
|
410
|
-
|
410
|
+
LM_GGML_LOG_ERROR("%s: duplicate key '%s' for tensors %zu and %" PRIi64 " \n", __func__, key.c_str(), j, i);
|
411
411
|
ok = false;
|
412
412
|
}
|
413
413
|
}
|
@@ -441,14 +441,14 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
441
441
|
case LM_GGUF_TYPE_ARRAY:
|
442
442
|
default:
|
443
443
|
{
|
444
|
-
|
444
|
+
LM_GGML_LOG_ERROR("%s: key '%s' has invalid GGUF type %d\n", __func__, key.c_str(), type);
|
445
445
|
ok = false;
|
446
446
|
} break;
|
447
447
|
}
|
448
448
|
}
|
449
449
|
|
450
450
|
if (!ok) {
|
451
|
-
|
451
|
+
LM_GGML_LOG_ERROR("%s: failed to read key-value pairs\n", __func__);
|
452
452
|
lm_gguf_free(ctx);
|
453
453
|
return nullptr;
|
454
454
|
}
|
@@ -458,7 +458,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
458
458
|
ctx->alignment = alignment_idx == -1 ? LM_GGUF_DEFAULT_ALIGNMENT : lm_gguf_get_val_u32(ctx, alignment_idx);
|
459
459
|
|
460
460
|
if (ctx->alignment == 0 || (ctx->alignment & (ctx->alignment - 1)) != 0) {
|
461
|
-
|
461
|
+
LM_GGML_LOG_ERROR("%s: alignment %zu is not a power of 2\n", __func__, ctx->alignment);
|
462
462
|
lm_gguf_free(ctx);
|
463
463
|
return nullptr;
|
464
464
|
}
|
@@ -474,14 +474,14 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
474
474
|
try {
|
475
475
|
ok = ok && gr.read(name);
|
476
476
|
} catch (std::length_error &) {
|
477
|
-
|
477
|
+
LM_GGML_LOG_ERROR("%s: encountered length_error while reading tensor name %" PRIi64 "\n", __func__, i);
|
478
478
|
ok = false;
|
479
479
|
} catch (std::bad_alloc &) {
|
480
|
-
|
480
|
+
LM_GGML_LOG_ERROR("%s: encountered bad_alloc error while reading tensor name %" PRIi64 "\n", __func__, i);
|
481
481
|
ok = false;
|
482
482
|
}
|
483
483
|
if (name.length() >= LM_GGML_MAX_NAME) {
|
484
|
-
|
484
|
+
LM_GGML_LOG_ERROR("%s: tensor name %" PRIi64 " is too long: %zu >= %d\n", __func__, i, name.length(), LM_GGML_MAX_NAME);
|
485
485
|
ok = false;
|
486
486
|
break;
|
487
487
|
}
|
@@ -490,7 +490,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
490
490
|
// make sure there are no duplicate tensor names
|
491
491
|
for (int64_t j = 0; ok && j < i; ++j) {
|
492
492
|
if (strcmp(info.t.name, ctx->info[j].t.name) == 0) {
|
493
|
-
|
493
|
+
LM_GGML_LOG_ERROR("%s: duplicate tensor name '%s' for tensors %" PRIi64 " and %" PRIi64 "\n", __func__, info.t.name, j, i);
|
494
494
|
ok = false;
|
495
495
|
break;
|
496
496
|
}
|
@@ -505,7 +505,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
505
505
|
uint32_t n_dims = -1;
|
506
506
|
ok = ok && gr.read(n_dims);
|
507
507
|
if (n_dims > LM_GGML_MAX_DIMS) {
|
508
|
-
|
508
|
+
LM_GGML_LOG_ERROR("%s: tensor '%s' has invalid number of dimensions: %" PRIu32 " > %" PRIu32 "\n",
|
509
509
|
__func__, info.t.name, n_dims, LM_GGML_MAX_DIMS);
|
510
510
|
ok = false;
|
511
511
|
break;
|
@@ -518,7 +518,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
518
518
|
|
519
519
|
// check that all ne are non-negative
|
520
520
|
if (info.t.ne[j] < 0) {
|
521
|
-
|
521
|
+
LM_GGML_LOG_ERROR("%s: tensor '%s' dimension %" PRIu32 " has invalid number of elements: %" PRIi64 " < 0\n",
|
522
522
|
__func__, info.t.name, j, info.t.ne[j]);
|
523
523
|
ok = false;
|
524
524
|
break;
|
@@ -530,7 +530,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
530
530
|
(INT64_MAX/info.t.ne[2] <= info.t.ne[0]*info.t.ne[1]) ||
|
531
531
|
(INT64_MAX/info.t.ne[3] <= info.t.ne[0]*info.t.ne[1]*info.t.ne[2]))) {
|
532
532
|
|
533
|
-
|
533
|
+
LM_GGML_LOG_ERROR("%s: total number of elements in tensor '%s' with shape "
|
534
534
|
"(%" PRIi64 ", %" PRIi64 ", %" PRIi64 ", %" PRIi64 ") is >= %" PRIi64 "\n",
|
535
535
|
__func__, info.t.name, info.t.ne[0], info.t.ne[1], info.t.ne[2], info.t.ne[3], INT64_MAX);
|
536
536
|
ok = false;
|
@@ -547,7 +547,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
547
547
|
|
548
548
|
// check that tensor type is within defined range
|
549
549
|
if (info.t.type < 0 || info.t.type >= LM_GGML_TYPE_COUNT) {
|
550
|
-
|
550
|
+
LM_GGML_LOG_ERROR("%s: tensor '%s' has invalid ggml type %d (%s)\n",
|
551
551
|
__func__, info.t.name, info.t.type, lm_ggml_type_name(info.t.type));
|
552
552
|
ok = false;
|
553
553
|
break;
|
@@ -557,7 +557,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
557
557
|
|
558
558
|
// check that row size is divisible by block size
|
559
559
|
if (blck_size == 0 || info.t.ne[0] % blck_size != 0) {
|
560
|
-
|
560
|
+
LM_GGML_LOG_ERROR("%s: tensor '%s' of type %d (%s) has %" PRId64 " elements per row, "
|
561
561
|
"not a multiple of block size (%" PRId64 ")\n",
|
562
562
|
__func__, info.t.name, (int) info.t.type, lm_ggml_type_name(info.t.type), info.t.ne[0], blck_size);
|
563
563
|
ok = false;
|
@@ -582,7 +582,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
582
582
|
}
|
583
583
|
|
584
584
|
if (!ok) {
|
585
|
-
|
585
|
+
LM_GGML_LOG_ERROR("%s: failed to read tensor info\n", __func__);
|
586
586
|
lm_gguf_free(ctx);
|
587
587
|
return nullptr;
|
588
588
|
}
|
@@ -590,7 +590,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
590
590
|
|
591
591
|
// we require the data section to be aligned, so take into account any padding
|
592
592
|
if (fseek(file, LM_GGML_PAD(ftell(file), ctx->alignment), SEEK_SET) != 0) {
|
593
|
-
|
593
|
+
LM_GGML_LOG_ERROR("%s: failed to seek to beginning of data section\n", __func__);
|
594
594
|
lm_gguf_free(ctx);
|
595
595
|
return nullptr;
|
596
596
|
}
|
@@ -604,9 +604,9 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
604
604
|
for (size_t i = 0; i < ctx->info.size(); ++i) {
|
605
605
|
const lm_gguf_tensor_info & ti = ctx->info[i];
|
606
606
|
if (ti.offset != ctx->size) {
|
607
|
-
|
607
|
+
LM_GGML_LOG_ERROR("%s: tensor '%s' has offset %" PRIu64 ", expected %zu\n",
|
608
608
|
__func__, ti.t.name, ti.offset, ctx->size);
|
609
|
-
|
609
|
+
LM_GGML_LOG_ERROR("%s: failed to read tensor data\n", __func__);
|
610
610
|
lm_gguf_free(ctx);
|
611
611
|
return nullptr;
|
612
612
|
}
|
@@ -634,7 +634,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
634
634
|
|
635
635
|
*params.ctx = lm_ggml_init(pdata);
|
636
636
|
if (*params.ctx == nullptr) {
|
637
|
-
|
637
|
+
LM_GGML_LOG_ERROR("%s: failed to initialize ggml context for storing tensors\n", __func__);
|
638
638
|
lm_gguf_free(ctx);
|
639
639
|
return nullptr;
|
640
640
|
}
|
@@ -656,7 +656,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
656
656
|
ok = ok && gr.read(data->data, ctx->size);
|
657
657
|
|
658
658
|
if (!ok) {
|
659
|
-
|
659
|
+
LM_GGML_LOG_ERROR("%s: failed to read tensor data binary blob\n", __func__);
|
660
660
|
lm_ggml_free(ctx_data);
|
661
661
|
*params.ctx = nullptr;
|
662
662
|
lm_gguf_free(ctx);
|
@@ -689,7 +689,7 @@ struct lm_gguf_context * lm_gguf_init_from_file_impl(FILE * file, struct lm_gguf
|
|
689
689
|
}
|
690
690
|
|
691
691
|
if (!ok) {
|
692
|
-
|
692
|
+
LM_GGML_LOG_ERROR("%s: failed to create tensors\n", __func__);
|
693
693
|
lm_ggml_free(ctx_data);
|
694
694
|
*params.ctx = nullptr;
|
695
695
|
lm_gguf_free(ctx);
|
@@ -706,7 +706,7 @@ struct lm_gguf_context * lm_gguf_init_from_file(const char * fname, struct lm_gg
|
|
706
706
|
FILE * file = lm_ggml_fopen(fname, "rb");
|
707
707
|
|
708
708
|
if (!file) {
|
709
|
-
|
709
|
+
LM_GGML_LOG_ERROR("%s: failed to open GGUF file '%s'\n", __func__, fname);
|
710
710
|
return nullptr;
|
711
711
|
}
|
712
712
|
|
@@ -1305,7 +1305,7 @@ bool lm_gguf_write_to_file(const struct lm_gguf_context * ctx, const char * fnam
|
|
1305
1305
|
FILE * file = lm_ggml_fopen(fname, "wb");
|
1306
1306
|
|
1307
1307
|
if (!file) {
|
1308
|
-
|
1308
|
+
LM_GGML_LOG_ERROR("%s: failed to open file '%s' for writing GGUF data\n", __func__, fname);
|
1309
1309
|
return false;
|
1310
1310
|
}
|
1311
1311
|
|
package/cpp/llama-adapter.cpp
CHANGED
@@ -253,6 +253,9 @@ static void llama_adapter_lora_init_impl(llama_model & model, const char * path_
|
|
253
253
|
std::vector<lm_ggml_backend_buffer_type_t> buft_extra;
|
254
254
|
{
|
255
255
|
auto * cpu_dev = lm_ggml_backend_dev_by_type(LM_GGML_BACKEND_DEVICE_TYPE_CPU);
|
256
|
+
if (!cpu_dev) {
|
257
|
+
throw std::runtime_error(format("%s: no CPU backend found", __func__));
|
258
|
+
}
|
256
259
|
auto * cpu_reg = lm_ggml_backend_dev_backend_reg(cpu_dev);
|
257
260
|
|
258
261
|
auto lm_ggml_backend_dev_get_extra_bufts_fn = (lm_ggml_backend_dev_get_extra_bufts_t)
|
@@ -291,6 +294,9 @@ static void llama_adapter_lora_init_impl(llama_model & model, const char * path_
|
|
291
294
|
LLAMA_LOG_WARN("%s: lora for '%s' cannot use buft '%s', fallback to CPU\n", __func__, model_tensor->name, lm_ggml_backend_buft_name(buft));
|
292
295
|
|
293
296
|
auto * cpu_dev = lm_ggml_backend_dev_by_type(LM_GGML_BACKEND_DEVICE_TYPE_CPU);
|
297
|
+
if (!cpu_dev) {
|
298
|
+
throw std::runtime_error(format("%s: no CPU backend found", __func__));
|
299
|
+
}
|
294
300
|
buft = lm_ggml_backend_dev_buffer_type(cpu_dev);
|
295
301
|
|
296
302
|
break;
|
package/cpp/llama-arch.cpp
CHANGED
@@ -1481,6 +1481,9 @@ static const std::map<llm_arch, std::map<llm_tensor, const char *>> LLM_TENSOR_N
|
|
1481
1481
|
{ LLM_TENSOR_FFN_GATE_EXPS, "blk.%d.ffn_gate_exps" },
|
1482
1482
|
{ LLM_TENSOR_FFN_DOWN_EXPS, "blk.%d.ffn_down_exps" },
|
1483
1483
|
{ LLM_TENSOR_FFN_UP_EXPS, "blk.%d.ffn_up_exps" },
|
1484
|
+
{ LLM_TENSOR_FFN_GATE_SHEXP, "blk.%d.ffn_gate_shexp" },
|
1485
|
+
{ LLM_TENSOR_FFN_DOWN_SHEXP, "blk.%d.ffn_down_shexp" },
|
1486
|
+
{ LLM_TENSOR_FFN_UP_SHEXP, "blk.%d.ffn_up_shexp" },
|
1484
1487
|
},
|
1485
1488
|
},
|
1486
1489
|
{
|
package/cpp/llama-batch.cpp
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#include "llama-batch.h"
|
2
2
|
|
3
|
+
#include <cassert>
|
3
4
|
#include <cstring>
|
4
5
|
#include <algorithm>
|
5
6
|
|
@@ -281,9 +282,10 @@ llama_batch_allocr::llama_batch_allocr(struct llama_batch in_batch, llama_pos p0
|
|
281
282
|
batch = in_batch;
|
282
283
|
LM_GGML_ASSERT(batch.n_tokens > 0);
|
283
284
|
if (!batch.pos) {
|
285
|
+
assert(p0 >= 0);
|
284
286
|
pos.resize(batch.n_tokens);
|
285
287
|
for (int32_t i = 0; i < batch.n_tokens; i++) {
|
286
|
-
pos[i] =
|
288
|
+
pos[i] = p0 + i;
|
287
289
|
}
|
288
290
|
batch.pos = pos.data();
|
289
291
|
}
|
package/cpp/llama-chat.cpp
CHANGED
@@ -35,6 +35,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
|
|
35
35
|
{ "mistral-v3", LLM_CHAT_TEMPLATE_MISTRAL_V3 },
|
36
36
|
{ "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
|
37
37
|
{ "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
|
38
|
+
{ "mistral-v7-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN },
|
38
39
|
{ "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
|
39
40
|
{ "phi4", LLM_CHAT_TEMPLATE_PHI_4 },
|
40
41
|
{ "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
|
@@ -202,19 +203,20 @@ int32_t llm_chat_apply_template(
|
|
202
203
|
if (add_ass) {
|
203
204
|
ss << "<|im_start|>assistant\n";
|
204
205
|
}
|
205
|
-
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7) {
|
206
|
+
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 || tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN) {
|
206
207
|
// Official mistral 'v7' template
|
207
208
|
// See: https://huggingface.co/mistralai/Mistral-Large-Instruct-2411#basic-instruct-template-v7
|
209
|
+
// https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#basic-instruct-template-v7-tekken
|
210
|
+
const char * trailing_space = tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 ? " " : "";
|
208
211
|
for (auto message : chat) {
|
209
212
|
std::string role(message->role);
|
210
213
|
std::string content(message->content);
|
211
214
|
if (role == "system") {
|
212
|
-
ss << "[SYSTEM_PROMPT]
|
215
|
+
ss << "[SYSTEM_PROMPT]" << trailing_space << content << "[/SYSTEM_PROMPT]";
|
213
216
|
} else if (role == "user") {
|
214
|
-
ss << "[INST]
|
215
|
-
}
|
216
|
-
|
217
|
-
ss << " " << content << "</s>";
|
217
|
+
ss << "[INST]" << trailing_space << content << "[/INST]";
|
218
|
+
} else {
|
219
|
+
ss << trailing_space << content << "</s>";
|
218
220
|
}
|
219
221
|
}
|
220
222
|
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V1
|
package/cpp/llama-chat.h
CHANGED