@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.
Files changed (989) hide show
  1. package/INTERFACE.md +389 -0
  2. package/LICENSE +201 -0
  3. package/README.md +235 -0
  4. package/RNLlamaCpp.podspec +69 -0
  5. package/android/CMakeLists.txt +107 -0
  6. package/android/build.gradle +111 -0
  7. package/android/generated/java/com/novastera/llamarn/NativeRNLlamaCppSpec.java +47 -0
  8. package/android/generated/jni/CMakeLists.txt +36 -0
  9. package/android/generated/jni/RNLlamaCppSpec-generated.cpp +44 -0
  10. package/android/generated/jni/RNLlamaCppSpec.h +31 -0
  11. package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI-generated.cpp +42 -0
  12. package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI.h +336 -0
  13. package/android/gradle.properties +5 -0
  14. package/android/src/main/AndroidManifest.xml +3 -0
  15. package/android/src/main/AndroidManifestNew.xml +2 -0
  16. package/android/src/main/cpp/include/llama-cpp.h +30 -0
  17. package/android/src/main/cpp/include/llama.h +1440 -0
  18. package/android/src/main/java/com/novastera/llamarn/RNLlamaCppPackage.kt +21 -0
  19. package/android/src/main/jniLibs/arm64-v8a/libOpenCL.so +0 -0
  20. package/android/src/main/jniLibs/arm64-v8a/libggml-base.so +0 -0
  21. package/android/src/main/jniLibs/arm64-v8a/libggml-cpu.so +0 -0
  22. package/android/src/main/jniLibs/arm64-v8a/libggml.so +0 -0
  23. package/android/src/main/jniLibs/arm64-v8a/libllama.so +0 -0
  24. package/android/src/main/jniLibs/x86_64/libOpenCL.so +0 -0
  25. package/android/src/main/jniLibs/x86_64/libggml-base.so +0 -0
  26. package/android/src/main/jniLibs/x86_64/libggml-cpu.so +0 -0
  27. package/android/src/main/jniLibs/x86_64/libggml.so +0 -0
  28. package/android/src/main/jniLibs/x86_64/libllama.so +0 -0
  29. package/cpp/LlamaCppModel.cpp +984 -0
  30. package/cpp/LlamaCppModel.h +162 -0
  31. package/cpp/PureCppImpl.cpp +308 -0
  32. package/cpp/PureCppImpl.h +59 -0
  33. package/cpp/SystemUtils.cpp +180 -0
  34. package/cpp/SystemUtils.h +74 -0
  35. package/cpp/build-info.cpp +4 -0
  36. package/cpp/llama.cpp/AUTHORS +1106 -0
  37. package/cpp/llama.cpp/CMakeLists.txt +254 -0
  38. package/cpp/llama.cpp/CMakePresets.json +84 -0
  39. package/cpp/llama.cpp/CODEOWNERS +11 -0
  40. package/cpp/llama.cpp/CONTRIBUTING.md +127 -0
  41. package/cpp/llama.cpp/LICENSE +21 -0
  42. package/cpp/llama.cpp/Makefile +1608 -0
  43. package/cpp/llama.cpp/README.md +575 -0
  44. package/cpp/llama.cpp/SECURITY.md +68 -0
  45. package/cpp/llama.cpp/build-xcframework.sh +540 -0
  46. package/cpp/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
  47. package/cpp/llama.cpp/cmake/arm64-windows-llvm.cmake +16 -0
  48. package/cpp/llama.cpp/cmake/build-info.cmake +64 -0
  49. package/cpp/llama.cpp/cmake/common.cmake +35 -0
  50. package/cpp/llama.cpp/cmake/git-vars.cmake +22 -0
  51. package/cpp/llama.cpp/cmake/llama-config.cmake.in +30 -0
  52. package/cpp/llama.cpp/cmake/llama.pc.in +10 -0
  53. package/cpp/llama.cpp/cmake/x64-windows-llvm.cmake +5 -0
  54. package/cpp/llama.cpp/common/CMakeLists.txt +170 -0
  55. package/cpp/llama.cpp/common/arg.cpp +3337 -0
  56. package/cpp/llama.cpp/common/arg.h +89 -0
  57. package/cpp/llama.cpp/common/base64.hpp +392 -0
  58. package/cpp/llama.cpp/common/build-info.cpp.in +4 -0
  59. package/cpp/llama.cpp/common/chat.cpp +1781 -0
  60. package/cpp/llama.cpp/common/chat.h +135 -0
  61. package/cpp/llama.cpp/common/cmake/build-info-gen-cpp.cmake +24 -0
  62. package/cpp/llama.cpp/common/common.cpp +1567 -0
  63. package/cpp/llama.cpp/common/common.h +668 -0
  64. package/cpp/llama.cpp/common/console.cpp +504 -0
  65. package/cpp/llama.cpp/common/console.h +19 -0
  66. package/cpp/llama.cpp/common/json-schema-to-grammar.cpp +1027 -0
  67. package/cpp/llama.cpp/common/json-schema-to-grammar.h +21 -0
  68. package/cpp/llama.cpp/common/json.hpp +24766 -0
  69. package/cpp/llama.cpp/common/llguidance.cpp +254 -0
  70. package/cpp/llama.cpp/common/log.cpp +393 -0
  71. package/cpp/llama.cpp/common/log.h +103 -0
  72. package/cpp/llama.cpp/common/minja/chat-template.hpp +537 -0
  73. package/cpp/llama.cpp/common/minja/minja.hpp +2941 -0
  74. package/cpp/llama.cpp/common/ngram-cache.cpp +286 -0
  75. package/cpp/llama.cpp/common/ngram-cache.h +101 -0
  76. package/cpp/llama.cpp/common/sampling.cpp +580 -0
  77. package/cpp/llama.cpp/common/sampling.h +107 -0
  78. package/cpp/llama.cpp/common/speculative.cpp +278 -0
  79. package/cpp/llama.cpp/common/speculative.h +28 -0
  80. package/cpp/llama.cpp/common/stb_image.h +7988 -0
  81. package/cpp/llama.cpp/convert_hf_to_gguf.py +6195 -0
  82. package/cpp/llama.cpp/convert_hf_to_gguf_update.py +393 -0
  83. package/cpp/llama.cpp/convert_llama_ggml_to_gguf.py +450 -0
  84. package/cpp/llama.cpp/convert_lora_to_gguf.py +461 -0
  85. package/cpp/llama.cpp/flake.lock +58 -0
  86. package/cpp/llama.cpp/flake.nix +185 -0
  87. package/cpp/llama.cpp/ggml/CMakeLists.txt +388 -0
  88. package/cpp/llama.cpp/ggml/cmake/GitVars.cmake +22 -0
  89. package/cpp/llama.cpp/ggml/cmake/common.cmake +26 -0
  90. package/cpp/llama.cpp/ggml/cmake/ggml-config.cmake.in +152 -0
  91. package/cpp/llama.cpp/ggml/include/ggml-alloc.h +76 -0
  92. package/cpp/llama.cpp/ggml/include/ggml-backend.h +354 -0
  93. package/cpp/llama.cpp/ggml/include/ggml-blas.h +25 -0
  94. package/cpp/llama.cpp/ggml/include/ggml-cann.h +123 -0
  95. package/cpp/llama.cpp/ggml/include/ggml-cpp.h +39 -0
  96. package/cpp/llama.cpp/ggml/include/ggml-cpu.h +143 -0
  97. package/cpp/llama.cpp/ggml/include/ggml-cuda.h +47 -0
  98. package/cpp/llama.cpp/ggml/include/ggml-kompute.h +50 -0
  99. package/cpp/llama.cpp/ggml/include/ggml-metal.h +66 -0
  100. package/cpp/llama.cpp/ggml/include/ggml-opencl.h +26 -0
  101. package/cpp/llama.cpp/ggml/include/ggml-opt.h +216 -0
  102. package/cpp/llama.cpp/ggml/include/ggml-rpc.h +33 -0
  103. package/cpp/llama.cpp/ggml/include/ggml-sycl.h +49 -0
  104. package/cpp/llama.cpp/ggml/include/ggml-vulkan.h +29 -0
  105. package/cpp/llama.cpp/ggml/include/ggml.h +2192 -0
  106. package/cpp/llama.cpp/ggml/include/gguf.h +202 -0
  107. package/cpp/llama.cpp/ggml/src/CMakeLists.txt +345 -0
  108. package/cpp/llama.cpp/ggml/src/ggml-alloc.c +1042 -0
  109. package/cpp/llama.cpp/ggml/src/ggml-backend-impl.h +255 -0
  110. package/cpp/llama.cpp/ggml/src/ggml-backend-reg.cpp +586 -0
  111. package/cpp/llama.cpp/ggml/src/ggml-backend.cpp +2008 -0
  112. package/cpp/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +87 -0
  113. package/cpp/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
  114. package/cpp/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +74 -0
  115. package/cpp/llama.cpp/ggml/src/ggml-cann/Doxyfile +2579 -0
  116. package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +179 -0
  117. package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +258 -0
  118. package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +2589 -0
  119. package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +1083 -0
  120. package/cpp/llama.cpp/ggml/src/ggml-cann/common.h +420 -0
  121. package/cpp/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +2554 -0
  122. package/cpp/llama.cpp/ggml/src/ggml-common.h +1857 -0
  123. package/cpp/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +495 -0
  124. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +221 -0
  125. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.h +8 -0
  126. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/common.h +91 -0
  127. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
  128. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  129. package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp +158 -0
  130. package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.h +16 -0
  131. package/cpp/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
  132. package/cpp/llama.cpp/ggml/src/ggml-cpu/common.h +72 -0
  133. package/cpp/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +327 -0
  134. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +6431 -0
  135. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
  136. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
  137. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
  138. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +512 -0
  139. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +13131 -0
  140. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
  141. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
  142. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
  143. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +3492 -0
  144. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +671 -0
  145. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.cpp +254 -0
  146. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.h +60 -0
  147. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +287 -0
  148. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
  149. package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +3544 -0
  150. package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
  151. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp +8796 -0
  152. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.h +110 -0
  153. package/cpp/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +892 -0
  154. package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.cpp +186 -0
  155. package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.h +28 -0
  156. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.cpp +252 -0
  157. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.h +802 -0
  158. package/cpp/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +184 -0
  159. package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cu +47 -0
  160. package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cuh +5 -0
  161. package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cu +34 -0
  162. package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cuh +5 -0
  163. package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cu +91 -0
  164. package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cuh +3 -0
  165. package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cu +104 -0
  166. package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cuh +3 -0
  167. package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cu +363 -0
  168. package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cuh +9 -0
  169. package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cu +45 -0
  170. package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cuh +5 -0
  171. package/cpp/llama.cpp/ggml/src/ggml-cuda/common.cuh +828 -0
  172. package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cu +221 -0
  173. package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cuh +5 -0
  174. package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cu +89 -0
  175. package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
  176. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cu +730 -0
  177. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cuh +26 -0
  178. package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cu +64 -0
  179. package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cuh +5 -0
  180. package/cpp/llama.cpp/ggml/src/ggml-cuda/cp-async.cuh +57 -0
  181. package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cu +695 -0
  182. package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cuh +11 -0
  183. package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cu +189 -0
  184. package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
  185. package/cpp/llama.cpp/ggml/src/ggml-cuda/dequantize.cuh +103 -0
  186. package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cu +40 -0
  187. package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cuh +5 -0
  188. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-common.cuh +873 -0
  189. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1269 -0
  190. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cu +357 -0
  191. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cuh +3 -0
  192. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cu +365 -0
  193. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cuh +3 -0
  194. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f16.cuh +437 -0
  195. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f32.cuh +428 -0
  196. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cu +634 -0
  197. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +3 -0
  198. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cu +345 -0
  199. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cuh +3 -0
  200. package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cu +275 -0
  201. package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cuh +15 -0
  202. package/cpp/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu +3501 -0
  203. package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cu +93 -0
  204. package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cuh +3 -0
  205. package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cu +103 -0
  206. package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cuh +5 -0
  207. package/cpp/llama.cpp/ggml/src/ggml-cuda/mma.cuh +396 -0
  208. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cu +322 -0
  209. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cuh +3217 -0
  210. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cu +336 -0
  211. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cuh +12 -0
  212. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cu +595 -0
  213. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cuh +12 -0
  214. package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cu +458 -0
  215. package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cuh +11 -0
  216. package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
  217. package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
  218. package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cu +68 -0
  219. package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cuh +3 -0
  220. package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cu +49 -0
  221. package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cuh +5 -0
  222. package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cu +94 -0
  223. package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cuh +5 -0
  224. package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cu +189 -0
  225. package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cuh +27 -0
  226. package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cu +456 -0
  227. package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cuh +7 -0
  228. package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cu +31 -0
  229. package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cuh +5 -0
  230. package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cu +283 -0
  231. package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cuh +7 -0
  232. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cu +148 -0
  233. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
  234. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cu +153 -0
  235. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
  236. package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cu +45 -0
  237. package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cuh +5 -0
  238. package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cu +39 -0
  239. package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cuh +5 -0
  240. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
  241. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +10 -0
  242. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
  243. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
  244. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +10 -0
  245. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
  246. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +10 -0
  247. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +10 -0
  248. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
  249. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
  250. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
  251. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
  252. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +10 -0
  253. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +10 -0
  254. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
  255. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
  256. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
  257. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +10 -0
  258. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +10 -0
  259. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-f16.cu +5 -0
  260. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_0.cu +5 -0
  261. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_1.cu +5 -0
  262. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_0.cu +5 -0
  263. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_1.cu +5 -0
  264. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q8_0.cu +5 -0
  265. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-f16.cu +5 -0
  266. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_0.cu +5 -0
  267. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_1.cu +5 -0
  268. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_0.cu +5 -0
  269. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_1.cu +5 -0
  270. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q8_0.cu +5 -0
  271. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-f16.cu +5 -0
  272. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_0.cu +5 -0
  273. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_1.cu +5 -0
  274. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_0.cu +5 -0
  275. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_1.cu +5 -0
  276. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q8_0.cu +5 -0
  277. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-f16.cu +5 -0
  278. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_0.cu +5 -0
  279. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_1.cu +5 -0
  280. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_0.cu +5 -0
  281. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_1.cu +5 -0
  282. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q8_0.cu +5 -0
  283. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-f16.cu +5 -0
  284. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_0.cu +5 -0
  285. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_1.cu +5 -0
  286. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_0.cu +5 -0
  287. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_1.cu +5 -0
  288. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q8_0.cu +5 -0
  289. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-f16.cu +5 -0
  290. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_0.cu +5 -0
  291. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_1.cu +5 -0
  292. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_0.cu +5 -0
  293. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_1.cu +5 -0
  294. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q8_0.cu +5 -0
  295. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs256-f16-f16.cu +5 -0
  296. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-f16.cu +5 -0
  297. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_0.cu +5 -0
  298. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_1.cu +5 -0
  299. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_0.cu +5 -0
  300. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_1.cu +5 -0
  301. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q8_0.cu +5 -0
  302. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-f16.cu +5 -0
  303. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_0.cu +5 -0
  304. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_1.cu +5 -0
  305. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_0.cu +5 -0
  306. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_1.cu +5 -0
  307. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q8_0.cu +5 -0
  308. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-f16.cu +5 -0
  309. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_0.cu +5 -0
  310. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_1.cu +5 -0
  311. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_0.cu +5 -0
  312. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_1.cu +5 -0
  313. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q8_0.cu +5 -0
  314. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-f16.cu +5 -0
  315. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_0.cu +5 -0
  316. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_1.cu +5 -0
  317. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_0.cu +5 -0
  318. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_1.cu +5 -0
  319. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q8_0.cu +5 -0
  320. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-f16.cu +5 -0
  321. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_0.cu +5 -0
  322. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_1.cu +5 -0
  323. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_0.cu +5 -0
  324. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_1.cu +5 -0
  325. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q8_0.cu +5 -0
  326. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-f16.cu +5 -0
  327. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_0.cu +5 -0
  328. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_1.cu +5 -0
  329. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_0.cu +5 -0
  330. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_1.cu +5 -0
  331. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q8_0.cu +5 -0
  332. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-f16.cu +5 -0
  333. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_0.cu +5 -0
  334. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_1.cu +5 -0
  335. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_0.cu +5 -0
  336. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_1.cu +5 -0
  337. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q8_0.cu +5 -0
  338. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs256-f16-f16.cu +5 -0
  339. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-f16.cu +5 -0
  340. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_0.cu +5 -0
  341. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_1.cu +5 -0
  342. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_0.cu +5 -0
  343. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_1.cu +5 -0
  344. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q8_0.cu +5 -0
  345. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +78 -0
  346. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
  347. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
  348. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
  349. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
  350. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
  351. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
  352. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
  353. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
  354. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
  355. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
  356. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
  357. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
  358. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
  359. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
  360. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
  361. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
  362. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
  363. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
  364. package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cu +47 -0
  365. package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cuh +5 -0
  366. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cu +279 -0
  367. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cuh +57 -0
  368. package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cu +51 -0
  369. package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cuh +5 -0
  370. package/cpp/llama.cpp/ggml/src/ggml-cuda/vecdotq.cuh +1135 -0
  371. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +15 -0
  372. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +243 -0
  373. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +140 -0
  374. package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cu +199 -0
  375. package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cuh +7 -0
  376. package/cpp/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +131 -0
  377. package/cpp/llama.cpp/ggml/src/ggml-impl.h +601 -0
  378. package/cpp/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +166 -0
  379. package/cpp/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
  380. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/common.comp +112 -0
  381. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +58 -0
  382. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +25 -0
  383. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +52 -0
  384. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +52 -0
  385. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +52 -0
  386. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +52 -0
  387. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +30 -0
  388. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +22 -0
  389. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +17 -0
  390. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +31 -0
  391. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +31 -0
  392. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +38 -0
  393. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +39 -0
  394. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +44 -0
  395. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +52 -0
  396. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +69 -0
  397. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +51 -0
  398. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +33 -0
  399. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +35 -0
  400. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +140 -0
  401. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +106 -0
  402. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +73 -0
  403. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +52 -0
  404. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +28 -0
  405. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +84 -0
  406. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +21 -0
  407. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +53 -0
  408. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +52 -0
  409. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +52 -0
  410. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +52 -0
  411. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +52 -0
  412. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +19 -0
  413. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +23 -0
  414. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +22 -0
  415. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +72 -0
  416. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +71 -0
  417. package/cpp/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +120 -0
  418. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +618 -0
  419. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.m +5916 -0
  420. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.metal +6891 -0
  421. package/cpp/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +107 -0
  422. package/cpp/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +96 -0
  423. package/cpp/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +4966 -0
  424. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/add.cl +83 -0
  425. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/clamp.cl +20 -0
  426. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cpy.cl +184 -0
  427. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cvt.cl +118 -0
  428. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/diag_mask_inf.cl +58 -0
  429. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/embed_kernel.py +26 -0
  430. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gelu.cl +62 -0
  431. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle.cl +268 -0
  432. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle_general.cl +274 -0
  433. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/get_rows.cl +163 -0
  434. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f16.cl +57 -0
  435. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f32.cl +57 -0
  436. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul.cl +79 -0
  437. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mat_Ab_Bi_8x4.cl +139 -0
  438. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f16.cl +118 -0
  439. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32.cl +118 -0
  440. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl +94 -0
  441. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +84 -0
  442. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f32_f32.cl +118 -0
  443. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32.cl +192 -0
  444. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_16x_flat.cl +307 -0
  445. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_8x_flat.cl +265 -0
  446. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_8x_flat.cl +272 -0
  447. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_v.cl +254 -0
  448. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q6_k.cl +190 -0
  449. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/norm.cl +81 -0
  450. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/relu.cl +16 -0
  451. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rms_norm.cl +96 -0
  452. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rope.cl +721 -0
  453. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/scale.cl +16 -0
  454. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/silu.cl +30 -0
  455. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +87 -0
  456. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +87 -0
  457. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f16.cl +86 -0
  458. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f32.cl +86 -0
  459. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/transpose.cl +84 -0
  460. package/cpp/llama.cpp/ggml/src/ggml-opt.cpp +854 -0
  461. package/cpp/llama.cpp/ggml/src/ggml-quants.c +5232 -0
  462. package/cpp/llama.cpp/ggml/src/ggml-quants.h +100 -0
  463. package/cpp/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +9 -0
  464. package/cpp/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +1813 -0
  465. package/cpp/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +183 -0
  466. package/cpp/llama.cpp/ggml/src/ggml-sycl/backend.hpp +37 -0
  467. package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +350 -0
  468. package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +39 -0
  469. package/cpp/llama.cpp/ggml/src/ggml-sycl/common.cpp +83 -0
  470. package/cpp/llama.cpp/ggml/src/ggml-sycl/common.hpp +493 -0
  471. package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.cpp +197 -0
  472. package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.hpp +20 -0
  473. package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.cpp +100 -0
  474. package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.hpp +20 -0
  475. package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.cpp +596 -0
  476. package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.hpp +34 -0
  477. package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +701 -0
  478. package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +11 -0
  479. package/cpp/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +753 -0
  480. package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +1154 -0
  481. package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +27 -0
  482. package/cpp/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +2957 -0
  483. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1559 -0
  484. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +75 -0
  485. package/cpp/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +70 -0
  486. package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +311 -0
  487. package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +20 -0
  488. package/cpp/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +4302 -0
  489. package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.cpp +105 -0
  490. package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.hpp +8 -0
  491. package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +136 -0
  492. package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +21 -0
  493. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +3030 -0
  494. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +33 -0
  495. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1081 -0
  496. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +27 -0
  497. package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.cpp +474 -0
  498. package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.hpp +26 -0
  499. package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +46 -0
  500. package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +10 -0
  501. package/cpp/llama.cpp/ggml/src/ggml-sycl/presets.hpp +74 -0
  502. package/cpp/llama.cpp/ggml/src/ggml-sycl/quants.hpp +61 -0
  503. package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.cpp +362 -0
  504. package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.hpp +20 -0
  505. package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +264 -0
  506. package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +20 -0
  507. package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +13 -0
  508. package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +23 -0
  509. package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +73 -0
  510. package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +20 -0
  511. package/cpp/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +1189 -0
  512. package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +305 -0
  513. package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +10 -0
  514. package/cpp/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
  515. package/cpp/llama.cpp/ggml/src/ggml-threading.h +14 -0
  516. package/cpp/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +202 -0
  517. package/cpp/llama.cpp/ggml/src/ggml-vulkan/cmake/host-toolchain.cmake.in +15 -0
  518. package/cpp/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +10502 -0
  519. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +22 -0
  520. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +29 -0
  521. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +29 -0
  522. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +51 -0
  523. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +69 -0
  524. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +17 -0
  525. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +41 -0
  526. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +49 -0
  527. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +105 -0
  528. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +23 -0
  529. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +51 -0
  530. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +242 -0
  531. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +17 -0
  532. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +31 -0
  533. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +20 -0
  534. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.comp +462 -0
  535. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.comp +699 -0
  536. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_head.comp +13 -0
  537. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +42 -0
  538. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +35 -0
  539. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +44 -0
  540. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +43 -0
  541. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +48 -0
  542. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +39 -0
  543. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +49 -0
  544. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +32 -0
  545. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +34 -0
  546. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +34 -0
  547. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +42 -0
  548. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +30 -0
  549. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +32 -0
  550. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +68 -0
  551. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +34 -0
  552. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +35 -0
  553. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +70 -0
  554. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +33 -0
  555. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +31 -0
  556. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +34 -0
  557. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +27 -0
  558. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +483 -0
  559. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +383 -0
  560. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +59 -0
  561. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +25 -0
  562. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +23 -0
  563. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.comp +64 -0
  564. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_head.comp +9 -0
  565. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.comp +76 -0
  566. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +33 -0
  567. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +41 -0
  568. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +66 -0
  569. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +100 -0
  570. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +41 -0
  571. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +22 -0
  572. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +27 -0
  573. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_split_k_reduce.comp +48 -0
  574. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +169 -0
  575. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.comp +118 -0
  576. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +82 -0
  577. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +79 -0
  578. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +90 -0
  579. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +87 -0
  580. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +87 -0
  581. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +90 -0
  582. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +88 -0
  583. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +118 -0
  584. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +154 -0
  585. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +130 -0
  586. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +132 -0
  587. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +136 -0
  588. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +167 -0
  589. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +130 -0
  590. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +868 -0
  591. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +441 -0
  592. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +442 -0
  593. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.comp +99 -0
  594. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +44 -0
  595. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +42 -0
  596. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +28 -0
  597. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +74 -0
  598. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +77 -0
  599. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +21 -0
  600. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +26 -0
  601. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +37 -0
  602. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +52 -0
  603. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +55 -0
  604. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.comp +58 -0
  605. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +60 -0
  606. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +43 -0
  607. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +43 -0
  608. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +47 -0
  609. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +24 -0
  610. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +20 -0
  611. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +22 -0
  612. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +26 -0
  613. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +17 -0
  614. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +173 -0
  615. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +50 -0
  616. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +17 -0
  617. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +29 -0
  618. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +37 -0
  619. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +20 -0
  620. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_bfloat16_support.comp +7 -0
  621. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat2_support.comp +7 -0
  622. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat_support.comp +7 -0
  623. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_integer_dot_support.comp +7 -0
  624. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +41 -0
  625. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/types.comp +1373 -0
  626. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +36 -0
  627. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +740 -0
  628. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv6.comp +87 -0
  629. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv7.comp +91 -0
  630. package/cpp/llama.cpp/ggml/src/ggml.c +6499 -0
  631. package/cpp/llama.cpp/ggml/src/gguf.cpp +1330 -0
  632. package/cpp/llama.cpp/gguf-py/LICENSE +21 -0
  633. package/cpp/llama.cpp/gguf-py/README.md +99 -0
  634. package/cpp/llama.cpp/gguf-py/examples/reader.py +49 -0
  635. package/cpp/llama.cpp/gguf-py/examples/writer.py +39 -0
  636. package/cpp/llama.cpp/gguf-py/gguf/__init__.py +9 -0
  637. package/cpp/llama.cpp/gguf-py/gguf/constants.py +2296 -0
  638. package/cpp/llama.cpp/gguf-py/gguf/gguf.py +15 -0
  639. package/cpp/llama.cpp/gguf-py/gguf/gguf_reader.py +367 -0
  640. package/cpp/llama.cpp/gguf-py/gguf/gguf_writer.py +1041 -0
  641. package/cpp/llama.cpp/gguf-py/gguf/lazy.py +223 -0
  642. package/cpp/llama.cpp/gguf-py/gguf/metadata.py +642 -0
  643. package/cpp/llama.cpp/gguf-py/gguf/py.typed +0 -0
  644. package/cpp/llama.cpp/gguf-py/gguf/quants.py +1269 -0
  645. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_convert_endian.py +182 -0
  646. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_dump.py +454 -0
  647. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_editor_gui.py +1610 -0
  648. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_hash.py +102 -0
  649. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_new_metadata.py +207 -0
  650. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_set_metadata.py +95 -0
  651. package/cpp/llama.cpp/gguf-py/gguf/tensor_mapping.py +1172 -0
  652. package/cpp/llama.cpp/gguf-py/gguf/utility.py +264 -0
  653. package/cpp/llama.cpp/gguf-py/gguf/vocab.py +492 -0
  654. package/cpp/llama.cpp/gguf-py/pyproject.toml +43 -0
  655. package/cpp/llama.cpp/gguf-py/tests/__init__.py +1 -0
  656. package/cpp/llama.cpp/gguf-py/tests/test_metadata.py +238 -0
  657. package/cpp/llama.cpp/gguf-py/tests/test_quants.py +238 -0
  658. package/cpp/llama.cpp/grammars/README.md +382 -0
  659. package/cpp/llama.cpp/grammars/arithmetic.gbnf +6 -0
  660. package/cpp/llama.cpp/grammars/c.gbnf +42 -0
  661. package/cpp/llama.cpp/grammars/chess.gbnf +13 -0
  662. package/cpp/llama.cpp/grammars/english.gbnf +6 -0
  663. package/cpp/llama.cpp/grammars/japanese.gbnf +7 -0
  664. package/cpp/llama.cpp/grammars/json.gbnf +25 -0
  665. package/cpp/llama.cpp/grammars/json_arr.gbnf +34 -0
  666. package/cpp/llama.cpp/grammars/list.gbnf +4 -0
  667. package/cpp/llama.cpp/include/llama-cpp.h +30 -0
  668. package/cpp/llama.cpp/include/llama.h +1440 -0
  669. package/cpp/llama.cpp/licenses/LICENSE-curl +9 -0
  670. package/cpp/llama.cpp/licenses/LICENSE-httplib +21 -0
  671. package/cpp/llama.cpp/licenses/LICENSE-jsonhpp +21 -0
  672. package/cpp/llama.cpp/licenses/LICENSE-linenoise +26 -0
  673. package/cpp/llama.cpp/media/llama0-banner.png +0 -0
  674. package/cpp/llama.cpp/media/llama0-logo.png +0 -0
  675. package/cpp/llama.cpp/media/llama1-banner.png +0 -0
  676. package/cpp/llama.cpp/media/llama1-logo.png +0 -0
  677. package/cpp/llama.cpp/media/llama1-logo.svg +34 -0
  678. package/cpp/llama.cpp/media/matmul.png +0 -0
  679. package/cpp/llama.cpp/media/matmul.svg +1238 -0
  680. package/cpp/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  681. package/cpp/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  682. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  683. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +112 -0
  684. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +46 -0
  685. package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +112 -0
  686. package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.out +46 -0
  687. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  688. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.inp +112 -0
  689. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.out +46 -0
  690. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  691. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
  692. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +46 -0
  693. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  694. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
  695. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +46 -0
  696. package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +112 -0
  697. package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +46 -0
  698. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  699. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.inp +112 -0
  700. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.out +46 -0
  701. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  702. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +112 -0
  703. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +46 -0
  704. package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +112 -0
  705. package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +46 -0
  706. package/cpp/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  707. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  708. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +112 -0
  709. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +46 -0
  710. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  711. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +112 -0
  712. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +46 -0
  713. package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.inp +112 -0
  714. package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.out +46 -0
  715. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  716. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.inp +112 -0
  717. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.out +46 -0
  718. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  719. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +112 -0
  720. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.out +46 -0
  721. package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +112 -0
  722. package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.out +46 -0
  723. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  724. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +112 -0
  725. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.out +46 -0
  726. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  727. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.inp +112 -0
  728. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.out +46 -0
  729. package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +112 -0
  730. package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +46 -0
  731. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  732. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +112 -0
  733. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.out +46 -0
  734. package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja +202 -0
  735. package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r7b-12-2024-tool_use.jinja +156 -0
  736. package/cpp/llama.cpp/models/templates/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use.jinja +152 -0
  737. package/cpp/llama.cpp/models/templates/NousResearch-Hermes-3-Llama-3.1-8B-tool_use.jinja +152 -0
  738. package/cpp/llama.cpp/models/templates/Qwen-Qwen2.5-7B-Instruct.jinja +54 -0
  739. package/cpp/llama.cpp/models/templates/README.md +22 -0
  740. package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Llama-8B.jinja +1 -0
  741. package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Qwen-32B.jinja +1 -0
  742. package/cpp/llama.cpp/models/templates/fireworks-ai-llama-3-firefunction-v2.jinja +57 -0
  743. package/cpp/llama.cpp/models/templates/google-gemma-2-2b-it.jinja +4 -0
  744. package/cpp/llama.cpp/models/templates/llama-cpp-deepseek-r1.jinja +76 -0
  745. package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.1.jinja +58 -0
  746. package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.2.jinja +287 -0
  747. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja +109 -0
  748. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.2-3B-Instruct.jinja +93 -0
  749. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.3-70B-Instruct.jinja +109 -0
  750. package/cpp/llama.cpp/models/templates/microsoft-Phi-3.5-mini-instruct.jinja +8 -0
  751. package/cpp/llama.cpp/models/templates/mistralai-Mistral-Nemo-Instruct-2407.jinja +87 -0
  752. package/cpp/llama.cpp/mypy.ini +7 -0
  753. package/cpp/llama.cpp/pocs/CMakeLists.txt +14 -0
  754. package/cpp/llama.cpp/pocs/vdot/CMakeLists.txt +9 -0
  755. package/cpp/llama.cpp/pocs/vdot/q8dot.cpp +173 -0
  756. package/cpp/llama.cpp/pocs/vdot/vdot.cpp +311 -0
  757. package/cpp/llama.cpp/poetry.lock +1197 -0
  758. package/cpp/llama.cpp/prompts/LLM-questions.txt +49 -0
  759. package/cpp/llama.cpp/prompts/alpaca.txt +1 -0
  760. package/cpp/llama.cpp/prompts/assistant.txt +31 -0
  761. package/cpp/llama.cpp/prompts/chat-with-baichuan.txt +4 -0
  762. package/cpp/llama.cpp/prompts/chat-with-bob.txt +7 -0
  763. package/cpp/llama.cpp/prompts/chat-with-qwen.txt +1 -0
  764. package/cpp/llama.cpp/prompts/chat-with-vicuna-v0.txt +7 -0
  765. package/cpp/llama.cpp/prompts/chat-with-vicuna-v1.txt +7 -0
  766. package/cpp/llama.cpp/prompts/chat.txt +28 -0
  767. package/cpp/llama.cpp/prompts/dan-modified.txt +1 -0
  768. package/cpp/llama.cpp/prompts/dan.txt +1 -0
  769. package/cpp/llama.cpp/prompts/mnemonics.txt +93 -0
  770. package/cpp/llama.cpp/prompts/parallel-questions.txt +43 -0
  771. package/cpp/llama.cpp/prompts/reason-act.txt +18 -0
  772. package/cpp/llama.cpp/pyproject.toml +45 -0
  773. package/cpp/llama.cpp/pyrightconfig.json +22 -0
  774. package/cpp/llama.cpp/requirements/requirements-all.txt +15 -0
  775. package/cpp/llama.cpp/requirements/requirements-compare-llama-bench.txt +2 -0
  776. package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +3 -0
  777. package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +3 -0
  778. package/cpp/llama.cpp/requirements/requirements-convert_legacy_llama.txt +5 -0
  779. package/cpp/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +1 -0
  780. package/cpp/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +2 -0
  781. package/cpp/llama.cpp/requirements/requirements-gguf_editor_gui.txt +3 -0
  782. package/cpp/llama.cpp/requirements/requirements-pydantic.txt +3 -0
  783. package/cpp/llama.cpp/requirements/requirements-test-tokenizer-random.txt +1 -0
  784. package/cpp/llama.cpp/requirements/requirements-tool_bench.txt +12 -0
  785. package/cpp/llama.cpp/requirements.txt +13 -0
  786. package/cpp/llama.cpp/src/CMakeLists.txt +45 -0
  787. package/cpp/llama.cpp/src/llama-adapter.cpp +388 -0
  788. package/cpp/llama.cpp/src/llama-adapter.h +76 -0
  789. package/cpp/llama.cpp/src/llama-arch.cpp +1743 -0
  790. package/cpp/llama.cpp/src/llama-arch.h +437 -0
  791. package/cpp/llama.cpp/src/llama-batch.cpp +372 -0
  792. package/cpp/llama.cpp/src/llama-batch.h +89 -0
  793. package/cpp/llama.cpp/src/llama-chat.cpp +663 -0
  794. package/cpp/llama.cpp/src/llama-chat.h +58 -0
  795. package/cpp/llama.cpp/src/llama-context.cpp +2459 -0
  796. package/cpp/llama.cpp/src/llama-context.h +246 -0
  797. package/cpp/llama.cpp/src/llama-cparams.cpp +1 -0
  798. package/cpp/llama.cpp/src/llama-cparams.h +39 -0
  799. package/cpp/llama.cpp/src/llama-grammar.cpp +1219 -0
  800. package/cpp/llama.cpp/src/llama-grammar.h +173 -0
  801. package/cpp/llama.cpp/src/llama-graph.cpp +1713 -0
  802. package/cpp/llama.cpp/src/llama-graph.h +595 -0
  803. package/cpp/llama.cpp/src/llama-hparams.cpp +79 -0
  804. package/cpp/llama.cpp/src/llama-hparams.h +161 -0
  805. package/cpp/llama.cpp/src/llama-impl.cpp +167 -0
  806. package/cpp/llama.cpp/src/llama-impl.h +61 -0
  807. package/cpp/llama.cpp/src/llama-io.cpp +15 -0
  808. package/cpp/llama.cpp/src/llama-io.h +35 -0
  809. package/cpp/llama.cpp/src/llama-kv-cache.cpp +2486 -0
  810. package/cpp/llama.cpp/src/llama-kv-cache.h +405 -0
  811. package/cpp/llama.cpp/src/llama-memory.cpp +1 -0
  812. package/cpp/llama.cpp/src/llama-memory.h +31 -0
  813. package/cpp/llama.cpp/src/llama-mmap.cpp +600 -0
  814. package/cpp/llama.cpp/src/llama-mmap.h +68 -0
  815. package/cpp/llama.cpp/src/llama-model-loader.cpp +1133 -0
  816. package/cpp/llama.cpp/src/llama-model-loader.h +169 -0
  817. package/cpp/llama.cpp/src/llama-model.cpp +13453 -0
  818. package/cpp/llama.cpp/src/llama-model.h +420 -0
  819. package/cpp/llama.cpp/src/llama-quant.cpp +964 -0
  820. package/cpp/llama.cpp/src/llama-quant.h +1 -0
  821. package/cpp/llama.cpp/src/llama-sampling.cpp +2575 -0
  822. package/cpp/llama.cpp/src/llama-sampling.h +32 -0
  823. package/cpp/llama.cpp/src/llama-vocab.cpp +3313 -0
  824. package/cpp/llama.cpp/src/llama-vocab.h +125 -0
  825. package/cpp/llama.cpp/src/llama.cpp +340 -0
  826. package/cpp/llama.cpp/src/unicode-data.cpp +7034 -0
  827. package/cpp/llama.cpp/src/unicode-data.h +20 -0
  828. package/cpp/llama.cpp/src/unicode.cpp +849 -0
  829. package/cpp/llama.cpp/src/unicode.h +66 -0
  830. package/cpp/rn-completion.cpp +431 -0
  831. package/cpp/rn-llama.hpp +60 -0
  832. package/cpp/rn-utils.hpp +331 -0
  833. package/ios/OnLoad.mm +22 -0
  834. package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec-generated.mm +64 -0
  835. package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec.h +251 -0
  836. package/ios/generated/RNLlamaCppSpecJSI-generated.cpp +42 -0
  837. package/ios/generated/RNLlamaCppSpecJSI.h +336 -0
  838. package/ios/include/chat.h +135 -0
  839. package/ios/include/common/base64.hpp +392 -0
  840. package/ios/include/common/json.hpp +24766 -0
  841. package/ios/include/common/minja/chat-template.hpp +537 -0
  842. package/ios/include/common/minja/minja.hpp +2941 -0
  843. package/ios/include/common.h +668 -0
  844. package/ios/include/json-schema-to-grammar.h +21 -0
  845. package/ios/include/llama-cpp.h +30 -0
  846. package/ios/include/llama.h +1440 -0
  847. package/ios/include/log.h +103 -0
  848. package/ios/include/ngram-cache.h +101 -0
  849. package/ios/include/sampling.h +107 -0
  850. package/ios/include/speculative.h +28 -0
  851. package/ios/libs/llama.xcframework/Info.plist +135 -0
  852. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  853. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  854. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
  855. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  856. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  857. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  858. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  859. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  860. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml.h +2192 -0
  861. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/gguf.h +202 -0
  862. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/llama.h +1440 -0
  863. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Info.plist +36 -0
  864. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Modules/module.modulemap +17 -0
  865. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/llama +0 -0
  866. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  867. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  868. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  869. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
  870. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  871. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  872. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  873. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  874. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  875. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  876. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  877. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  878. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Info.plist +36 -0
  879. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  880. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/llama +0 -0
  881. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  882. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  883. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  884. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3442 -0
  885. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-alloc.h +76 -0
  886. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-backend.h +354 -0
  887. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-blas.h +25 -0
  888. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-cpu.h +143 -0
  889. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-metal.h +66 -0
  890. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml.h +2192 -0
  891. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/gguf.h +202 -0
  892. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/llama.h +1440 -0
  893. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Modules/module.modulemap +17 -0
  894. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Resources/Info.plist +32 -0
  895. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-alloc.h +76 -0
  896. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-backend.h +354 -0
  897. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-blas.h +25 -0
  898. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-cpu.h +143 -0
  899. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-metal.h +66 -0
  900. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml.h +2192 -0
  901. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/gguf.h +202 -0
  902. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/llama.h +1440 -0
  903. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Modules/module.modulemap +17 -0
  904. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Resources/Info.plist +32 -0
  905. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/llama +0 -0
  906. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-alloc.h +76 -0
  907. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-backend.h +354 -0
  908. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-blas.h +25 -0
  909. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-cpu.h +143 -0
  910. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-metal.h +66 -0
  911. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml.h +2192 -0
  912. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/gguf.h +202 -0
  913. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/llama.h +1440 -0
  914. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Modules/module.modulemap +17 -0
  915. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Resources/Info.plist +32 -0
  916. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/llama +0 -0
  917. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/llama +0 -0
  918. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  919. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  920. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
  921. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  922. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  923. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  924. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  925. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  926. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml.h +2192 -0
  927. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/gguf.h +202 -0
  928. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/llama.h +1440 -0
  929. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Info.plist +35 -0
  930. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Modules/module.modulemap +17 -0
  931. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/llama +0 -0
  932. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  933. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  934. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  935. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
  936. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  937. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  938. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  939. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  940. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  941. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  942. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  943. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  944. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Info.plist +35 -0
  945. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  946. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/llama +0 -0
  947. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  948. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  949. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4528 -0
  950. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  951. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  952. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  953. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  954. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  955. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml.h +2192 -0
  956. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/gguf.h +202 -0
  957. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/llama.h +1440 -0
  958. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Info.plist +32 -0
  959. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Modules/module.modulemap +17 -0
  960. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/llama +0 -0
  961. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  962. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  963. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4549 -0
  964. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3470 -0
  965. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  966. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  967. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  968. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  969. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  970. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  971. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  972. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  973. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Info.plist +32 -0
  974. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  975. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/llama +0 -0
  976. package/lib/module/NativeRNLlamaCpp.js +35 -0
  977. package/lib/module/NativeRNLlamaCpp.js.map +1 -0
  978. package/lib/module/index.js +20 -0
  979. package/lib/module/index.js.map +1 -0
  980. package/lib/module/package.json +1 -0
  981. package/lib/typescript/package.json +1 -0
  982. package/lib/typescript/src/NativeRNLlamaCpp.d.ts +222 -0
  983. package/lib/typescript/src/NativeRNLlamaCpp.d.ts.map +1 -0
  984. package/lib/typescript/src/index.d.ts +5 -0
  985. package/lib/typescript/src/index.d.ts.map +1 -0
  986. package/package.json +161 -0
  987. package/react-native.config.js +15 -0
  988. package/src/NativeRNLlamaCpp.ts +282 -0
  989. package/src/index.tsx +54 -0
@@ -0,0 +1,1713 @@
1
+ #include "llama-graph.h"
2
+
3
+ #include "llama-impl.h"
4
+ #include "llama-batch.h"
5
+ #include "llama-cparams.h"
6
+ #include "llama-kv-cache.h"
7
+
8
+ #include <cassert>
9
+ #include <cmath>
10
+ #include <cstring>
11
+
12
+ static int32_t llama_relative_position_bucket(llama_pos x, llama_pos y, uint64_t n_buckets, bool bidirectional) {
13
+ // TODO move to hparams if a T5 variant appears that uses a different value
14
+ const int64_t max_distance = 128;
15
+
16
+ if (bidirectional) {
17
+ n_buckets >>= 1;
18
+ }
19
+
20
+ const int64_t max_exact = n_buckets >> 1;
21
+
22
+ int32_t relative_position = x - y;
23
+ int32_t relative_bucket = 0;
24
+
25
+ if (bidirectional) {
26
+ relative_bucket += (relative_position > 0) * n_buckets;
27
+ relative_position = abs(relative_position);
28
+ } else {
29
+ relative_position = -std::min<int32_t>(relative_position, 0);
30
+ }
31
+
32
+ int32_t relative_position_if_large = floorf(max_exact + logf(1.0 * relative_position / max_exact) * (n_buckets - max_exact) / log(1.0 * max_distance / max_exact));
33
+ relative_position_if_large = std::min<int32_t>(relative_position_if_large, n_buckets - 1);
34
+ relative_bucket += (relative_position < max_exact ? relative_position : relative_position_if_large);
35
+
36
+ return relative_bucket;
37
+ }
38
+
39
+ void llm_graph_input_embd::set_input(const llama_ubatch * ubatch) {
40
+ if (ubatch->token) {
41
+ const int64_t n_tokens = ubatch->n_tokens;
42
+
43
+ ggml_backend_tensor_set(tokens, ubatch->token, 0, n_tokens*ggml_element_size(tokens));
44
+ }
45
+
46
+ if (ubatch->embd) {
47
+ const int64_t n_embd = embd->ne[0];
48
+ const int64_t n_tokens = ubatch->n_tokens;
49
+
50
+ ggml_backend_tensor_set(embd, ubatch->embd, 0, n_tokens*n_embd*ggml_element_size(embd));
51
+ }
52
+ }
53
+
54
+ void llm_graph_input_pos::set_input(const llama_ubatch * ubatch) {
55
+ if (ubatch->pos && pos) {
56
+ const int64_t n_tokens = ubatch->n_tokens;
57
+
58
+ if (ubatch->token && n_pos_per_embd == 4) {
59
+ // in case we're using M-RoPE with text tokens, convert the 1D positions to 4D
60
+ // the 3 first dims are the same, and 4th dim is all 0
61
+ std::vector<llama_pos> pos_data(n_tokens*n_pos_per_embd);
62
+ // copy the first dimension
63
+ for (int i = 0; i < n_tokens; ++i) {
64
+ pos_data[ i] = ubatch->pos[i];
65
+ pos_data[ n_tokens + i] = ubatch->pos[i];
66
+ pos_data[2 * n_tokens + i] = ubatch->pos[i];
67
+ pos_data[3 * n_tokens + i] = 0; // 4th dim is 0
68
+ }
69
+ ggml_backend_tensor_set(pos, pos_data.data(), 0, pos_data.size()*ggml_element_size(pos));
70
+ } else {
71
+ ggml_backend_tensor_set(pos, ubatch->pos, 0, n_tokens*n_pos_per_embd*ggml_element_size(pos));
72
+ }
73
+ }
74
+ }
75
+
76
+ void llm_graph_input_attn_temp::set_input(const llama_ubatch * ubatch) {
77
+ if (ubatch->pos && attn_scale) {
78
+ const int64_t n_tokens = ubatch->n_tokens;
79
+
80
+ std::vector<float> attn_scale_data(n_tokens, 0.0f);
81
+ for (int i = 0; i < n_tokens; ++i) {
82
+ const float pos = ubatch->pos[i];
83
+ attn_scale_data[i] = std::log(
84
+ std::floor((pos + 1.0f) / n_attn_temp_floor_scale) + 1.0
85
+ ) * f_attn_temp_scale + 1.0;
86
+ }
87
+
88
+ ggml_backend_tensor_set(attn_scale, attn_scale_data.data(), 0, n_tokens*ggml_element_size(attn_scale));
89
+ }
90
+ }
91
+
92
+ void llm_graph_input_pos_bucket::set_input(const llama_ubatch * ubatch) {
93
+ if (pos_bucket) {
94
+ const int64_t n_tokens = ubatch->n_tokens;
95
+
96
+ GGML_ASSERT(ggml_backend_buffer_is_host(pos_bucket->buffer));
97
+ GGML_ASSERT(!ubatch->equal_seqs); // TODO: use ubatch->n_seqs instead of failing
98
+
99
+ int32_t * data = (int32_t *) pos_bucket->data;
100
+
101
+ for (int h = 0; h < 1; ++h) {
102
+ for (int j = 0; j < n_tokens; ++j) {
103
+ for (int i = 0; i < n_tokens; ++i) {
104
+ data[h*(n_tokens*n_tokens) + j*n_tokens + i] = llama_relative_position_bucket(ubatch->pos[i], ubatch->pos[j], hparams.n_rel_attn_bkts, true);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ void llm_graph_input_pos_bucket_kv::set_input(const llama_ubatch * ubatch) {
112
+ if (pos_bucket) {
113
+ const int64_t n_tokens = ubatch->n_tokens;
114
+
115
+ GGML_ASSERT(ggml_backend_buffer_is_host(pos_bucket->buffer));
116
+ GGML_ASSERT(!ubatch->equal_seqs); // TODO: use ubatch->n_seqs instead of failing
117
+
118
+ int32_t * data = (int32_t *) pos_bucket->data;
119
+
120
+ const int64_t n_kv = kv_self->n;
121
+
122
+ for (int h = 0; h < 1; ++h) {
123
+ for (int j = 0; j < n_tokens; ++j) {
124
+ for (int i = 0; i < n_kv; ++i) {
125
+ data[h*(n_kv*n_tokens) + j*n_kv + i] = llama_relative_position_bucket(kv_self->cells[i].pos, ubatch->pos[j], hparams.n_rel_attn_bkts, false);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ void llm_graph_input_out_ids::set_input(const llama_ubatch * ubatch) {
133
+ if (hparams.causal_attn || cparams.pooling_type == LLAMA_POOLING_TYPE_NONE) {
134
+ //GGML_ASSERT(out_ids && "every model that can must skip unused outputs");
135
+
136
+ if (!out_ids) {
137
+ LLAMA_LOG_WARN("%s: 'out_ids' is not created\n", __func__);
138
+ } else {
139
+ const int64_t n_tokens = ubatch->n_tokens;
140
+
141
+ GGML_ASSERT(ggml_backend_buffer_is_host(out_ids->buffer));
142
+ int32_t * data = (int32_t *) out_ids->data;
143
+
144
+ if (n_outputs == n_tokens) {
145
+ for (int i = 0; i < n_tokens; ++i) {
146
+ data[i] = i;
147
+ }
148
+ } else if (ubatch->output) {
149
+ int32_t n_outputs = 0;
150
+ for (int i = 0; i < n_tokens; ++i) {
151
+ if (ubatch->output[i]) {
152
+ data[n_outputs++] = i;
153
+ }
154
+ }
155
+ // the graph needs to have been passed the correct number of outputs
156
+ GGML_ASSERT(n_outputs == n_outputs);
157
+ } else if (n_outputs == 1) {
158
+ // only keep last output
159
+ data[0] = n_tokens - 1;
160
+ } else {
161
+ GGML_ASSERT(n_outputs == 0);
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ void llm_graph_input_mean::set_input(const llama_ubatch * ubatch) {
168
+ if (cparams.embeddings && cparams.pooling_type == LLAMA_POOLING_TYPE_MEAN) {
169
+ const int64_t n_tokens = ubatch->n_tokens;
170
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
171
+ const int64_t n_seqs = ubatch->n_seqs;
172
+
173
+ GGML_ASSERT(mean);
174
+ GGML_ASSERT(ggml_backend_buffer_is_host(mean->buffer));
175
+
176
+ float * data = (float *) mean->data;
177
+ memset(mean->data, 0, n_tokens * n_tokens * ggml_element_size(mean));
178
+
179
+ std::vector<uint64_t> sum(n_tokens, 0);
180
+
181
+ for (int s = 0; s < n_seqs; ++s) {
182
+ const llama_seq_id seq_id = ubatch->seq_id[s][0];
183
+
184
+ // TODO: adapt limits to n_seqs when ubatch->equal_seqs is true
185
+ GGML_ASSERT(seq_id < n_tokens && "seq_id cannot be larger than n_tokens with pooling_type == MEAN");
186
+
187
+ sum[seq_id] += ubatch->n_seq_tokens;
188
+ }
189
+
190
+ std::vector<float> div(n_tokens, 0.0f);
191
+ for (int i = 0; i < n_tokens; ++i) {
192
+ const uint64_t s = sum[i];
193
+ if (s > 0) {
194
+ div[i] = 1.0f/float(s);
195
+ }
196
+ }
197
+
198
+ for (int s = 0; s < n_seqs; ++s) {
199
+ const llama_seq_id seq_id = ubatch->seq_id[s][0];
200
+
201
+ for (int i = 0; i < n_seq_tokens; ++i) {
202
+ data[seq_id*n_tokens + s*n_seq_tokens + i] = div[seq_id];
203
+ }
204
+ }
205
+ }
206
+ }
207
+
208
+ void llm_graph_input_cls::set_input(const llama_ubatch * ubatch) {
209
+ if (cparams.embeddings && (
210
+ cparams.pooling_type == LLAMA_POOLING_TYPE_CLS ||
211
+ cparams.pooling_type == LLAMA_POOLING_TYPE_RANK)) {
212
+ const int64_t n_tokens = ubatch->n_tokens;
213
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
214
+ const int64_t n_seqs = ubatch->n_seqs;
215
+
216
+ GGML_ASSERT(cls);
217
+ GGML_ASSERT(ggml_backend_buffer_is_host(cls->buffer));
218
+
219
+ uint32_t * data = (uint32_t *) cls->data;
220
+ memset(cls->data, 0, n_tokens * ggml_element_size(cls));
221
+
222
+ for (int s = 0; s < n_seqs; ++s) {
223
+ const llama_seq_id seq_id = ubatch->seq_id[s][0];
224
+
225
+ // TODO: adapt limits to n_seqs when ubatch->equal_seqs is true
226
+ GGML_ASSERT(seq_id < n_tokens && "seq_id cannot be larger than n_tokens with pooling_type == CLS or RANK");
227
+
228
+ for (int i = 0; i < n_seq_tokens; ++i) {
229
+ const llama_pos pos = ubatch->pos[s*n_seq_tokens + i];
230
+
231
+ if (pos == 0) {
232
+ data[seq_id] = s*n_seq_tokens + i;
233
+ }
234
+ }
235
+ }
236
+ }
237
+
238
+ if (cparams.embeddings && cparams.pooling_type == LLAMA_POOLING_TYPE_LAST) {
239
+ const int64_t n_tokens = ubatch->n_tokens;
240
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
241
+ const int64_t n_seqs = ubatch->n_seqs;
242
+
243
+ GGML_ASSERT(cls);
244
+ GGML_ASSERT(ggml_backend_buffer_is_host(cls->buffer));
245
+
246
+ uint32_t * data = (uint32_t *) cls->data;
247
+ memset(cls->data, 0, n_tokens * ggml_element_size(cls));
248
+
249
+ std::vector<int> last_pos(n_tokens, -1);
250
+ std::vector<int> last_row(n_tokens, -1);
251
+
252
+ for (int s = 0; s < n_seqs; ++s) {
253
+ const llama_seq_id seq_id = ubatch->seq_id[s][0];
254
+
255
+ // TODO: adapt limits to n_seqs when ubatch->equal_seqs is true
256
+ GGML_ASSERT(seq_id < n_tokens && "seq_id cannot be larger than n_tokens with pooling_type == LAST");
257
+
258
+ for (int i = 0; i < n_seq_tokens; ++i) {
259
+ const llama_pos pos = ubatch->pos[s*n_seq_tokens + i];
260
+
261
+ if (pos >= last_pos[seq_id]) {
262
+ last_pos[seq_id] = pos;
263
+ last_row[seq_id] = s*n_seq_tokens + i;
264
+ }
265
+ }
266
+ }
267
+
268
+ for (int i = 0; i < n_tokens; ++i) {
269
+ if (last_row[i] >= 0) {
270
+ data[i] = last_row[i];
271
+ }
272
+ }
273
+ }
274
+ }
275
+
276
+ void llm_graph_input_s_copy::set_input(const llama_ubatch * ubatch) {
277
+ GGML_UNUSED(ubatch);
278
+
279
+ const int64_t n_kv = kv_self->n;
280
+
281
+ if (s_copy) {
282
+ GGML_ASSERT(ggml_backend_buffer_is_host(s_copy->buffer));
283
+ int32_t * data = (int32_t *) s_copy->data;
284
+
285
+ // assuming copy destinations ALWAYS happen ONLY on the cells between head and head+n
286
+ for (uint32_t i = 0; i < n_kv; ++i) {
287
+ data[i] = kv_self->s_copy(i);
288
+ }
289
+ }
290
+ }
291
+
292
+ void llm_graph_input_s_mask::set_input(const llama_ubatch * ubatch) {
293
+ GGML_UNUSED(ubatch);
294
+
295
+ const int64_t n_kv = kv_self->n;
296
+
297
+ if (s_mask) {
298
+ GGML_ASSERT(ggml_backend_buffer_is_host(s_mask->buffer));
299
+ float * data = (float *) s_mask->data;
300
+
301
+ // clear unused states
302
+ for (int i = 0; i < n_kv; ++i) {
303
+ data[i] = kv_self->s_mask(i);
304
+ }
305
+ }
306
+ }
307
+
308
+ void llm_graph_input_cross_embd::set_input(const llama_ubatch * ubatch) {
309
+ GGML_UNUSED(ubatch);
310
+
311
+ if (cross_embd && !cross->v_embd.empty()) {
312
+ assert(cross_embd->type == GGML_TYPE_F32);
313
+
314
+ ggml_backend_tensor_set(cross_embd, cross->v_embd.data(), 0, ggml_nbytes(cross_embd));
315
+ }
316
+ }
317
+
318
+ void llm_graph_input_attn_no_cache::set_input(const llama_ubatch * ubatch) {
319
+ if (kq_mask) {
320
+ if (cparams.causal_attn) {
321
+ const int64_t n_kv = ubatch->n_tokens;
322
+ const int64_t n_tokens = ubatch->n_tokens;
323
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
324
+ const int64_t n_seqs = ubatch->n_seqs;
325
+
326
+ GGML_ASSERT(ggml_backend_buffer_is_host(kq_mask->buffer));
327
+ float * data = (float *) kq_mask->data;
328
+
329
+ for (int h = 0; h < 1; ++h) {
330
+ for (int s1 = 0; s1 < n_seqs; ++s1) {
331
+ const llama_seq_id seq_id = ubatch->seq_id[s1][0];
332
+
333
+ for (int j = 0; j < n_seq_tokens; ++j) {
334
+ const int32_t tj = s1*n_seq_tokens + j;
335
+
336
+ for (int s0 = 0; s0 < n_seqs; ++s0) {
337
+ for (int i = 0; i < n_seq_tokens; ++i) {
338
+ const int32_t ti = s0*n_seq_tokens + i;
339
+ float f = -INFINITY;
340
+
341
+ for (int s = 0; s < ubatch->n_seq_id[s0]; ++s) {
342
+ if (ubatch->seq_id[s0][s] == seq_id && ubatch->pos[ti] <= ubatch->pos[tj]) {
343
+ if (hparams.use_alibi) {
344
+ f = -std::abs(ubatch->pos[ti] - ubatch->pos[tj]);
345
+ } else {
346
+ f = 0.0f;
347
+ }
348
+ break;
349
+ }
350
+ }
351
+
352
+ data[h*(n_kv*n_tokens) + tj*n_kv + ti] = f;
353
+ }
354
+ }
355
+ }
356
+ }
357
+ }
358
+ } else {
359
+ const int64_t n_tokens = ubatch->n_tokens;
360
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
361
+ const int64_t n_seqs = ubatch->n_seqs;
362
+ const int64_t n_stride = ubatch->n_tokens;
363
+
364
+ GGML_ASSERT(ggml_backend_buffer_is_host(kq_mask->buffer));
365
+
366
+ float * data = (float *) kq_mask->data;
367
+
368
+ for (int h = 0; h < 1; ++h) {
369
+ for (int s1 = 0; s1 < n_seqs; ++s1) {
370
+ const llama_seq_id seq_id = ubatch->seq_id[s1][0];
371
+
372
+ for (int j = 0; j < n_seq_tokens; ++j) {
373
+ const int32_t tj = s1*n_seq_tokens + j;
374
+
375
+ for (int s0 = 0; s0 < n_seqs; ++s0) {
376
+ for (int i = 0; i < n_seq_tokens; ++i) {
377
+ const int32_t ti = s0*n_seq_tokens + i;
378
+ float f = -INFINITY;
379
+
380
+ for (int s = 0; s < ubatch->n_seq_id[s0]; ++s) {
381
+ if (ubatch->seq_id[s0][s] == seq_id) {
382
+ if (hparams.use_alibi) {
383
+ f = -std::abs(ubatch->pos[ti] - ubatch->pos[tj]);
384
+ } else {
385
+ f = 0.0f;
386
+ }
387
+ break;
388
+ }
389
+ }
390
+
391
+ data[h*(n_tokens*n_tokens) + tj*n_stride + ti] = f;
392
+ }
393
+ }
394
+
395
+ for (int i = n_tokens; i < n_stride; ++i) {
396
+ data[h*(n_tokens*n_tokens) + tj*n_stride + i] = -INFINITY;
397
+ }
398
+ }
399
+ }
400
+ }
401
+ }
402
+ }
403
+ }
404
+
405
+ void llm_graph_input_attn_kv_unified::set_input(const llama_ubatch * ubatch) {
406
+ if (self_kq_mask || self_kq_mask_swa) {
407
+ const int64_t n_kv = kv_self->n;
408
+ const int64_t n_tokens = ubatch->n_tokens;
409
+ const int64_t n_seq_tokens = ubatch->n_seq_tokens;
410
+ const int64_t n_seqs = ubatch->n_seqs;
411
+
412
+ float * data = nullptr;
413
+ float * data_swa = nullptr;
414
+
415
+ if (self_kq_mask) {
416
+ GGML_ASSERT(ggml_backend_buffer_is_host(self_kq_mask->buffer));
417
+ data = (float *) self_kq_mask->data;
418
+ }
419
+
420
+ if (self_kq_mask_swa) {
421
+ GGML_ASSERT(ggml_backend_buffer_is_host(self_kq_mask_swa->buffer));
422
+ data_swa = (float *) self_kq_mask_swa->data;
423
+ }
424
+
425
+ // Use only the previous KV cells of the correct sequence for each token of the ubatch.
426
+ // It's assumed that if a token in the batch has multiple sequences, they are equivalent.
427
+ // Example with a cache of 10 tokens, 2 tokens populated in cache and 3 tokens in batch:
428
+ // Causal mask:
429
+ // xxx-------
430
+ // xxxx------
431
+ // xxxxx-----
432
+ // Non-causal mask:
433
+ // xxxxx-----
434
+ // xxxxx-----
435
+ // xxxxx-----
436
+ // To visualize the mask, see https://github.com/ggml-org/llama.cpp/pull/12615
437
+ for (int h = 0; h < 1; ++h) {
438
+ for (int s = 0; s < n_seqs; ++s) {
439
+ const llama_seq_id seq_id = ubatch->seq_id[s][0];
440
+
441
+ for (int j = 0; j < n_seq_tokens; ++j) {
442
+ const llama_pos pos = ubatch->pos[s*n_seq_tokens + j];
443
+ for (int i = 0; i < n_kv; ++i) {
444
+ float f;
445
+ // mask the token if:
446
+ if (!kv_self->cells[i].has_seq_id(seq_id) // not the correct sequence
447
+ || (cparams.causal_attn && kv_self->cells[i].pos > pos) // for causal, mask future tokens
448
+ ) {
449
+ f = -INFINITY;
450
+ } else {
451
+ if (hparams.use_alibi) {
452
+ f = -std::abs(kv_self->cells[i].pos - pos);
453
+ } else {
454
+ f = 0.0f;
455
+ }
456
+ }
457
+
458
+ if (data) {
459
+ data[h*(n_kv*n_tokens) + s*(n_kv*n_seq_tokens) + j*n_kv + i] = f;
460
+ }
461
+
462
+ // may need to cut off old tokens for sliding window
463
+ // TODO @ngxson : we are currently re-using the swa logic to store the chunked mask, we should rename SWA to something more generic like "aux mask"
464
+ if (data_swa) {
465
+ if (hparams.n_attn_chunk) {
466
+ llama_pos pos_chunk_start = (pos / hparams.n_attn_chunk) * hparams.n_attn_chunk;
467
+ if (kv_self->cells[i].pos < pos_chunk_start || pos < pos_chunk_start) {
468
+ f = -INFINITY;
469
+ }
470
+ } else {
471
+ if (pos - kv_self->cells[i].pos >= (int32_t)hparams.n_swa) {
472
+ f = -INFINITY;
473
+ }
474
+ }
475
+ data_swa[h*(n_kv*n_tokens) + s*(n_kv*n_seq_tokens) + j*n_kv + i] = f;
476
+ }
477
+ }
478
+ }
479
+ }
480
+
481
+ // mask padded tokens
482
+ if (data) {
483
+ for (int i = n_tokens; i < GGML_PAD(n_tokens, GGML_KQ_MASK_PAD); ++i) {
484
+ for (int j = 0; j < n_kv; ++j) {
485
+ data[h*(n_kv*n_tokens) + i*n_kv + j] = -INFINITY;
486
+ }
487
+ }
488
+ }
489
+
490
+ // mask padded tokens
491
+ if (data_swa) {
492
+ for (int i = n_tokens; i < GGML_PAD(n_tokens, GGML_KQ_MASK_PAD); ++i) {
493
+ for (int j = 0; j < n_kv; ++j) {
494
+ data_swa[h*(n_kv*n_tokens) + i*n_kv + j] = -INFINITY;
495
+ }
496
+ }
497
+ }
498
+ }
499
+ }
500
+ }
501
+
502
+ void llm_graph_input_attn_cross::set_input(const llama_ubatch * ubatch) {
503
+ if (cross_kq_mask) {
504
+ const int64_t n_enc = cross_kq_mask->ne[0];
505
+ const int64_t n_tokens = ubatch->n_tokens;
506
+
507
+ GGML_ASSERT(ggml_backend_buffer_is_host(cross_kq_mask->buffer));
508
+ GGML_ASSERT(!ubatch->equal_seqs); // TODO: use ubatch->n_seqs instead of failing
509
+
510
+ float * data = (float *) cross_kq_mask->data;
511
+
512
+ for (int h = 0; h < 1; ++h) {
513
+ for (int j = 0; j < n_tokens; ++j) {
514
+ for (int i = 0; i < n_enc; ++i) {
515
+ float f = -INFINITY;
516
+ for (int s = 0; s < ubatch->n_seq_id[j]; ++s) {
517
+ const llama_seq_id seq_id = ubatch->seq_id[j][s];
518
+ if (cross->seq_ids_enc[i].find(seq_id) != cross->seq_ids_enc[i].end()) {
519
+ f = 0.0f;
520
+ }
521
+ }
522
+ data[h*(n_enc*n_tokens) + j*n_enc + i] = f;
523
+ }
524
+ }
525
+
526
+ for (int i = n_tokens; i < GGML_PAD(n_tokens, GGML_KQ_MASK_PAD); ++i) {
527
+ for (int j = 0; j < n_enc; ++j) {
528
+ data[h*(n_enc*n_tokens) + i*n_enc + j] = -INFINITY;
529
+ }
530
+ }
531
+ }
532
+ }
533
+ }
534
+
535
+ //
536
+ // llm_graph_context
537
+ //
538
+
539
+ llm_graph_context::llm_graph_context(const llm_graph_params & params) :
540
+ arch (params.arch),
541
+ hparams (params.hparams),
542
+ cparams (params.cparams),
543
+ ubatch (params.ubatch),
544
+ n_embd (hparams.n_embd),
545
+ n_layer (hparams.n_layer),
546
+ n_rot (hparams.n_rot),
547
+ n_ctx (cparams.n_ctx),
548
+ n_ctx_per_seq (cparams.n_ctx / cparams.n_seq_max),
549
+ n_head (hparams.n_head()),
550
+ n_head_kv (hparams.n_head_kv()),
551
+ n_embd_head_k (hparams.n_embd_head_k),
552
+ n_embd_k_gqa (hparams.n_embd_k_gqa()),
553
+ n_embd_head_v (hparams.n_embd_head_v),
554
+ n_embd_v_gqa (hparams.n_embd_v_gqa()),
555
+ n_expert (hparams.n_expert),
556
+ n_expert_used (cparams.warmup ? hparams.n_expert : hparams.n_expert_used),
557
+ freq_base (cparams.rope_freq_base),
558
+ freq_scale (cparams.rope_freq_scale),
559
+ ext_factor (cparams.yarn_ext_factor),
560
+ attn_factor (cparams.yarn_attn_factor),
561
+ beta_fast (cparams.yarn_beta_fast),
562
+ beta_slow (cparams.yarn_beta_slow),
563
+ norm_eps (hparams.f_norm_eps),
564
+ norm_rms_eps (hparams.f_norm_rms_eps),
565
+ n_tokens (ubatch.n_tokens),
566
+ n_outputs (params.n_outputs),
567
+ n_ctx_orig (cparams.n_ctx_orig_yarn),
568
+ pooling_type (cparams.pooling_type),
569
+ rope_type (hparams.rope_type),
570
+ ctx0 (params.ctx),
571
+ sched (params.sched),
572
+ backend_cpu (params.backend_cpu),
573
+ cvec (params.cvec),
574
+ loras (params.loras),
575
+ memory (params.memory),
576
+ cross (params.cross),
577
+ cb_func (params.cb),
578
+ res (std::make_unique<llm_graph_result>()) {
579
+ }
580
+
581
+ int64_t llm_graph_context::n_pos_per_embd() const {
582
+ return arch == LLM_ARCH_QWEN2VL ? 4 : 1;
583
+ }
584
+
585
+ void llm_graph_context::cb(ggml_tensor * cur, const char * name, int il) const {
586
+ if (cb_func) {
587
+ cb_func(ubatch, cur, name, il);
588
+ }
589
+ }
590
+
591
+ ggml_tensor * llm_graph_context::build_cvec(
592
+ ggml_tensor * cur,
593
+ int il) const {
594
+ return cvec->apply_to(ctx0, cur, il);
595
+ }
596
+
597
+ ggml_tensor * llm_graph_context::build_lora_mm(
598
+ ggml_tensor * w,
599
+ ggml_tensor * cur) const {
600
+ ggml_tensor * res = ggml_mul_mat(ctx0, w, cur);
601
+
602
+ for (const auto & lora : *loras) {
603
+ llama_adapter_lora_weight * lw = lora.first->get_weight(w);
604
+ if (lw == nullptr) {
605
+ continue;
606
+ }
607
+
608
+ const float adapter_scale = lora.second;
609
+ const float scale = lw->get_scale(lora.first->alpha, adapter_scale);
610
+
611
+ ggml_tensor * ab_cur = ggml_mul_mat(
612
+ ctx0, lw->b,
613
+ ggml_mul_mat(ctx0, lw->a, cur)
614
+ );
615
+
616
+ ab_cur = ggml_scale(ctx0, ab_cur, scale);
617
+ res = ggml_add(ctx0, res, ab_cur);
618
+ }
619
+
620
+ return res;
621
+ }
622
+
623
+ ggml_tensor * llm_graph_context::build_lora_mm_id(
624
+ ggml_tensor * w, // ggml_tensor * as
625
+ ggml_tensor * cur, // ggml_tensor * b
626
+ ggml_tensor * ids) const {
627
+ ggml_tensor * res = ggml_mul_mat_id(ctx0, w, cur, ids);
628
+ for (const auto & lora : *loras) {
629
+ llama_adapter_lora_weight * lw = lora.first->get_weight(w);
630
+ if (lw == nullptr) {
631
+ continue;
632
+ }
633
+
634
+ const float alpha = lora.first->alpha;
635
+ const float rank = (float) lw->b->ne[0];
636
+ const float scale = alpha ? lora.second * alpha / rank : lora.second;
637
+
638
+ ggml_tensor * ab_cur = ggml_mul_mat_id(
639
+ ctx0, lw->b,
640
+ ggml_mul_mat_id(ctx0, lw->a, cur, ids),
641
+ ids
642
+ );
643
+
644
+ ab_cur = ggml_scale(ctx0, ab_cur, scale);
645
+ res = ggml_add(ctx0, res, ab_cur);
646
+ }
647
+
648
+ return res;
649
+ }
650
+
651
+ ggml_tensor * llm_graph_context::build_norm(
652
+ ggml_tensor * cur,
653
+ ggml_tensor * mw,
654
+ ggml_tensor * mb,
655
+ llm_norm_type type,
656
+ int il) const {
657
+ switch (type) {
658
+ case LLM_NORM: cur = ggml_norm (ctx0, cur, hparams.f_norm_eps); break;
659
+ case LLM_NORM_RMS: cur = ggml_rms_norm(ctx0, cur, hparams.f_norm_rms_eps); break;
660
+ case LLM_NORM_GROUP:
661
+ {
662
+ cur = ggml_reshape_3d(ctx0, cur, cur->ne[0], 1, cur->ne[1]);
663
+ cur = ggml_group_norm(ctx0, cur, hparams.n_norm_groups, hparams.f_norm_group_eps);
664
+ cur = ggml_reshape_2d(ctx0, cur, cur->ne[0], cur->ne[2]);
665
+ } break;
666
+ }
667
+
668
+ if (mw || mb) {
669
+ cb(cur, "norm", il);
670
+ }
671
+
672
+ if (mw) {
673
+ cur = ggml_mul(ctx0, cur, mw);
674
+ if (mb) {
675
+ cb(cur, "norm_w", il);
676
+ }
677
+ }
678
+
679
+ if (mb) {
680
+ cur = ggml_add(ctx0, cur, mb);
681
+ }
682
+
683
+ return cur;
684
+ }
685
+
686
+ ggml_tensor * llm_graph_context::build_ffn(
687
+ ggml_tensor * cur,
688
+ ggml_tensor * up,
689
+ ggml_tensor * up_b,
690
+ ggml_tensor * up_s,
691
+ ggml_tensor * gate,
692
+ ggml_tensor * gate_b,
693
+ ggml_tensor * gate_s,
694
+ ggml_tensor * down,
695
+ ggml_tensor * down_b,
696
+ ggml_tensor * down_s,
697
+ ggml_tensor * act_scales,
698
+ llm_ffn_op_type type_op,
699
+ llm_ffn_gate_type type_gate,
700
+ int il) const {
701
+ ggml_tensor * tmp = up ? build_lora_mm(up, cur) : cur;
702
+ cb(tmp, "ffn_up", il);
703
+
704
+ if (up_b) {
705
+ tmp = ggml_add(ctx0, tmp, up_b);
706
+ cb(tmp, "ffn_up_b", il);
707
+ }
708
+
709
+ if (up_s) {
710
+ tmp = ggml_mul(ctx0, tmp, up_s);
711
+ cb(tmp, "ffn_up_s", il);
712
+ }
713
+
714
+ if (gate) {
715
+ switch (type_gate) {
716
+ case LLM_FFN_SEQ:
717
+ {
718
+ cur = build_lora_mm(gate, tmp);
719
+ cb(cur, "ffn_gate", il);
720
+ } break;
721
+ case LLM_FFN_PAR:
722
+ {
723
+ cur = build_lora_mm(gate, cur);
724
+ cb(cur, "ffn_gate", il);
725
+ } break;
726
+ }
727
+
728
+ if (gate_b) {
729
+ cur = ggml_add(ctx0, cur, gate_b);
730
+ cb(cur, "ffn_gate_b", il);
731
+ }
732
+
733
+ if (gate_s) {
734
+ cur = ggml_mul(ctx0, cur, gate_s);
735
+ cb(cur, "ffn_gate_s", il);
736
+ }
737
+
738
+ } else {
739
+ cur = tmp;
740
+ }
741
+
742
+ switch (type_op) {
743
+ case LLM_FFN_SILU:
744
+ {
745
+ cur = ggml_silu(ctx0, cur);
746
+ cb(cur, "ffn_silu", il);
747
+ } break;
748
+ case LLM_FFN_GELU:
749
+ {
750
+ cur = ggml_gelu(ctx0, cur);
751
+ cb(cur, "ffn_gelu", il);
752
+ if (act_scales != NULL) {
753
+ cur = ggml_div(ctx0, cur, act_scales);
754
+ cb(cur, "ffn_act", il);
755
+ }
756
+ } break;
757
+ case LLM_FFN_RELU:
758
+ {
759
+ cur = ggml_relu(ctx0, cur);
760
+ cb(cur, "ffn_relu", il);
761
+ } break;
762
+ case LLM_FFN_RELU_SQR:
763
+ {
764
+ cur = ggml_relu(ctx0, cur);
765
+ cb(cur, "ffn_relu", il);
766
+
767
+ cur = ggml_sqr(ctx0, cur);
768
+ cb(cur, "ffn_sqr(relu)", il);
769
+ } break;
770
+ case LLM_FFN_SWIGLU:
771
+ {
772
+ // Project to 4h. If using swiglu double the output width, see https://arxiv.org/pdf/2002.05202.pdf
773
+ int64_t split_point = cur->ne[0] / 2;
774
+ ggml_tensor * x0 = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, split_point, cur->ne[1], cur->nb[1], 0));
775
+ ggml_tensor * x1 = ggml_cont(ctx0, ggml_view_2d(ctx0, cur, split_point, cur->ne[1], cur->nb[1], split_point * ggml_element_size(cur)));
776
+
777
+ x0 = ggml_silu(ctx0, x0);
778
+ cb(cur, "ffn_silu", il);
779
+
780
+ cur = ggml_mul(ctx0, x0, x1);
781
+ cb(cur, "ffn_mul", il);
782
+ } break;
783
+ }
784
+
785
+ if (gate && type_gate == LLM_FFN_PAR) {
786
+ cur = ggml_mul(ctx0, cur, tmp);
787
+ cb(cur, "ffn_gate_par", il);
788
+ }
789
+
790
+ if (down) {
791
+ cur = build_lora_mm(down, cur);
792
+ if (arch == LLM_ARCH_GLM4) {
793
+ // GLM4 seems to have numerical issues with half-precision accumulators
794
+ ggml_mul_mat_set_prec(cur, GGML_PREC_F32);
795
+ }
796
+ }
797
+
798
+ if (down_b) {
799
+ cb(cur, "ffn_down", il);
800
+ }
801
+
802
+ if (down_b) {
803
+ cur = ggml_add(ctx0, cur, down_b);
804
+ }
805
+
806
+ if (down_s) {
807
+ cur = ggml_mul(ctx0, cur, down_s);
808
+ cb(cur, "ffn_down_s", il);
809
+ }
810
+
811
+ return cur;
812
+ }
813
+
814
+ ggml_tensor * llm_graph_context::build_moe_ffn(
815
+ ggml_tensor * cur,
816
+ ggml_tensor * gate_inp,
817
+ ggml_tensor * up_exps,
818
+ ggml_tensor * gate_exps,
819
+ ggml_tensor * down_exps,
820
+ ggml_tensor * exp_probs_b,
821
+ int64_t n_expert,
822
+ int64_t n_expert_used,
823
+ llm_ffn_op_type type_op,
824
+ bool norm_w,
825
+ bool scale_w,
826
+ float w_scale,
827
+ llama_expert_gating_func_type gating_op,
828
+ int il) const {
829
+ const int64_t n_embd = cur->ne[0];
830
+ const int64_t n_tokens = cur->ne[1];
831
+ const bool weight_before_ffn = arch == LLM_ARCH_LLAMA4; // for llama4, we apply the sigmoid-ed weights before the FFN
832
+
833
+ ggml_tensor * logits = build_lora_mm(gate_inp, cur); // [n_expert, n_tokens]
834
+ cb(logits, "ffn_moe_logits", il);
835
+
836
+ ggml_tensor * probs = nullptr;
837
+ switch (gating_op) {
838
+ case LLAMA_EXPERT_GATING_FUNC_TYPE_SOFTMAX:
839
+ {
840
+ probs = ggml_soft_max(ctx0, logits); // [n_expert, n_tokens]
841
+ } break;
842
+ case LLAMA_EXPERT_GATING_FUNC_TYPE_SIGMOID:
843
+ {
844
+ probs = ggml_sigmoid(ctx0, logits); // [n_expert, n_tokens]
845
+ } break;
846
+ default:
847
+ GGML_ABORT("fatal error");
848
+ }
849
+ cb(probs, "ffn_moe_probs", il);
850
+
851
+ // add experts selection bias - introduced in DeepSeek V3
852
+ // leave probs unbiased as it's later used to get expert weights
853
+ ggml_tensor * selection_probs = probs;
854
+ if (exp_probs_b != nullptr) {
855
+ selection_probs = ggml_add(ctx0, probs, exp_probs_b);
856
+ cb(selection_probs, "ffn_moe_probs_biased", il);
857
+ }
858
+
859
+ // llama4 doesn't have exp_probs_b, and sigmoid is only used after top_k
860
+ // see: https://github.com/meta-llama/llama-models/blob/699a02993512fb36936b1b0741e13c06790bcf98/models/llama4/moe.py#L183-L198
861
+ if (arch == LLM_ARCH_LLAMA4) {
862
+ selection_probs = logits;
863
+ }
864
+
865
+ // select experts
866
+ ggml_tensor * selected_experts = ggml_top_k(ctx0, selection_probs, n_expert_used); // [n_expert_used, n_tokens]
867
+ cb(selected_experts->src[0], "ffn_moe_argsort", il);
868
+ cb(selected_experts, "ffn_moe_topk", il);
869
+
870
+ ggml_tensor * weights = ggml_get_rows(ctx0,
871
+ ggml_reshape_3d(ctx0, probs, 1, n_expert, n_tokens), selected_experts); // [1, n_expert_used, n_tokens]
872
+ cb(weights, "ffn_moe_weights", il);
873
+
874
+ if (norm_w) {
875
+ weights = ggml_reshape_2d(ctx0, weights, n_expert_used, n_tokens);
876
+
877
+ ggml_tensor * weights_sum = ggml_sum_rows(ctx0, weights); // [1, n_tokens]
878
+ cb(weights_sum, "ffn_moe_weights_sum", il);
879
+
880
+ weights = ggml_div(ctx0, weights, weights_sum); // [n_expert_used, n_tokens]
881
+ cb(weights, "ffn_moe_weights_norm", il);
882
+
883
+ weights = ggml_reshape_3d(ctx0, weights, 1, n_expert_used, n_tokens);
884
+ }
885
+ if (scale_w) {
886
+ weights = ggml_scale(ctx0, weights, w_scale);
887
+ cb(weights, "ffn_moe_weights_scaled", il);
888
+ }
889
+
890
+ cur = ggml_reshape_3d(ctx0, cur, n_embd, 1, n_tokens);
891
+
892
+ if (weight_before_ffn) {
893
+ // TODO: this is a workaround as we don't yet have a repeat op that takes custom dim (ggml_repeat_4d)
894
+ ggml_tensor * repeated = ggml_new_tensor_3d(ctx0, cur->type, n_embd, n_expert_used, n_tokens);
895
+ repeated = ggml_repeat(ctx0, cur, repeated); // [n_embd, n_expert_used, n_tokens]
896
+ cur = ggml_mul(ctx0, repeated, weights);
897
+ cb(cur, "ffn_moe_weighted", il);
898
+ }
899
+
900
+ ggml_tensor * up = build_lora_mm_id(up_exps, cur, selected_experts); // [n_ff, n_expert_used, n_tokens]
901
+ cb(up, "ffn_moe_up", il);
902
+
903
+ ggml_tensor * experts = nullptr;
904
+ if (gate_exps) {
905
+ cur = build_lora_mm_id(gate_exps, cur, selected_experts); // [n_ff, n_expert_used, n_tokens]
906
+ cb(cur, "ffn_moe_gate", il);
907
+ } else {
908
+ cur = up;
909
+ }
910
+
911
+ switch (type_op) {
912
+ case LLM_FFN_SILU:
913
+ {
914
+ cur = ggml_silu(ctx0, cur);
915
+ cb(cur, "ffn_moe_silu", il);
916
+ } break;
917
+ case LLM_FFN_GELU:
918
+ {
919
+ cur = ggml_gelu(ctx0, cur);
920
+ cb(cur, "ffn_moe_gelu", il);
921
+ } break;
922
+ default:
923
+ GGML_ABORT("fatal error");
924
+ }
925
+
926
+ if (gate_exps) {
927
+ cur = ggml_mul(ctx0, cur, up); // [n_ff, n_expert_used, n_tokens]
928
+ cb(cur, "ffn_moe_gate_par", il);
929
+ }
930
+
931
+ experts = build_lora_mm_id(down_exps, cur, selected_experts); // [n_embd, n_expert_used, n_tokens]
932
+ cb(experts, "ffn_moe_down", il);
933
+
934
+ if (!weight_before_ffn) {
935
+ experts = ggml_mul(ctx0, experts, weights);
936
+ cb(cur, "ffn_moe_weighted", il);
937
+ }
938
+
939
+ // aggregate experts
940
+ ggml_tensor * moe_out = nullptr;
941
+ for (int i = 0; i < n_expert_used; ++i) {
942
+ ggml_tensor * cur_expert = ggml_view_2d(ctx0, experts, n_embd, n_tokens,
943
+ experts->nb[2], i*experts->nb[1]);
944
+
945
+ if (i == 0) {
946
+ moe_out = cur_expert;
947
+ } else {
948
+ moe_out = ggml_add(ctx0, moe_out, cur_expert);
949
+ }
950
+ }
951
+
952
+ if (n_expert_used == 1) {
953
+ // avoid returning a non-contiguous tensor
954
+ moe_out = ggml_cont(ctx0, moe_out);
955
+ }
956
+
957
+ cb(moe_out, "ffn_moe_out", il);
958
+
959
+ return moe_out;
960
+ }
961
+
962
+ // input embeddings with optional lora
963
+ ggml_tensor * llm_graph_context::build_inp_embd(ggml_tensor * tok_embd) const {
964
+ const int64_t n_embd = hparams.n_embd;
965
+
966
+ auto inp = std::make_unique<llm_graph_input_embd>();
967
+
968
+ ggml_tensor * cur = nullptr;
969
+
970
+ if (ubatch.token) {
971
+ inp->tokens = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ubatch.n_tokens);
972
+ //cb(inp->tokens, "inp_tokens", -1);
973
+ ggml_set_input(inp->tokens);
974
+
975
+ cur = ggml_get_rows(ctx0, tok_embd, inp->tokens);
976
+
977
+ // apply lora for embedding tokens if needed
978
+ for (const auto & lora : *loras) {
979
+ llama_adapter_lora_weight * lw = lora.first->get_weight(tok_embd);
980
+ if (lw == nullptr) {
981
+ continue;
982
+ }
983
+
984
+ const float adapter_scale = lora.second;
985
+ const float scale = lw->get_scale(lora.first->alpha, adapter_scale);
986
+
987
+ ggml_tensor * inpL_delta = ggml_scale(ctx0, ggml_mul_mat(
988
+ ctx0, lw->b, // non-transposed lora_b
989
+ ggml_get_rows(ctx0, lw->a, inp->tokens)
990
+ ), scale);
991
+
992
+ cur = ggml_add(ctx0, cur, inpL_delta);
993
+ }
994
+ } else {
995
+ inp->embd = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_embd, ubatch.n_tokens);
996
+ ggml_set_input(inp->embd);
997
+
998
+ cur = inp->embd;
999
+ }
1000
+
1001
+ // For Granite architecture
1002
+ if (hparams.f_embedding_scale != 0.0f) {
1003
+ cur = ggml_scale(ctx0, cur, hparams.f_embedding_scale);
1004
+ }
1005
+
1006
+ cb(cur, "inp_embd", -1);
1007
+
1008
+ res->add_input(std::move(inp));
1009
+
1010
+ return cur;
1011
+ }
1012
+
1013
+ ggml_tensor * llm_graph_context::build_inp_pos() const {
1014
+ auto inp = std::make_unique<llm_graph_input_pos>(n_pos_per_embd());
1015
+
1016
+ auto & cur = inp->pos;
1017
+
1018
+ cur = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens*n_pos_per_embd());
1019
+ ggml_set_input(cur);
1020
+
1021
+ res->add_input(std::move(inp));
1022
+
1023
+ return cur;
1024
+ }
1025
+
1026
+ ggml_tensor * llm_graph_context::build_inp_attn_scale() const {
1027
+ auto inp = std::make_unique<llm_graph_input_attn_temp>(hparams.n_attn_temp_floor_scale, hparams.f_attn_temp_scale);
1028
+
1029
+ auto & cur = inp->attn_scale;
1030
+
1031
+ // this need to be 1x1xN for broadcasting
1032
+ cur = ggml_new_tensor_3d(ctx0, GGML_TYPE_F32, 1, 1, n_tokens);
1033
+ ggml_set_input(cur);
1034
+
1035
+ res->add_input(std::move(inp));
1036
+
1037
+ return cur;
1038
+ }
1039
+
1040
+ ggml_tensor * llm_graph_context::build_inp_out_ids() const {
1041
+ auto inp = std::make_unique<llm_graph_input_out_ids>(hparams, cparams, n_outputs);
1042
+
1043
+ auto & cur = inp->out_ids;
1044
+
1045
+ cur = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_outputs);
1046
+ ggml_set_input(cur);
1047
+
1048
+ res->add_input(std::move(inp));
1049
+
1050
+ return cur;
1051
+ }
1052
+
1053
+ ggml_tensor * llm_graph_context::build_inp_mean() const {
1054
+ auto inp = std::make_unique<llm_graph_input_mean>(cparams);
1055
+
1056
+ auto & cur = inp->mean;
1057
+
1058
+ cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_tokens, n_tokens);
1059
+ ggml_set_input(cur);
1060
+
1061
+ res->add_input(std::move(inp));
1062
+
1063
+ return cur;
1064
+ }
1065
+
1066
+ ggml_tensor * llm_graph_context::build_inp_cls() const {
1067
+ auto inp = std::make_unique<llm_graph_input_cls>(cparams);
1068
+
1069
+ auto & cur = inp->cls;
1070
+
1071
+ cur = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_tokens);
1072
+ ggml_set_input(cur);
1073
+
1074
+ res->add_input(std::move(inp));
1075
+
1076
+ return cur;
1077
+ }
1078
+
1079
+ ggml_tensor * llm_graph_context::build_inp_s_copy() const {
1080
+ const llama_kv_cache_recurrent * kv_self = static_cast<const llama_kv_cache_recurrent *>(memory);
1081
+
1082
+ auto inp = std::make_unique<llm_graph_input_s_copy>(kv_self);
1083
+
1084
+ const auto n_kv = kv_self->n;
1085
+
1086
+ auto & cur = inp->s_copy;
1087
+
1088
+ cur = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_kv);
1089
+ ggml_set_input(cur);
1090
+
1091
+ res->add_input(std::move(inp));
1092
+
1093
+ return cur;
1094
+ }
1095
+
1096
+ ggml_tensor * llm_graph_context::build_inp_s_mask() const {
1097
+ const llama_kv_cache_recurrent * kv_self = static_cast<const llama_kv_cache_recurrent *>(memory);
1098
+
1099
+ auto inp = std::make_unique<llm_graph_input_s_mask>(kv_self);
1100
+
1101
+ const auto n_kv = kv_self->n;
1102
+
1103
+ auto & cur = inp->s_mask;
1104
+
1105
+ cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, 1, n_kv);
1106
+ ggml_set_input(cur);
1107
+
1108
+ res->add_input(std::move(inp));
1109
+
1110
+ return cur;
1111
+ }
1112
+
1113
+ ggml_tensor * llm_graph_context::build_inp_cross_embd() const {
1114
+ auto inp = std::make_unique<llm_graph_input_cross_embd>(cross);
1115
+
1116
+ auto & cur = inp->cross_embd;
1117
+
1118
+ // if we have the output embeddings from the encoder, use them directly
1119
+ // TODO: needs more work to be correct, for now just use the tensor shape
1120
+ //if (cross->t_embd) {
1121
+ // cur = ggml_view_tensor(ctx0, cross->t_embd);
1122
+
1123
+ // return cur;
1124
+ //}
1125
+
1126
+ const auto n_embd = !cross->v_embd.empty() ? cross->n_embd : hparams.n_embd;
1127
+ const auto n_enc = !cross->v_embd.empty() ? cross->n_enc : hparams.n_ctx_train;
1128
+
1129
+ cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_embd, n_enc);
1130
+ ggml_set_input(cur);
1131
+
1132
+ res->add_input(std::move(inp));
1133
+
1134
+ return cur;
1135
+ }
1136
+
1137
+ ggml_tensor * llm_graph_context::build_inp_pos_bucket_enc() const {
1138
+ auto inp = std::make_unique<llm_graph_input_pos_bucket>(hparams);
1139
+
1140
+ auto & cur = inp->pos_bucket;
1141
+
1142
+ cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_I32, n_tokens, n_tokens);
1143
+ ggml_set_input(cur);
1144
+
1145
+ res->add_input(std::move(inp));
1146
+
1147
+ return cur;
1148
+ }
1149
+
1150
+ ggml_tensor * llm_graph_context::build_inp_pos_bucket_dec() const {
1151
+ const llama_kv_cache_unified * kv_self = static_cast<const llama_kv_cache_unified *>(memory);
1152
+
1153
+ auto inp = std::make_unique<llm_graph_input_pos_bucket_kv>(hparams, kv_self);
1154
+
1155
+ const auto n_kv = kv_self->n;
1156
+
1157
+ auto & cur = inp->pos_bucket;
1158
+
1159
+ cur = ggml_new_tensor_2d(ctx0, GGML_TYPE_I32, n_kv, n_tokens);
1160
+ ggml_set_input(cur);
1161
+
1162
+ res->add_input(std::move(inp));
1163
+
1164
+ return cur;
1165
+ }
1166
+
1167
+ ggml_tensor * llm_graph_context::build_pos_bias(ggml_tensor * pos_bucket, ggml_tensor * attn_rel_b) const {
1168
+ ggml_tensor * pos_bucket_1d = ggml_reshape_1d(ctx0, pos_bucket, pos_bucket->ne[0] * pos_bucket->ne[1]);
1169
+ cb(pos_bucket_1d, "pos_bucket_1d", -1);
1170
+
1171
+ ggml_tensor * pos_bias = ggml_get_rows(ctx0, attn_rel_b, pos_bucket_1d);
1172
+
1173
+ pos_bias = ggml_reshape_3d(ctx0, pos_bias, pos_bias->ne[0], pos_bucket->ne[0], pos_bucket->ne[1]);
1174
+ pos_bias = ggml_permute (ctx0, pos_bias, 2, 0, 1, 3);
1175
+ pos_bias = ggml_cont (ctx0, pos_bias);
1176
+
1177
+ cb(pos_bias, "pos_bias", -1);
1178
+
1179
+ return pos_bias;
1180
+ }
1181
+
1182
+ ggml_tensor * llm_graph_context::build_attn_mha(
1183
+ ggml_cgraph * gf,
1184
+ ggml_tensor * q,
1185
+ ggml_tensor * k,
1186
+ ggml_tensor * v,
1187
+ ggml_tensor * kq_b,
1188
+ ggml_tensor * kq_mask,
1189
+ ggml_tensor * v_mla,
1190
+ bool v_trans,
1191
+ float kq_scale) const {
1192
+ //const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
1193
+ //const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(il);
1194
+
1195
+ //const int64_t n_head = hparams.n_head(il);
1196
+ //const int64_t n_head_kv = hparams.n_head_kv(il);
1197
+
1198
+ //const auto & n_embd_head_k = hparams.n_embd_head_k;
1199
+ //const auto & n_embd_head_v = hparams.n_embd_head_v;
1200
+
1201
+ const auto n_tokens = q->ne[1];
1202
+ const auto n_head = q->ne[2];
1203
+ const auto n_kv = k->ne[1];
1204
+
1205
+ ggml_tensor * cur;
1206
+
1207
+ // TODO: replace hardcoded padding with ggml-provided padding
1208
+ if (cparams.flash_attn && (n_kv % 256 == 0) && kq_b == nullptr) {
1209
+ GGML_ASSERT(kq_b == nullptr && "Flash attention does not support KQ bias yet");
1210
+
1211
+ if (v_trans) {
1212
+ v = ggml_transpose(ctx0, v);
1213
+ }
1214
+
1215
+ // this can happen when KV cache is not used (e.g. an embedding model with non-causal attn)
1216
+ if (k->type == GGML_TYPE_F32) {
1217
+ k = ggml_cast(ctx0, k, GGML_TYPE_F16);
1218
+ }
1219
+
1220
+ if (v->type == GGML_TYPE_F32) {
1221
+ v = ggml_cast(ctx0, v, GGML_TYPE_F16);
1222
+ }
1223
+
1224
+ cur = ggml_flash_attn_ext(ctx0, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
1225
+ hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
1226
+
1227
+ ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
1228
+
1229
+ if (v_mla) {
1230
+ #if 0
1231
+ // v_mla can be applied as a matrix-vector multiplication with broadcasting across dimension 3 == n_tokens.
1232
+ // However, the code is optimized for dimensions 0 and 1 being large, so this is ineffient.
1233
+ cur = ggml_reshape_4d(ctx0, cur, v_mla->ne[0], 1, n_head, n_tokens);
1234
+ cur = ggml_mul_mat(ctx0, v_mla, cur);
1235
+ #else
1236
+ // It's preferable to do the calculation as a matrix-matrix multiplication with n_tokens in dimension 1.
1237
+ // The permutations are noops and only change how the tensor data is interpreted.
1238
+ cur = ggml_permute(ctx0, cur, 0, 2, 1, 3);
1239
+ cur = ggml_mul_mat(ctx0, v_mla, cur);
1240
+ cur = ggml_permute(ctx0, cur, 0, 2, 1, 3);
1241
+ cur = ggml_cont(ctx0, cur); // Needed because ggml_reshape_2d expects contiguous inputs.
1242
+ #endif
1243
+ }
1244
+
1245
+ cur = ggml_reshape_2d(ctx0, cur, cur->ne[0]*n_head, n_tokens);
1246
+ } else {
1247
+ ggml_tensor * kq = ggml_mul_mat(ctx0, k, q);
1248
+
1249
+ // note: this op tends to require high floating point range
1250
+ // while for some models F16 is enough, for others it is not, so we default to F32 here
1251
+ ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
1252
+
1253
+ if (arch == LLM_ARCH_GROK) {
1254
+ // need to do the following:
1255
+ // multiply by attn_output_multiplyer of 0.08838834764831845
1256
+ // and then :
1257
+ // kq = 30 * tanh(kq / 30)
1258
+ // before the softmax below
1259
+
1260
+ kq = ggml_tanh(ctx0, ggml_scale(ctx0, kq, 0.08838834764831845f/30.0f));
1261
+ kq = ggml_scale(ctx0, kq, 30);
1262
+ }
1263
+
1264
+ if (hparams.attn_soft_cap) {
1265
+ kq = ggml_scale(ctx0, kq, 1.0f / hparams.f_attn_logit_softcapping);
1266
+ kq = ggml_tanh (ctx0, kq);
1267
+ kq = ggml_scale(ctx0, kq, hparams.f_attn_logit_softcapping);
1268
+ }
1269
+
1270
+ if (kq_b) {
1271
+ kq = ggml_add(ctx0, kq, kq_b);
1272
+ }
1273
+
1274
+ kq = ggml_soft_max_ext(ctx0, kq, kq_mask, kq_scale, hparams.f_max_alibi_bias);
1275
+
1276
+ if (!v_trans) {
1277
+ // note: avoid this branch
1278
+ v = ggml_cont(ctx0, ggml_transpose(ctx0, v));
1279
+ }
1280
+
1281
+ ggml_tensor * kqv = ggml_mul_mat(ctx0, v, kq);
1282
+
1283
+ // for MLA with the absorption optimization, we need to "decompress" from MQA back to MHA
1284
+ if (v_mla) {
1285
+ kqv = ggml_mul_mat(ctx0, v_mla, kqv);
1286
+ }
1287
+
1288
+ cur = ggml_permute(ctx0, kqv, 0, 2, 1, 3);
1289
+
1290
+ cur = ggml_cont_2d(ctx0, cur, cur->ne[0]*n_head, n_tokens);
1291
+
1292
+ if (!cparams.offload_kqv) {
1293
+ // all nodes between the KV store and the attention output are run on the CPU
1294
+ ggml_backend_sched_set_tensor_backend(sched, cur, backend_cpu);
1295
+ }
1296
+ }
1297
+
1298
+ ggml_build_forward_expand(gf, cur);
1299
+
1300
+ return cur;
1301
+ }
1302
+
1303
+ llm_graph_input_attn_no_cache * llm_graph_context::build_attn_inp_no_cache() const {
1304
+ auto inp = std::make_unique<llm_graph_input_attn_no_cache>(hparams, cparams);
1305
+
1306
+ // note: there is no KV cache, so the number of KV values is equal to the number of tokens in the batch
1307
+ inp->kq_mask = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_tokens, GGML_PAD(n_tokens, GGML_KQ_MASK_PAD));
1308
+ //cb(inp_kq_mask, "KQ_mask", -1);
1309
+ ggml_set_input(inp->kq_mask);
1310
+
1311
+ inp->kq_mask_cnv = cparams.flash_attn ? ggml_cast(ctx0, inp->kq_mask, GGML_TYPE_F16) : inp->kq_mask;
1312
+
1313
+ return (llm_graph_input_attn_no_cache *) res->add_input(std::move(inp));
1314
+ }
1315
+
1316
+ ggml_tensor * llm_graph_context::build_attn(
1317
+ llm_graph_input_attn_no_cache * inp,
1318
+ ggml_cgraph * gf,
1319
+ ggml_tensor * wo,
1320
+ ggml_tensor * wo_b,
1321
+ ggml_tensor * q_cur,
1322
+ ggml_tensor * k_cur,
1323
+ ggml_tensor * v_cur,
1324
+ ggml_tensor * kq_b,
1325
+ ggml_tensor * v_mla,
1326
+ float kq_scale,
1327
+ int il) const {
1328
+ GGML_UNUSED(n_tokens);
1329
+
1330
+ // these nodes are added to the graph together so that they are not reordered
1331
+ // by doing so, the number of splits in the graph is reduced
1332
+ ggml_build_forward_expand(gf, q_cur);
1333
+ ggml_build_forward_expand(gf, k_cur);
1334
+ ggml_build_forward_expand(gf, v_cur);
1335
+
1336
+ const auto & kq_mask = inp->get_kq_mask();
1337
+
1338
+ ggml_tensor * q = ggml_permute(ctx0, q_cur, 0, 2, 1, 3);
1339
+ //cb(q, "q", il);
1340
+
1341
+ ggml_tensor * k = ggml_permute(ctx0, k_cur, 0, 2, 1, 3);
1342
+ //cb(k, "k", il);
1343
+
1344
+ ggml_tensor * v = ggml_permute(ctx0, v_cur, 0, 2, 1, 3);
1345
+ //cb(k, "v", il);
1346
+
1347
+ ggml_tensor * cur = build_attn_mha(gf, q, k, v, kq_b, kq_mask, v_mla, false, kq_scale);
1348
+
1349
+ cb(cur, "kqv_out", il);
1350
+
1351
+ if (wo) {
1352
+ cur = build_lora_mm(wo, cur);
1353
+ }
1354
+
1355
+ if (wo_b) {
1356
+ //cb(cur, "kqv_wo", il);
1357
+ }
1358
+
1359
+ if (wo_b) {
1360
+ cur = ggml_add(ctx0, cur, wo_b);
1361
+ }
1362
+
1363
+ return cur;
1364
+ }
1365
+
1366
+ llm_graph_input_attn_kv_unified * llm_graph_context::build_attn_inp_kv_unified() const {
1367
+ const llama_kv_cache_unified * kv_self = static_cast<const llama_kv_cache_unified *>(memory);
1368
+
1369
+ auto inp = std::make_unique<llm_graph_input_attn_kv_unified>(hparams, cparams, kv_self);
1370
+
1371
+ const auto n_kv = kv_self->n;
1372
+
1373
+ inp->self_kq_mask = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_kv, GGML_PAD(n_tokens, GGML_KQ_MASK_PAD));
1374
+ //cb(inp->self_kq_mask, "KQ_mask", -1);
1375
+ ggml_set_input(inp->self_kq_mask);
1376
+
1377
+ inp->self_kq_mask_cnv = cparams.flash_attn ? ggml_cast(ctx0, inp->self_kq_mask, GGML_TYPE_F16) : inp->self_kq_mask;
1378
+
1379
+ if (hparams.n_swa_pattern > 1) {
1380
+ GGML_ASSERT(hparams.n_swa > 0);
1381
+
1382
+ inp->self_kq_mask_swa = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_kv, GGML_PAD(n_tokens, GGML_KQ_MASK_PAD));
1383
+ //cb(inp->self_kq_mask_swa, "KQ_mask_swa", -1);
1384
+ ggml_set_input(inp->self_kq_mask_swa);
1385
+
1386
+ inp->self_kq_mask_swa_cnv = cparams.flash_attn ? ggml_cast(ctx0, inp->self_kq_mask_swa, GGML_TYPE_F16) : inp->self_kq_mask_swa;
1387
+ }
1388
+
1389
+ return (llm_graph_input_attn_kv_unified *) res->add_input(std::move(inp));
1390
+ }
1391
+
1392
+ ggml_tensor * llm_graph_context::build_attn(
1393
+ llm_graph_input_attn_kv_unified * inp,
1394
+ ggml_cgraph * gf,
1395
+ ggml_tensor * wo,
1396
+ ggml_tensor * wo_b,
1397
+ ggml_tensor * q_cur,
1398
+ ggml_tensor * k_cur,
1399
+ ggml_tensor * v_cur,
1400
+ ggml_tensor * kq_b,
1401
+ ggml_tensor * v_mla,
1402
+ float kq_scale,
1403
+ int il) const {
1404
+ // these nodes are added to the graph together so that they are not reordered
1405
+ // by doing so, the number of splits in the graph is reduced
1406
+ ggml_build_forward_expand(gf, q_cur);
1407
+ ggml_build_forward_expand(gf, k_cur);
1408
+ ggml_build_forward_expand(gf, v_cur);
1409
+
1410
+ const llama_kv_cache_unified * kv_self = static_cast<const llama_kv_cache_unified *>(memory);
1411
+ const auto & n_ctx = cparams.n_ctx;
1412
+
1413
+ const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
1414
+ const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(il);
1415
+
1416
+ const auto n_tokens = q_cur->ne[2];
1417
+
1418
+ const bool v_trans = !cparams.flash_attn;
1419
+
1420
+ // store to KV cache
1421
+ {
1422
+ const auto kv_head = kv_self->head;
1423
+
1424
+ GGML_ASSERT(kv_self->size == n_ctx);
1425
+
1426
+ ggml_tensor * k_cache_view = ggml_view_1d(ctx0, kv_self->k_l[il], n_tokens*n_embd_k_gqa, ggml_row_size(kv_self->k_l[il]->type, n_embd_k_gqa)*kv_head);
1427
+ //cb(k_cache_view, "k_cache_view", il);
1428
+
1429
+ // note: storing RoPE-ed version of K in the KV cache
1430
+ ggml_build_forward_expand(gf, ggml_cpy(ctx0, k_cur, k_cache_view));
1431
+
1432
+ v_cur = ggml_reshape_2d(ctx0, v_cur, n_embd_v_gqa, n_tokens);
1433
+
1434
+ ggml_tensor * v_cache_view = nullptr;
1435
+
1436
+ if (!v_trans) {
1437
+ v_cache_view = ggml_view_1d(ctx0, kv_self->v_l[il], n_tokens*n_embd_v_gqa, ggml_row_size(kv_self->v_l[il]->type, n_embd_v_gqa)*kv_head);
1438
+ } else {
1439
+ // note: the V cache is transposed when not using flash attention
1440
+ v_cache_view = ggml_view_2d(ctx0, kv_self->v_l[il], n_tokens, n_embd_v_gqa,
1441
+ ( n_ctx)*ggml_element_size(kv_self->v_l[il]),
1442
+ (kv_head)*ggml_element_size(kv_self->v_l[il]));
1443
+
1444
+ v_cur = ggml_transpose(ctx0, v_cur);
1445
+ }
1446
+ //cb(v_cache_view, "v_cache_view", il);
1447
+
1448
+ ggml_build_forward_expand(gf, ggml_cpy(ctx0, v_cur, v_cache_view));
1449
+ }
1450
+
1451
+ const bool is_swa = hparams.is_swa(il);
1452
+
1453
+ const auto & kq_mask = is_swa ? inp->get_kq_mask_swa() : inp->get_kq_mask();
1454
+
1455
+ const auto n_kv = kv_self->n;
1456
+
1457
+ const int64_t n_head_kv = hparams.n_head_kv(il);
1458
+
1459
+ const auto & n_embd_head_k = hparams.n_embd_head_k;
1460
+ const auto & n_embd_head_v = hparams.n_embd_head_v;
1461
+
1462
+ ggml_tensor * q = ggml_permute(ctx0, q_cur, 0, 2, 1, 3);
1463
+ //cb(q, "q", il);
1464
+
1465
+ ggml_tensor * k =
1466
+ ggml_view_3d(ctx0, kv_self->k_l[il],
1467
+ n_embd_head_k, n_kv, n_head_kv,
1468
+ ggml_row_size(kv_self->k_l[il]->type, n_embd_k_gqa),
1469
+ ggml_row_size(kv_self->k_l[il]->type, n_embd_head_k),
1470
+ 0);
1471
+ //cb(k, "k", il);
1472
+
1473
+ ggml_tensor * v = !v_trans ?
1474
+ ggml_view_3d(ctx0, kv_self->v_l[il],
1475
+ n_embd_head_v, n_kv, n_head_kv,
1476
+ ggml_row_size(kv_self->v_l[il]->type, n_embd_v_gqa),
1477
+ ggml_row_size(kv_self->v_l[il]->type, n_embd_head_v),
1478
+ 0) :
1479
+ ggml_view_3d(ctx0, kv_self->v_l[il],
1480
+ n_kv, n_embd_head_v, n_head_kv,
1481
+ ggml_element_size(kv_self->v_l[il])*n_ctx,
1482
+ ggml_element_size(kv_self->v_l[il])*n_ctx*n_embd_head_v,
1483
+ 0);
1484
+
1485
+ ggml_tensor * cur = build_attn_mha(gf, q, k, v, kq_b, kq_mask, v_mla, v_trans, kq_scale);
1486
+ cb(cur, "kqv_out", il);
1487
+
1488
+ if (wo) {
1489
+ cur = build_lora_mm(wo, cur);
1490
+ }
1491
+
1492
+ if (wo_b) {
1493
+ //cb(cur, "kqv_wo", il);
1494
+ }
1495
+
1496
+ if (wo_b) {
1497
+ cur = ggml_add(ctx0, cur, wo_b);
1498
+ }
1499
+
1500
+ return cur;
1501
+ }
1502
+
1503
+ llm_graph_input_attn_cross * llm_graph_context::build_attn_inp_cross() const {
1504
+ auto inp = std::make_unique<llm_graph_input_attn_cross>(cross);
1505
+
1506
+ const int32_t n_enc = !cross->v_embd.empty() ? cross->n_enc : hparams.n_ctx_train;
1507
+
1508
+ inp->cross_kq_mask = ggml_new_tensor_2d(ctx0, GGML_TYPE_F32, n_enc, GGML_PAD(n_tokens, GGML_KQ_MASK_PAD));
1509
+ ggml_set_input(inp->cross_kq_mask);
1510
+
1511
+ inp->cross_kq_mask_cnv = cparams.flash_attn ? ggml_cast(ctx0, inp->cross_kq_mask, GGML_TYPE_F16) : inp->cross_kq_mask;
1512
+
1513
+ return (llm_graph_input_attn_cross *) res->add_input(std::move(inp));
1514
+ }
1515
+
1516
+ ggml_tensor * llm_graph_context::build_attn(
1517
+ llm_graph_input_attn_cross * inp,
1518
+ ggml_cgraph * gf,
1519
+ ggml_tensor * wo,
1520
+ ggml_tensor * wo_b,
1521
+ ggml_tensor * q_cur,
1522
+ ggml_tensor * k_cur,
1523
+ ggml_tensor * v_cur,
1524
+ ggml_tensor * kq_b,
1525
+ ggml_tensor * v_mla,
1526
+ float kq_scale,
1527
+ int il) const {
1528
+ // these nodes are added to the graph together so that they are not reordered
1529
+ // by doing so, the number of splits in the graph is reduced
1530
+ ggml_build_forward_expand(gf, q_cur);
1531
+ ggml_build_forward_expand(gf, k_cur);
1532
+ ggml_build_forward_expand(gf, v_cur);
1533
+
1534
+ const auto & kq_mask = inp->get_kq_mask_cross();
1535
+
1536
+ ggml_tensor * q = ggml_permute(ctx0, q_cur, 0, 2, 1, 3);
1537
+ //cb(q, "q", il);
1538
+
1539
+ ggml_tensor * k = ggml_permute(ctx0, k_cur, 0, 2, 1, 3);
1540
+ //cb(k, "k", il);
1541
+
1542
+ ggml_tensor * v = ggml_permute(ctx0, v_cur, 0, 2, 1, 3);
1543
+ //cb(k, "v", il);
1544
+
1545
+ ggml_tensor * cur = build_attn_mha(gf, q, k, v, kq_b, kq_mask, v_mla, false, kq_scale);
1546
+
1547
+ cb(cur, "kqv_out", il);
1548
+
1549
+ if (wo) {
1550
+ cur = build_lora_mm(wo, cur);
1551
+ }
1552
+
1553
+ if (wo_b) {
1554
+ //cb(cur, "kqv_wo", il);
1555
+ }
1556
+
1557
+ if (wo_b) {
1558
+ cur = ggml_add(ctx0, cur, wo_b);
1559
+ }
1560
+
1561
+ return cur;
1562
+ }
1563
+
1564
+ ggml_tensor * llm_graph_context::build_copy_mask_state(
1565
+ ggml_cgraph * gf,
1566
+ ggml_tensor * s,
1567
+ ggml_tensor * state_copy,
1568
+ ggml_tensor * state_mask,
1569
+ int32_t n_state,
1570
+ int32_t n_seqs) const {
1571
+ const llama_kv_cache_recurrent * kv_self = static_cast<const llama_kv_cache_recurrent *>(memory);
1572
+
1573
+ const auto n_kv = kv_self->n;
1574
+ const auto kv_head = kv_self->head;
1575
+
1576
+ ggml_tensor * states = ggml_reshape_2d(ctx0, s, n_state, kv_self->size);
1577
+
1578
+ // copy states
1579
+ // NOTE: assuming the copy destinations are ALL contained between kv_head and kv_head + n_kv
1580
+ // this shrinks the tensors's ne[1] to n_kv
1581
+ states = ggml_get_rows(ctx0, states, state_copy);
1582
+
1583
+ // clear states of sequences which are starting at the beginning of this batch
1584
+ // FIXME: zero-out NANs?
1585
+ states = ggml_mul(ctx0, states, state_mask);
1586
+
1587
+ // copy states which won't be changed further (between n_seqs and n_kv)
1588
+ ggml_build_forward_expand(gf,
1589
+ ggml_cpy(ctx0,
1590
+ ggml_view_1d(ctx0, states, n_state*(n_kv - n_seqs), (n_seqs )*n_state*ggml_element_size(states)),
1591
+ ggml_view_1d(ctx0, s, n_state*(n_kv - n_seqs), (kv_head + n_seqs)*n_state*ggml_element_size(s))));
1592
+
1593
+ // the part of the states that will be used and modified
1594
+ return ggml_view_2d(ctx0, states, n_state, n_seqs, states->nb[1], 0);
1595
+ }
1596
+
1597
+ ggml_tensor * llm_graph_context::build_rwkv_token_shift_load(
1598
+ ggml_cgraph * gf,
1599
+ ggml_tensor * state_copy,
1600
+ ggml_tensor * state_mask,
1601
+ const llama_ubatch & ubatch,
1602
+ int il) const {
1603
+ const llama_kv_cache_recurrent * kv_self = static_cast<const llama_kv_cache_recurrent *>(memory);
1604
+
1605
+ const auto token_shift_count = hparams.token_shift_count;
1606
+
1607
+ const int64_t n_seqs = ubatch.n_seqs;
1608
+
1609
+ ggml_tensor * token_shift_all = kv_self->k_l[il];
1610
+
1611
+ ggml_tensor * token_shift = build_copy_mask_state(
1612
+ gf, token_shift_all, state_copy, state_mask,
1613
+ hparams.n_embd_k_s(), n_seqs);
1614
+
1615
+ token_shift = ggml_reshape_3d(ctx0, token_shift, hparams.n_embd, token_shift_count, n_seqs);
1616
+
1617
+ return token_shift;
1618
+ }
1619
+
1620
+ ggml_tensor * llm_graph_context::build_rwkv_token_shift_store(
1621
+ ggml_tensor * token_shift,
1622
+ const llama_ubatch & ubatch,
1623
+ int il) const {
1624
+ const llama_kv_cache_recurrent * kv_self = static_cast<const llama_kv_cache_recurrent *>(memory);
1625
+
1626
+ const auto token_shift_count = hparams.token_shift_count;
1627
+ const auto n_embd = hparams.n_embd;
1628
+
1629
+ const int64_t n_seqs = ubatch.n_seqs;
1630
+
1631
+ const auto kv_head = kv_self->head;
1632
+
1633
+ return ggml_cpy(
1634
+ ctx0,
1635
+ ggml_view_1d(ctx0, token_shift, n_embd * n_seqs * token_shift_count, 0),
1636
+ ggml_view_1d(ctx0, kv_self->k_l[il], hparams.n_embd_k_s() * n_seqs, hparams.n_embd_k_s() * kv_head * ggml_element_size(kv_self->k_l[il]))
1637
+ );
1638
+ }
1639
+
1640
+ void llm_graph_context::build_pooling(
1641
+ ggml_cgraph * gf,
1642
+ ggml_tensor * cls,
1643
+ ggml_tensor * cls_b,
1644
+ ggml_tensor * cls_out,
1645
+ ggml_tensor * cls_out_b) const {
1646
+ if (!cparams.embeddings) {
1647
+ return;
1648
+ }
1649
+
1650
+ ggml_tensor * inp = res->t_embd;
1651
+
1652
+ //// find result_norm tensor for input
1653
+ //for (int i = ggml_graph_n_nodes(gf) - 1; i >= 0; --i) {
1654
+ // inp = ggml_graph_node(gf, i);
1655
+ // if (strcmp(inp->name, "result_norm") == 0 || strcmp(inp->name, "result_embd") == 0) {
1656
+ // break;
1657
+ // }
1658
+
1659
+ // inp = nullptr;
1660
+ //}
1661
+
1662
+ GGML_ASSERT(inp != nullptr && "missing result_norm/result_embd tensor");
1663
+
1664
+ ggml_tensor * cur;
1665
+
1666
+ switch (pooling_type) {
1667
+ case LLAMA_POOLING_TYPE_NONE:
1668
+ {
1669
+ cur = inp;
1670
+ } break;
1671
+ case LLAMA_POOLING_TYPE_MEAN:
1672
+ {
1673
+ ggml_tensor * inp_mean = build_inp_mean();
1674
+ cur = ggml_mul_mat(ctx0, ggml_cont(ctx0, ggml_transpose(ctx0, inp)), inp_mean);
1675
+ } break;
1676
+ case LLAMA_POOLING_TYPE_CLS:
1677
+ case LLAMA_POOLING_TYPE_LAST:
1678
+ {
1679
+ ggml_tensor * inp_cls = build_inp_cls();
1680
+ cur = ggml_get_rows(ctx0, inp, inp_cls);
1681
+ } break;
1682
+ case LLAMA_POOLING_TYPE_RANK:
1683
+ {
1684
+ ggml_tensor * inp_cls = build_inp_cls();
1685
+ inp = ggml_get_rows(ctx0, inp, inp_cls);
1686
+
1687
+ // classification head
1688
+ // https://github.com/huggingface/transformers/blob/5af7d41e49bbfc8319f462eb45253dcb3863dfb7/src/transformers/models/roberta/modeling_roberta.py#L1566
1689
+ GGML_ASSERT(cls != nullptr);
1690
+ GGML_ASSERT(cls_b != nullptr);
1691
+
1692
+ cur = ggml_add (ctx0, ggml_mul_mat(ctx0, cls, inp), cls_b);
1693
+ cur = ggml_tanh(ctx0, cur);
1694
+
1695
+ // some models don't have `cls_out`, for example: https://huggingface.co/jinaai/jina-reranker-v1-tiny-en
1696
+ // https://huggingface.co/jinaai/jina-reranker-v1-tiny-en/blob/cb5347e43979c3084a890e3f99491952603ae1b7/modeling_bert.py#L884-L896
1697
+ if (cls_out) {
1698
+ GGML_ASSERT(cls_out_b != nullptr);
1699
+
1700
+ cur = ggml_add (ctx0, ggml_mul_mat(ctx0, cls_out, cur), cls_out_b);
1701
+ }
1702
+ } break;
1703
+ default:
1704
+ {
1705
+ GGML_ABORT("unknown pooling type");
1706
+ }
1707
+ }
1708
+
1709
+ cb(cur, "result_embd_pooled", -1);
1710
+ res->t_embd_pooled = cur;
1711
+
1712
+ ggml_build_forward_expand(gf, cur);
1713
+ }