@novastera-oss/llamarn 0.0.1-alpha.4
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/INTERFACE.md +389 -0
- package/LICENSE +201 -0
- package/README.md +235 -0
- package/RNLlamaCpp.podspec +69 -0
- package/android/CMakeLists.txt +107 -0
- package/android/build.gradle +111 -0
- package/android/generated/java/com/novastera/llamarn/NativeRNLlamaCppSpec.java +47 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNLlamaCppSpec-generated.cpp +44 -0
- package/android/generated/jni/RNLlamaCppSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI-generated.cpp +42 -0
- package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI.h +336 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/cpp/include/llama-cpp.h +30 -0
- package/android/src/main/cpp/include/llama.h +1440 -0
- package/android/src/main/java/com/novastera/llamarn/RNLlamaCppPackage.kt +21 -0
- package/android/src/main/jniLibs/arm64-v8a/libOpenCL.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libggml-base.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libggml.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libllama.so +0 -0
- package/android/src/main/jniLibs/x86_64/libOpenCL.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml-base.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml.so +0 -0
- package/android/src/main/jniLibs/x86_64/libllama.so +0 -0
- package/cpp/LlamaCppModel.cpp +984 -0
- package/cpp/LlamaCppModel.h +162 -0
- package/cpp/PureCppImpl.cpp +308 -0
- package/cpp/PureCppImpl.h +59 -0
- package/cpp/SystemUtils.cpp +180 -0
- package/cpp/SystemUtils.h +74 -0
- package/cpp/build-info.cpp +4 -0
- package/cpp/llama.cpp/AUTHORS +1106 -0
- package/cpp/llama.cpp/CMakeLists.txt +254 -0
- package/cpp/llama.cpp/CMakePresets.json +84 -0
- package/cpp/llama.cpp/CODEOWNERS +11 -0
- package/cpp/llama.cpp/CONTRIBUTING.md +127 -0
- package/cpp/llama.cpp/LICENSE +21 -0
- package/cpp/llama.cpp/Makefile +1608 -0
- package/cpp/llama.cpp/README.md +575 -0
- package/cpp/llama.cpp/SECURITY.md +68 -0
- package/cpp/llama.cpp/build-xcframework.sh +540 -0
- package/cpp/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
- package/cpp/llama.cpp/cmake/arm64-windows-llvm.cmake +16 -0
- package/cpp/llama.cpp/cmake/build-info.cmake +64 -0
- package/cpp/llama.cpp/cmake/common.cmake +35 -0
- package/cpp/llama.cpp/cmake/git-vars.cmake +22 -0
- package/cpp/llama.cpp/cmake/llama-config.cmake.in +30 -0
- package/cpp/llama.cpp/cmake/llama.pc.in +10 -0
- package/cpp/llama.cpp/cmake/x64-windows-llvm.cmake +5 -0
- package/cpp/llama.cpp/common/CMakeLists.txt +170 -0
- package/cpp/llama.cpp/common/arg.cpp +3337 -0
- package/cpp/llama.cpp/common/arg.h +89 -0
- package/cpp/llama.cpp/common/base64.hpp +392 -0
- package/cpp/llama.cpp/common/build-info.cpp.in +4 -0
- package/cpp/llama.cpp/common/chat.cpp +1781 -0
- package/cpp/llama.cpp/common/chat.h +135 -0
- package/cpp/llama.cpp/common/cmake/build-info-gen-cpp.cmake +24 -0
- package/cpp/llama.cpp/common/common.cpp +1567 -0
- package/cpp/llama.cpp/common/common.h +668 -0
- package/cpp/llama.cpp/common/console.cpp +504 -0
- package/cpp/llama.cpp/common/console.h +19 -0
- package/cpp/llama.cpp/common/json-schema-to-grammar.cpp +1027 -0
- package/cpp/llama.cpp/common/json-schema-to-grammar.h +21 -0
- package/cpp/llama.cpp/common/json.hpp +24766 -0
- package/cpp/llama.cpp/common/llguidance.cpp +254 -0
- package/cpp/llama.cpp/common/log.cpp +393 -0
- package/cpp/llama.cpp/common/log.h +103 -0
- package/cpp/llama.cpp/common/minja/chat-template.hpp +537 -0
- package/cpp/llama.cpp/common/minja/minja.hpp +2941 -0
- package/cpp/llama.cpp/common/ngram-cache.cpp +286 -0
- package/cpp/llama.cpp/common/ngram-cache.h +101 -0
- package/cpp/llama.cpp/common/sampling.cpp +580 -0
- package/cpp/llama.cpp/common/sampling.h +107 -0
- package/cpp/llama.cpp/common/speculative.cpp +278 -0
- package/cpp/llama.cpp/common/speculative.h +28 -0
- package/cpp/llama.cpp/common/stb_image.h +7988 -0
- package/cpp/llama.cpp/convert_hf_to_gguf.py +6195 -0
- package/cpp/llama.cpp/convert_hf_to_gguf_update.py +393 -0
- package/cpp/llama.cpp/convert_llama_ggml_to_gguf.py +450 -0
- package/cpp/llama.cpp/convert_lora_to_gguf.py +461 -0
- package/cpp/llama.cpp/flake.lock +58 -0
- package/cpp/llama.cpp/flake.nix +185 -0
- package/cpp/llama.cpp/ggml/CMakeLists.txt +388 -0
- package/cpp/llama.cpp/ggml/cmake/GitVars.cmake +22 -0
- package/cpp/llama.cpp/ggml/cmake/common.cmake +26 -0
- package/cpp/llama.cpp/ggml/cmake/ggml-config.cmake.in +152 -0
- package/cpp/llama.cpp/ggml/include/ggml-alloc.h +76 -0
- package/cpp/llama.cpp/ggml/include/ggml-backend.h +354 -0
- package/cpp/llama.cpp/ggml/include/ggml-blas.h +25 -0
- package/cpp/llama.cpp/ggml/include/ggml-cann.h +123 -0
- package/cpp/llama.cpp/ggml/include/ggml-cpp.h +39 -0
- package/cpp/llama.cpp/ggml/include/ggml-cpu.h +143 -0
- package/cpp/llama.cpp/ggml/include/ggml-cuda.h +47 -0
- package/cpp/llama.cpp/ggml/include/ggml-kompute.h +50 -0
- package/cpp/llama.cpp/ggml/include/ggml-metal.h +66 -0
- package/cpp/llama.cpp/ggml/include/ggml-opencl.h +26 -0
- package/cpp/llama.cpp/ggml/include/ggml-opt.h +216 -0
- package/cpp/llama.cpp/ggml/include/ggml-rpc.h +33 -0
- package/cpp/llama.cpp/ggml/include/ggml-sycl.h +49 -0
- package/cpp/llama.cpp/ggml/include/ggml-vulkan.h +29 -0
- package/cpp/llama.cpp/ggml/include/ggml.h +2192 -0
- package/cpp/llama.cpp/ggml/include/gguf.h +202 -0
- package/cpp/llama.cpp/ggml/src/CMakeLists.txt +345 -0
- package/cpp/llama.cpp/ggml/src/ggml-alloc.c +1042 -0
- package/cpp/llama.cpp/ggml/src/ggml-backend-impl.h +255 -0
- package/cpp/llama.cpp/ggml/src/ggml-backend-reg.cpp +586 -0
- package/cpp/llama.cpp/ggml/src/ggml-backend.cpp +2008 -0
- package/cpp/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +74 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/Doxyfile +2579 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +179 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +258 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +2589 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +1083 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/common.h +420 -0
- package/cpp/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +2554 -0
- package/cpp/llama.cpp/ggml/src/ggml-common.h +1857 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +495 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +221 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.h +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/common.h +91 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp +158 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.h +16 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/common.h +72 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +327 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +6431 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +512 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +13131 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +3492 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +671 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.cpp +254 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.h +60 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +287 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +3544 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp +8796 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.h +110 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +892 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.cpp +186 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.h +28 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.cpp +252 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.h +802 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +184 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cu +47 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cu +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cu +91 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cu +104 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cu +363 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cuh +9 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cu +45 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/common.cuh +828 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cu +221 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cu +89 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cu +730 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cuh +26 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cu +64 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cp-async.cuh +57 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cu +695 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cuh +11 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cu +189 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/dequantize.cuh +103 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cu +40 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-common.cuh +873 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1269 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cu +357 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cu +365 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f16.cuh +437 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f32.cuh +428 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cu +634 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cu +345 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cu +275 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cuh +15 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu +3501 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cu +93 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cu +103 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mma.cuh +396 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cu +322 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cuh +3217 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cu +336 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cuh +12 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cu +595 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cuh +12 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cu +458 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cuh +11 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cu +68 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cu +49 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cu +94 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cu +189 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cuh +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cu +456 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cuh +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cu +31 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cu +283 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cuh +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cu +148 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cu +153 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cu +45 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cu +39 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs256-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs256-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-f16.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +78 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cu +47 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cu +279 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cuh +57 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cu +51 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/vecdotq.cuh +1135 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +15 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +243 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +140 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cu +199 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cuh +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +131 -0
- package/cpp/llama.cpp/ggml/src/ggml-impl.h +601 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +166 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/common.comp +112 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +58 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +25 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +30 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +31 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +31 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +38 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +39 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +44 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +69 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +51 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +33 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +35 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +140 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +106 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +73 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +28 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +84 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +21 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +53 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +19 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +23 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +72 -0
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +71 -0
- package/cpp/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +120 -0
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +618 -0
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.m +5916 -0
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.metal +6891 -0
- package/cpp/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +107 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +96 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +4966 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/add.cl +83 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/clamp.cl +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cpy.cl +184 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cvt.cl +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/diag_mask_inf.cl +58 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/embed_kernel.py +26 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gelu.cl +62 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle.cl +268 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle_general.cl +274 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/get_rows.cl +163 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f16.cl +57 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f32.cl +57 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul.cl +79 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mat_Ab_Bi_8x4.cl +139 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f16.cl +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32.cl +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl +94 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +84 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f32_f32.cl +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32.cl +192 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_16x_flat.cl +307 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_8x_flat.cl +265 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_8x_flat.cl +272 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_v.cl +254 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q6_k.cl +190 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/norm.cl +81 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/relu.cl +16 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rms_norm.cl +96 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rope.cl +721 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/scale.cl +16 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/silu.cl +30 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f16.cl +86 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f32.cl +86 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/transpose.cl +84 -0
- package/cpp/llama.cpp/ggml/src/ggml-opt.cpp +854 -0
- package/cpp/llama.cpp/ggml/src/ggml-quants.c +5232 -0
- package/cpp/llama.cpp/ggml/src/ggml-quants.h +100 -0
- package/cpp/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +9 -0
- package/cpp/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +1813 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +183 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/backend.hpp +37 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +350 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +39 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/common.cpp +83 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/common.hpp +493 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.cpp +197 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.cpp +100 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.cpp +596 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.hpp +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +701 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +11 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +753 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +1154 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +2957 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1559 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +75 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +70 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +311 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +4302 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.cpp +105 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.hpp +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +136 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +21 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +3030 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +33 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1081 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.cpp +474 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.hpp +26 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +46 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/presets.hpp +74 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/quants.hpp +61 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.cpp +362 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +264 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +13 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +23 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +73 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +1189 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +305 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +10 -0
- package/cpp/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
- package/cpp/llama.cpp/ggml/src/ggml-threading.h +14 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +202 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/cmake/host-toolchain.cmake.in +15 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +10502 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +29 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +29 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +51 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +69 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +41 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +49 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +105 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +23 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +51 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +242 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +31 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.comp +462 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.comp +699 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_head.comp +13 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +42 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +35 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +44 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +43 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +48 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +39 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +49 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +32 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +42 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +30 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +32 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +68 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +35 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +70 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +33 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +31 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +34 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +483 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +383 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +59 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +25 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +23 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.comp +64 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_head.comp +9 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.comp +76 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +33 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +41 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +66 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +100 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +41 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_split_k_reduce.comp +48 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +169 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.comp +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +82 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +79 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +90 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +90 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +88 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +118 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +154 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +130 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +132 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +136 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +167 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +130 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +868 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +441 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +442 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.comp +99 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +44 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +42 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +28 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +74 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +77 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +21 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +26 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +37 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +52 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +55 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.comp +58 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +60 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +43 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +43 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +47 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +24 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +26 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +173 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +50 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +17 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +29 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +37 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +20 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_bfloat16_support.comp +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat2_support.comp +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat_support.comp +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_integer_dot_support.comp +7 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +41 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/types.comp +1373 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +36 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +740 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv6.comp +87 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv7.comp +91 -0
- package/cpp/llama.cpp/ggml/src/ggml.c +6499 -0
- package/cpp/llama.cpp/ggml/src/gguf.cpp +1330 -0
- package/cpp/llama.cpp/gguf-py/LICENSE +21 -0
- package/cpp/llama.cpp/gguf-py/README.md +99 -0
- package/cpp/llama.cpp/gguf-py/examples/reader.py +49 -0
- package/cpp/llama.cpp/gguf-py/examples/writer.py +39 -0
- package/cpp/llama.cpp/gguf-py/gguf/__init__.py +9 -0
- package/cpp/llama.cpp/gguf-py/gguf/constants.py +2296 -0
- package/cpp/llama.cpp/gguf-py/gguf/gguf.py +15 -0
- package/cpp/llama.cpp/gguf-py/gguf/gguf_reader.py +367 -0
- package/cpp/llama.cpp/gguf-py/gguf/gguf_writer.py +1041 -0
- package/cpp/llama.cpp/gguf-py/gguf/lazy.py +223 -0
- package/cpp/llama.cpp/gguf-py/gguf/metadata.py +642 -0
- package/cpp/llama.cpp/gguf-py/gguf/py.typed +0 -0
- package/cpp/llama.cpp/gguf-py/gguf/quants.py +1269 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_convert_endian.py +182 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_dump.py +454 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_editor_gui.py +1610 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_hash.py +102 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_new_metadata.py +207 -0
- package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_set_metadata.py +95 -0
- package/cpp/llama.cpp/gguf-py/gguf/tensor_mapping.py +1172 -0
- package/cpp/llama.cpp/gguf-py/gguf/utility.py +264 -0
- package/cpp/llama.cpp/gguf-py/gguf/vocab.py +492 -0
- package/cpp/llama.cpp/gguf-py/pyproject.toml +43 -0
- package/cpp/llama.cpp/gguf-py/tests/__init__.py +1 -0
- package/cpp/llama.cpp/gguf-py/tests/test_metadata.py +238 -0
- package/cpp/llama.cpp/gguf-py/tests/test_quants.py +238 -0
- package/cpp/llama.cpp/grammars/README.md +382 -0
- package/cpp/llama.cpp/grammars/arithmetic.gbnf +6 -0
- package/cpp/llama.cpp/grammars/c.gbnf +42 -0
- package/cpp/llama.cpp/grammars/chess.gbnf +13 -0
- package/cpp/llama.cpp/grammars/english.gbnf +6 -0
- package/cpp/llama.cpp/grammars/japanese.gbnf +7 -0
- package/cpp/llama.cpp/grammars/json.gbnf +25 -0
- package/cpp/llama.cpp/grammars/json_arr.gbnf +34 -0
- package/cpp/llama.cpp/grammars/list.gbnf +4 -0
- package/cpp/llama.cpp/include/llama-cpp.h +30 -0
- package/cpp/llama.cpp/include/llama.h +1440 -0
- package/cpp/llama.cpp/licenses/LICENSE-curl +9 -0
- package/cpp/llama.cpp/licenses/LICENSE-httplib +21 -0
- package/cpp/llama.cpp/licenses/LICENSE-jsonhpp +21 -0
- package/cpp/llama.cpp/licenses/LICENSE-linenoise +26 -0
- package/cpp/llama.cpp/media/llama0-banner.png +0 -0
- package/cpp/llama.cpp/media/llama0-logo.png +0 -0
- package/cpp/llama.cpp/media/llama1-banner.png +0 -0
- package/cpp/llama.cpp/media/llama1-logo.png +0 -0
- package/cpp/llama.cpp/media/llama1-logo.svg +34 -0
- package/cpp/llama.cpp/media/matmul.png +0 -0
- package/cpp/llama.cpp/media/matmul.svg +1238 -0
- package/cpp/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +46 -0
- package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
- package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +112 -0
- package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.out +46 -0
- package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja +202 -0
- package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r7b-12-2024-tool_use.jinja +156 -0
- package/cpp/llama.cpp/models/templates/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use.jinja +152 -0
- package/cpp/llama.cpp/models/templates/NousResearch-Hermes-3-Llama-3.1-8B-tool_use.jinja +152 -0
- package/cpp/llama.cpp/models/templates/Qwen-Qwen2.5-7B-Instruct.jinja +54 -0
- package/cpp/llama.cpp/models/templates/README.md +22 -0
- package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Llama-8B.jinja +1 -0
- package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Qwen-32B.jinja +1 -0
- package/cpp/llama.cpp/models/templates/fireworks-ai-llama-3-firefunction-v2.jinja +57 -0
- package/cpp/llama.cpp/models/templates/google-gemma-2-2b-it.jinja +4 -0
- package/cpp/llama.cpp/models/templates/llama-cpp-deepseek-r1.jinja +76 -0
- package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.1.jinja +58 -0
- package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.2.jinja +287 -0
- package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja +109 -0
- package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.2-3B-Instruct.jinja +93 -0
- package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.3-70B-Instruct.jinja +109 -0
- package/cpp/llama.cpp/models/templates/microsoft-Phi-3.5-mini-instruct.jinja +8 -0
- package/cpp/llama.cpp/models/templates/mistralai-Mistral-Nemo-Instruct-2407.jinja +87 -0
- package/cpp/llama.cpp/mypy.ini +7 -0
- package/cpp/llama.cpp/pocs/CMakeLists.txt +14 -0
- package/cpp/llama.cpp/pocs/vdot/CMakeLists.txt +9 -0
- package/cpp/llama.cpp/pocs/vdot/q8dot.cpp +173 -0
- package/cpp/llama.cpp/pocs/vdot/vdot.cpp +311 -0
- package/cpp/llama.cpp/poetry.lock +1197 -0
- package/cpp/llama.cpp/prompts/LLM-questions.txt +49 -0
- package/cpp/llama.cpp/prompts/alpaca.txt +1 -0
- package/cpp/llama.cpp/prompts/assistant.txt +31 -0
- package/cpp/llama.cpp/prompts/chat-with-baichuan.txt +4 -0
- package/cpp/llama.cpp/prompts/chat-with-bob.txt +7 -0
- package/cpp/llama.cpp/prompts/chat-with-qwen.txt +1 -0
- package/cpp/llama.cpp/prompts/chat-with-vicuna-v0.txt +7 -0
- package/cpp/llama.cpp/prompts/chat-with-vicuna-v1.txt +7 -0
- package/cpp/llama.cpp/prompts/chat.txt +28 -0
- package/cpp/llama.cpp/prompts/dan-modified.txt +1 -0
- package/cpp/llama.cpp/prompts/dan.txt +1 -0
- package/cpp/llama.cpp/prompts/mnemonics.txt +93 -0
- package/cpp/llama.cpp/prompts/parallel-questions.txt +43 -0
- package/cpp/llama.cpp/prompts/reason-act.txt +18 -0
- package/cpp/llama.cpp/pyproject.toml +45 -0
- package/cpp/llama.cpp/pyrightconfig.json +22 -0
- package/cpp/llama.cpp/requirements/requirements-all.txt +15 -0
- package/cpp/llama.cpp/requirements/requirements-compare-llama-bench.txt +2 -0
- package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +3 -0
- package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +3 -0
- package/cpp/llama.cpp/requirements/requirements-convert_legacy_llama.txt +5 -0
- package/cpp/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +1 -0
- package/cpp/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +2 -0
- package/cpp/llama.cpp/requirements/requirements-gguf_editor_gui.txt +3 -0
- package/cpp/llama.cpp/requirements/requirements-pydantic.txt +3 -0
- package/cpp/llama.cpp/requirements/requirements-test-tokenizer-random.txt +1 -0
- package/cpp/llama.cpp/requirements/requirements-tool_bench.txt +12 -0
- package/cpp/llama.cpp/requirements.txt +13 -0
- package/cpp/llama.cpp/src/CMakeLists.txt +45 -0
- package/cpp/llama.cpp/src/llama-adapter.cpp +388 -0
- package/cpp/llama.cpp/src/llama-adapter.h +76 -0
- package/cpp/llama.cpp/src/llama-arch.cpp +1743 -0
- package/cpp/llama.cpp/src/llama-arch.h +437 -0
- package/cpp/llama.cpp/src/llama-batch.cpp +372 -0
- package/cpp/llama.cpp/src/llama-batch.h +89 -0
- package/cpp/llama.cpp/src/llama-chat.cpp +663 -0
- package/cpp/llama.cpp/src/llama-chat.h +58 -0
- package/cpp/llama.cpp/src/llama-context.cpp +2459 -0
- package/cpp/llama.cpp/src/llama-context.h +246 -0
- package/cpp/llama.cpp/src/llama-cparams.cpp +1 -0
- package/cpp/llama.cpp/src/llama-cparams.h +39 -0
- package/cpp/llama.cpp/src/llama-grammar.cpp +1219 -0
- package/cpp/llama.cpp/src/llama-grammar.h +173 -0
- package/cpp/llama.cpp/src/llama-graph.cpp +1713 -0
- package/cpp/llama.cpp/src/llama-graph.h +595 -0
- package/cpp/llama.cpp/src/llama-hparams.cpp +79 -0
- package/cpp/llama.cpp/src/llama-hparams.h +161 -0
- package/cpp/llama.cpp/src/llama-impl.cpp +167 -0
- package/cpp/llama.cpp/src/llama-impl.h +61 -0
- package/cpp/llama.cpp/src/llama-io.cpp +15 -0
- package/cpp/llama.cpp/src/llama-io.h +35 -0
- package/cpp/llama.cpp/src/llama-kv-cache.cpp +2486 -0
- package/cpp/llama.cpp/src/llama-kv-cache.h +405 -0
- package/cpp/llama.cpp/src/llama-memory.cpp +1 -0
- package/cpp/llama.cpp/src/llama-memory.h +31 -0
- package/cpp/llama.cpp/src/llama-mmap.cpp +600 -0
- package/cpp/llama.cpp/src/llama-mmap.h +68 -0
- package/cpp/llama.cpp/src/llama-model-loader.cpp +1133 -0
- package/cpp/llama.cpp/src/llama-model-loader.h +169 -0
- package/cpp/llama.cpp/src/llama-model.cpp +13453 -0
- package/cpp/llama.cpp/src/llama-model.h +420 -0
- package/cpp/llama.cpp/src/llama-quant.cpp +964 -0
- package/cpp/llama.cpp/src/llama-quant.h +1 -0
- package/cpp/llama.cpp/src/llama-sampling.cpp +2575 -0
- package/cpp/llama.cpp/src/llama-sampling.h +32 -0
- package/cpp/llama.cpp/src/llama-vocab.cpp +3313 -0
- package/cpp/llama.cpp/src/llama-vocab.h +125 -0
- package/cpp/llama.cpp/src/llama.cpp +340 -0
- package/cpp/llama.cpp/src/unicode-data.cpp +7034 -0
- package/cpp/llama.cpp/src/unicode-data.h +20 -0
- package/cpp/llama.cpp/src/unicode.cpp +849 -0
- package/cpp/llama.cpp/src/unicode.h +66 -0
- package/cpp/rn-completion.cpp +431 -0
- package/cpp/rn-llama.hpp +60 -0
- package/cpp/rn-utils.hpp +331 -0
- package/ios/OnLoad.mm +22 -0
- package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec-generated.mm +64 -0
- package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec.h +251 -0
- package/ios/generated/RNLlamaCppSpecJSI-generated.cpp +42 -0
- package/ios/generated/RNLlamaCppSpecJSI.h +336 -0
- package/ios/include/chat.h +135 -0
- package/ios/include/common/base64.hpp +392 -0
- package/ios/include/common/json.hpp +24766 -0
- package/ios/include/common/minja/chat-template.hpp +537 -0
- package/ios/include/common/minja/minja.hpp +2941 -0
- package/ios/include/common.h +668 -0
- package/ios/include/json-schema-to-grammar.h +21 -0
- package/ios/include/llama-cpp.h +30 -0
- package/ios/include/llama.h +1440 -0
- package/ios/include/log.h +103 -0
- package/ios/include/ngram-cache.h +101 -0
- package/ios/include/sampling.h +107 -0
- package/ios/include/speculative.h +28 -0
- package/ios/libs/llama.xcframework/Info.plist +135 -0
- package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Info.plist +36 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Info.plist +36 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3442 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Resources/Info.plist +32 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Resources/Info.plist +32 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Resources/Info.plist +32 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Info.plist +35 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Info.plist +35 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4528 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Info.plist +32 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4549 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3470 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Info.plist +32 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/lib/module/NativeRNLlamaCpp.js +35 -0
- package/lib/module/NativeRNLlamaCpp.js.map +1 -0
- package/lib/module/index.js +20 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeRNLlamaCpp.d.ts +222 -0
- package/lib/typescript/src/NativeRNLlamaCpp.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +161 -0
- package/react-native.config.js +15 -0
- package/src/NativeRNLlamaCpp.ts +282 -0
- package/src/index.tsx +54 -0
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
#include "LlamaCppModel.h"
|
|
2
|
+
#include <jsi/jsi.h>
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstdlib>
|
|
6
|
+
#include <ctime>
|
|
7
|
+
#include <chrono>
|
|
8
|
+
#include <fstream>
|
|
9
|
+
#include <iostream>
|
|
10
|
+
#include <random>
|
|
11
|
+
#include <sstream>
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <vector>
|
|
15
|
+
#include <mutex>
|
|
16
|
+
#include <condition_variable>
|
|
17
|
+
#include <memory>
|
|
18
|
+
|
|
19
|
+
// Include rn-completion integration
|
|
20
|
+
#include "rn-utils.hpp"
|
|
21
|
+
#include "rn-llama.hpp"
|
|
22
|
+
|
|
23
|
+
// Include llama.cpp headers
|
|
24
|
+
#include "llama.h"
|
|
25
|
+
#include "chat.h"
|
|
26
|
+
#include "common.h"
|
|
27
|
+
#include "json-schema-to-grammar.h"
|
|
28
|
+
#include "sampling.h"
|
|
29
|
+
|
|
30
|
+
// System utilities
|
|
31
|
+
#include "SystemUtils.h"
|
|
32
|
+
|
|
33
|
+
// Remove the global 'using namespace' to avoid namespace conflicts
|
|
34
|
+
// using namespace facebook::react;
|
|
35
|
+
|
|
36
|
+
namespace facebook::react {
|
|
37
|
+
|
|
38
|
+
LlamaCppModel::LlamaCppModel(rn_llama_context* rn_ctx)
|
|
39
|
+
: rn_ctx_(rn_ctx), should_stop_completion_(false), is_predicting_(false) {
|
|
40
|
+
initHelpers();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void LlamaCppModel::initHelpers() {
|
|
44
|
+
// No longer need tool handler initialization
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
LlamaCppModel::~LlamaCppModel() {
|
|
48
|
+
// Note: We don't automatically release resources here
|
|
49
|
+
// as the user should call release() explicitly
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void LlamaCppModel::release() {
|
|
53
|
+
// Cancel any ongoing predictions
|
|
54
|
+
if (is_predicting_) {
|
|
55
|
+
should_stop_completion_ = true;
|
|
56
|
+
|
|
57
|
+
// Optionally wait a bit for completion to stop
|
|
58
|
+
int retry = 0;
|
|
59
|
+
while (is_predicting_ && retry < 10) {
|
|
60
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
61
|
+
retry++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Clean up our resources
|
|
66
|
+
if (rn_ctx_) {
|
|
67
|
+
if (rn_ctx_->ctx) {
|
|
68
|
+
llama_free(rn_ctx_->ctx);
|
|
69
|
+
rn_ctx_->ctx = nullptr;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (rn_ctx_->model) {
|
|
73
|
+
llama_model_free(rn_ctx_->model);
|
|
74
|
+
rn_ctx_->model = nullptr;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Note: rn_ctx_ itself is owned by the module, so we don't delete it here
|
|
78
|
+
rn_ctx_ = nullptr;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
int32_t LlamaCppModel::getVocabSize() const {
|
|
83
|
+
if (!rn_ctx_ || !rn_ctx_->model) {
|
|
84
|
+
throw std::runtime_error("Model not loaded");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return llama_vocab_n_tokens(rn_ctx_->vocab);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
int32_t LlamaCppModel::getContextSize() const {
|
|
91
|
+
if (!rn_ctx_ || !rn_ctx_->ctx) {
|
|
92
|
+
throw std::runtime_error("Context not initialized");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return llama_n_ctx(rn_ctx_->ctx);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bool LlamaCppModel::shouldStopCompletion() const {
|
|
99
|
+
return should_stop_completion_;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void LlamaCppModel::setShouldStopCompletion(bool value) {
|
|
103
|
+
should_stop_completion_ = value;
|
|
104
|
+
if (value) {
|
|
105
|
+
// Reset the predicting flag when stopping completion
|
|
106
|
+
is_predicting_ = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Parse the CompletionOptions from a JS object
|
|
111
|
+
CompletionOptions LlamaCppModel::parseCompletionOptions(jsi::Runtime& rt, const jsi::Object& obj) {
|
|
112
|
+
CompletionOptions options;
|
|
113
|
+
|
|
114
|
+
// Extract basic options
|
|
115
|
+
if (obj.hasProperty(rt, "prompt") && !obj.getProperty(rt, "prompt").isUndefined()) {
|
|
116
|
+
options.prompt = obj.getProperty(rt, "prompt").asString(rt).utf8(rt);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Parse sampling parameters
|
|
120
|
+
if (obj.hasProperty(rt, "temperature") && !obj.getProperty(rt, "temperature").isUndefined()) {
|
|
121
|
+
options.temperature = obj.getProperty(rt, "temperature").asNumber();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (obj.hasProperty(rt, "top_p") && !obj.getProperty(rt, "top_p").isUndefined()) {
|
|
125
|
+
options.top_p = obj.getProperty(rt, "top_p").asNumber();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (obj.hasProperty(rt, "top_k") && !obj.getProperty(rt, "top_k").isUndefined()) {
|
|
129
|
+
options.top_k = obj.getProperty(rt, "top_k").asNumber();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (obj.hasProperty(rt, "min_p") && !obj.getProperty(rt, "min_p").isUndefined()) {
|
|
133
|
+
options.min_p = obj.getProperty(rt, "min_p").asNumber();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (obj.hasProperty(rt, "n_predict") && !obj.getProperty(rt, "n_predict").isUndefined()) {
|
|
137
|
+
options.n_predict = obj.getProperty(rt, "n_predict").asNumber();
|
|
138
|
+
} else if (obj.hasProperty(rt, "max_tokens") && !obj.getProperty(rt, "max_tokens").isUndefined()) {
|
|
139
|
+
options.n_predict = obj.getProperty(rt, "max_tokens").asNumber();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (obj.hasProperty(rt, "n_keep") && !obj.getProperty(rt, "n_keep").isUndefined()) {
|
|
143
|
+
options.n_keep = obj.getProperty(rt, "n_keep").asNumber();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Extract seed
|
|
147
|
+
if (obj.hasProperty(rt, "seed") && !obj.getProperty(rt, "seed").isUndefined()) {
|
|
148
|
+
options.seed = obj.getProperty(rt, "seed").asNumber();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Extract stop sequences
|
|
152
|
+
if (obj.hasProperty(rt, "stop") && !obj.getProperty(rt, "stop").isUndefined()) {
|
|
153
|
+
auto stopVal = obj.getProperty(rt, "stop");
|
|
154
|
+
if (stopVal.isString()) {
|
|
155
|
+
options.stop.push_back(stopVal.asString(rt).utf8(rt));
|
|
156
|
+
} else if (stopVal.isObject() && stopVal.getObject(rt).isArray(rt)) {
|
|
157
|
+
auto stopArr = stopVal.getObject(rt).getArray(rt);
|
|
158
|
+
for (size_t i = 0; i < stopArr.size(rt); i++) {
|
|
159
|
+
auto item = stopArr.getValueAtIndex(rt, i);
|
|
160
|
+
if (item.isString()) {
|
|
161
|
+
options.stop.push_back(item.asString(rt).utf8(rt));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Extract grammar
|
|
168
|
+
if (obj.hasProperty(rt, "grammar") && !obj.getProperty(rt, "grammar").isUndefined()) {
|
|
169
|
+
options.grammar = obj.getProperty(rt, "grammar").asString(rt).utf8(rt);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (obj.hasProperty(rt, "ignore_eos") && !obj.getProperty(rt, "ignore_eos").isUndefined()) {
|
|
173
|
+
options.ignore_eos = obj.getProperty(rt, "ignore_eos").asBool();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (obj.hasProperty(rt, "stream") && !obj.getProperty(rt, "stream").isUndefined()) {
|
|
177
|
+
options.stream = obj.getProperty(rt, "stream").asBool();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Extract and parse messages if present (for chat completion)
|
|
181
|
+
if (obj.hasProperty(rt, "messages") && obj.getProperty(rt, "messages").isObject()) {
|
|
182
|
+
auto messagesVal = obj.getProperty(rt, "messages").getObject(rt);
|
|
183
|
+
if (messagesVal.isArray(rt)) {
|
|
184
|
+
json messagesJson = json::array();
|
|
185
|
+
auto messagesArr = messagesVal.getArray(rt);
|
|
186
|
+
|
|
187
|
+
// Convert JSI messages to JSON format
|
|
188
|
+
for (size_t i = 0; i < messagesArr.size(rt); i++) {
|
|
189
|
+
auto msgVal = messagesArr.getValueAtIndex(rt, i);
|
|
190
|
+
if (msgVal.isObject()) {
|
|
191
|
+
auto msgObj = msgVal.getObject(rt);
|
|
192
|
+
|
|
193
|
+
json msgJson = json::object();
|
|
194
|
+
if (msgObj.hasProperty(rt, "role")) {
|
|
195
|
+
msgJson["role"] = msgObj.getProperty(rt, "role").asString(rt).utf8(rt);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (msgObj.hasProperty(rt, "content")) {
|
|
199
|
+
auto contentVal = msgObj.getProperty(rt, "content");
|
|
200
|
+
if (contentVal.isString()) {
|
|
201
|
+
msgJson["content"] = contentVal.asString(rt).utf8(rt);
|
|
202
|
+
} else if (contentVal.isNull()) {
|
|
203
|
+
msgJson["content"] = nullptr;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (msgObj.hasProperty(rt, "name")) {
|
|
208
|
+
msgJson["name"] = msgObj.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Handle tool_calls if present
|
|
212
|
+
if (msgObj.hasProperty(rt, "tool_calls") && msgObj.getProperty(rt, "tool_calls").isObject()) {
|
|
213
|
+
auto toolCallsVal = msgObj.getProperty(rt, "tool_calls").getObject(rt);
|
|
214
|
+
if (toolCallsVal.isArray(rt)) {
|
|
215
|
+
auto toolCallsArr = toolCallsVal.getArray(rt);
|
|
216
|
+
json toolCallsJson = json::array();
|
|
217
|
+
|
|
218
|
+
for (size_t j = 0; j < toolCallsArr.size(rt); j++) {
|
|
219
|
+
auto tcVal = toolCallsArr.getValueAtIndex(rt, j);
|
|
220
|
+
if (tcVal.isObject()) {
|
|
221
|
+
auto tcObj = tcVal.getObject(rt);
|
|
222
|
+
json tcJson = json::object();
|
|
223
|
+
|
|
224
|
+
if (tcObj.hasProperty(rt, "id")) {
|
|
225
|
+
tcJson["id"] = tcObj.getProperty(rt, "id").asString(rt).utf8(rt);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (tcObj.hasProperty(rt, "type")) {
|
|
229
|
+
tcJson["type"] = tcObj.getProperty(rt, "type").asString(rt).utf8(rt);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (tcObj.hasProperty(rt, "function") && tcObj.getProperty(rt, "function").isObject()) {
|
|
233
|
+
auto fnObj = tcObj.getProperty(rt, "function").getObject(rt);
|
|
234
|
+
json fnJson = json::object();
|
|
235
|
+
|
|
236
|
+
if (fnObj.hasProperty(rt, "name")) {
|
|
237
|
+
fnJson["name"] = fnObj.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (fnObj.hasProperty(rt, "parameters")) {
|
|
241
|
+
// For parameters, parse it as a JSON object
|
|
242
|
+
auto paramsVal = fnObj.getProperty(rt, "parameters");
|
|
243
|
+
if (paramsVal.isObject()) {
|
|
244
|
+
try {
|
|
245
|
+
// Convert the JSI object directly to nlohmann::json
|
|
246
|
+
auto paramsObj = paramsVal.getObject(rt);
|
|
247
|
+
json fnParams = json::object();
|
|
248
|
+
|
|
249
|
+
// Extract properties directly from the JSI object
|
|
250
|
+
jsi::Array propNames = paramsObj.getPropertyNames(rt);
|
|
251
|
+
size_t propCount = propNames.size(rt);
|
|
252
|
+
for (size_t i = 0; i < propCount; i++) {
|
|
253
|
+
jsi::String propName = propNames.getValueAtIndex(rt, i).asString(rt);
|
|
254
|
+
std::string key = propName.utf8(rt);
|
|
255
|
+
auto value = paramsObj.getProperty(rt, propName);
|
|
256
|
+
|
|
257
|
+
if (value.isString()) {
|
|
258
|
+
fnParams[key] = value.asString(rt).utf8(rt);
|
|
259
|
+
} else if (value.isNumber()) {
|
|
260
|
+
fnParams[key] = value.asNumber();
|
|
261
|
+
} else if (value.isBool()) {
|
|
262
|
+
fnParams[key] = value.getBool();
|
|
263
|
+
} else if (value.isNull()) {
|
|
264
|
+
fnParams[key] = nullptr;
|
|
265
|
+
} else if (value.isObject()) {
|
|
266
|
+
if (value.getObject(rt).isArray(rt)) {
|
|
267
|
+
fnParams[key] = json::array();
|
|
268
|
+
} else {
|
|
269
|
+
fnParams[key] = json::object();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
fnJson["parameters"] = fnParams;
|
|
275
|
+
} catch (const std::exception&) {
|
|
276
|
+
fnJson["parameters"] = json::object();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
tcJson["function"] = fnJson;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
toolCallsJson.push_back(tcJson);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
msgJson["tool_calls"] = toolCallsJson;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Handle tool_call_id if present
|
|
293
|
+
if (msgObj.hasProperty(rt, "tool_call_id")) {
|
|
294
|
+
msgJson["tool_call_id"] = msgObj.getProperty(rt, "tool_call_id").asString(rt).utf8(rt);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
messagesJson.push_back(msgJson);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
options.messages = messagesJson;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Extract and parse tools if present
|
|
306
|
+
if (obj.hasProperty(rt, "tools") && obj.getProperty(rt, "tools").isObject()) {
|
|
307
|
+
auto toolsVal = obj.getProperty(rt, "tools").getObject(rt);
|
|
308
|
+
if (toolsVal.isArray(rt)) {
|
|
309
|
+
auto toolsArr = toolsVal.getArray(rt);
|
|
310
|
+
json toolsJson = json::array();
|
|
311
|
+
|
|
312
|
+
for (size_t i = 0; i < toolsArr.size(rt); i++) {
|
|
313
|
+
auto toolVal = toolsArr.getValueAtIndex(rt, i);
|
|
314
|
+
if (toolVal.isObject()) {
|
|
315
|
+
auto toolObj = toolVal.getObject(rt);
|
|
316
|
+
json toolJson = json::object();
|
|
317
|
+
|
|
318
|
+
if (toolObj.hasProperty(rt, "type")) {
|
|
319
|
+
toolJson["type"] = toolObj.getProperty(rt, "type").asString(rt).utf8(rt);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (toolObj.hasProperty(rt, "function") && toolObj.getProperty(rt, "function").isObject()) {
|
|
323
|
+
auto fnObj = toolObj.getProperty(rt, "function").getObject(rt);
|
|
324
|
+
json fnJson = json::object();
|
|
325
|
+
|
|
326
|
+
if (fnObj.hasProperty(rt, "name")) {
|
|
327
|
+
fnJson["name"] = fnObj.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (fnObj.hasProperty(rt, "description")) {
|
|
331
|
+
fnJson["description"] = fnObj.getProperty(rt, "description").asString(rt).utf8(rt);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (fnObj.hasProperty(rt, "parameters")) {
|
|
335
|
+
// For parameters, parse it as a JSON object
|
|
336
|
+
auto paramsVal = fnObj.getProperty(rt, "parameters");
|
|
337
|
+
if (paramsVal.isObject()) {
|
|
338
|
+
try {
|
|
339
|
+
// Convert the JSI object directly to nlohmann::json
|
|
340
|
+
auto paramsObj = paramsVal.getObject(rt);
|
|
341
|
+
json fnParams = json::object();
|
|
342
|
+
|
|
343
|
+
// Extract properties directly from the JSI object
|
|
344
|
+
jsi::Array propNames = paramsObj.getPropertyNames(rt);
|
|
345
|
+
size_t propCount = propNames.size(rt);
|
|
346
|
+
for (size_t i = 0; i < propCount; i++) {
|
|
347
|
+
jsi::String propName = propNames.getValueAtIndex(rt, i).asString(rt);
|
|
348
|
+
std::string key = propName.utf8(rt);
|
|
349
|
+
auto value = paramsObj.getProperty(rt, propName);
|
|
350
|
+
|
|
351
|
+
if (value.isString()) {
|
|
352
|
+
fnParams[key] = value.asString(rt).utf8(rt);
|
|
353
|
+
} else if (value.isNumber()) {
|
|
354
|
+
fnParams[key] = value.asNumber();
|
|
355
|
+
} else if (value.isBool()) {
|
|
356
|
+
fnParams[key] = value.getBool();
|
|
357
|
+
} else if (value.isNull()) {
|
|
358
|
+
fnParams[key] = nullptr;
|
|
359
|
+
} else if (value.isObject()) {
|
|
360
|
+
// For nested objects, we use a simplified approach
|
|
361
|
+
if (value.getObject(rt).isArray(rt)) {
|
|
362
|
+
fnParams[key] = json::array();
|
|
363
|
+
} else {
|
|
364
|
+
fnParams[key] = json::object();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
fnJson["parameters"] = fnParams;
|
|
370
|
+
} catch (const std::exception&) {
|
|
371
|
+
fnJson["parameters"] = json::object();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
toolJson["function"] = fnJson;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
toolsJson.push_back(toolJson);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
options.tools = toolsJson;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Extract tool_choice if present
|
|
388
|
+
if (obj.hasProperty(rt, "tool_choice") && !obj.getProperty(rt, "tool_choice").isUndefined()) {
|
|
389
|
+
auto toolChoiceVal = obj.getProperty(rt, "tool_choice");
|
|
390
|
+
if (toolChoiceVal.isString()) {
|
|
391
|
+
options.tool_choice = toolChoiceVal.asString(rt).utf8(rt);
|
|
392
|
+
} else if (toolChoiceVal.isObject()) {
|
|
393
|
+
// Handle the case where tool_choice is an object with "type": "function", etc.
|
|
394
|
+
options.tool_choice = "required"; // Default to "required" if a specific tool is selected
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Extract chat template name if provided
|
|
399
|
+
if (obj.hasProperty(rt, "chat_template") && !obj.getProperty(rt, "chat_template").isUndefined()) {
|
|
400
|
+
options.chat_template = obj.getProperty(rt, "chat_template").asString(rt).utf8(rt);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return options;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Modify the completion function to use this helper
|
|
407
|
+
CompletionResult LlamaCppModel::completion(const CompletionOptions& options, std::function<void(jsi::Runtime&, const char*)> partialCallback, jsi::Runtime* runtime) {
|
|
408
|
+
if (!rn_ctx_ || !rn_ctx_->model || !rn_ctx_->ctx) {
|
|
409
|
+
CompletionResult result;
|
|
410
|
+
result.content = "";
|
|
411
|
+
result.success = false;
|
|
412
|
+
result.error_msg = "Model or context not initialized";
|
|
413
|
+
result.error_type = RN_ERROR_MODEL_LOAD;
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Lock the mutex during completion to avoid concurrent accesses
|
|
418
|
+
std::lock_guard<std::mutex> lock(rn_ctx_->mutex);
|
|
419
|
+
|
|
420
|
+
// Clear the context KV cache
|
|
421
|
+
llama_kv_self_clear(rn_ctx_->ctx);
|
|
422
|
+
|
|
423
|
+
// Store original sampling parameters to restore later
|
|
424
|
+
float orig_temp = rn_ctx_->params.sampling.temp;
|
|
425
|
+
float orig_top_p = rn_ctx_->params.sampling.top_p;
|
|
426
|
+
float orig_top_k = rn_ctx_->params.sampling.top_k;
|
|
427
|
+
float orig_min_p = rn_ctx_->params.sampling.min_p;
|
|
428
|
+
int orig_n_predict = rn_ctx_->params.n_predict;
|
|
429
|
+
|
|
430
|
+
// Set sampling parameters from options
|
|
431
|
+
rn_ctx_->params.sampling.temp = options.temperature;
|
|
432
|
+
rn_ctx_->params.sampling.top_p = options.top_p;
|
|
433
|
+
rn_ctx_->params.sampling.top_k = options.top_k;
|
|
434
|
+
rn_ctx_->params.sampling.min_p = options.min_p;
|
|
435
|
+
rn_ctx_->params.n_predict = options.n_predict;
|
|
436
|
+
|
|
437
|
+
// Check for a partial callback
|
|
438
|
+
auto callback_adapter = [&partialCallback, runtime](const std::string& token, bool is_done) -> bool {
|
|
439
|
+
if (partialCallback && runtime && !is_done) {
|
|
440
|
+
partialCallback(*runtime, token.c_str());
|
|
441
|
+
}
|
|
442
|
+
return true;
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// Run the completion based on whether we have messages or prompt
|
|
446
|
+
CompletionResult result;
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
// Set the predicting flag to prevent interruption
|
|
450
|
+
is_predicting_ = true;
|
|
451
|
+
should_stop_completion_ = false;
|
|
452
|
+
|
|
453
|
+
if (!options.messages.empty()) {
|
|
454
|
+
// Chat completion (with messages)
|
|
455
|
+
result = run_chat_completion(rn_ctx_, options, callback_adapter);
|
|
456
|
+
} else {
|
|
457
|
+
// Regular completion (with prompt)
|
|
458
|
+
result = run_completion(rn_ctx_, options, callback_adapter);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Reset the predicting flag
|
|
462
|
+
is_predicting_ = false;
|
|
463
|
+
} catch (const std::exception& e) {
|
|
464
|
+
is_predicting_ = false;
|
|
465
|
+
result.success = false;
|
|
466
|
+
result.error_msg = std::string("Completion failed: ") + e.what();
|
|
467
|
+
result.error_type = RN_ERROR_INFERENCE;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Restore original parameters
|
|
471
|
+
rn_ctx_->params.sampling.temp = orig_temp;
|
|
472
|
+
rn_ctx_->params.sampling.top_p = orig_top_p;
|
|
473
|
+
rn_ctx_->params.sampling.top_k = orig_top_k;
|
|
474
|
+
rn_ctx_->params.sampling.min_p = orig_min_p;
|
|
475
|
+
rn_ctx_->params.n_predict = orig_n_predict;
|
|
476
|
+
|
|
477
|
+
return result;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Helper to convert from the rn-utils CompletionResult to a JSI object
|
|
481
|
+
jsi::Object LlamaCppModel::completionResultToJsi(jsi::Runtime& rt, const CompletionResult& result) {
|
|
482
|
+
jsi::Object jsResult(rt);
|
|
483
|
+
|
|
484
|
+
// Check if this is a chat completion
|
|
485
|
+
if (!result.chat_response.empty()) {
|
|
486
|
+
// For chat completions, convert the JSON response directly to JSI
|
|
487
|
+
jsi::Object chatResponse = jsonToJsi(rt, result.chat_response).asObject(rt);
|
|
488
|
+
|
|
489
|
+
// Add tool_calls as a top-level property for compatibility with clients
|
|
490
|
+
// that expect tool_calls at the top level rather than under choices[0].message
|
|
491
|
+
if (result.chat_response.contains("choices") &&
|
|
492
|
+
!result.chat_response["choices"].empty() &&
|
|
493
|
+
result.chat_response["choices"][0].contains("message") &&
|
|
494
|
+
result.chat_response["choices"][0]["message"].contains("tool_calls")) {
|
|
495
|
+
|
|
496
|
+
// Always add tool_calls to the top level (don't check if it exists)
|
|
497
|
+
chatResponse.setProperty(rt, "tool_calls",
|
|
498
|
+
jsonToJsi(rt, result.chat_response["choices"][0]["message"]["tool_calls"]));
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
return chatResponse;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// Standard completion result
|
|
505
|
+
jsResult.setProperty(rt, "content", jsi::String::createFromUtf8(rt, result.content));
|
|
506
|
+
jsResult.setProperty(rt, "timings", jsi::Object(rt));
|
|
507
|
+
jsResult.setProperty(rt, "success", jsi::Value(result.success));
|
|
508
|
+
jsResult.setProperty(rt, "promptTokens", jsi::Value(result.n_prompt_tokens));
|
|
509
|
+
jsResult.setProperty(rt, "completionTokens", jsi::Value(result.n_predicted_tokens));
|
|
510
|
+
|
|
511
|
+
if (!result.success) {
|
|
512
|
+
jsResult.setProperty(rt, "error", jsi::String::createFromUtf8(rt, result.error_msg));
|
|
513
|
+
jsResult.setProperty(rt, "errorType", jsi::Value((int)result.error_type));
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return jsResult;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Convert a JSON object to a JSI value
|
|
520
|
+
jsi::Value LlamaCppModel::jsonToJsi(jsi::Runtime& rt, const json& j) {
|
|
521
|
+
if (j.is_null()) {
|
|
522
|
+
return jsi::Value::null();
|
|
523
|
+
} else if (j.is_boolean()) {
|
|
524
|
+
return jsi::Value(j.get<bool>());
|
|
525
|
+
} else if (j.is_number_integer()) {
|
|
526
|
+
return jsi::Value(j.get<int>());
|
|
527
|
+
} else if (j.is_number_float()) {
|
|
528
|
+
return jsi::Value(j.get<double>());
|
|
529
|
+
} else if (j.is_string()) {
|
|
530
|
+
return jsi::String::createFromUtf8(rt, j.get<std::string>());
|
|
531
|
+
} else if (j.is_array()) {
|
|
532
|
+
jsi::Array array(rt, j.size());
|
|
533
|
+
for (size_t i = 0; i < j.size(); i++) {
|
|
534
|
+
array.setValueAtIndex(rt, i, jsonToJsi(rt, j[i]));
|
|
535
|
+
}
|
|
536
|
+
return array;
|
|
537
|
+
} else if (j.is_object()) {
|
|
538
|
+
jsi::Object object(rt);
|
|
539
|
+
for (const auto& item : j.items()) {
|
|
540
|
+
object.setProperty(rt, item.key().c_str(), jsonToJsi(rt, item.value()));
|
|
541
|
+
}
|
|
542
|
+
return object;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Default case (shouldn't happen)
|
|
546
|
+
return jsi::Value::undefined();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// JSI method for completions
|
|
550
|
+
jsi::Value LlamaCppModel::completionJsi(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
|
551
|
+
if (count < 1 || !args[0].isObject()) {
|
|
552
|
+
throw jsi::JSError(rt, "completion requires an options object");
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Create partial callback function for token streaming
|
|
556
|
+
std::function<void(jsi::Runtime&, const char*)> partialCallback = nullptr;
|
|
557
|
+
|
|
558
|
+
if (count > 1 && args[1].isObject() && args[1].getObject(rt).isFunction(rt)) {
|
|
559
|
+
auto callbackFn = std::make_shared<jsi::Function>(args[1].getObject(rt).getFunction(rt));
|
|
560
|
+
partialCallback = [callbackFn](jsi::Runtime& rt, const char* token) {
|
|
561
|
+
jsi::Object data(rt);
|
|
562
|
+
data.setProperty(rt, "token", jsi::String::createFromUtf8(rt, token));
|
|
563
|
+
callbackFn->call(rt, data);
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
try {
|
|
568
|
+
// Parse options from JSI object
|
|
569
|
+
CompletionOptions options = parseCompletionOptions(rt, args[0].getObject(rt));
|
|
570
|
+
|
|
571
|
+
// Set streaming flag based on callback presence
|
|
572
|
+
options.stream = (partialCallback != nullptr);
|
|
573
|
+
|
|
574
|
+
// Call our C++ completion method which properly initializes rn_llama_context
|
|
575
|
+
CompletionResult result = completion(options, partialCallback, &rt);
|
|
576
|
+
|
|
577
|
+
// Convert the result to a JSI object using our helper
|
|
578
|
+
return completionResultToJsi(rt, result);
|
|
579
|
+
} catch (const std::exception& e) {
|
|
580
|
+
throw jsi::JSError(rt, e.what());
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
jsi::Value LlamaCppModel::tokenizeJsi(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
|
585
|
+
if (count < 1 || !args[0].isObject()) {
|
|
586
|
+
throw jsi::JSError(rt, "tokenize requires an options object with 'content' field");
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
try {
|
|
590
|
+
jsi::Object options = args[0].getObject(rt);
|
|
591
|
+
|
|
592
|
+
// Extract required content parameter
|
|
593
|
+
if (!options.hasProperty(rt, "content") || !options.getProperty(rt, "content").isString()) {
|
|
594
|
+
throw jsi::JSError(rt, "tokenize requires a 'content' string field");
|
|
595
|
+
}
|
|
596
|
+
std::string content = options.getProperty(rt, "content").getString(rt).utf8(rt);
|
|
597
|
+
|
|
598
|
+
// Extract optional parameters using SystemUtils helpers
|
|
599
|
+
bool add_special = false;
|
|
600
|
+
bool with_pieces = false;
|
|
601
|
+
SystemUtils::setIfExists(rt, options, "add_special", add_special);
|
|
602
|
+
SystemUtils::setIfExists(rt, options, "with_pieces", with_pieces);
|
|
603
|
+
|
|
604
|
+
// Parameter for llama_tokenize
|
|
605
|
+
bool parse_special = true;
|
|
606
|
+
|
|
607
|
+
if (!rn_ctx_ || !rn_ctx_->model || !rn_ctx_->vocab) {
|
|
608
|
+
throw std::runtime_error("Model not loaded or vocab not available");
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Use the common_token_to_piece function from llama.cpp for more consistent tokenization
|
|
612
|
+
std::vector<llama_token> tokens;
|
|
613
|
+
|
|
614
|
+
if (content.empty()) {
|
|
615
|
+
// Handle empty content specially
|
|
616
|
+
tokens = {};
|
|
617
|
+
} else {
|
|
618
|
+
// First determine how many tokens are needed
|
|
619
|
+
int n_tokens = llama_tokenize(rn_ctx_->vocab, content.c_str(), content.length(), nullptr, 0, add_special, parse_special);
|
|
620
|
+
if (n_tokens < 0) {
|
|
621
|
+
n_tokens = -n_tokens; // Convert negative value (indicates insufficient buffer)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// Allocate buffer and do the actual tokenization
|
|
625
|
+
tokens.resize(n_tokens);
|
|
626
|
+
n_tokens = llama_tokenize(rn_ctx_->vocab, content.c_str(), content.length(), tokens.data(), tokens.size(), add_special, parse_special);
|
|
627
|
+
|
|
628
|
+
if (n_tokens < 0) {
|
|
629
|
+
throw std::runtime_error("Tokenization failed: insufficient buffer");
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Resize to the actual number of tokens used
|
|
633
|
+
tokens.resize(n_tokens);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Create result object with tokens array
|
|
637
|
+
jsi::Object result(rt);
|
|
638
|
+
jsi::Array tokensArray(rt, tokens.size());
|
|
639
|
+
|
|
640
|
+
// Fill the tokens array with token IDs and text
|
|
641
|
+
for (size_t i = 0; i < tokens.size(); i++) {
|
|
642
|
+
if (with_pieces) {
|
|
643
|
+
// Create an object with ID and piece text
|
|
644
|
+
jsi::Object tokenObj(rt);
|
|
645
|
+
tokenObj.setProperty(rt, "id", jsi::Value((int)tokens[i]));
|
|
646
|
+
|
|
647
|
+
// Get the text piece for this token
|
|
648
|
+
std::string piece = common_token_to_piece(rn_ctx_->vocab, tokens[i]);
|
|
649
|
+
tokenObj.setProperty(rt, "text", jsi::String::createFromUtf8(rt, piece));
|
|
650
|
+
|
|
651
|
+
tokensArray.setValueAtIndex(rt, i, tokenObj);
|
|
652
|
+
} else {
|
|
653
|
+
// Just add the token ID
|
|
654
|
+
tokensArray.setValueAtIndex(rt, i, jsi::Value((int)tokens[i]));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
result.setProperty(rt, "tokens", tokensArray);
|
|
659
|
+
result.setProperty(rt, "count", jsi::Value((int)tokens.size()));
|
|
660
|
+
|
|
661
|
+
return result;
|
|
662
|
+
} catch (const std::exception& e) {
|
|
663
|
+
throw jsi::JSError(rt, std::string("Tokenization error: ") + e.what());
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
jsi::Value LlamaCppModel::detokenizeJsi(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
|
668
|
+
if (count < 1 || !args[0].isObject()) {
|
|
669
|
+
throw jsi::JSError(rt, "detokenize requires an options object with 'tokens' field");
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
try {
|
|
673
|
+
jsi::Object options = args[0].getObject(rt);
|
|
674
|
+
|
|
675
|
+
// Extract required tokens parameter
|
|
676
|
+
if (!options.hasProperty(rt, "tokens") || !options.getProperty(rt, "tokens").isObject()) {
|
|
677
|
+
throw jsi::JSError(rt, "detokenize requires a 'tokens' array field");
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
auto tokensVal = options.getProperty(rt, "tokens").getObject(rt);
|
|
681
|
+
if (!tokensVal.isArray(rt)) {
|
|
682
|
+
throw jsi::JSError(rt, "tokens must be an array");
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
jsi::Array tokensArr = tokensVal.getArray(rt);
|
|
686
|
+
int token_count = tokensArr.size(rt);
|
|
687
|
+
|
|
688
|
+
if (!rn_ctx_ || !rn_ctx_->model || !rn_ctx_->vocab) {
|
|
689
|
+
throw std::runtime_error("Model not loaded or vocab not available");
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Create a vector of token IDs
|
|
693
|
+
std::vector<llama_token> tokens;
|
|
694
|
+
tokens.reserve(token_count);
|
|
695
|
+
|
|
696
|
+
for (int i = 0; i < token_count; i++) {
|
|
697
|
+
auto val = tokensArr.getValueAtIndex(rt, i);
|
|
698
|
+
if (val.isNumber()) {
|
|
699
|
+
tokens.push_back(static_cast<llama_token>(val.asNumber()));
|
|
700
|
+
} else if (val.isObject() && val.getObject(rt).hasProperty(rt, "id")) {
|
|
701
|
+
auto id = val.getObject(rt).getProperty(rt, "id");
|
|
702
|
+
if (id.isNumber()) {
|
|
703
|
+
tokens.push_back(static_cast<llama_token>(id.asNumber()));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Use common_token_to_piece for each token and concatenate the results
|
|
709
|
+
std::string result_text;
|
|
710
|
+
for (auto token : tokens) {
|
|
711
|
+
result_text += common_token_to_piece(rn_ctx_->vocab, token);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// Create result object
|
|
715
|
+
jsi::Object result(rt);
|
|
716
|
+
result.setProperty(rt, "text", jsi::String::createFromUtf8(rt, result_text));
|
|
717
|
+
|
|
718
|
+
return result;
|
|
719
|
+
} catch (const std::exception& e) {
|
|
720
|
+
throw jsi::JSError(rt, std::string("Detokenization error: ") + e.what());
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Get embedding size for the model
|
|
725
|
+
int32_t LlamaCppModel::getEmbeddingSize() const {
|
|
726
|
+
if (!rn_ctx_ || !rn_ctx_->model) {
|
|
727
|
+
throw std::runtime_error("Model not loaded");
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return llama_model_n_embd(rn_ctx_->model);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// Fixed embeddingJsi method with corrected API calls
|
|
734
|
+
jsi::Value LlamaCppModel::embeddingJsi(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
|
735
|
+
if (count < 1 || !args[0].isObject()) {
|
|
736
|
+
throw jsi::JSError(rt, "embedding requires an options object with 'input' or 'content' field");
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
try {
|
|
740
|
+
jsi::Object options = args[0].getObject(rt);
|
|
741
|
+
|
|
742
|
+
// Extract required content parameter, support both 'input' (OpenAI) and 'content' (custom format)
|
|
743
|
+
std::string content;
|
|
744
|
+
|
|
745
|
+
if (options.hasProperty(rt, "input") && options.getProperty(rt, "input").isString()) {
|
|
746
|
+
content = options.getProperty(rt, "input").getString(rt).utf8(rt);
|
|
747
|
+
} else if (options.hasProperty(rt, "content") && options.getProperty(rt, "content").isString()) {
|
|
748
|
+
content = options.getProperty(rt, "content").getString(rt).utf8(rt);
|
|
749
|
+
} else {
|
|
750
|
+
throw jsi::JSError(rt, "embedding requires either 'input' or 'content' string field");
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Check optional parameters
|
|
754
|
+
std::string encoding_format = "float";
|
|
755
|
+
if (options.hasProperty(rt, "encoding_format") && options.getProperty(rt, "encoding_format").isString()) {
|
|
756
|
+
encoding_format = options.getProperty(rt, "encoding_format").getString(rt).utf8(rt);
|
|
757
|
+
if (encoding_format != "float" && encoding_format != "base64") {
|
|
758
|
+
throw jsi::JSError(rt, "encoding_format must be either 'float' or 'base64'");
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
bool add_bos = true;
|
|
763
|
+
if (options.hasProperty(rt, "add_bos_token") && options.getProperty(rt, "add_bos_token").isBool()) {
|
|
764
|
+
add_bos = options.getProperty(rt, "add_bos_token").getBool();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Check model and context
|
|
768
|
+
if (!rn_ctx_ || !rn_ctx_->model || !rn_ctx_->ctx || !rn_ctx_->vocab) {
|
|
769
|
+
throw std::runtime_error("Model not loaded or context not initialized");
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// Tokenize the input text
|
|
773
|
+
std::vector<llama_token> tokens;
|
|
774
|
+
int n_tokens = llama_tokenize(rn_ctx_->vocab, content.c_str(), content.length(), nullptr, 0, add_bos, true);
|
|
775
|
+
if (n_tokens < 0) {
|
|
776
|
+
n_tokens = -n_tokens;
|
|
777
|
+
}
|
|
778
|
+
tokens.resize(n_tokens);
|
|
779
|
+
n_tokens = llama_tokenize(rn_ctx_->vocab, content.c_str(), content.length(), tokens.data(), n_tokens, add_bos, true);
|
|
780
|
+
if (n_tokens < 0) {
|
|
781
|
+
throw std::runtime_error("Tokenization failed for embedding");
|
|
782
|
+
}
|
|
783
|
+
tokens.resize(n_tokens);
|
|
784
|
+
|
|
785
|
+
if (tokens.empty()) {
|
|
786
|
+
throw jsi::JSError(rt, "No tokens generated from input text");
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// Clear the context KV cache to ensure clean embedding
|
|
790
|
+
llama_kv_self_clear(rn_ctx_->ctx);
|
|
791
|
+
|
|
792
|
+
// Enable embedding mode
|
|
793
|
+
llama_set_embeddings(rn_ctx_->ctx, true);
|
|
794
|
+
|
|
795
|
+
// Evaluate tokens one by one
|
|
796
|
+
for (int i = 0; i < (int)tokens.size(); i++) {
|
|
797
|
+
llama_token token = tokens[i];
|
|
798
|
+
llama_batch batch = {
|
|
799
|
+
/* n_tokens */ 1,
|
|
800
|
+
/* token */ &token,
|
|
801
|
+
/* embd */ nullptr,
|
|
802
|
+
/* pos */ &i,
|
|
803
|
+
/* n_seq_id */ nullptr,
|
|
804
|
+
/* seq_id */ nullptr,
|
|
805
|
+
/* logits */ nullptr
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
if (llama_decode(rn_ctx_->ctx, batch) != 0) {
|
|
809
|
+
throw std::runtime_error("Failed to decode token for embedding");
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Get embedding size from the model
|
|
814
|
+
const int n_embd = llama_model_n_embd(rn_ctx_->model);
|
|
815
|
+
if (n_embd <= 0) {
|
|
816
|
+
throw std::runtime_error("Invalid embedding dimension");
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// For OpenAI compatibility, default to mean pooling
|
|
820
|
+
enum llama_pooling_type pooling_type = LLAMA_POOLING_TYPE_MEAN;
|
|
821
|
+
if (options.hasProperty(rt, "pooling") && options.getProperty(rt, "pooling").isString()) {
|
|
822
|
+
std::string pooling = options.getProperty(rt, "pooling").getString(rt).utf8(rt);
|
|
823
|
+
if (pooling == "last") {
|
|
824
|
+
pooling_type = LLAMA_POOLING_TYPE_LAST;
|
|
825
|
+
} else if (pooling == "cls" || pooling == "first") {
|
|
826
|
+
pooling_type = LLAMA_POOLING_TYPE_CLS;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// Get the embeddings
|
|
831
|
+
std::vector<float> embedding_vec(n_embd);
|
|
832
|
+
const float* embd = llama_get_embeddings(rn_ctx_->ctx);
|
|
833
|
+
|
|
834
|
+
if (!embd) {
|
|
835
|
+
throw std::runtime_error("Failed to extract embeddings");
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// Copy embeddings to our vector
|
|
839
|
+
std::copy(embd, embd + n_embd, embedding_vec.begin());
|
|
840
|
+
|
|
841
|
+
// Normalize embedding
|
|
842
|
+
float norm = 0.0f;
|
|
843
|
+
for (int i = 0; i < n_embd; ++i) {
|
|
844
|
+
norm += embedding_vec[i] * embedding_vec[i];
|
|
845
|
+
}
|
|
846
|
+
norm = std::sqrt(norm);
|
|
847
|
+
|
|
848
|
+
if (norm > 0) {
|
|
849
|
+
for (int i = 0; i < n_embd; ++i) {
|
|
850
|
+
embedding_vec[i] /= norm;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// Create OpenAI-compatible response
|
|
855
|
+
jsi::Object response(rt);
|
|
856
|
+
|
|
857
|
+
// Add embedding data
|
|
858
|
+
jsi::Array dataArray(rt, 1);
|
|
859
|
+
jsi::Object embeddingObj(rt);
|
|
860
|
+
|
|
861
|
+
if (encoding_format == "base64") {
|
|
862
|
+
// Base64 encode the embedding vector
|
|
863
|
+
const char* data_ptr = reinterpret_cast<const char*>(embedding_vec.data());
|
|
864
|
+
size_t data_size = embedding_vec.size() * sizeof(float);
|
|
865
|
+
std::string base64_str = base64::encode(data_ptr, data_size);
|
|
866
|
+
|
|
867
|
+
embeddingObj.setProperty(rt, "embedding", jsi::String::createFromUtf8(rt, base64_str));
|
|
868
|
+
embeddingObj.setProperty(rt, "encoding_format", jsi::String::createFromUtf8(rt, "base64"));
|
|
869
|
+
} else {
|
|
870
|
+
// Create embedding array of floats
|
|
871
|
+
jsi::Array embeddingArray(rt, n_embd);
|
|
872
|
+
for (int i = 0; i < n_embd; i++) {
|
|
873
|
+
embeddingArray.setValueAtIndex(rt, i, jsi::Value(embedding_vec[i]));
|
|
874
|
+
}
|
|
875
|
+
embeddingObj.setProperty(rt, "embedding", embeddingArray);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
embeddingObj.setProperty(rt, "object", jsi::String::createFromUtf8(rt, "embedding"));
|
|
879
|
+
embeddingObj.setProperty(rt, "index", jsi::Value(0));
|
|
880
|
+
|
|
881
|
+
dataArray.setValueAtIndex(rt, 0, embeddingObj);
|
|
882
|
+
|
|
883
|
+
// Create model info
|
|
884
|
+
std::string model_name = "llamacpp";
|
|
885
|
+
if (options.hasProperty(rt, "model") && options.getProperty(rt, "model").isString()) {
|
|
886
|
+
model_name = options.getProperty(rt, "model").getString(rt).utf8(rt);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Create usage info
|
|
890
|
+
jsi::Object usage(rt);
|
|
891
|
+
usage.setProperty(rt, "prompt_tokens", jsi::Value((int)tokens.size()));
|
|
892
|
+
usage.setProperty(rt, "total_tokens", jsi::Value((int)tokens.size()));
|
|
893
|
+
|
|
894
|
+
// Assemble the response
|
|
895
|
+
response.setProperty(rt, "object", jsi::String::createFromUtf8(rt, "list"));
|
|
896
|
+
response.setProperty(rt, "data", dataArray);
|
|
897
|
+
response.setProperty(rt, "model", jsi::String::createFromUtf8(rt, model_name));
|
|
898
|
+
response.setProperty(rt, "usage", usage);
|
|
899
|
+
|
|
900
|
+
return response;
|
|
901
|
+
} catch (const std::exception& e) {
|
|
902
|
+
throw jsi::JSError(rt, std::string("Embedding error: ") + e.what());
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
jsi::Value LlamaCppModel::releaseJsi(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
|
907
|
+
try {
|
|
908
|
+
release();
|
|
909
|
+
return jsi::Value(true);
|
|
910
|
+
} catch (const std::exception& e) {
|
|
911
|
+
throw jsi::JSError(rt, e.what());
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
jsi::Value LlamaCppModel::get(jsi::Runtime& rt, const jsi::PropNameID& name) {
|
|
916
|
+
auto nameStr = name.utf8(rt);
|
|
917
|
+
|
|
918
|
+
if (nameStr == "tokenize") {
|
|
919
|
+
return jsi::Function::createFromHostFunction(
|
|
920
|
+
rt, name, 1,
|
|
921
|
+
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) {
|
|
922
|
+
return this->tokenizeJsi(runtime, args, count);
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
else if (nameStr == "detokenize") {
|
|
926
|
+
return jsi::Function::createFromHostFunction(
|
|
927
|
+
rt, name, 1,
|
|
928
|
+
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) {
|
|
929
|
+
return this->detokenizeJsi(runtime, args, count);
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
else if (nameStr == "completion") {
|
|
933
|
+
return jsi::Function::createFromHostFunction(
|
|
934
|
+
rt, name, 2,
|
|
935
|
+
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) {
|
|
936
|
+
return this->completionJsi(runtime, args, count);
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
else if (nameStr == "embedding") {
|
|
940
|
+
return jsi::Function::createFromHostFunction(
|
|
941
|
+
rt, name, 1,
|
|
942
|
+
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) {
|
|
943
|
+
return this->embeddingJsi(runtime, args, count);
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
else if (nameStr == "release") {
|
|
947
|
+
return jsi::Function::createFromHostFunction(
|
|
948
|
+
rt, name, 0,
|
|
949
|
+
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) {
|
|
950
|
+
return this->releaseJsi(runtime, args, count);
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
else if (nameStr == "n_vocab") {
|
|
954
|
+
return jsi::Value(getVocabSize());
|
|
955
|
+
}
|
|
956
|
+
else if (nameStr == "n_ctx") {
|
|
957
|
+
return jsi::Value(getContextSize());
|
|
958
|
+
}
|
|
959
|
+
else if (nameStr == "n_embd") {
|
|
960
|
+
return jsi::Value(getEmbeddingSize());
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
return jsi::Value::undefined();
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
void LlamaCppModel::set(jsi::Runtime& rt, const jsi::PropNameID& name, const jsi::Value& value) {
|
|
967
|
+
// Currently we don't support setting properties
|
|
968
|
+
throw jsi::JSError(rt, "Cannot modify llama model properties");
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
std::vector<jsi::PropNameID> LlamaCppModel::getPropertyNames(jsi::Runtime& rt) {
|
|
972
|
+
std::vector<jsi::PropNameID> result;
|
|
973
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "tokenize"));
|
|
974
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "detokenize"));
|
|
975
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "completion"));
|
|
976
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "embedding"));
|
|
977
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "release"));
|
|
978
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "n_vocab"));
|
|
979
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "n_ctx"));
|
|
980
|
+
result.push_back(jsi::PropNameID::forAscii(rt, "n_embd"));
|
|
981
|
+
return result;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
} // namespace facebook::react
|