@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,2192 @@
1
+ #pragma once
2
+
3
+ //
4
+ // GGML Tensor Library
5
+ //
6
+ // This documentation is still a work in progress.
7
+ // If you wish some specific topics to be covered, feel free to drop a comment:
8
+ //
9
+ // https://github.com/ggerganov/whisper.cpp/issues/40
10
+ //
11
+ // ## Overview
12
+ //
13
+ // This library implements:
14
+ //
15
+ // - a set of tensor operations
16
+ // - automatic differentiation
17
+ // - basic optimization algorithms
18
+ //
19
+ // The aim of this library is to provide a minimalistic approach for various machine learning tasks. This includes,
20
+ // but is not limited to, the following:
21
+ //
22
+ // - linear regression
23
+ // - support vector machines
24
+ // - neural networks
25
+ //
26
+ // The library allows the user to define a certain function using the available tensor operations. This function
27
+ // definition is represented internally via a computation graph. Each tensor operation in the function definition
28
+ // corresponds to a node in the graph. Having the computation graph defined, the user can choose to compute the
29
+ // function's value and/or its gradient with respect to the input variables. Optionally, the function can be optimized
30
+ // using one of the available optimization algorithms.
31
+ //
32
+ // For example, here we define the function: f(x) = a*x^2 + b
33
+ //
34
+ // {
35
+ // struct ggml_init_params params = {
36
+ // .mem_size = 16*1024*1024,
37
+ // .mem_buffer = NULL,
38
+ // };
39
+ //
40
+ // // memory allocation happens here
41
+ // struct ggml_context * ctx = ggml_init(params);
42
+ //
43
+ // struct ggml_tensor * x = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
44
+ //
45
+ // ggml_set_param(ctx, x); // x is an input variable
46
+ //
47
+ // struct ggml_tensor * a = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
48
+ // struct ggml_tensor * b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
49
+ // struct ggml_tensor * x2 = ggml_mul(ctx, x, x);
50
+ // struct ggml_tensor * f = ggml_add(ctx, ggml_mul(ctx, a, x2), b);
51
+ //
52
+ // ...
53
+ // }
54
+ //
55
+ // Notice that the function definition above does not involve any actual computation. The computation is performed only
56
+ // when the user explicitly requests it. For example, to compute the function's value at x = 2.0:
57
+ //
58
+ // {
59
+ // ...
60
+ //
61
+ // struct ggml_cgraph * gf = ggml_new_graph(ctx);
62
+ // ggml_build_forward_expand(gf, f);
63
+ //
64
+ // // set the input variable and parameter values
65
+ // ggml_set_f32(x, 2.0f);
66
+ // ggml_set_f32(a, 3.0f);
67
+ // ggml_set_f32(b, 4.0f);
68
+ //
69
+ // ggml_graph_compute_with_ctx(ctx, &gf, n_threads);
70
+ //
71
+ // printf("f = %f\n", ggml_get_f32_1d(f, 0));
72
+ //
73
+ // ...
74
+ // }
75
+ //
76
+ // The actual computation is performed in the ggml_graph_compute() function.
77
+ //
78
+ // The ggml_new_tensor_...() functions create new tensors. They are allocated in the memory buffer provided to the
79
+ // ggml_init() function. You have to be careful not to exceed the memory buffer size. Therefore, you have to know
80
+ // in advance how much memory you need for your computation. Alternatively, you can allocate a large enough memory
81
+ // and after defining the computation graph, call the ggml_used_mem() function to find out how much memory was
82
+ // actually needed.
83
+ //
84
+ // The ggml_set_param() function marks a tensor as an input variable. This is used by the automatic
85
+ // differentiation and optimization algorithms.
86
+ //
87
+ // The described approach allows to define the function graph once and then compute its forward or backward graphs
88
+ // multiple times. All computations will use the same memory buffer allocated in the ggml_init() function. This way
89
+ // the user can avoid the memory allocation overhead at runtime.
90
+ //
91
+ // The library supports multi-dimensional tensors - up to 4 dimensions. The FP16 and FP32 data types are first class
92
+ // citizens, but in theory the library can be extended to support FP8 and integer data types.
93
+ //
94
+ // Each tensor operation produces a new tensor. Initially the library was envisioned to support only the use of unary
95
+ // and binary operations. Most of the available operations fall into one of these two categories. With time, it became
96
+ // clear that the library needs to support more complex operations. The way to support these operations is not clear
97
+ // yet, but a few examples are demonstrated in the following operations:
98
+ //
99
+ // - ggml_permute()
100
+ // - ggml_conv_1d_1s()
101
+ // - ggml_conv_1d_2s()
102
+ //
103
+ // For each tensor operator, the library implements a forward and backward computation function. The forward function
104
+ // computes the output tensor value given the input tensor values. The backward function computes the adjoint of the
105
+ // input tensors given the adjoint of the output tensor. For a detailed explanation of what this means, take a
106
+ // calculus class, or watch the following video:
107
+ //
108
+ // What is Automatic Differentiation?
109
+ // https://www.youtube.com/watch?v=wG_nF1awSSY
110
+ //
111
+ //
112
+ // ## Tensor data (struct ggml_tensor)
113
+ //
114
+ // The tensors are stored in memory via the ggml_tensor struct. The structure provides information about the size of
115
+ // the tensor, the data type, and the memory buffer where the tensor data is stored. Additionally, it contains
116
+ // pointers to the "source" tensors - i.e. the tensors that were used to compute the current tensor. For example:
117
+ //
118
+ // {
119
+ // struct ggml_tensor * c = ggml_add(ctx, a, b);
120
+ //
121
+ // assert(c->src[0] == a);
122
+ // assert(c->src[1] == b);
123
+ // }
124
+ //
125
+ // The multi-dimensional tensors are stored in row-major order. The ggml_tensor struct contains fields for the
126
+ // number of elements in each dimension ("ne") as well as the number of bytes ("nb", a.k.a. stride). This allows
127
+ // to store tensors that are not contiguous in memory, which is useful for operations such as transposition and
128
+ // permutation. All tensor operations have to take the stride into account and not assume that the tensor is
129
+ // contiguous in memory.
130
+ //
131
+ // The data of the tensor is accessed via the "data" pointer. For example:
132
+ //
133
+ // {
134
+ // const int nx = 2;
135
+ // const int ny = 3;
136
+ //
137
+ // struct ggml_tensor * a = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, nx, ny);
138
+ //
139
+ // for (int y = 0; y < ny; y++) {
140
+ // for (int x = 0; x < nx; x++) {
141
+ // *(float *) ((char *) a->data + y*a->nb[1] + x*a->nb[0]) = x + y;
142
+ // }
143
+ // }
144
+ //
145
+ // ...
146
+ // }
147
+ //
148
+ // Alternatively, there are helper functions, such as ggml_get_f32_1d() and ggml_set_f32_1d() that can be used.
149
+ //
150
+ // ## The matrix multiplication operator (ggml_mul_mat)
151
+ //
152
+ // TODO
153
+ //
154
+ //
155
+ // ## Multi-threading
156
+ //
157
+ // TODO
158
+ //
159
+ //
160
+ // ## Overview of ggml.c
161
+ //
162
+ // TODO
163
+ //
164
+ //
165
+ // ## SIMD optimizations
166
+ //
167
+ // TODO
168
+ //
169
+ //
170
+ // ## Debugging ggml
171
+ //
172
+ // TODO
173
+ //
174
+ //
175
+
176
+ #ifdef GGML_SHARED
177
+ # if defined(_WIN32) && !defined(__MINGW32__)
178
+ # ifdef GGML_BUILD
179
+ # define GGML_API __declspec(dllexport) extern
180
+ # else
181
+ # define GGML_API __declspec(dllimport) extern
182
+ # endif
183
+ # else
184
+ # define GGML_API __attribute__ ((visibility ("default"))) extern
185
+ # endif
186
+ #else
187
+ # define GGML_API extern
188
+ #endif
189
+
190
+ // TODO: support for clang
191
+ #ifdef __GNUC__
192
+ # define GGML_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
193
+ #elif defined(_MSC_VER)
194
+ # define GGML_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
195
+ #else
196
+ # define GGML_DEPRECATED(func, hint) func
197
+ #endif
198
+
199
+ #ifndef __GNUC__
200
+ # define GGML_ATTRIBUTE_FORMAT(...)
201
+ #elif defined(__MINGW32__) && !defined(__clang__)
202
+ # define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
203
+ #else
204
+ # define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
205
+ #endif
206
+
207
+ #include <stdbool.h>
208
+ #include <stddef.h>
209
+ #include <stdint.h>
210
+ #include <stdio.h>
211
+
212
+ #define GGML_FILE_MAGIC 0x67676d6c // "ggml"
213
+ #define GGML_FILE_VERSION 2
214
+
215
+ #define GGML_QNT_VERSION 2 // bump this on quantization format changes
216
+ #define GGML_QNT_VERSION_FACTOR 1000 // do not change this
217
+
218
+ #define GGML_MAX_DIMS 4
219
+ #define GGML_MAX_PARAMS 2048
220
+ #define GGML_MAX_SRC 10
221
+ #define GGML_MAX_N_THREADS 512
222
+ #define GGML_MAX_OP_PARAMS 64
223
+
224
+ #ifndef GGML_MAX_NAME
225
+ # define GGML_MAX_NAME 64
226
+ #endif
227
+
228
+ #define GGML_DEFAULT_N_THREADS 4
229
+ #define GGML_DEFAULT_GRAPH_SIZE 2048
230
+
231
+ #if UINTPTR_MAX == 0xFFFFFFFF
232
+ #define GGML_MEM_ALIGN 4
233
+ #else
234
+ #define GGML_MEM_ALIGN 16
235
+ #endif
236
+
237
+ #define GGML_EXIT_SUCCESS 0
238
+ #define GGML_EXIT_ABORTED 1
239
+
240
+ #define GGML_ROPE_TYPE_NEOX 2
241
+ #define GGML_ROPE_TYPE_MROPE 8
242
+ #define GGML_ROPE_TYPE_VISION 24
243
+
244
+ #define GGML_UNUSED(x) (void)(x)
245
+
246
+ #define GGML_PAD(x, n) (((x) + (n) - 1) & ~((n) - 1))
247
+
248
+ #ifndef NDEBUG
249
+ # define GGML_UNREACHABLE() do { fprintf(stderr, "statement should be unreachable\n"); abort(); } while(0)
250
+ #elif defined(__GNUC__)
251
+ # define GGML_UNREACHABLE() __builtin_unreachable()
252
+ #elif defined(_MSC_VER)
253
+ # define GGML_UNREACHABLE() __assume(0)
254
+ #else
255
+ # define GGML_UNREACHABLE() ((void) 0)
256
+ #endif
257
+
258
+ #ifdef __cplusplus
259
+ # define GGML_NORETURN [[noreturn]]
260
+ #elif defined(_MSC_VER)
261
+ # define GGML_NORETURN __declspec(noreturn)
262
+ #else
263
+ # define GGML_NORETURN _Noreturn
264
+ #endif
265
+
266
+ #define GGML_ABORT(...) ggml_abort(__FILE__, __LINE__, __VA_ARGS__)
267
+ #define GGML_ASSERT(x) if (!(x)) GGML_ABORT("GGML_ASSERT(%s) failed", #x)
268
+
269
+ // used to copy the number of elements and stride in bytes of tensors into local variables.
270
+ // main purpose is to reduce code duplication and improve readability.
271
+ //
272
+ // example:
273
+ //
274
+ // GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne);
275
+ // GGML_TENSOR_LOCALS(size_t, nb1, src1, nb);
276
+ //
277
+ #define GGML_TENSOR_LOCALS_1(type, prefix, pointer, array) \
278
+ const type prefix##0 = (pointer)->array[0]; \
279
+ GGML_UNUSED(prefix##0);
280
+ #define GGML_TENSOR_LOCALS_2(type, prefix, pointer, array) \
281
+ GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array) \
282
+ const type prefix##1 = (pointer)->array[1]; \
283
+ GGML_UNUSED(prefix##1);
284
+ #define GGML_TENSOR_LOCALS_3(type, prefix, pointer, array) \
285
+ GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array) \
286
+ const type prefix##2 = (pointer)->array[2]; \
287
+ GGML_UNUSED(prefix##2);
288
+ #define GGML_TENSOR_LOCALS(type, prefix, pointer, array) \
289
+ GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array) \
290
+ const type prefix##3 = (pointer)->array[3]; \
291
+ GGML_UNUSED(prefix##3);
292
+
293
+ #define GGML_TENSOR_UNARY_OP_LOCALS \
294
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
295
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
296
+ GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
297
+ GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
298
+
299
+ #define GGML_TENSOR_BINARY_OP_LOCALS \
300
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
301
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
302
+ GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
303
+ GGML_TENSOR_LOCALS(size_t, nb1, src1, nb) \
304
+ GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
305
+ GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
306
+
307
+ #define GGML_TENSOR_BINARY_OP_LOCALS01 \
308
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
309
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
310
+ GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
311
+ GGML_TENSOR_LOCALS(size_t, nb1, src1, nb)
312
+
313
+ #ifdef __cplusplus
314
+ extern "C" {
315
+ #endif
316
+
317
+ GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
318
+ GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
319
+
320
+ enum ggml_status {
321
+ GGML_STATUS_ALLOC_FAILED = -2,
322
+ GGML_STATUS_FAILED = -1,
323
+ GGML_STATUS_SUCCESS = 0,
324
+ GGML_STATUS_ABORTED = 1,
325
+ };
326
+
327
+ // get ggml_status name string
328
+ GGML_API const char * ggml_status_to_string(enum ggml_status status);
329
+
330
+ // ieee 754-2008 half-precision float16
331
+ // todo: make this not an integral type
332
+ typedef uint16_t ggml_fp16_t;
333
+ GGML_API float ggml_fp16_to_fp32(ggml_fp16_t);
334
+ GGML_API ggml_fp16_t ggml_fp32_to_fp16(float);
335
+ GGML_API void ggml_fp16_to_fp32_row(const ggml_fp16_t *, float *, int64_t);
336
+ GGML_API void ggml_fp32_to_fp16_row(const float *, ggml_fp16_t *, int64_t);
337
+
338
+ // google brain half-precision bfloat16
339
+ typedef struct { uint16_t bits; } ggml_bf16_t;
340
+ GGML_API ggml_bf16_t ggml_fp32_to_bf16(float);
341
+ GGML_API float ggml_bf16_to_fp32(ggml_bf16_t); // consider just doing << 16
342
+ GGML_API void ggml_bf16_to_fp32_row(const ggml_bf16_t *, float *, int64_t);
343
+ GGML_API void ggml_fp32_to_bf16_row_ref(const float *, ggml_bf16_t *, int64_t);
344
+ GGML_API void ggml_fp32_to_bf16_row(const float *, ggml_bf16_t *, int64_t);
345
+
346
+ struct ggml_object;
347
+ struct ggml_context;
348
+ struct ggml_cgraph;
349
+
350
+ // NOTE: always add types at the end of the enum to keep backward compatibility
351
+ enum ggml_type {
352
+ GGML_TYPE_F32 = 0,
353
+ GGML_TYPE_F16 = 1,
354
+ GGML_TYPE_Q4_0 = 2,
355
+ GGML_TYPE_Q4_1 = 3,
356
+ // GGML_TYPE_Q4_2 = 4, support has been removed
357
+ // GGML_TYPE_Q4_3 = 5, support has been removed
358
+ GGML_TYPE_Q5_0 = 6,
359
+ GGML_TYPE_Q5_1 = 7,
360
+ GGML_TYPE_Q8_0 = 8,
361
+ GGML_TYPE_Q8_1 = 9,
362
+ GGML_TYPE_Q2_K = 10,
363
+ GGML_TYPE_Q3_K = 11,
364
+ GGML_TYPE_Q4_K = 12,
365
+ GGML_TYPE_Q5_K = 13,
366
+ GGML_TYPE_Q6_K = 14,
367
+ GGML_TYPE_Q8_K = 15,
368
+ GGML_TYPE_IQ2_XXS = 16,
369
+ GGML_TYPE_IQ2_XS = 17,
370
+ GGML_TYPE_IQ3_XXS = 18,
371
+ GGML_TYPE_IQ1_S = 19,
372
+ GGML_TYPE_IQ4_NL = 20,
373
+ GGML_TYPE_IQ3_S = 21,
374
+ GGML_TYPE_IQ2_S = 22,
375
+ GGML_TYPE_IQ4_XS = 23,
376
+ GGML_TYPE_I8 = 24,
377
+ GGML_TYPE_I16 = 25,
378
+ GGML_TYPE_I32 = 26,
379
+ GGML_TYPE_I64 = 27,
380
+ GGML_TYPE_F64 = 28,
381
+ GGML_TYPE_IQ1_M = 29,
382
+ GGML_TYPE_BF16 = 30,
383
+ // GGML_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files
384
+ // GGML_TYPE_Q4_0_4_8 = 32,
385
+ // GGML_TYPE_Q4_0_8_8 = 33,
386
+ GGML_TYPE_TQ1_0 = 34,
387
+ GGML_TYPE_TQ2_0 = 35,
388
+ // GGML_TYPE_IQ4_NL_4_4 = 36,
389
+ // GGML_TYPE_IQ4_NL_4_8 = 37,
390
+ // GGML_TYPE_IQ4_NL_8_8 = 38,
391
+ GGML_TYPE_COUNT = 39,
392
+ };
393
+
394
+ // precision
395
+ enum ggml_prec {
396
+ GGML_PREC_DEFAULT = 0, // stored as ggml_tensor.op_params, 0 by default
397
+ GGML_PREC_F32 = 10,
398
+ };
399
+
400
+ // model file types
401
+ enum ggml_ftype {
402
+ GGML_FTYPE_UNKNOWN = -1,
403
+ GGML_FTYPE_ALL_F32 = 0,
404
+ GGML_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
405
+ GGML_FTYPE_MOSTLY_Q4_0 = 2, // except 1d tensors
406
+ GGML_FTYPE_MOSTLY_Q4_1 = 3, // except 1d tensors
407
+ GGML_FTYPE_MOSTLY_Q4_1_SOME_F16 = 4, // tok_embeddings.weight and output.weight are F16
408
+ GGML_FTYPE_MOSTLY_Q8_0 = 7, // except 1d tensors
409
+ GGML_FTYPE_MOSTLY_Q5_0 = 8, // except 1d tensors
410
+ GGML_FTYPE_MOSTLY_Q5_1 = 9, // except 1d tensors
411
+ GGML_FTYPE_MOSTLY_Q2_K = 10, // except 1d tensors
412
+ GGML_FTYPE_MOSTLY_Q3_K = 11, // except 1d tensors
413
+ GGML_FTYPE_MOSTLY_Q4_K = 12, // except 1d tensors
414
+ GGML_FTYPE_MOSTLY_Q5_K = 13, // except 1d tensors
415
+ GGML_FTYPE_MOSTLY_Q6_K = 14, // except 1d tensors
416
+ GGML_FTYPE_MOSTLY_IQ2_XXS = 15, // except 1d tensors
417
+ GGML_FTYPE_MOSTLY_IQ2_XS = 16, // except 1d tensors
418
+ GGML_FTYPE_MOSTLY_IQ3_XXS = 17, // except 1d tensors
419
+ GGML_FTYPE_MOSTLY_IQ1_S = 18, // except 1d tensors
420
+ GGML_FTYPE_MOSTLY_IQ4_NL = 19, // except 1d tensors
421
+ GGML_FTYPE_MOSTLY_IQ3_S = 20, // except 1d tensors
422
+ GGML_FTYPE_MOSTLY_IQ2_S = 21, // except 1d tensors
423
+ GGML_FTYPE_MOSTLY_IQ4_XS = 22, // except 1d tensors
424
+ GGML_FTYPE_MOSTLY_IQ1_M = 23, // except 1d tensors
425
+ GGML_FTYPE_MOSTLY_BF16 = 24, // except 1d tensors
426
+ };
427
+
428
+ // available tensor operations:
429
+ enum ggml_op {
430
+ GGML_OP_NONE = 0,
431
+
432
+ GGML_OP_DUP,
433
+ GGML_OP_ADD,
434
+ GGML_OP_ADD1,
435
+ GGML_OP_ACC,
436
+ GGML_OP_SUB,
437
+ GGML_OP_MUL,
438
+ GGML_OP_DIV,
439
+ GGML_OP_SQR,
440
+ GGML_OP_SQRT,
441
+ GGML_OP_LOG,
442
+ GGML_OP_SIN,
443
+ GGML_OP_COS,
444
+ GGML_OP_SUM,
445
+ GGML_OP_SUM_ROWS,
446
+ GGML_OP_MEAN,
447
+ GGML_OP_ARGMAX,
448
+ GGML_OP_COUNT_EQUAL,
449
+ GGML_OP_REPEAT,
450
+ GGML_OP_REPEAT_BACK,
451
+ GGML_OP_CONCAT,
452
+ GGML_OP_SILU_BACK,
453
+ GGML_OP_NORM, // normalize
454
+ GGML_OP_RMS_NORM,
455
+ GGML_OP_RMS_NORM_BACK,
456
+ GGML_OP_GROUP_NORM,
457
+ GGML_OP_L2_NORM,
458
+
459
+ GGML_OP_MUL_MAT,
460
+ GGML_OP_MUL_MAT_ID,
461
+ GGML_OP_OUT_PROD,
462
+
463
+ GGML_OP_SCALE,
464
+ GGML_OP_SET,
465
+ GGML_OP_CPY,
466
+ GGML_OP_CONT,
467
+ GGML_OP_RESHAPE,
468
+ GGML_OP_VIEW,
469
+ GGML_OP_PERMUTE,
470
+ GGML_OP_TRANSPOSE,
471
+ GGML_OP_GET_ROWS,
472
+ GGML_OP_GET_ROWS_BACK,
473
+ GGML_OP_DIAG,
474
+ GGML_OP_DIAG_MASK_INF,
475
+ GGML_OP_DIAG_MASK_ZERO,
476
+ GGML_OP_SOFT_MAX,
477
+ GGML_OP_SOFT_MAX_BACK,
478
+ GGML_OP_ROPE,
479
+ GGML_OP_ROPE_BACK,
480
+ GGML_OP_CLAMP,
481
+ GGML_OP_CONV_TRANSPOSE_1D,
482
+ GGML_OP_IM2COL,
483
+ GGML_OP_IM2COL_BACK,
484
+ GGML_OP_CONV_2D_DW,
485
+ GGML_OP_CONV_TRANSPOSE_2D,
486
+ GGML_OP_POOL_1D,
487
+ GGML_OP_POOL_2D,
488
+ GGML_OP_POOL_2D_BACK,
489
+ GGML_OP_UPSCALE, // nearest interpolate
490
+ GGML_OP_PAD,
491
+ GGML_OP_PAD_REFLECT_1D,
492
+ GGML_OP_ARANGE,
493
+ GGML_OP_TIMESTEP_EMBEDDING,
494
+ GGML_OP_ARGSORT,
495
+ GGML_OP_LEAKY_RELU,
496
+
497
+ GGML_OP_FLASH_ATTN_EXT,
498
+ GGML_OP_FLASH_ATTN_BACK,
499
+ GGML_OP_SSM_CONV,
500
+ GGML_OP_SSM_SCAN,
501
+ GGML_OP_WIN_PART,
502
+ GGML_OP_WIN_UNPART,
503
+ GGML_OP_GET_REL_POS,
504
+ GGML_OP_ADD_REL_POS,
505
+ GGML_OP_RWKV_WKV6,
506
+ GGML_OP_GATED_LINEAR_ATTN,
507
+ GGML_OP_RWKV_WKV7,
508
+
509
+ GGML_OP_UNARY,
510
+
511
+ GGML_OP_MAP_CUSTOM1,
512
+ GGML_OP_MAP_CUSTOM2,
513
+ GGML_OP_MAP_CUSTOM3,
514
+
515
+ GGML_OP_CUSTOM,
516
+
517
+ GGML_OP_CROSS_ENTROPY_LOSS,
518
+ GGML_OP_CROSS_ENTROPY_LOSS_BACK,
519
+ GGML_OP_OPT_STEP_ADAMW,
520
+
521
+ GGML_OP_COUNT,
522
+ };
523
+
524
+ enum ggml_unary_op {
525
+ GGML_UNARY_OP_ABS,
526
+ GGML_UNARY_OP_SGN,
527
+ GGML_UNARY_OP_NEG,
528
+ GGML_UNARY_OP_STEP,
529
+ GGML_UNARY_OP_TANH,
530
+ GGML_UNARY_OP_ELU,
531
+ GGML_UNARY_OP_RELU,
532
+ GGML_UNARY_OP_SIGMOID,
533
+ GGML_UNARY_OP_GELU,
534
+ GGML_UNARY_OP_GELU_QUICK,
535
+ GGML_UNARY_OP_SILU,
536
+ GGML_UNARY_OP_HARDSWISH,
537
+ GGML_UNARY_OP_HARDSIGMOID,
538
+ GGML_UNARY_OP_EXP,
539
+
540
+ GGML_UNARY_OP_COUNT,
541
+ };
542
+
543
+ enum ggml_object_type {
544
+ GGML_OBJECT_TYPE_TENSOR,
545
+ GGML_OBJECT_TYPE_GRAPH,
546
+ GGML_OBJECT_TYPE_WORK_BUFFER
547
+ };
548
+
549
+ enum ggml_log_level {
550
+ GGML_LOG_LEVEL_NONE = 0,
551
+ GGML_LOG_LEVEL_DEBUG = 1,
552
+ GGML_LOG_LEVEL_INFO = 2,
553
+ GGML_LOG_LEVEL_WARN = 3,
554
+ GGML_LOG_LEVEL_ERROR = 4,
555
+ GGML_LOG_LEVEL_CONT = 5, // continue previous log
556
+ };
557
+
558
+ // this tensor...
559
+ enum ggml_tensor_flag {
560
+ GGML_TENSOR_FLAG_INPUT = 1, // ...is an input for the GGML compute graph
561
+ GGML_TENSOR_FLAG_OUTPUT = 2, // ...is an output for the GGML compute graph
562
+ GGML_TENSOR_FLAG_PARAM = 4, // ...contains trainable parameters
563
+ GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
564
+ };
565
+
566
+ struct ggml_init_params {
567
+ // memory pool
568
+ size_t mem_size; // bytes
569
+ void * mem_buffer; // if NULL, memory will be allocated internally
570
+ bool no_alloc; // don't allocate memory for the tensor data
571
+ };
572
+
573
+ // n-dimensional tensor
574
+ struct ggml_tensor {
575
+ enum ggml_type type;
576
+
577
+ struct ggml_backend_buffer * buffer;
578
+
579
+ int64_t ne[GGML_MAX_DIMS]; // number of elements
580
+ size_t nb[GGML_MAX_DIMS]; // stride in bytes:
581
+ // nb[0] = ggml_type_size(type)
582
+ // nb[1] = nb[0] * (ne[0] / ggml_blck_size(type)) + padding
583
+ // nb[i] = nb[i-1] * ne[i-1]
584
+
585
+ // compute data
586
+ enum ggml_op op;
587
+
588
+ // op params - allocated as int32_t for alignment
589
+ int32_t op_params[GGML_MAX_OP_PARAMS / sizeof(int32_t)];
590
+
591
+ int32_t flags;
592
+
593
+ struct ggml_tensor * src[GGML_MAX_SRC];
594
+
595
+ // source tensor and offset for views
596
+ struct ggml_tensor * view_src;
597
+ size_t view_offs;
598
+
599
+ void * data;
600
+
601
+ char name[GGML_MAX_NAME];
602
+
603
+ void * extra; // extra things e.g. for ggml-cuda.cu
604
+
605
+ char padding[8];
606
+ };
607
+
608
+ static const size_t GGML_TENSOR_SIZE = sizeof(struct ggml_tensor);
609
+
610
+ // Abort callback
611
+ // If not NULL, called before ggml computation
612
+ // If it returns true, the computation is aborted
613
+ typedef bool (*ggml_abort_callback)(void * data);
614
+
615
+
616
+ //
617
+ // GUID
618
+ //
619
+
620
+ // GUID types
621
+ typedef uint8_t ggml_guid[16];
622
+ typedef ggml_guid * ggml_guid_t;
623
+
624
+ GGML_API bool ggml_guid_matches(ggml_guid_t guid_a, ggml_guid_t guid_b);
625
+
626
+ // misc
627
+
628
+ GGML_API void ggml_time_init(void); // call this once at the beginning of the program
629
+ GGML_API int64_t ggml_time_ms(void);
630
+ GGML_API int64_t ggml_time_us(void);
631
+ GGML_API int64_t ggml_cycles(void);
632
+ GGML_API int64_t ggml_cycles_per_ms(void);
633
+
634
+ // accepts a UTF-8 path, even on Windows
635
+ GGML_API FILE * ggml_fopen(const char * fname, const char * mode);
636
+
637
+ GGML_API void ggml_print_object (const struct ggml_object * obj);
638
+ GGML_API void ggml_print_objects(const struct ggml_context * ctx);
639
+
640
+ GGML_API int64_t ggml_nelements (const struct ggml_tensor * tensor);
641
+ GGML_API int64_t ggml_nrows (const struct ggml_tensor * tensor);
642
+ GGML_API size_t ggml_nbytes (const struct ggml_tensor * tensor);
643
+ GGML_API size_t ggml_nbytes_pad(const struct ggml_tensor * tensor); // same as ggml_nbytes() but padded to GGML_MEM_ALIGN
644
+
645
+ GGML_API int64_t ggml_blck_size(enum ggml_type type);
646
+ GGML_API size_t ggml_type_size(enum ggml_type type); // size in bytes for all elements in a block
647
+ GGML_API size_t ggml_row_size (enum ggml_type type, int64_t ne); // size in bytes for all elements in a row
648
+
649
+ GGML_DEPRECATED(
650
+ GGML_API double ggml_type_sizef(enum ggml_type type), // ggml_type_size()/ggml_blck_size() as float
651
+ "use ggml_row_size() instead");
652
+
653
+ GGML_API const char * ggml_type_name(enum ggml_type type);
654
+ GGML_API const char * ggml_op_name (enum ggml_op op);
655
+ GGML_API const char * ggml_op_symbol(enum ggml_op op);
656
+
657
+ GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op);
658
+ GGML_API const char * ggml_op_desc(const struct ggml_tensor * t); // unary or op name
659
+
660
+ GGML_API size_t ggml_element_size(const struct ggml_tensor * tensor);
661
+
662
+ GGML_API bool ggml_is_quantized(enum ggml_type type);
663
+
664
+ // TODO: temporary until model loading of ggml examples is refactored
665
+ GGML_API enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype);
666
+
667
+ GGML_API bool ggml_is_transposed(const struct ggml_tensor * tensor);
668
+ GGML_API bool ggml_is_permuted (const struct ggml_tensor * tensor);
669
+ GGML_API bool ggml_is_empty (const struct ggml_tensor * tensor);
670
+ GGML_API bool ggml_is_scalar (const struct ggml_tensor * tensor);
671
+ GGML_API bool ggml_is_vector (const struct ggml_tensor * tensor);
672
+ GGML_API bool ggml_is_matrix (const struct ggml_tensor * tensor);
673
+ GGML_API bool ggml_is_3d (const struct ggml_tensor * tensor);
674
+ GGML_API int ggml_n_dims (const struct ggml_tensor * tensor); // returns 1 for scalars
675
+
676
+ // returns whether the tensor elements can be iterated over with a flattened index (no gaps, no permutation)
677
+ GGML_API bool ggml_is_contiguous (const struct ggml_tensor * tensor);
678
+ GGML_API bool ggml_is_contiguous_0(const struct ggml_tensor * tensor); // same as ggml_is_contiguous()
679
+ GGML_API bool ggml_is_contiguous_1(const struct ggml_tensor * tensor); // contiguous for dims >= 1
680
+ GGML_API bool ggml_is_contiguous_2(const struct ggml_tensor * tensor); // contiguous for dims >= 2
681
+
682
+ // returns whether the tensor elements are allocated as one contiguous block of memory (no gaps, but permutation ok)
683
+ GGML_API bool ggml_is_contiguously_allocated(const struct ggml_tensor * tensor);
684
+
685
+ // true for tensor that is stored in memory as CxWxHxN and has been permuted to WxHxCxN
686
+ GGML_API bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor);
687
+
688
+ GGML_API bool ggml_are_same_shape (const struct ggml_tensor * t0, const struct ggml_tensor * t1);
689
+ GGML_API bool ggml_are_same_stride(const struct ggml_tensor * t0, const struct ggml_tensor * t1);
690
+
691
+ GGML_API bool ggml_can_repeat(const struct ggml_tensor * t0, const struct ggml_tensor * t1);
692
+
693
+ // use this to compute the memory overhead of a tensor
694
+ GGML_API size_t ggml_tensor_overhead(void);
695
+
696
+ GGML_API bool ggml_validate_row_data(enum ggml_type type, const void * data, size_t nbytes);
697
+
698
+ // main
699
+
700
+ GGML_API struct ggml_context * ggml_init (struct ggml_init_params params);
701
+ GGML_API void ggml_reset(struct ggml_context * ctx);
702
+ GGML_API void ggml_free (struct ggml_context * ctx);
703
+
704
+ GGML_API size_t ggml_used_mem(const struct ggml_context * ctx);
705
+
706
+ GGML_API bool ggml_get_no_alloc(struct ggml_context * ctx);
707
+ GGML_API void ggml_set_no_alloc(struct ggml_context * ctx, bool no_alloc);
708
+
709
+ GGML_API void * ggml_get_mem_buffer (const struct ggml_context * ctx);
710
+ GGML_API size_t ggml_get_mem_size (const struct ggml_context * ctx);
711
+ GGML_API size_t ggml_get_max_tensor_size(const struct ggml_context * ctx);
712
+
713
+ GGML_API struct ggml_tensor * ggml_new_tensor(
714
+ struct ggml_context * ctx,
715
+ enum ggml_type type,
716
+ int n_dims,
717
+ const int64_t *ne);
718
+
719
+ GGML_API struct ggml_tensor * ggml_new_tensor_1d(
720
+ struct ggml_context * ctx,
721
+ enum ggml_type type,
722
+ int64_t ne0);
723
+
724
+ GGML_API struct ggml_tensor * ggml_new_tensor_2d(
725
+ struct ggml_context * ctx,
726
+ enum ggml_type type,
727
+ int64_t ne0,
728
+ int64_t ne1);
729
+
730
+ GGML_API struct ggml_tensor * ggml_new_tensor_3d(
731
+ struct ggml_context * ctx,
732
+ enum ggml_type type,
733
+ int64_t ne0,
734
+ int64_t ne1,
735
+ int64_t ne2);
736
+
737
+ GGML_API struct ggml_tensor * ggml_new_tensor_4d(
738
+ struct ggml_context * ctx,
739
+ enum ggml_type type,
740
+ int64_t ne0,
741
+ int64_t ne1,
742
+ int64_t ne2,
743
+ int64_t ne3);
744
+
745
+ GGML_API void * ggml_new_buffer(struct ggml_context * ctx, size_t nbytes);
746
+
747
+ GGML_API struct ggml_tensor * ggml_dup_tensor (struct ggml_context * ctx, const struct ggml_tensor * src);
748
+ GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, struct ggml_tensor * src);
749
+
750
+ // Context tensor enumeration and lookup
751
+ GGML_API struct ggml_tensor * ggml_get_first_tensor(const struct ggml_context * ctx);
752
+ GGML_API struct ggml_tensor * ggml_get_next_tensor (const struct ggml_context * ctx, struct ggml_tensor * tensor);
753
+ GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);
754
+
755
+ // Converts a flat index into coordinates
756
+ GGML_API void ggml_unravel_index(const struct ggml_tensor * tensor, int64_t i, int64_t * i0, int64_t * i1, int64_t * i2, int64_t * i3);
757
+
758
+ GGML_API enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor);
759
+
760
+ GGML_API void * ggml_get_data (const struct ggml_tensor * tensor);
761
+ GGML_API float * ggml_get_data_f32(const struct ggml_tensor * tensor);
762
+
763
+ GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
764
+ GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
765
+ GGML_ATTRIBUTE_FORMAT(2, 3)
766
+ GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
767
+
768
+ // Tensor flags
769
+ GGML_API void ggml_set_input(struct ggml_tensor * tensor);
770
+ GGML_API void ggml_set_output(struct ggml_tensor * tensor);
771
+ GGML_API void ggml_set_param(struct ggml_context * ctx, struct ggml_tensor * tensor);
772
+ GGML_API void ggml_set_loss(struct ggml_tensor * tensor);
773
+
774
+ //
775
+ // operations on tensors with backpropagation
776
+ //
777
+
778
+ GGML_API struct ggml_tensor * ggml_dup(
779
+ struct ggml_context * ctx,
780
+ struct ggml_tensor * a);
781
+
782
+ // in-place, returns view(a)
783
+ GGML_API struct ggml_tensor * ggml_dup_inplace(
784
+ struct ggml_context * ctx,
785
+ struct ggml_tensor * a);
786
+
787
+ GGML_API struct ggml_tensor * ggml_add(
788
+ struct ggml_context * ctx,
789
+ struct ggml_tensor * a,
790
+ struct ggml_tensor * b);
791
+
792
+ GGML_API struct ggml_tensor * ggml_add_inplace(
793
+ struct ggml_context * ctx,
794
+ struct ggml_tensor * a,
795
+ struct ggml_tensor * b);
796
+
797
+ GGML_API struct ggml_tensor * ggml_add_cast(
798
+ struct ggml_context * ctx,
799
+ struct ggml_tensor * a,
800
+ struct ggml_tensor * b,
801
+ enum ggml_type type);
802
+
803
+ GGML_API struct ggml_tensor * ggml_add1(
804
+ struct ggml_context * ctx,
805
+ struct ggml_tensor * a,
806
+ struct ggml_tensor * b);
807
+
808
+ GGML_API struct ggml_tensor * ggml_add1_inplace(
809
+ struct ggml_context * ctx,
810
+ struct ggml_tensor * a,
811
+ struct ggml_tensor * b);
812
+
813
+ // dst = a
814
+ // view(dst, nb1, nb2, nb3, offset) += b
815
+ // return dst
816
+ GGML_API struct ggml_tensor * ggml_acc(
817
+ struct ggml_context * ctx,
818
+ struct ggml_tensor * a,
819
+ struct ggml_tensor * b,
820
+ size_t nb1,
821
+ size_t nb2,
822
+ size_t nb3,
823
+ size_t offset);
824
+
825
+ GGML_API struct ggml_tensor * ggml_acc_inplace(
826
+ struct ggml_context * ctx,
827
+ struct ggml_tensor * a,
828
+ struct ggml_tensor * b,
829
+ size_t nb1,
830
+ size_t nb2,
831
+ size_t nb3,
832
+ size_t offset);
833
+
834
+ GGML_API struct ggml_tensor * ggml_sub(
835
+ struct ggml_context * ctx,
836
+ struct ggml_tensor * a,
837
+ struct ggml_tensor * b);
838
+
839
+ GGML_API struct ggml_tensor * ggml_sub_inplace(
840
+ struct ggml_context * ctx,
841
+ struct ggml_tensor * a,
842
+ struct ggml_tensor * b);
843
+
844
+ GGML_API struct ggml_tensor * ggml_mul(
845
+ struct ggml_context * ctx,
846
+ struct ggml_tensor * a,
847
+ struct ggml_tensor * b);
848
+
849
+ GGML_API struct ggml_tensor * ggml_mul_inplace(
850
+ struct ggml_context * ctx,
851
+ struct ggml_tensor * a,
852
+ struct ggml_tensor * b);
853
+
854
+ GGML_API struct ggml_tensor * ggml_div(
855
+ struct ggml_context * ctx,
856
+ struct ggml_tensor * a,
857
+ struct ggml_tensor * b);
858
+
859
+ GGML_API struct ggml_tensor * ggml_div_inplace(
860
+ struct ggml_context * ctx,
861
+ struct ggml_tensor * a,
862
+ struct ggml_tensor * b);
863
+
864
+ GGML_API struct ggml_tensor * ggml_sqr(
865
+ struct ggml_context * ctx,
866
+ struct ggml_tensor * a);
867
+
868
+ GGML_API struct ggml_tensor * ggml_sqr_inplace(
869
+ struct ggml_context * ctx,
870
+ struct ggml_tensor * a);
871
+
872
+ GGML_API struct ggml_tensor * ggml_sqrt(
873
+ struct ggml_context * ctx,
874
+ struct ggml_tensor * a);
875
+
876
+ GGML_API struct ggml_tensor * ggml_sqrt_inplace(
877
+ struct ggml_context * ctx,
878
+ struct ggml_tensor * a);
879
+
880
+ GGML_API struct ggml_tensor * ggml_log(
881
+ struct ggml_context * ctx,
882
+ struct ggml_tensor * a);
883
+
884
+ GGML_API struct ggml_tensor * ggml_log_inplace(
885
+ struct ggml_context * ctx,
886
+ struct ggml_tensor * a);
887
+
888
+ GGML_API struct ggml_tensor * ggml_sin(
889
+ struct ggml_context * ctx,
890
+ struct ggml_tensor * a);
891
+
892
+ GGML_API struct ggml_tensor * ggml_sin_inplace(
893
+ struct ggml_context * ctx,
894
+ struct ggml_tensor * a);
895
+
896
+ GGML_API struct ggml_tensor * ggml_cos(
897
+ struct ggml_context * ctx,
898
+ struct ggml_tensor * a);
899
+
900
+ GGML_API struct ggml_tensor * ggml_cos_inplace(
901
+ struct ggml_context * ctx,
902
+ struct ggml_tensor * a);
903
+
904
+ // return scalar
905
+ GGML_API struct ggml_tensor * ggml_sum(
906
+ struct ggml_context * ctx,
907
+ struct ggml_tensor * a);
908
+
909
+ // sums along rows, with input shape [a,b,c,d] return shape [1,b,c,d]
910
+ GGML_API struct ggml_tensor * ggml_sum_rows(
911
+ struct ggml_context * ctx,
912
+ struct ggml_tensor * a);
913
+
914
+ // mean along rows
915
+ GGML_API struct ggml_tensor * ggml_mean(
916
+ struct ggml_context * ctx,
917
+ struct ggml_tensor * a);
918
+
919
+ // argmax along rows
920
+ GGML_API struct ggml_tensor * ggml_argmax(
921
+ struct ggml_context * ctx,
922
+ struct ggml_tensor * a);
923
+
924
+ // count number of equal elements in a and b
925
+ GGML_API struct ggml_tensor * ggml_count_equal(
926
+ struct ggml_context * ctx,
927
+ struct ggml_tensor * a,
928
+ struct ggml_tensor * b);
929
+
930
+ // if a is the same shape as b, and a is not parameter, return a
931
+ // otherwise, return a new tensor: repeat(a) to fit in b
932
+ GGML_API struct ggml_tensor * ggml_repeat(
933
+ struct ggml_context * ctx,
934
+ struct ggml_tensor * a,
935
+ struct ggml_tensor * b);
936
+
937
+ // sums repetitions in a into shape of b
938
+ GGML_API struct ggml_tensor * ggml_repeat_back(
939
+ struct ggml_context * ctx,
940
+ struct ggml_tensor * a,
941
+ struct ggml_tensor * b);
942
+
943
+ // concat a and b along dim
944
+ // used in stable-diffusion
945
+ GGML_API struct ggml_tensor * ggml_concat(
946
+ struct ggml_context * ctx,
947
+ struct ggml_tensor * a,
948
+ struct ggml_tensor * b,
949
+ int dim);
950
+
951
+ GGML_API struct ggml_tensor * ggml_abs(
952
+ struct ggml_context * ctx,
953
+ struct ggml_tensor * a);
954
+
955
+ GGML_API struct ggml_tensor * ggml_abs_inplace(
956
+ struct ggml_context * ctx,
957
+ struct ggml_tensor * a);
958
+
959
+ GGML_API struct ggml_tensor * ggml_sgn(
960
+ struct ggml_context * ctx,
961
+ struct ggml_tensor * a);
962
+
963
+ GGML_API struct ggml_tensor * ggml_sgn_inplace(
964
+ struct ggml_context * ctx,
965
+ struct ggml_tensor * a);
966
+
967
+ GGML_API struct ggml_tensor * ggml_neg(
968
+ struct ggml_context * ctx,
969
+ struct ggml_tensor * a);
970
+
971
+ GGML_API struct ggml_tensor * ggml_neg_inplace(
972
+ struct ggml_context * ctx,
973
+ struct ggml_tensor * a);
974
+
975
+ GGML_API struct ggml_tensor * ggml_step(
976
+ struct ggml_context * ctx,
977
+ struct ggml_tensor * a);
978
+
979
+ GGML_API struct ggml_tensor * ggml_step_inplace(
980
+ struct ggml_context * ctx,
981
+ struct ggml_tensor * a);
982
+
983
+ GGML_API struct ggml_tensor * ggml_tanh(
984
+ struct ggml_context * ctx,
985
+ struct ggml_tensor * a);
986
+
987
+ GGML_API struct ggml_tensor * ggml_tanh_inplace(
988
+ struct ggml_context * ctx,
989
+ struct ggml_tensor * a);
990
+
991
+ GGML_API struct ggml_tensor * ggml_elu(
992
+ struct ggml_context * ctx,
993
+ struct ggml_tensor * a);
994
+
995
+ GGML_API struct ggml_tensor * ggml_elu_inplace(
996
+ struct ggml_context * ctx,
997
+ struct ggml_tensor * a);
998
+
999
+ GGML_API struct ggml_tensor * ggml_relu(
1000
+ struct ggml_context * ctx,
1001
+ struct ggml_tensor * a);
1002
+
1003
+ GGML_API struct ggml_tensor * ggml_leaky_relu(
1004
+ struct ggml_context * ctx,
1005
+ struct ggml_tensor * a, float negative_slope, bool inplace);
1006
+
1007
+ GGML_API struct ggml_tensor * ggml_relu_inplace(
1008
+ struct ggml_context * ctx,
1009
+ struct ggml_tensor * a);
1010
+
1011
+ GGML_API struct ggml_tensor * ggml_sigmoid(
1012
+ struct ggml_context * ctx,
1013
+ struct ggml_tensor * a);
1014
+
1015
+ GGML_API struct ggml_tensor * ggml_sigmoid_inplace(
1016
+ struct ggml_context * ctx,
1017
+ struct ggml_tensor * a);
1018
+
1019
+ GGML_API struct ggml_tensor * ggml_gelu(
1020
+ struct ggml_context * ctx,
1021
+ struct ggml_tensor * a);
1022
+
1023
+ GGML_API struct ggml_tensor * ggml_gelu_inplace(
1024
+ struct ggml_context * ctx,
1025
+ struct ggml_tensor * a);
1026
+
1027
+ GGML_API struct ggml_tensor * ggml_gelu_quick(
1028
+ struct ggml_context * ctx,
1029
+ struct ggml_tensor * a);
1030
+
1031
+ GGML_API struct ggml_tensor * ggml_gelu_quick_inplace(
1032
+ struct ggml_context * ctx,
1033
+ struct ggml_tensor * a);
1034
+
1035
+ GGML_API struct ggml_tensor * ggml_silu(
1036
+ struct ggml_context * ctx,
1037
+ struct ggml_tensor * a);
1038
+
1039
+ GGML_API struct ggml_tensor * ggml_silu_inplace(
1040
+ struct ggml_context * ctx,
1041
+ struct ggml_tensor * a);
1042
+
1043
+ // a - x
1044
+ // b - dy
1045
+ GGML_API struct ggml_tensor * ggml_silu_back(
1046
+ struct ggml_context * ctx,
1047
+ struct ggml_tensor * a,
1048
+ struct ggml_tensor * b);
1049
+
1050
+ // hardswish(x) = x * relu6(x + 3) / 6
1051
+ GGML_API struct ggml_tensor * ggml_hardswish(
1052
+ struct ggml_context * ctx,
1053
+ struct ggml_tensor * a);
1054
+
1055
+ // hardsigmoid(x) = relu6(x + 3) / 6
1056
+ GGML_API struct ggml_tensor * ggml_hardsigmoid(
1057
+ struct ggml_context * ctx,
1058
+ struct ggml_tensor * a);
1059
+
1060
+ GGML_API struct ggml_tensor * ggml_exp(
1061
+ struct ggml_context * ctx,
1062
+ struct ggml_tensor * a);
1063
+
1064
+ GGML_API struct ggml_tensor * ggml_exp_inplace(
1065
+ struct ggml_context * ctx,
1066
+ struct ggml_tensor * a);
1067
+
1068
+ // normalize along rows
1069
+ GGML_API struct ggml_tensor * ggml_norm(
1070
+ struct ggml_context * ctx,
1071
+ struct ggml_tensor * a,
1072
+ float eps);
1073
+
1074
+ GGML_API struct ggml_tensor * ggml_norm_inplace(
1075
+ struct ggml_context * ctx,
1076
+ struct ggml_tensor * a,
1077
+ float eps);
1078
+
1079
+ GGML_API struct ggml_tensor * ggml_rms_norm(
1080
+ struct ggml_context * ctx,
1081
+ struct ggml_tensor * a,
1082
+ float eps);
1083
+
1084
+ GGML_API struct ggml_tensor * ggml_rms_norm_inplace(
1085
+ struct ggml_context * ctx,
1086
+ struct ggml_tensor * a,
1087
+ float eps);
1088
+
1089
+ // group normalize along ne0*ne1*n_groups
1090
+ // used in stable-diffusion
1091
+ GGML_API struct ggml_tensor * ggml_group_norm(
1092
+ struct ggml_context * ctx,
1093
+ struct ggml_tensor * a,
1094
+ int n_groups,
1095
+ float eps);
1096
+
1097
+ GGML_API struct ggml_tensor * ggml_group_norm_inplace(
1098
+ struct ggml_context * ctx,
1099
+ struct ggml_tensor * a,
1100
+ int n_groups,
1101
+ float eps);
1102
+
1103
+ // l2 normalize along rows
1104
+ // used in rwkv v7
1105
+ GGML_API struct ggml_tensor * ggml_l2_norm(
1106
+ struct ggml_context * ctx,
1107
+ struct ggml_tensor * a,
1108
+ float eps);
1109
+
1110
+ GGML_API struct ggml_tensor * ggml_l2_norm_inplace(
1111
+ struct ggml_context * ctx,
1112
+ struct ggml_tensor * a,
1113
+ float eps);
1114
+
1115
+ // a - x
1116
+ // b - dy
1117
+ GGML_API struct ggml_tensor * ggml_rms_norm_back(
1118
+ struct ggml_context * ctx,
1119
+ struct ggml_tensor * a,
1120
+ struct ggml_tensor * b,
1121
+ float eps);
1122
+
1123
+ // A: k columns, n rows => [ne03, ne02, n, k]
1124
+ // B: k columns, m rows (i.e. we transpose it internally) => [ne03 * x, ne02 * y, m, k]
1125
+ // result is n columns, m rows => [ne03 * x, ne02 * y, m, n]
1126
+ GGML_API struct ggml_tensor * ggml_mul_mat(
1127
+ struct ggml_context * ctx,
1128
+ struct ggml_tensor * a,
1129
+ struct ggml_tensor * b);
1130
+
1131
+ // change the precision of a matrix multiplication
1132
+ // set to GGML_PREC_F32 for higher precision (useful for phi-2)
1133
+ GGML_API void ggml_mul_mat_set_prec(
1134
+ struct ggml_tensor * a,
1135
+ enum ggml_prec prec);
1136
+
1137
+ // indirect matrix multiplication
1138
+ GGML_API struct ggml_tensor * ggml_mul_mat_id(
1139
+ struct ggml_context * ctx,
1140
+ struct ggml_tensor * as,
1141
+ struct ggml_tensor * b,
1142
+ struct ggml_tensor * ids);
1143
+
1144
+ // A: m columns, n rows,
1145
+ // B: p columns, n rows,
1146
+ // result is m columns, p rows
1147
+ GGML_API struct ggml_tensor * ggml_out_prod(
1148
+ struct ggml_context * ctx,
1149
+ struct ggml_tensor * a,
1150
+ struct ggml_tensor * b);
1151
+
1152
+ //
1153
+ // operations on tensors without backpropagation
1154
+ //
1155
+
1156
+ GGML_API struct ggml_tensor * ggml_scale(
1157
+ struct ggml_context * ctx,
1158
+ struct ggml_tensor * a,
1159
+ float s);
1160
+
1161
+ // in-place, returns view(a)
1162
+ GGML_API struct ggml_tensor * ggml_scale_inplace(
1163
+ struct ggml_context * ctx,
1164
+ struct ggml_tensor * a,
1165
+ float s);
1166
+
1167
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1168
+ GGML_API struct ggml_tensor * ggml_set(
1169
+ struct ggml_context * ctx,
1170
+ struct ggml_tensor * a,
1171
+ struct ggml_tensor * b,
1172
+ size_t nb1,
1173
+ size_t nb2,
1174
+ size_t nb3,
1175
+ size_t offset); // in bytes
1176
+
1177
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1178
+ GGML_API struct ggml_tensor * ggml_set_inplace(
1179
+ struct ggml_context * ctx,
1180
+ struct ggml_tensor * a,
1181
+ struct ggml_tensor * b,
1182
+ size_t nb1,
1183
+ size_t nb2,
1184
+ size_t nb3,
1185
+ size_t offset); // in bytes
1186
+
1187
+ GGML_API struct ggml_tensor * ggml_set_1d(
1188
+ struct ggml_context * ctx,
1189
+ struct ggml_tensor * a,
1190
+ struct ggml_tensor * b,
1191
+ size_t offset); // in bytes
1192
+
1193
+ GGML_API struct ggml_tensor * ggml_set_1d_inplace(
1194
+ struct ggml_context * ctx,
1195
+ struct ggml_tensor * a,
1196
+ struct ggml_tensor * b,
1197
+ size_t offset); // in bytes
1198
+
1199
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1200
+ GGML_API struct ggml_tensor * ggml_set_2d(
1201
+ struct ggml_context * ctx,
1202
+ struct ggml_tensor * a,
1203
+ struct ggml_tensor * b,
1204
+ size_t nb1,
1205
+ size_t offset); // in bytes
1206
+
1207
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1208
+ GGML_API struct ggml_tensor * ggml_set_2d_inplace(
1209
+ struct ggml_context * ctx,
1210
+ struct ggml_tensor * a,
1211
+ struct ggml_tensor * b,
1212
+ size_t nb1,
1213
+ size_t offset); // in bytes
1214
+
1215
+ // a -> b, return view(b)
1216
+ GGML_API struct ggml_tensor * ggml_cpy(
1217
+ struct ggml_context * ctx,
1218
+ struct ggml_tensor * a,
1219
+ struct ggml_tensor * b);
1220
+
1221
+ GGML_API struct ggml_tensor * ggml_cast(
1222
+ struct ggml_context * ctx,
1223
+ struct ggml_tensor * a,
1224
+ enum ggml_type type);
1225
+
1226
+ // make contiguous
1227
+ GGML_API struct ggml_tensor * ggml_cont(
1228
+ struct ggml_context * ctx,
1229
+ struct ggml_tensor * a);
1230
+
1231
+ // make contiguous, with new shape
1232
+ GGML_API struct ggml_tensor * ggml_cont_1d(
1233
+ struct ggml_context * ctx,
1234
+ struct ggml_tensor * a,
1235
+ int64_t ne0);
1236
+
1237
+ GGML_API struct ggml_tensor * ggml_cont_2d(
1238
+ struct ggml_context * ctx,
1239
+ struct ggml_tensor * a,
1240
+ int64_t ne0,
1241
+ int64_t ne1);
1242
+
1243
+ GGML_API struct ggml_tensor * ggml_cont_3d(
1244
+ struct ggml_context * ctx,
1245
+ struct ggml_tensor * a,
1246
+ int64_t ne0,
1247
+ int64_t ne1,
1248
+ int64_t ne2);
1249
+
1250
+ GGML_API struct ggml_tensor * ggml_cont_4d(
1251
+ struct ggml_context * ctx,
1252
+ struct ggml_tensor * a,
1253
+ int64_t ne0,
1254
+ int64_t ne1,
1255
+ int64_t ne2,
1256
+ int64_t ne3);
1257
+
1258
+ // return view(a), b specifies the new shape
1259
+ // TODO: when we start computing gradient, make a copy instead of view
1260
+ GGML_API struct ggml_tensor * ggml_reshape(
1261
+ struct ggml_context * ctx,
1262
+ struct ggml_tensor * a,
1263
+ struct ggml_tensor * b);
1264
+
1265
+ // return view(a)
1266
+ // TODO: when we start computing gradient, make a copy instead of view
1267
+ GGML_API struct ggml_tensor * ggml_reshape_1d(
1268
+ struct ggml_context * ctx,
1269
+ struct ggml_tensor * a,
1270
+ int64_t ne0);
1271
+
1272
+ GGML_API struct ggml_tensor * ggml_reshape_2d(
1273
+ struct ggml_context * ctx,
1274
+ struct ggml_tensor * a,
1275
+ int64_t ne0,
1276
+ int64_t ne1);
1277
+
1278
+ // return view(a)
1279
+ // TODO: when we start computing gradient, make a copy instead of view
1280
+ GGML_API struct ggml_tensor * ggml_reshape_3d(
1281
+ struct ggml_context * ctx,
1282
+ struct ggml_tensor * a,
1283
+ int64_t ne0,
1284
+ int64_t ne1,
1285
+ int64_t ne2);
1286
+
1287
+ GGML_API struct ggml_tensor * ggml_reshape_4d(
1288
+ struct ggml_context * ctx,
1289
+ struct ggml_tensor * a,
1290
+ int64_t ne0,
1291
+ int64_t ne1,
1292
+ int64_t ne2,
1293
+ int64_t ne3);
1294
+
1295
+ // offset in bytes
1296
+ GGML_API struct ggml_tensor * ggml_view_1d(
1297
+ struct ggml_context * ctx,
1298
+ struct ggml_tensor * a,
1299
+ int64_t ne0,
1300
+ size_t offset);
1301
+
1302
+ GGML_API struct ggml_tensor * ggml_view_2d(
1303
+ struct ggml_context * ctx,
1304
+ struct ggml_tensor * a,
1305
+ int64_t ne0,
1306
+ int64_t ne1,
1307
+ size_t nb1, // row stride in bytes
1308
+ size_t offset);
1309
+
1310
+ GGML_API struct ggml_tensor * ggml_view_3d(
1311
+ struct ggml_context * ctx,
1312
+ struct ggml_tensor * a,
1313
+ int64_t ne0,
1314
+ int64_t ne1,
1315
+ int64_t ne2,
1316
+ size_t nb1, // row stride in bytes
1317
+ size_t nb2, // slice stride in bytes
1318
+ size_t offset);
1319
+
1320
+ GGML_API struct ggml_tensor * ggml_view_4d(
1321
+ struct ggml_context * ctx,
1322
+ struct ggml_tensor * a,
1323
+ int64_t ne0,
1324
+ int64_t ne1,
1325
+ int64_t ne2,
1326
+ int64_t ne3,
1327
+ size_t nb1, // row stride in bytes
1328
+ size_t nb2, // slice stride in bytes
1329
+ size_t nb3,
1330
+ size_t offset);
1331
+
1332
+ GGML_API struct ggml_tensor * ggml_permute(
1333
+ struct ggml_context * ctx,
1334
+ struct ggml_tensor * a,
1335
+ int axis0,
1336
+ int axis1,
1337
+ int axis2,
1338
+ int axis3);
1339
+
1340
+ // alias for ggml_permute(ctx, a, 1, 0, 2, 3)
1341
+ GGML_API struct ggml_tensor * ggml_transpose(
1342
+ struct ggml_context * ctx,
1343
+ struct ggml_tensor * a);
1344
+
1345
+ // supports 3D: a->ne[2] == b->ne[1]
1346
+ GGML_API struct ggml_tensor * ggml_get_rows(
1347
+ struct ggml_context * ctx,
1348
+ struct ggml_tensor * a, // data
1349
+ struct ggml_tensor * b); // row indices
1350
+
1351
+ GGML_API struct ggml_tensor * ggml_get_rows_back(
1352
+ struct ggml_context * ctx,
1353
+ struct ggml_tensor * a, // gradients of ggml_get_rows result
1354
+ struct ggml_tensor * b, // row indices
1355
+ struct ggml_tensor * c); // data for ggml_get_rows, only used for its shape
1356
+
1357
+ GGML_API struct ggml_tensor * ggml_diag(
1358
+ struct ggml_context * ctx,
1359
+ struct ggml_tensor * a);
1360
+
1361
+ // set elements above the diagonal to -INF
1362
+ GGML_API struct ggml_tensor * ggml_diag_mask_inf(
1363
+ struct ggml_context * ctx,
1364
+ struct ggml_tensor * a,
1365
+ int n_past);
1366
+
1367
+ // in-place, returns view(a)
1368
+ GGML_API struct ggml_tensor * ggml_diag_mask_inf_inplace(
1369
+ struct ggml_context * ctx,
1370
+ struct ggml_tensor * a,
1371
+ int n_past);
1372
+
1373
+ // set elements above the diagonal to 0
1374
+ GGML_API struct ggml_tensor * ggml_diag_mask_zero(
1375
+ struct ggml_context * ctx,
1376
+ struct ggml_tensor * a,
1377
+ int n_past);
1378
+
1379
+ // in-place, returns view(a)
1380
+ GGML_API struct ggml_tensor * ggml_diag_mask_zero_inplace(
1381
+ struct ggml_context * ctx,
1382
+ struct ggml_tensor * a,
1383
+ int n_past);
1384
+
1385
+ GGML_API struct ggml_tensor * ggml_soft_max(
1386
+ struct ggml_context * ctx,
1387
+ struct ggml_tensor * a);
1388
+
1389
+ // in-place, returns view(a)
1390
+ GGML_API struct ggml_tensor * ggml_soft_max_inplace(
1391
+ struct ggml_context * ctx,
1392
+ struct ggml_tensor * a);
1393
+
1394
+ // fused soft_max(a*scale + mask*(ALiBi slope))
1395
+ // mask is optional
1396
+ // max_bias = 0.0f for no ALiBi
1397
+ GGML_API struct ggml_tensor * ggml_soft_max_ext(
1398
+ struct ggml_context * ctx,
1399
+ struct ggml_tensor * a,
1400
+ struct ggml_tensor * mask,
1401
+ float scale,
1402
+ float max_bias);
1403
+
1404
+ GGML_API struct ggml_tensor * ggml_soft_max_ext_back(
1405
+ struct ggml_context * ctx,
1406
+ struct ggml_tensor * a,
1407
+ struct ggml_tensor * b,
1408
+ float scale,
1409
+ float max_bias);
1410
+
1411
+ // in-place, returns view(a)
1412
+ GGML_API struct ggml_tensor * ggml_soft_max_ext_back_inplace(
1413
+ struct ggml_context * ctx,
1414
+ struct ggml_tensor * a,
1415
+ struct ggml_tensor * b,
1416
+ float scale,
1417
+ float max_bias);
1418
+
1419
+ // rotary position embedding
1420
+ // if (mode & 1) - skip n_past elements (NOT SUPPORTED)
1421
+ // if (mode & GGML_ROPE_TYPE_NEOX) - GPT-NeoX style
1422
+ //
1423
+ // b is an int32 vector with size a->ne[2], it contains the positions
1424
+ GGML_API struct ggml_tensor * ggml_rope(
1425
+ struct ggml_context * ctx,
1426
+ struct ggml_tensor * a,
1427
+ struct ggml_tensor * b,
1428
+ int n_dims,
1429
+ int mode);
1430
+
1431
+ // in-place, returns view(a)
1432
+ GGML_API struct ggml_tensor * ggml_rope_inplace(
1433
+ struct ggml_context * ctx,
1434
+ struct ggml_tensor * a,
1435
+ struct ggml_tensor * b,
1436
+ int n_dims,
1437
+ int mode);
1438
+
1439
+ // custom RoPE
1440
+ // c is freq factors (e.g. phi3-128k), (optional)
1441
+ GGML_API struct ggml_tensor * ggml_rope_ext(
1442
+ struct ggml_context * ctx,
1443
+ struct ggml_tensor * a,
1444
+ struct ggml_tensor * b,
1445
+ struct ggml_tensor * c,
1446
+ int n_dims,
1447
+ int mode,
1448
+ int n_ctx_orig,
1449
+ float freq_base,
1450
+ float freq_scale,
1451
+ float ext_factor,
1452
+ float attn_factor,
1453
+ float beta_fast,
1454
+ float beta_slow);
1455
+
1456
+ GGML_API struct ggml_tensor * ggml_rope_multi(
1457
+ struct ggml_context * ctx,
1458
+ struct ggml_tensor * a,
1459
+ struct ggml_tensor * b,
1460
+ struct ggml_tensor * c,
1461
+ int n_dims,
1462
+ int sections[4],
1463
+ int mode,
1464
+ int n_ctx_orig,
1465
+ float freq_base,
1466
+ float freq_scale,
1467
+ float ext_factor,
1468
+ float attn_factor,
1469
+ float beta_fast,
1470
+ float beta_slow);
1471
+
1472
+ // in-place, returns view(a)
1473
+ GGML_API struct ggml_tensor * ggml_rope_ext_inplace(
1474
+ struct ggml_context * ctx,
1475
+ struct ggml_tensor * a,
1476
+ struct ggml_tensor * b,
1477
+ struct ggml_tensor * c,
1478
+ int n_dims,
1479
+ int mode,
1480
+ int n_ctx_orig,
1481
+ float freq_base,
1482
+ float freq_scale,
1483
+ float ext_factor,
1484
+ float attn_factor,
1485
+ float beta_fast,
1486
+ float beta_slow);
1487
+
1488
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_rope_custom(
1489
+ struct ggml_context * ctx,
1490
+ struct ggml_tensor * a,
1491
+ struct ggml_tensor * b,
1492
+ int n_dims,
1493
+ int mode,
1494
+ int n_ctx_orig,
1495
+ float freq_base,
1496
+ float freq_scale,
1497
+ float ext_factor,
1498
+ float attn_factor,
1499
+ float beta_fast,
1500
+ float beta_slow),
1501
+ "use ggml_rope_ext instead");
1502
+
1503
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_rope_custom_inplace(
1504
+ struct ggml_context * ctx,
1505
+ struct ggml_tensor * a,
1506
+ struct ggml_tensor * b,
1507
+ int n_dims,
1508
+ int mode,
1509
+ int n_ctx_orig,
1510
+ float freq_base,
1511
+ float freq_scale,
1512
+ float ext_factor,
1513
+ float attn_factor,
1514
+ float beta_fast,
1515
+ float beta_slow),
1516
+ "use ggml_rope_ext_inplace instead");
1517
+
1518
+ // compute correction dims for YaRN RoPE scaling
1519
+ GGML_API void ggml_rope_yarn_corr_dims(
1520
+ int n_dims, int n_ctx_orig, float freq_base, float beta_fast, float beta_slow, float dims[2]);
1521
+
1522
+ // rotary position embedding backward, i.e compute dx from dy
1523
+ // a - dy
1524
+ GGML_API struct ggml_tensor * ggml_rope_ext_back(
1525
+ struct ggml_context * ctx,
1526
+ struct ggml_tensor * a, // gradients of ggml_rope result
1527
+ struct ggml_tensor * b, // positions
1528
+ struct ggml_tensor * c, // freq factors
1529
+ int n_dims,
1530
+ int mode,
1531
+ int n_ctx_orig,
1532
+ float freq_base,
1533
+ float freq_scale,
1534
+ float ext_factor,
1535
+ float attn_factor,
1536
+ float beta_fast,
1537
+ float beta_slow);
1538
+
1539
+ GGML_API struct ggml_tensor * ggml_rope_multi_back(
1540
+ struct ggml_context * ctx,
1541
+ struct ggml_tensor * a,
1542
+ struct ggml_tensor * b,
1543
+ struct ggml_tensor * c,
1544
+ int n_dims,
1545
+ int sections[4],
1546
+ int mode,
1547
+ int n_ctx_orig,
1548
+ float freq_base,
1549
+ float freq_scale,
1550
+ float ext_factor,
1551
+ float attn_factor,
1552
+ float beta_fast,
1553
+ float beta_slow);
1554
+
1555
+
1556
+ // clamp
1557
+ // in-place, returns view(a)
1558
+ GGML_API struct ggml_tensor * ggml_clamp(
1559
+ struct ggml_context * ctx,
1560
+ struct ggml_tensor * a,
1561
+ float min,
1562
+ float max);
1563
+
1564
+ // im2col
1565
+ // converts data into a format that effectively results in a convolution when combined with matrix multiplication
1566
+ GGML_API struct ggml_tensor * ggml_im2col(
1567
+ struct ggml_context * ctx,
1568
+ struct ggml_tensor * a, // convolution kernel
1569
+ struct ggml_tensor * b, // data
1570
+ int s0, // stride dimension 0
1571
+ int s1, // stride dimension 1
1572
+ int p0, // padding dimension 0
1573
+ int p1, // padding dimension 1
1574
+ int d0, // dilation dimension 0
1575
+ int d1, // dilation dimension 1
1576
+ bool is_2D,
1577
+ enum ggml_type dst_type);
1578
+
1579
+ GGML_API struct ggml_tensor * ggml_im2col_back(
1580
+ struct ggml_context * ctx,
1581
+ struct ggml_tensor * a, // convolution kernel
1582
+ struct ggml_tensor * b, // gradient of im2col output
1583
+ int64_t * ne, // shape of im2col input
1584
+ int s0, // stride dimension 0
1585
+ int s1, // stride dimension 1
1586
+ int p0, // padding dimension 0
1587
+ int p1, // padding dimension 1
1588
+ int d0, // dilation dimension 0
1589
+ int d1, // dilation dimension 1
1590
+ bool is_2D);
1591
+
1592
+ GGML_API struct ggml_tensor * ggml_conv_1d(
1593
+ struct ggml_context * ctx,
1594
+ struct ggml_tensor * a, // convolution kernel
1595
+ struct ggml_tensor * b, // data
1596
+ int s0, // stride
1597
+ int p0, // padding
1598
+ int d0); // dilation
1599
+
1600
+ // conv_1d with padding = half
1601
+ // alias for ggml_conv_1d(a, b, s, a->ne[0]/2, d)
1602
+ GGML_API struct ggml_tensor* ggml_conv_1d_ph(
1603
+ struct ggml_context * ctx,
1604
+ struct ggml_tensor * a, // convolution kernel
1605
+ struct ggml_tensor * b, // data
1606
+ int s, // stride
1607
+ int d); // dilation
1608
+
1609
+ // depthwise
1610
+ // TODO: this is very likely wrong for some cases! - needs more testing
1611
+ GGML_API struct ggml_tensor * ggml_conv_1d_dw(
1612
+ struct ggml_context * ctx,
1613
+ struct ggml_tensor * a, // convolution kernel
1614
+ struct ggml_tensor * b, // data
1615
+ int s0, // stride
1616
+ int p0, // padding
1617
+ int d0); // dilation
1618
+
1619
+ GGML_API struct ggml_tensor * ggml_conv_1d_dw_ph(
1620
+ struct ggml_context * ctx,
1621
+ struct ggml_tensor * a, // convolution kernel
1622
+ struct ggml_tensor * b, // data
1623
+ int s0, // stride
1624
+ int d0); // dilation
1625
+
1626
+ GGML_API struct ggml_tensor * ggml_conv_transpose_1d(
1627
+ struct ggml_context * ctx,
1628
+ struct ggml_tensor * a, // convolution kernel
1629
+ struct ggml_tensor * b, // data
1630
+ int s0, // stride
1631
+ int p0, // padding
1632
+ int d0); // dilation
1633
+
1634
+ GGML_API struct ggml_tensor * ggml_conv_2d(
1635
+ struct ggml_context * ctx,
1636
+ struct ggml_tensor * a, // convolution kernel
1637
+ struct ggml_tensor * b, // data
1638
+ int s0, // stride dimension 0
1639
+ int s1, // stride dimension 1
1640
+ int p0, // padding dimension 0
1641
+ int p1, // padding dimension 1
1642
+ int d0, // dilation dimension 0
1643
+ int d1); // dilation dimension 1
1644
+
1645
+ // kernel size is a->ne[0] x a->ne[1]
1646
+ // stride is equal to kernel size
1647
+ // padding is zero
1648
+ // example:
1649
+ // a: 16 16 3 768
1650
+ // b: 1024 1024 3 1
1651
+ // res: 64 64 768 1
1652
+ // used in sam
1653
+ GGML_API struct ggml_tensor * ggml_conv_2d_sk_p0(
1654
+ struct ggml_context * ctx,
1655
+ struct ggml_tensor * a,
1656
+ struct ggml_tensor * b);
1657
+
1658
+ // kernel size is a->ne[0] x a->ne[1]
1659
+ // stride is 1
1660
+ // padding is half
1661
+ // example:
1662
+ // a: 3 3 256 256
1663
+ // b: 64 64 256 1
1664
+ // res: 64 64 256 1
1665
+ // used in sam
1666
+ GGML_API struct ggml_tensor * ggml_conv_2d_s1_ph(
1667
+ struct ggml_context * ctx,
1668
+ struct ggml_tensor * a,
1669
+ struct ggml_tensor * b);
1670
+
1671
+ // depthwise (via im2col and mul_mat)
1672
+ GGML_API struct ggml_tensor * ggml_conv_2d_dw(
1673
+ struct ggml_context * ctx,
1674
+ struct ggml_tensor * a, // convolution kernel
1675
+ struct ggml_tensor * b, // data
1676
+ int s0, // stride dimension 0
1677
+ int s1, // stride dimension 1
1678
+ int p0, // padding dimension 0
1679
+ int p1, // padding dimension 1
1680
+ int d0, // dilation dimension 0
1681
+ int d1); // dilation dimension 1
1682
+
1683
+ // Depthwise 2D convolution
1684
+ // may be faster than ggml_conv_2d_dw, but not available in all backends
1685
+ // a: KW KH 1 C convolution kernel
1686
+ // b: W H C N input data
1687
+ // res: W_out H_out C N
1688
+ GGML_API struct ggml_tensor * ggml_conv_2d_dw_direct(
1689
+ struct ggml_context * ctx,
1690
+ struct ggml_tensor * a,
1691
+ struct ggml_tensor * b,
1692
+ int stride0,
1693
+ int stride1,
1694
+ int pad0,
1695
+ int pad1,
1696
+ int dilation0,
1697
+ int dilation1);
1698
+
1699
+ GGML_API struct ggml_tensor * ggml_conv_transpose_2d_p0(
1700
+ struct ggml_context * ctx,
1701
+ struct ggml_tensor * a,
1702
+ struct ggml_tensor * b,
1703
+ int stride);
1704
+
1705
+ enum ggml_op_pool {
1706
+ GGML_OP_POOL_MAX,
1707
+ GGML_OP_POOL_AVG,
1708
+ GGML_OP_POOL_COUNT,
1709
+ };
1710
+
1711
+ GGML_API struct ggml_tensor * ggml_pool_1d(
1712
+ struct ggml_context * ctx,
1713
+ struct ggml_tensor * a,
1714
+ enum ggml_op_pool op,
1715
+ int k0, // kernel size
1716
+ int s0, // stride
1717
+ int p0); // padding
1718
+
1719
+ // the result will have 2*p0 padding for the first dimension
1720
+ // and 2*p1 padding for the second dimension
1721
+ GGML_API struct ggml_tensor * ggml_pool_2d(
1722
+ struct ggml_context * ctx,
1723
+ struct ggml_tensor * a,
1724
+ enum ggml_op_pool op,
1725
+ int k0,
1726
+ int k1,
1727
+ int s0,
1728
+ int s1,
1729
+ float p0,
1730
+ float p1);
1731
+
1732
+ GGML_API struct ggml_tensor * ggml_pool_2d_back(
1733
+ struct ggml_context * ctx,
1734
+ struct ggml_tensor * a,
1735
+ struct ggml_tensor * af, // "a"/input used in forward pass
1736
+ enum ggml_op_pool op,
1737
+ int k0,
1738
+ int k1,
1739
+ int s0,
1740
+ int s1,
1741
+ float p0,
1742
+ float p1);
1743
+
1744
+ enum ggml_scale_mode {
1745
+ GGML_SCALE_MODE_NEAREST = 0,
1746
+ GGML_SCALE_MODE_BILINEAR = 1,
1747
+ };
1748
+
1749
+ // interpolate
1750
+ // multiplies ne0 and ne1 by scale factor
1751
+ GGML_API struct ggml_tensor * ggml_upscale(
1752
+ struct ggml_context * ctx,
1753
+ struct ggml_tensor * a,
1754
+ int scale_factor,
1755
+ enum ggml_scale_mode mode);
1756
+
1757
+ // interpolate
1758
+ // interpolate scale to specified dimensions
1759
+ GGML_API struct ggml_tensor * ggml_upscale_ext(
1760
+ struct ggml_context * ctx,
1761
+ struct ggml_tensor * a,
1762
+ int ne0,
1763
+ int ne1,
1764
+ int ne2,
1765
+ int ne3,
1766
+ enum ggml_scale_mode mode);
1767
+
1768
+ // pad each dimension with zeros: [x, ..., x] -> [x, ..., x, 0, ..., 0]
1769
+ GGML_API struct ggml_tensor * ggml_pad(
1770
+ struct ggml_context * ctx,
1771
+ struct ggml_tensor * a,
1772
+ int p0,
1773
+ int p1,
1774
+ int p2,
1775
+ int p3);
1776
+
1777
+ // pad each dimension with reflection: [a, b, c, d] -> [b, a, b, c, d, c]
1778
+ GGML_API struct ggml_tensor * ggml_pad_reflect_1d(
1779
+ struct ggml_context * ctx,
1780
+ struct ggml_tensor * a,
1781
+ int p0,
1782
+ int p1);
1783
+
1784
+ // Ref: https://github.com/CompVis/stable-diffusion/blob/main/ldm/modules/diffusionmodules/util.py#L151
1785
+ // timesteps: [N,]
1786
+ // return: [N, dim]
1787
+ GGML_API struct ggml_tensor * ggml_timestep_embedding(
1788
+ struct ggml_context * ctx,
1789
+ struct ggml_tensor * timesteps,
1790
+ int dim,
1791
+ int max_period);
1792
+
1793
+ // sort rows
1794
+ enum ggml_sort_order {
1795
+ GGML_SORT_ORDER_ASC,
1796
+ GGML_SORT_ORDER_DESC,
1797
+ };
1798
+
1799
+ GGML_API struct ggml_tensor * ggml_argsort(
1800
+ struct ggml_context * ctx,
1801
+ struct ggml_tensor * a,
1802
+ enum ggml_sort_order order);
1803
+
1804
+ GGML_API struct ggml_tensor * ggml_arange(
1805
+ struct ggml_context * ctx,
1806
+ float start,
1807
+ float stop,
1808
+ float step);
1809
+
1810
+ // top k elements per row
1811
+ GGML_API struct ggml_tensor * ggml_top_k(
1812
+ struct ggml_context * ctx,
1813
+ struct ggml_tensor * a,
1814
+ int k);
1815
+
1816
+ #define GGML_KQ_MASK_PAD 64
1817
+
1818
+ // q: [n_embd_k, n_batch, n_head, 1]
1819
+ // k: [n_embd_k, n_kv, n_head_kv, 1]
1820
+ // v: [n_embd_v, n_kv, n_head_kv, 1] !! not transposed !!
1821
+ // mask: [n_kv, n_batch_pad, 1, 1] !! n_batch_pad = GGML_PAD(n_batch, GGML_KQ_MASK_PAD) !!
1822
+ // res: [n_embd_v, n_head, n_batch, 1] !! permuted !!
1823
+ GGML_API struct ggml_tensor * ggml_flash_attn_ext(
1824
+ struct ggml_context * ctx,
1825
+ struct ggml_tensor * q,
1826
+ struct ggml_tensor * k,
1827
+ struct ggml_tensor * v,
1828
+ struct ggml_tensor * mask,
1829
+ float scale,
1830
+ float max_bias,
1831
+ float logit_softcap);
1832
+
1833
+ GGML_API void ggml_flash_attn_ext_set_prec(
1834
+ struct ggml_tensor * a,
1835
+ enum ggml_prec prec);
1836
+
1837
+ GGML_API enum ggml_prec ggml_flash_attn_ext_get_prec(
1838
+ const struct ggml_tensor * a);
1839
+
1840
+ // TODO: needs to be adapted to ggml_flash_attn_ext
1841
+ GGML_API struct ggml_tensor * ggml_flash_attn_back(
1842
+ struct ggml_context * ctx,
1843
+ struct ggml_tensor * q,
1844
+ struct ggml_tensor * k,
1845
+ struct ggml_tensor * v,
1846
+ struct ggml_tensor * d,
1847
+ bool masked);
1848
+
1849
+ GGML_API struct ggml_tensor * ggml_ssm_conv(
1850
+ struct ggml_context * ctx,
1851
+ struct ggml_tensor * sx,
1852
+ struct ggml_tensor * c);
1853
+
1854
+ GGML_API struct ggml_tensor * ggml_ssm_scan(
1855
+ struct ggml_context * ctx,
1856
+ struct ggml_tensor * s,
1857
+ struct ggml_tensor * x,
1858
+ struct ggml_tensor * dt,
1859
+ struct ggml_tensor * A,
1860
+ struct ggml_tensor * B,
1861
+ struct ggml_tensor * C);
1862
+
1863
+ // partition into non-overlapping windows with padding if needed
1864
+ // example:
1865
+ // a: 768 64 64 1
1866
+ // w: 14
1867
+ // res: 768 14 14 25
1868
+ // used in sam
1869
+ GGML_API struct ggml_tensor * ggml_win_part(
1870
+ struct ggml_context * ctx,
1871
+ struct ggml_tensor * a,
1872
+ int w);
1873
+
1874
+ // reverse of ggml_win_part
1875
+ // used in sam
1876
+ GGML_API struct ggml_tensor * ggml_win_unpart(
1877
+ struct ggml_context * ctx,
1878
+ struct ggml_tensor * a,
1879
+ int w0,
1880
+ int h0,
1881
+ int w);
1882
+
1883
+ GGML_API struct ggml_tensor * ggml_unary(
1884
+ struct ggml_context * ctx,
1885
+ struct ggml_tensor * a,
1886
+ enum ggml_unary_op op);
1887
+
1888
+ GGML_API struct ggml_tensor * ggml_unary_inplace(
1889
+ struct ggml_context * ctx,
1890
+ struct ggml_tensor * a,
1891
+ enum ggml_unary_op op);
1892
+
1893
+ // used in sam
1894
+ GGML_API struct ggml_tensor * ggml_get_rel_pos(
1895
+ struct ggml_context * ctx,
1896
+ struct ggml_tensor * a,
1897
+ int qh,
1898
+ int kh);
1899
+
1900
+ // used in sam
1901
+ GGML_API struct ggml_tensor * ggml_add_rel_pos(
1902
+ struct ggml_context * ctx,
1903
+ struct ggml_tensor * a,
1904
+ struct ggml_tensor * pw,
1905
+ struct ggml_tensor * ph);
1906
+
1907
+ GGML_API struct ggml_tensor * ggml_add_rel_pos_inplace(
1908
+ struct ggml_context * ctx,
1909
+ struct ggml_tensor * a,
1910
+ struct ggml_tensor * pw,
1911
+ struct ggml_tensor * ph);
1912
+
1913
+ GGML_API struct ggml_tensor * ggml_rwkv_wkv6(
1914
+ struct ggml_context * ctx,
1915
+ struct ggml_tensor * k,
1916
+ struct ggml_tensor * v,
1917
+ struct ggml_tensor * r,
1918
+ struct ggml_tensor * tf,
1919
+ struct ggml_tensor * td,
1920
+ struct ggml_tensor * state);
1921
+
1922
+ GGML_API struct ggml_tensor * ggml_gated_linear_attn(
1923
+ struct ggml_context * ctx,
1924
+ struct ggml_tensor * k,
1925
+ struct ggml_tensor * v,
1926
+ struct ggml_tensor * q,
1927
+ struct ggml_tensor * g,
1928
+ struct ggml_tensor * state,
1929
+ float scale);
1930
+
1931
+ GGML_API struct ggml_tensor * ggml_rwkv_wkv7(
1932
+ struct ggml_context * ctx,
1933
+ struct ggml_tensor * r,
1934
+ struct ggml_tensor * w,
1935
+ struct ggml_tensor * k,
1936
+ struct ggml_tensor * v,
1937
+ struct ggml_tensor * a,
1938
+ struct ggml_tensor * b,
1939
+ struct ggml_tensor * state);
1940
+
1941
+ // custom operators
1942
+
1943
+ typedef void (*ggml_custom1_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, int ith, int nth, void * userdata);
1944
+ typedef void (*ggml_custom2_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, int ith, int nth, void * userdata);
1945
+ typedef void (*ggml_custom3_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, const struct ggml_tensor * c, int ith, int nth, void * userdata);
1946
+
1947
+ #define GGML_N_TASKS_MAX (-1)
1948
+ // n_tasks == GGML_N_TASKS_MAX means to use max number of tasks
1949
+
1950
+ GGML_API struct ggml_tensor * ggml_map_custom1(
1951
+ struct ggml_context * ctx,
1952
+ struct ggml_tensor * a,
1953
+ ggml_custom1_op_t fun,
1954
+ int n_tasks,
1955
+ void * userdata);
1956
+
1957
+ GGML_API struct ggml_tensor * ggml_map_custom1_inplace(
1958
+ struct ggml_context * ctx,
1959
+ struct ggml_tensor * a,
1960
+ ggml_custom1_op_t fun,
1961
+ int n_tasks,
1962
+ void * userdata);
1963
+
1964
+ GGML_API struct ggml_tensor * ggml_map_custom2(
1965
+ struct ggml_context * ctx,
1966
+ struct ggml_tensor * a,
1967
+ struct ggml_tensor * b,
1968
+ ggml_custom2_op_t fun,
1969
+ int n_tasks,
1970
+ void * userdata);
1971
+
1972
+ GGML_API struct ggml_tensor * ggml_map_custom2_inplace(
1973
+ struct ggml_context * ctx,
1974
+ struct ggml_tensor * a,
1975
+ struct ggml_tensor * b,
1976
+ ggml_custom2_op_t fun,
1977
+ int n_tasks,
1978
+ void * userdata);
1979
+
1980
+ GGML_API struct ggml_tensor * ggml_map_custom3(
1981
+ struct ggml_context * ctx,
1982
+ struct ggml_tensor * a,
1983
+ struct ggml_tensor * b,
1984
+ struct ggml_tensor * c,
1985
+ ggml_custom3_op_t fun,
1986
+ int n_tasks,
1987
+ void * userdata);
1988
+
1989
+ GGML_API struct ggml_tensor * ggml_map_custom3_inplace(
1990
+ struct ggml_context * ctx,
1991
+ struct ggml_tensor * a,
1992
+ struct ggml_tensor * b,
1993
+ struct ggml_tensor * c,
1994
+ ggml_custom3_op_t fun,
1995
+ int n_tasks,
1996
+ void * userdata);
1997
+
1998
+ typedef void (*ggml_custom_op_t)(struct ggml_tensor * dst , int ith, int nth, void * userdata);
1999
+
2000
+ GGML_API struct ggml_tensor * ggml_custom_4d(
2001
+ struct ggml_context * ctx,
2002
+ enum ggml_type type,
2003
+ int64_t ne0,
2004
+ int64_t ne1,
2005
+ int64_t ne2,
2006
+ int64_t ne3,
2007
+ struct ggml_tensor ** args,
2008
+ int n_args,
2009
+ ggml_custom_op_t fun,
2010
+ int n_tasks,
2011
+ void * userdata);
2012
+
2013
+ GGML_API struct ggml_tensor * ggml_custom_inplace(
2014
+ struct ggml_context * ctx,
2015
+ struct ggml_tensor * a,
2016
+ struct ggml_tensor ** args,
2017
+ int n_args,
2018
+ ggml_custom_op_t fun,
2019
+ int n_tasks,
2020
+ void * userdata);
2021
+
2022
+ // loss function
2023
+
2024
+ GGML_API struct ggml_tensor * ggml_cross_entropy_loss(
2025
+ struct ggml_context * ctx,
2026
+ struct ggml_tensor * a, // logits
2027
+ struct ggml_tensor * b); // labels
2028
+
2029
+ GGML_API struct ggml_tensor * ggml_cross_entropy_loss_back(
2030
+ struct ggml_context * ctx,
2031
+ struct ggml_tensor * a, // logits
2032
+ struct ggml_tensor * b, // labels
2033
+ struct ggml_tensor * c); // gradients of cross_entropy_loss result
2034
+
2035
+ // AdamW optimizer step
2036
+ // Paper: https://arxiv.org/pdf/1711.05101v3.pdf
2037
+ // PyTorch: https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html
2038
+ GGML_API struct ggml_tensor * ggml_opt_step_adamw(
2039
+ struct ggml_context * ctx,
2040
+ struct ggml_tensor * a,
2041
+ struct ggml_tensor * grad,
2042
+ struct ggml_tensor * m,
2043
+ struct ggml_tensor * v,
2044
+ struct ggml_tensor * adamw_params); // parameters such a the learning rate
2045
+
2046
+ //
2047
+ // automatic differentiation
2048
+ //
2049
+
2050
+ GGML_API void ggml_build_forward_expand(struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);
2051
+ GGML_API void ggml_build_backward_expand(
2052
+ struct ggml_context * ctx_static, // context for static gradients (loss + gradient accumulation)
2053
+ struct ggml_context * ctx_compute, // context for gradient computation
2054
+ struct ggml_cgraph * cgraph,
2055
+ bool accumulate); // whether or not gradients should be accumulated, requires static allocation of tensors in ctx_static
2056
+
2057
+ // graph allocation in a context
2058
+ GGML_API struct ggml_cgraph * ggml_new_graph (struct ggml_context * ctx); // size = GGML_DEFAULT_GRAPH_SIZE, grads = false
2059
+ GGML_API struct ggml_cgraph * ggml_new_graph_custom(struct ggml_context * ctx, size_t size, bool grads);
2060
+ GGML_API struct ggml_cgraph * ggml_graph_dup (struct ggml_context * ctx, struct ggml_cgraph * cgraph);
2061
+ GGML_API void ggml_graph_cpy (struct ggml_cgraph * src, struct ggml_cgraph * dst);
2062
+ GGML_API void ggml_graph_reset (struct ggml_cgraph * cgraph); // set regular grads + optimizer momenta to 0, set loss grad to 1
2063
+ GGML_API void ggml_graph_clear (struct ggml_cgraph * cgraph);
2064
+
2065
+ GGML_API int ggml_graph_size (struct ggml_cgraph * cgraph);
2066
+ GGML_API struct ggml_tensor * ggml_graph_node (struct ggml_cgraph * cgraph, int i); // if i < 0, returns nodes[n_nodes + i]
2067
+ GGML_API struct ggml_tensor ** ggml_graph_nodes (struct ggml_cgraph * cgraph);
2068
+ GGML_API int ggml_graph_n_nodes(struct ggml_cgraph * cgraph);
2069
+
2070
+ GGML_API void ggml_graph_add_node(struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);
2071
+
2072
+ GGML_API size_t ggml_graph_overhead(void);
2073
+ GGML_API size_t ggml_graph_overhead_custom(size_t size, bool grads);
2074
+
2075
+ GGML_API struct ggml_tensor * ggml_graph_get_tensor (const struct ggml_cgraph * cgraph, const char * name);
2076
+ GGML_API struct ggml_tensor * ggml_graph_get_grad (const struct ggml_cgraph * cgraph, const struct ggml_tensor * node);
2077
+ GGML_API struct ggml_tensor * ggml_graph_get_grad_acc(const struct ggml_cgraph * cgraph, const struct ggml_tensor * node);
2078
+
2079
+ GGML_API void ggml_graph_export(const struct ggml_cgraph * cgraph, const char * fname);
2080
+ GGML_API struct ggml_cgraph * ggml_graph_import(const char * fname, struct ggml_context ** ctx_data, struct ggml_context ** ctx_eval);
2081
+
2082
+ // print info and performance information for the graph
2083
+ GGML_API void ggml_graph_print(const struct ggml_cgraph * cgraph);
2084
+
2085
+ // dump the graph into a file using the dot format
2086
+ GGML_API void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * gf, const char * filename);
2087
+
2088
+ // TODO these functions were sandwiched in the old optimization interface, is there a better place for them?
2089
+ typedef void (*ggml_log_callback)(enum ggml_log_level level, const char * text, void * user_data);
2090
+
2091
+ // Set callback for all future logging events.
2092
+ // If this is not called, or NULL is supplied, everything is output on stderr.
2093
+ GGML_API void ggml_log_set(ggml_log_callback log_callback, void * user_data);
2094
+
2095
+ GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);
2096
+
2097
+ //
2098
+ // quantization
2099
+ //
2100
+
2101
+ // - ggml_quantize_init can be called multiple times with the same type
2102
+ // it will only initialize the quantization tables for the first call or after ggml_quantize_free
2103
+ // automatically called by ggml_quantize_chunk for convenience
2104
+ //
2105
+ // - ggml_quantize_free will free any memory allocated by ggml_quantize_init
2106
+ // call this at the end of the program to avoid memory leaks
2107
+ //
2108
+ // note: these are thread-safe
2109
+ //
2110
+ GGML_API void ggml_quantize_init(enum ggml_type type);
2111
+ GGML_API void ggml_quantize_free(void);
2112
+
2113
+ // some quantization type cannot be used without an importance matrix
2114
+ GGML_API bool ggml_quantize_requires_imatrix(enum ggml_type type);
2115
+
2116
+ // calls ggml_quantize_init internally (i.e. can allocate memory)
2117
+ GGML_API size_t ggml_quantize_chunk(
2118
+ enum ggml_type type,
2119
+ const float * src,
2120
+ void * dst,
2121
+ int64_t start,
2122
+ int64_t nrows,
2123
+ int64_t n_per_row,
2124
+ const float * imatrix);
2125
+
2126
+ #ifdef __cplusplus
2127
+ // restrict not standard in C++
2128
+ # if defined(__GNUC__)
2129
+ # define GGML_RESTRICT __restrict__
2130
+ # elif defined(__clang__)
2131
+ # define GGML_RESTRICT __restrict
2132
+ # elif defined(_MSC_VER)
2133
+ # define GGML_RESTRICT __restrict
2134
+ # else
2135
+ # define GGML_RESTRICT
2136
+ # endif
2137
+ #else
2138
+ # if defined (_MSC_VER) && (__STDC_VERSION__ < 201112L)
2139
+ # define GGML_RESTRICT __restrict
2140
+ # else
2141
+ # define GGML_RESTRICT restrict
2142
+ # endif
2143
+ #endif
2144
+ typedef void (*ggml_to_float_t) (const void * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
2145
+ typedef void (*ggml_from_float_t)(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
2146
+
2147
+ struct ggml_type_traits {
2148
+ const char * type_name;
2149
+ int64_t blck_size;
2150
+ int64_t blck_size_interleave; // interleave elements in blocks
2151
+ size_t type_size;
2152
+ bool is_quantized;
2153
+ ggml_to_float_t to_float;
2154
+ ggml_from_float_t from_float_ref;
2155
+ };
2156
+
2157
+ GGML_API const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type);
2158
+
2159
+ // ggml threadpool
2160
+ // TODO: currently, only a few functions are in the base ggml API, while the rest are in the CPU backend
2161
+ // the goal should be to create an API that other backends can use move everything to the ggml base
2162
+
2163
+ // scheduling priorities
2164
+ enum ggml_sched_priority {
2165
+ GGML_SCHED_PRIO_NORMAL,
2166
+ GGML_SCHED_PRIO_MEDIUM,
2167
+ GGML_SCHED_PRIO_HIGH,
2168
+ GGML_SCHED_PRIO_REALTIME
2169
+ };
2170
+
2171
+ // threadpool params
2172
+ // Use ggml_threadpool_params_default() or ggml_threadpool_params_init() to populate the defaults
2173
+ struct ggml_threadpool_params {
2174
+ bool cpumask[GGML_MAX_N_THREADS]; // mask of cpu cores (all-zeros means use default affinity settings)
2175
+ int n_threads; // number of threads
2176
+ enum ggml_sched_priority prio; // thread priority
2177
+ uint32_t poll; // polling level (0 - no polling, 100 - aggressive polling)
2178
+ bool strict_cpu; // strict cpu placement
2179
+ bool paused; // start in paused state
2180
+ };
2181
+
2182
+ struct ggml_threadpool; // forward declaration, see ggml.c
2183
+
2184
+ typedef struct ggml_threadpool * ggml_threadpool_t;
2185
+
2186
+ GGML_API struct ggml_threadpool_params ggml_threadpool_params_default(int n_threads);
2187
+ GGML_API void ggml_threadpool_params_init (struct ggml_threadpool_params * p, int n_threads);
2188
+ GGML_API bool ggml_threadpool_params_match (const struct ggml_threadpool_params * p0, const struct ggml_threadpool_params * p1);
2189
+
2190
+ #ifdef __cplusplus
2191
+ }
2192
+ #endif