@fugood/llama.node 0.3.1 → 0.3.3
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/CMakeLists.txt +1 -8
- package/bin/darwin/arm64/llama-node.node +0 -0
- package/bin/darwin/x64/llama-node.node +0 -0
- package/bin/linux/arm64/llama-node.node +0 -0
- package/bin/linux/x64/llama-node.node +0 -0
- package/bin/linux-vulkan/arm64/llama-node.node +0 -0
- package/bin/linux-vulkan/x64/llama-node.node +0 -0
- package/bin/win32/arm64/llama-node.node +0 -0
- package/bin/win32/arm64/node.lib +0 -0
- package/bin/win32/x64/llama-node.node +0 -0
- package/bin/win32/x64/node.lib +0 -0
- package/bin/win32-vulkan/arm64/llama-node.node +0 -0
- package/bin/win32-vulkan/arm64/node.lib +0 -0
- package/bin/win32-vulkan/x64/llama-node.node +0 -0
- package/bin/win32-vulkan/x64/node.lib +0 -0
- package/package.json +4 -2
- package/src/DetokenizeWorker.cpp +1 -1
- package/src/EmbeddingWorker.cpp +2 -2
- package/src/LlamaCompletionWorker.cpp +10 -10
- package/src/LlamaCompletionWorker.h +2 -2
- package/src/LlamaContext.cpp +14 -17
- package/src/TokenizeWorker.cpp +1 -1
- package/src/common.hpp +5 -4
- package/src/llama.cpp/.github/workflows/build.yml +137 -29
- package/src/llama.cpp/.github/workflows/close-issue.yml +5 -0
- package/src/llama.cpp/.github/workflows/docker.yml +46 -34
- package/src/llama.cpp/.github/workflows/nix-ci-aarch64.yml +7 -0
- package/src/llama.cpp/.github/workflows/nix-ci.yml +7 -0
- package/src/llama.cpp/.github/workflows/python-check-requirements.yml +2 -4
- package/src/llama.cpp/.github/workflows/python-type-check.yml +3 -1
- package/src/llama.cpp/.github/workflows/server.yml +7 -0
- package/src/llama.cpp/CMakeLists.txt +26 -11
- package/src/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
- package/src/llama.cpp/common/CMakeLists.txt +10 -10
- package/src/llama.cpp/common/arg.cpp +2041 -0
- package/src/llama.cpp/common/arg.h +77 -0
- package/src/llama.cpp/common/common.cpp +523 -1861
- package/src/llama.cpp/common/common.h +234 -106
- package/src/llama.cpp/common/console.cpp +3 -0
- package/src/llama.cpp/common/json-schema-to-grammar.cpp +1 -1
- package/src/llama.cpp/common/log.cpp +401 -0
- package/src/llama.cpp/common/log.h +66 -698
- package/src/llama.cpp/common/ngram-cache.cpp +39 -36
- package/src/llama.cpp/common/ngram-cache.h +19 -19
- package/src/llama.cpp/common/sampling.cpp +356 -350
- package/src/llama.cpp/common/sampling.h +62 -139
- package/src/llama.cpp/common/stb_image.h +5990 -6398
- package/src/llama.cpp/docs/build.md +72 -17
- package/src/llama.cpp/examples/CMakeLists.txt +1 -2
- package/src/llama.cpp/examples/batched/batched.cpp +49 -65
- package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +42 -53
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +55 -52
- package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +22 -22
- package/src/llama.cpp/examples/cvector-generator/pca.hpp +3 -13
- package/src/llama.cpp/examples/embedding/embedding.cpp +147 -91
- package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +37 -37
- package/src/llama.cpp/examples/export-lora/export-lora.cpp +39 -38
- package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +14 -39
- package/src/llama.cpp/examples/{baby-llama → gen-docs}/CMakeLists.txt +2 -2
- package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +83 -0
- package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +58 -39
- package/src/llama.cpp/examples/gritlm/gritlm.cpp +46 -39
- package/src/llama.cpp/examples/imatrix/imatrix.cpp +75 -69
- package/src/llama.cpp/examples/infill/infill.cpp +131 -192
- package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +276 -178
- package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +1 -0
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +40 -36
- package/src/llama.cpp/examples/llava/CMakeLists.txt +7 -0
- package/src/llama.cpp/examples/llava/clip.cpp +686 -150
- package/src/llama.cpp/examples/llava/clip.h +11 -2
- package/src/llama.cpp/examples/llava/llava-cli.cpp +60 -71
- package/src/llama.cpp/examples/llava/llava.cpp +146 -26
- package/src/llama.cpp/examples/llava/llava.h +2 -3
- package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +323 -0
- package/src/llama.cpp/examples/llava/requirements.txt +1 -0
- package/src/llama.cpp/examples/lookahead/lookahead.cpp +55 -56
- package/src/llama.cpp/examples/lookup/lookup-create.cpp +15 -13
- package/src/llama.cpp/examples/lookup/lookup-merge.cpp +4 -4
- package/src/llama.cpp/examples/lookup/lookup-stats.cpp +34 -33
- package/src/llama.cpp/examples/lookup/lookup.cpp +60 -63
- package/src/llama.cpp/examples/main/main.cpp +216 -313
- package/src/llama.cpp/examples/parallel/parallel.cpp +58 -59
- package/src/llama.cpp/examples/passkey/passkey.cpp +53 -61
- package/src/llama.cpp/examples/perplexity/perplexity.cpp +277 -311
- package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/quantize/quantize.cpp +27 -9
- package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +12 -12
- package/src/llama.cpp/examples/retrieval/retrieval.cpp +57 -52
- package/src/llama.cpp/examples/rpc/rpc-server.cpp +27 -2
- package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +60 -46
- package/src/llama.cpp/examples/server/CMakeLists.txt +7 -18
- package/src/llama.cpp/examples/server/server.cpp +1347 -1531
- package/src/llama.cpp/examples/server/tests/requirements.txt +2 -1
- package/src/llama.cpp/examples/server/utils.hpp +396 -107
- package/src/llama.cpp/examples/simple/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/simple/simple.cpp +132 -106
- package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +197 -0
- package/src/llama.cpp/examples/speculative/speculative.cpp +153 -124
- package/src/llama.cpp/examples/sycl/run-llama2.sh +10 -19
- package/src/llama.cpp/examples/sycl/win-run-llama2.bat +1 -1
- package/src/llama.cpp/examples/tokenize/tokenize.cpp +27 -29
- package/src/llama.cpp/ggml/CMakeLists.txt +29 -12
- package/src/llama.cpp/ggml/include/ggml-alloc.h +3 -3
- package/src/llama.cpp/ggml/include/ggml-amx.h +25 -0
- package/src/llama.cpp/ggml/include/ggml-backend.h +166 -68
- package/src/llama.cpp/ggml/include/ggml-blas.h +5 -3
- package/src/llama.cpp/ggml/include/ggml-cann.h +17 -19
- package/src/llama.cpp/ggml/include/ggml-cpp.h +38 -0
- package/src/llama.cpp/ggml/include/ggml-cpu.h +177 -0
- package/src/llama.cpp/ggml/include/ggml-cuda.h +17 -17
- package/src/llama.cpp/ggml/include/ggml-kompute.h +7 -3
- package/src/llama.cpp/ggml/include/ggml-metal.h +13 -12
- package/src/llama.cpp/ggml/include/ggml-opt.h +216 -0
- package/src/llama.cpp/ggml/include/ggml-rpc.h +9 -5
- package/src/llama.cpp/ggml/include/ggml-sycl.h +18 -11
- package/src/llama.cpp/ggml/include/ggml-vulkan.h +10 -8
- package/src/llama.cpp/ggml/include/ggml.h +272 -505
- package/src/llama.cpp/ggml/src/CMakeLists.txt +69 -1110
- package/src/llama.cpp/ggml/src/ggml-aarch64.c +52 -2116
- package/src/llama.cpp/ggml/src/ggml-aarch64.h +0 -20
- package/src/llama.cpp/ggml/src/ggml-alloc.c +29 -27
- package/src/llama.cpp/ggml/src/ggml-amx/CMakeLists.txt +107 -0
- package/src/llama.cpp/ggml/src/ggml-amx/common.h +94 -0
- package/src/llama.cpp/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
- package/src/llama.cpp/ggml/src/ggml-amx/mmq.cpp +2510 -0
- package/src/llama.cpp/ggml/src/ggml-amx/mmq.h +17 -0
- package/src/llama.cpp/ggml/src/ggml-backend-impl.h +144 -81
- package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +195 -0
- package/src/llama.cpp/ggml/src/{ggml-backend.c → ggml-backend.cpp} +394 -635
- package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +91 -0
- package/src/llama.cpp/ggml/src/{ggml-blas.cpp → ggml-blas/ggml-blas.cpp} +217 -70
- package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +46 -0
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +4 -27
- package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +32 -4
- package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +179 -41
- package/src/llama.cpp/ggml/src/ggml-cann/common.h +1 -0
- package/src/llama.cpp/ggml/src/{ggml-cann.cpp → ggml-cann/ggml-cann.cpp} +458 -353
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +2 -1
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/ascendc_kernels.h +2 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +278 -0
- package/src/llama.cpp/ggml/src/ggml-common.h +20 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +261 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.c +3560 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +30 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +371 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +10822 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +13970 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +663 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1885 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +155 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +178 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +134 -0
- package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +106 -0
- package/src/llama.cpp/ggml/src/ggml-impl.h +380 -584
- package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +162 -0
- package/src/llama.cpp/ggml/src/{ggml-kompute.cpp → ggml-kompute/ggml-kompute.cpp} +233 -87
- package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +108 -0
- package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +249 -0
- package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +100 -0
- package/src/llama.cpp/ggml/src/ggml-opt.cpp +867 -0
- package/src/llama.cpp/ggml/src/ggml-quants.c +369 -9994
- package/src/llama.cpp/ggml/src/ggml-quants.h +78 -110
- package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +11 -0
- package/src/llama.cpp/ggml/src/{ggml-rpc.cpp → ggml-rpc/ggml-rpc.cpp} +560 -335
- package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +81 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +6 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +51 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +310 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +1 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +99 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +21 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +57 -57
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +106 -106
- package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +4 -4
- package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +18 -25
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1011 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +76 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +101 -0
- package/src/llama.cpp/ggml/src/{ggml-sycl.cpp → ggml-sycl/ggml-sycl.cpp} +3350 -3980
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +125 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +23 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +70 -68
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +9 -6
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +56 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +11 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +8 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +71 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +21 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +4 -4
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.cpp +138 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.hpp +10 -0
- package/src/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
- package/src/llama.cpp/ggml/src/ggml-threading.h +12 -0
- package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +78 -0
- package/src/llama.cpp/ggml/src/{ggml-vulkan.cpp → ggml-vulkan/ggml-vulkan.cpp} +2034 -1718
- package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/CMakeLists.txt +2 -0
- package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/vulkan-shaders-gen.cpp +152 -185
- package/src/llama.cpp/ggml/src/ggml.c +2075 -16579
- package/src/llama.cpp/include/llama.h +296 -285
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +112 -0
- package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +46 -0
- package/src/llama.cpp/pocs/vdot/q8dot.cpp +4 -3
- package/src/llama.cpp/pocs/vdot/vdot.cpp +8 -7
- package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +1 -1
- package/src/llama.cpp/src/CMakeLists.txt +2 -1
- package/src/llama.cpp/src/llama-grammar.cpp +721 -122
- package/src/llama.cpp/src/llama-grammar.h +120 -15
- package/src/llama.cpp/src/llama-impl.h +156 -1
- package/src/llama.cpp/src/llama-sampling.cpp +2058 -346
- package/src/llama.cpp/src/llama-sampling.h +39 -47
- package/src/llama.cpp/src/llama-vocab.cpp +390 -127
- package/src/llama.cpp/src/llama-vocab.h +60 -20
- package/src/llama.cpp/src/llama.cpp +6215 -3263
- package/src/llama.cpp/src/unicode-data.cpp +6 -4
- package/src/llama.cpp/src/unicode-data.h +4 -4
- package/src/llama.cpp/src/unicode.cpp +15 -7
- package/src/llama.cpp/tests/CMakeLists.txt +4 -2
- package/src/llama.cpp/tests/test-arg-parser.cpp +131 -0
- package/src/llama.cpp/tests/test-backend-ops.cpp +1725 -297
- package/src/llama.cpp/tests/test-barrier.cpp +94 -0
- package/src/llama.cpp/tests/test-chat-template.cpp +9 -5
- package/src/llama.cpp/tests/test-grammar-integration.cpp +23 -38
- package/src/llama.cpp/tests/test-grammar-parser.cpp +6 -4
- package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +23 -8
- package/src/llama.cpp/tests/test-llama-grammar.cpp +9 -8
- package/src/llama.cpp/tests/test-log.cpp +39 -0
- package/src/llama.cpp/tests/test-opt.cpp +853 -142
- package/src/llama.cpp/tests/test-quantize-fns.cpp +28 -19
- package/src/llama.cpp/tests/test-quantize-perf.cpp +16 -14
- package/src/llama.cpp/tests/test-rope.cpp +2 -1
- package/src/llama.cpp/tests/test-sampling.cpp +226 -142
- package/src/llama.cpp/tests/test-tokenizer-0.cpp +56 -36
- package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +5 -5
- package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +5 -5
- package/patches/llama.patch +0 -22
- package/src/llama.cpp/.github/workflows/bench.yml +0 -310
- package/src/llama.cpp/common/grammar-parser.cpp +0 -536
- package/src/llama.cpp/common/grammar-parser.h +0 -29
- package/src/llama.cpp/common/train.cpp +0 -1513
- package/src/llama.cpp/common/train.h +0 -233
- package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +0 -1640
- package/src/llama.cpp/examples/benchmark/CMakeLists.txt +0 -6
- package/src/llama.cpp/examples/benchmark/benchmark-matmult.cpp +0 -275
- package/src/llama.cpp/ggml/src/llamafile/sgemm.cpp +0 -1027
- package/src/llama.cpp/tests/test-grad0.cpp +0 -1566
- /package/src/llama.cpp/ggml/{cmake → src/ggml-cpu/cmake}/FindSIMD.cmake +0 -0
- /package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.h +0 -0
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
#include <unordered_map>
|
|
8
8
|
#include <unordered_set>
|
|
9
9
|
|
|
10
|
-
const std::
|
|
10
|
+
const std::initializer_list<std::pair<uint32_t, uint16_t>> unicode_ranges_flags = { // start, flags // last=next_start-1
|
|
11
11
|
{0x000000, 0x0080},
|
|
12
12
|
{0x000020, 0x0008},
|
|
13
13
|
{0x000021, 0x0020},
|
|
@@ -2311,7 +2311,8 @@ const std::unordered_set<uint32_t> unicode_set_whitespace = {
|
|
|
2311
2311
|
0x003000,
|
|
2312
2312
|
};
|
|
2313
2313
|
|
|
2314
|
-
|
|
2314
|
+
// list is always in ascending order, to enable binary search
|
|
2315
|
+
const std::initializer_list<std::pair<uint32_t, uint32_t>> unicode_map_lowercase = {
|
|
2315
2316
|
{0x000041, 0x000061},
|
|
2316
2317
|
{0x000042, 0x000062},
|
|
2317
2318
|
{0x000043, 0x000063},
|
|
@@ -3747,7 +3748,8 @@ const std::unordered_map<uint32_t, uint32_t> unicode_map_lowercase = {
|
|
|
3747
3748
|
{0x01E921, 0x01E943},
|
|
3748
3749
|
};
|
|
3749
3750
|
|
|
3750
|
-
|
|
3751
|
+
// list is always in ascending order, to enable binary search
|
|
3752
|
+
const std::initializer_list<std::pair<uint32_t, uint32_t>> unicode_map_uppercase = {
|
|
3751
3753
|
{0x000061, 0x000041},
|
|
3752
3754
|
{0x000062, 0x000042},
|
|
3753
3755
|
{0x000063, 0x000043},
|
|
@@ -5200,7 +5202,7 @@ const std::unordered_map<uint32_t, uint32_t> unicode_map_uppercase = {
|
|
|
5200
5202
|
{0x01E943, 0x01E921},
|
|
5201
5203
|
};
|
|
5202
5204
|
|
|
5203
|
-
const std::
|
|
5205
|
+
const std::initializer_list<range_nfd> unicode_ranges_nfd = { // start, last, nfd
|
|
5204
5206
|
{0x000000, 0x000000, 0x000000},
|
|
5205
5207
|
{0x0000C0, 0x0000C5, 0x000041},
|
|
5206
5208
|
{0x0000C7, 0x0000C7, 0x000043},
|
|
@@ -13,8 +13,8 @@ struct range_nfd {
|
|
|
13
13
|
|
|
14
14
|
static const uint32_t MAX_CODEPOINTS = 0x110000;
|
|
15
15
|
|
|
16
|
-
extern const std::
|
|
16
|
+
extern const std::initializer_list<std::pair<uint32_t, uint16_t>> unicode_ranges_flags;
|
|
17
17
|
extern const std::unordered_set<uint32_t> unicode_set_whitespace;
|
|
18
|
-
extern const std::
|
|
19
|
-
extern const std::
|
|
20
|
-
extern const std::
|
|
18
|
+
extern const std::initializer_list<std::pair<uint32_t, uint32_t>> unicode_map_lowercase;
|
|
19
|
+
extern const std::initializer_list<std::pair<uint32_t, uint32_t>> unicode_map_uppercase;
|
|
20
|
+
extern const std::initializer_list<range_nfd> unicode_ranges_nfd;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "unicode.h"
|
|
6
6
|
#include "unicode-data.h"
|
|
7
7
|
|
|
8
|
+
#include <algorithm>
|
|
8
9
|
#include <cassert>
|
|
9
10
|
#include <cstddef>
|
|
10
11
|
#include <cstdint>
|
|
@@ -122,11 +123,11 @@ uint32_t unicode_cpt_from_utf8(const std::string & utf8, size_t & offset) {
|
|
|
122
123
|
static std::vector<codepoint_flags> unicode_cpt_flags_array() {
|
|
123
124
|
std::vector<codepoint_flags> cpt_flags(MAX_CODEPOINTS, codepoint_flags::UNDEFINED);
|
|
124
125
|
|
|
125
|
-
assert (unicode_ranges_flags.
|
|
126
|
-
assert (unicode_ranges_flags.
|
|
126
|
+
assert (unicode_ranges_flags.begin()[0].first == 0);
|
|
127
|
+
assert (unicode_ranges_flags.begin()[unicode_ranges_flags.size()-1].first == MAX_CODEPOINTS);
|
|
127
128
|
for (size_t i = 1; i < unicode_ranges_flags.size(); ++i) {
|
|
128
|
-
const auto range_ini = unicode_ranges_flags[i-1]; // codepoint_ini, flags
|
|
129
|
-
const auto range_end = unicode_ranges_flags[i]; // codepoint_end, flags
|
|
129
|
+
const auto range_ini = unicode_ranges_flags.begin()[i-1]; // codepoint_ini, flags
|
|
130
|
+
const auto range_end = unicode_ranges_flags.begin()[i]; // codepoint_end, flags
|
|
130
131
|
for (uint32_t cpt = range_ini.first; cpt < range_end.first; ++cpt) {
|
|
131
132
|
cpt_flags[cpt] = range_ini.second;
|
|
132
133
|
}
|
|
@@ -596,7 +597,7 @@ std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & c
|
|
|
596
597
|
std::vector<uint32_t> result(cpts.size());
|
|
597
598
|
for (size_t i = 0; i < cpts.size(); ++i) {
|
|
598
599
|
const uint32_t cpt = cpts[i];
|
|
599
|
-
auto it = std::upper_bound(unicode_ranges_nfd.
|
|
600
|
+
auto it = std::upper_bound(unicode_ranges_nfd.begin(), unicode_ranges_nfd.end(), cpt, comp) - 1;
|
|
600
601
|
result[i] = (it->first <= cpt && cpt <= it->last) ? it->nfd : cpt;
|
|
601
602
|
}
|
|
602
603
|
return result;
|
|
@@ -638,8 +639,15 @@ uint8_t unicode_utf8_to_byte(const std::string & utf8) {
|
|
|
638
639
|
}
|
|
639
640
|
|
|
640
641
|
uint32_t unicode_tolower(uint32_t cp) {
|
|
641
|
-
|
|
642
|
-
|
|
642
|
+
// binary search
|
|
643
|
+
auto it = std::lower_bound(unicode_map_lowercase.begin(), unicode_map_lowercase.end(), cp,
|
|
644
|
+
[](const std::pair<uint32_t, uint32_t> & pair, uint32_t value) {
|
|
645
|
+
return pair.first < value;
|
|
646
|
+
});
|
|
647
|
+
if (it != unicode_map_lowercase.end() && it->first == cp) {
|
|
648
|
+
return it->second;
|
|
649
|
+
}
|
|
650
|
+
return cp; // Return the original code point if no lowercase mapping is found
|
|
643
651
|
}
|
|
644
652
|
|
|
645
653
|
std::vector<std::string> unicode_regex_split(const std::string & text, const std::vector<std::string> & regex_exprs) {
|
|
@@ -108,15 +108,17 @@ llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-llama-spm ARGS ${CMAKE_CU
|
|
|
108
108
|
#llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-baichuan ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf)
|
|
109
109
|
|
|
110
110
|
# llama_target_and_test(test-double-float.cpp) # SLOW
|
|
111
|
+
llama_target_and_test(test-log.cpp)
|
|
112
|
+
llama_target_and_test(test-arg-parser.cpp)
|
|
111
113
|
llama_target_and_test(test-quantize-fns.cpp)
|
|
112
114
|
llama_target_and_test(test-quantize-perf.cpp)
|
|
113
115
|
llama_target_and_test(test-sampling.cpp)
|
|
114
116
|
llama_target_and_test(test-chat-template.cpp)
|
|
115
117
|
|
|
116
118
|
llama_target_and_test(test-grammar-parser.cpp)
|
|
117
|
-
llama_target_and_test(test-llama-grammar.cpp)
|
|
118
119
|
llama_target_and_test(test-grammar-integration.cpp)
|
|
119
|
-
llama_target_and_test(test-
|
|
120
|
+
llama_target_and_test(test-llama-grammar.cpp)
|
|
121
|
+
llama_target_and_test(test-barrier.cpp)
|
|
120
122
|
# llama_target_and_test(test-opt.cpp) # SLOW
|
|
121
123
|
llama_target_and_test(test-backend-ops.cpp)
|
|
122
124
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#include "arg.h"
|
|
2
|
+
#include "common.h"
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <sstream>
|
|
7
|
+
#include <unordered_set>
|
|
8
|
+
|
|
9
|
+
#undef NDEBUG
|
|
10
|
+
#include <cassert>
|
|
11
|
+
|
|
12
|
+
int main(void) {
|
|
13
|
+
common_params params;
|
|
14
|
+
|
|
15
|
+
printf("test-arg-parser: make sure there is no duplicated arguments in any examples\n\n");
|
|
16
|
+
for (int ex = 0; ex < LLAMA_EXAMPLE_COUNT; ex++) {
|
|
17
|
+
try {
|
|
18
|
+
auto ctx_arg = common_params_parser_init(params, (enum llama_example)ex);
|
|
19
|
+
std::unordered_set<std::string> seen_args;
|
|
20
|
+
std::unordered_set<std::string> seen_env_vars;
|
|
21
|
+
for (const auto & opt : ctx_arg.options) {
|
|
22
|
+
// check for args duplications
|
|
23
|
+
for (const auto & arg : opt.args) {
|
|
24
|
+
if (seen_args.find(arg) == seen_args.end()) {
|
|
25
|
+
seen_args.insert(arg);
|
|
26
|
+
} else {
|
|
27
|
+
fprintf(stderr, "test-arg-parser: found different handlers for the same argument: %s", arg);
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// check for env var duplications
|
|
32
|
+
if (opt.env) {
|
|
33
|
+
if (seen_env_vars.find(opt.env) == seen_env_vars.end()) {
|
|
34
|
+
seen_env_vars.insert(opt.env);
|
|
35
|
+
} else {
|
|
36
|
+
fprintf(stderr, "test-arg-parser: found different handlers for the same env var: %s", opt.env);
|
|
37
|
+
exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch (std::exception & e) {
|
|
42
|
+
printf("%s\n", e.what());
|
|
43
|
+
assert(false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
auto list_str_to_char = [](std::vector<std::string> & argv) -> std::vector<char *> {
|
|
48
|
+
std::vector<char *> res;
|
|
49
|
+
for (auto & arg : argv) {
|
|
50
|
+
res.push_back(const_cast<char *>(arg.data()));
|
|
51
|
+
}
|
|
52
|
+
return res;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
std::vector<std::string> argv;
|
|
56
|
+
|
|
57
|
+
printf("test-arg-parser: test invalid usage\n\n");
|
|
58
|
+
|
|
59
|
+
// missing value
|
|
60
|
+
argv = {"binary_name", "-m"};
|
|
61
|
+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
62
|
+
|
|
63
|
+
// wrong value (int)
|
|
64
|
+
argv = {"binary_name", "-ngl", "hello"};
|
|
65
|
+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
66
|
+
|
|
67
|
+
// wrong value (enum)
|
|
68
|
+
argv = {"binary_name", "-sm", "hello"};
|
|
69
|
+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
70
|
+
|
|
71
|
+
// non-existence arg in specific example (--draft cannot be used outside llama-speculative)
|
|
72
|
+
argv = {"binary_name", "--draft", "123"};
|
|
73
|
+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_SERVER));
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
printf("test-arg-parser: test valid usage\n\n");
|
|
77
|
+
|
|
78
|
+
argv = {"binary_name", "-m", "model_file.gguf"};
|
|
79
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
80
|
+
assert(params.model == "model_file.gguf");
|
|
81
|
+
|
|
82
|
+
argv = {"binary_name", "-t", "1234"};
|
|
83
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
84
|
+
assert(params.cpuparams.n_threads == 1234);
|
|
85
|
+
|
|
86
|
+
argv = {"binary_name", "--verbose"};
|
|
87
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
88
|
+
assert(params.verbosity > 1);
|
|
89
|
+
|
|
90
|
+
argv = {"binary_name", "-m", "abc.gguf", "--predict", "6789", "--batch-size", "9090"};
|
|
91
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
92
|
+
assert(params.model == "abc.gguf");
|
|
93
|
+
assert(params.n_predict == 6789);
|
|
94
|
+
assert(params.n_batch == 9090);
|
|
95
|
+
|
|
96
|
+
// --draft cannot be used outside llama-speculative
|
|
97
|
+
argv = {"binary_name", "--draft", "123"};
|
|
98
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_SPECULATIVE));
|
|
99
|
+
assert(params.n_draft == 123);
|
|
100
|
+
|
|
101
|
+
// skip this part on windows, because setenv is not supported
|
|
102
|
+
#ifdef _WIN32
|
|
103
|
+
printf("test-arg-parser: skip on windows build\n");
|
|
104
|
+
#else
|
|
105
|
+
printf("test-arg-parser: test environment variables (valid + invalid usages)\n\n");
|
|
106
|
+
|
|
107
|
+
setenv("LLAMA_ARG_THREADS", "blah", true);
|
|
108
|
+
argv = {"binary_name"};
|
|
109
|
+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
110
|
+
|
|
111
|
+
setenv("LLAMA_ARG_MODEL", "blah.gguf", true);
|
|
112
|
+
setenv("LLAMA_ARG_THREADS", "1010", true);
|
|
113
|
+
argv = {"binary_name"};
|
|
114
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
115
|
+
assert(params.model == "blah.gguf");
|
|
116
|
+
assert(params.cpuparams.n_threads == 1010);
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
printf("test-arg-parser: test environment variables being overwritten\n\n");
|
|
120
|
+
|
|
121
|
+
setenv("LLAMA_ARG_MODEL", "blah.gguf", true);
|
|
122
|
+
setenv("LLAMA_ARG_THREADS", "1010", true);
|
|
123
|
+
argv = {"binary_name", "-m", "overwritten.gguf"};
|
|
124
|
+
assert(true == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
|
|
125
|
+
assert(params.model == "overwritten.gguf");
|
|
126
|
+
assert(params.cpuparams.n_threads == 1010);
|
|
127
|
+
#endif // _WIN32
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
printf("test-arg-parser: all tests OK\n\n");
|
|
131
|
+
}
|