@fugood/llama.node 0.6.2 → 1.0.0-beta.1

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 (378) hide show
  1. package/CMakeLists.txt +40 -30
  2. package/README.md +4 -1
  3. package/lib/binding.js +41 -29
  4. package/lib/binding.ts +26 -25
  5. package/package.json +45 -10
  6. package/scripts/build.js +47 -0
  7. package/scripts/llama.cpp.patch +109 -0
  8. package/src/anyascii.c +22223 -0
  9. package/src/anyascii.h +42 -0
  10. package/src/tts_utils.cpp +20 -7
  11. package/src/tts_utils.h +2 -0
  12. package/bin/darwin/arm64/llama-node.node +0 -0
  13. package/bin/darwin/x64/llama-node.node +0 -0
  14. package/bin/linux/arm64/llama-node.node +0 -0
  15. package/bin/linux/x64/llama-node.node +0 -0
  16. package/bin/linux-cuda/arm64/llama-node.node +0 -0
  17. package/bin/linux-cuda/x64/llama-node.node +0 -0
  18. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  19. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  20. package/bin/win32/x64/llama-node.node +0 -0
  21. package/bin/win32/x64/node.lib +0 -0
  22. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  23. package/bin/win32-vulkan/arm64/node.lib +0 -0
  24. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  25. package/bin/win32-vulkan/x64/node.lib +0 -0
  26. package/patches/node-api-headers+1.1.0.patch +0 -26
  27. package/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
  28. package/src/llama.cpp/.github/workflows/build.yml +0 -1078
  29. package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
  30. package/src/llama.cpp/.github/workflows/docker.yml +0 -178
  31. package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
  32. package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
  33. package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
  34. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
  35. package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
  36. package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
  37. package/src/llama.cpp/.github/workflows/release.yml +0 -739
  38. package/src/llama.cpp/.github/workflows/server.yml +0 -237
  39. package/src/llama.cpp/.github/workflows/winget.yml +0 -42
  40. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
  41. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
  42. package/src/llama.cpp/cmake/build-info.cmake +0 -64
  43. package/src/llama.cpp/cmake/common.cmake +0 -35
  44. package/src/llama.cpp/cmake/git-vars.cmake +0 -22
  45. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
  46. package/src/llama.cpp/common/build-info.cpp.in +0 -4
  47. package/src/llama.cpp/docs/build.md +0 -561
  48. package/src/llama.cpp/examples/CMakeLists.txt +0 -43
  49. package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
  50. package/src/llama.cpp/examples/batched/batched.cpp +0 -246
  51. package/src/llama.cpp/examples/chat-13B.bat +0 -57
  52. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
  53. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
  54. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
  55. package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
  56. package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
  57. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
  58. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
  59. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
  60. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
  61. package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
  62. package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
  63. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
  64. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
  65. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
  66. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
  67. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
  68. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
  69. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
  70. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
  71. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
  72. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
  73. package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
  74. package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
  75. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
  76. package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
  77. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
  78. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
  79. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
  80. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
  81. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
  82. package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
  83. package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
  84. package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
  85. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
  86. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
  87. package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
  88. package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
  89. package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
  90. package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
  91. package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
  92. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
  93. package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
  94. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
  95. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
  96. package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
  97. package/src/llama.cpp/examples/simple/simple.cpp +0 -206
  98. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
  99. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
  100. package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
  101. package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
  102. package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
  103. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
  104. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
  105. package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
  106. package/src/llama.cpp/examples/sycl/build.sh +0 -23
  107. package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
  108. package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
  109. package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
  110. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
  111. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
  112. package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
  113. package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
  114. package/src/llama.cpp/examples/training/finetune.cpp +0 -96
  115. package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
  116. package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
  117. package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
  118. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
  119. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
  120. package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
  121. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
  122. package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
  123. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
  124. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
  125. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
  126. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
  127. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
  128. package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
  129. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
  130. package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
  131. package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
  132. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
  133. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
  134. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
  135. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
  136. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
  137. package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
  138. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  139. package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  140. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
  141. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
  142. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
  143. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
  144. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
  145. package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
  146. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
  147. package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
  148. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
  149. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
  150. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
  151. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
  152. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
  153. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
  154. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
  155. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
  156. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
  157. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
  158. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
  159. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
  160. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
  161. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
  162. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
  163. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
  164. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
  165. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
  166. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
  167. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
  168. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
  169. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
  170. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
  171. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
  172. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
  173. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
  174. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
  175. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
  176. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
  177. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
  178. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
  179. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
  180. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
  181. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
  182. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
  183. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
  184. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
  185. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
  186. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
  187. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
  188. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
  189. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
  190. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
  191. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
  192. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
  193. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
  194. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
  195. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
  196. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
  197. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
  198. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
  199. package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
  200. package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
  201. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
  202. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
  203. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
  204. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
  205. package/src/llama.cpp/ggml/src/ggml.c +0 -6550
  206. package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
  207. package/src/llama.cpp/models/.editorconfig +0 -1
  208. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  209. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  210. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  211. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
  212. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
  213. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
  214. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
  215. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  216. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
  217. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
  218. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  219. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
  220. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
  221. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  222. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
  223. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
  225. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
  226. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  227. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
  228. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
  229. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  230. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
  231. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
  232. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
  233. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
  234. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  236. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
  237. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
  238. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  239. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
  240. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
  241. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
  242. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
  245. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
  246. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
  248. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
  249. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
  250. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
  253. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
  256. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
  257. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
  258. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
  259. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  260. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
  261. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
  262. package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
  263. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
  264. package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
  265. package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
  266. package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
  267. package/src/llama.cpp/prompts/alpaca.txt +0 -1
  268. package/src/llama.cpp/prompts/assistant.txt +0 -31
  269. package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
  270. package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
  271. package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
  272. package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
  273. package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
  274. package/src/llama.cpp/prompts/chat.txt +0 -28
  275. package/src/llama.cpp/prompts/dan-modified.txt +0 -1
  276. package/src/llama.cpp/prompts/dan.txt +0 -1
  277. package/src/llama.cpp/prompts/mnemonics.txt +0 -93
  278. package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
  279. package/src/llama.cpp/prompts/reason-act.txt +0 -18
  280. package/src/llama.cpp/requirements/requirements-all.txt +0 -15
  281. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
  282. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
  283. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
  284. package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
  285. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
  286. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
  287. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
  288. package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
  289. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
  290. package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
  291. package/src/llama.cpp/requirements.txt +0 -13
  292. package/src/llama.cpp/scripts/build-info.sh +0 -30
  293. package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
  294. package/src/llama.cpp/scripts/xxd.cmake +0 -16
  295. package/src/llama.cpp/tests/CMakeLists.txt +0 -177
  296. package/src/llama.cpp/tests/get-model.cpp +0 -21
  297. package/src/llama.cpp/tests/get-model.h +0 -2
  298. package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
  299. package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
  300. package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
  301. package/src/llama.cpp/tests/test-barrier.cpp +0 -94
  302. package/src/llama.cpp/tests/test-c.c +0 -7
  303. package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
  304. package/src/llama.cpp/tests/test-chat.cpp +0 -985
  305. package/src/llama.cpp/tests/test-double-float.cpp +0 -57
  306. package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
  307. package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
  308. package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
  309. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
  310. package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
  311. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
  312. package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
  313. package/src/llama.cpp/tests/test-log.cpp +0 -39
  314. package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
  315. package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
  316. package/src/llama.cpp/tests/test-opt.cpp +0 -904
  317. package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
  318. package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
  319. package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
  320. package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
  321. package/src/llama.cpp/tests/test-rope.cpp +0 -262
  322. package/src/llama.cpp/tests/test-sampling.cpp +0 -399
  323. package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
  324. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
  325. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
  326. package/src/llama.cpp/tools/CMakeLists.txt +0 -39
  327. package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
  328. package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
  329. package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
  330. package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
  331. package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
  332. package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
  333. package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
  334. package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
  335. package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
  336. package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
  337. package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
  338. package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
  339. package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
  340. package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
  341. package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
  342. package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
  343. package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
  344. package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
  345. package/src/llama.cpp/tools/main/main.cpp +0 -977
  346. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
  347. package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
  348. package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
  349. package/src/llama.cpp/tools/mtmd/clip.h +0 -101
  350. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
  351. package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
  352. package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
  353. package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
  354. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
  355. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
  356. package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
  357. package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
  358. package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
  359. package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
  360. package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
  361. package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
  362. package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
  363. package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
  364. package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
  365. package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
  366. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
  367. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
  368. package/src/llama.cpp/tools/run/run.cpp +0 -1261
  369. package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
  370. package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
  371. package/src/llama.cpp/tools/server/httplib.h +0 -10506
  372. package/src/llama.cpp/tools/server/server.cpp +0 -4966
  373. package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
  374. package/src/llama.cpp/tools/server/utils.hpp +0 -1337
  375. package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
  376. package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
  377. package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
  378. package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
@@ -1,179 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2024 The ggml authors
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to
6
- * deal in the Software without restriction, including without limitation the
7
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
- * sell copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
- * IN THE SOFTWARE.
21
- */
22
-
23
- #include "acl_tensor.h"
24
-
25
- #include <algorithm>
26
- #include <cstring>
27
-
28
- aclDataType ggml_cann_type_mapping(ggml_type type) {
29
- switch (type) {
30
- case GGML_TYPE_F32:
31
- return ACL_FLOAT;
32
- case GGML_TYPE_F16:
33
- return ACL_FLOAT16;
34
- case GGML_TYPE_I8:
35
- return ACL_INT8;
36
- case GGML_TYPE_I16:
37
- return ACL_INT16;
38
- case GGML_TYPE_I32:
39
- return ACL_INT32;
40
- case GGML_TYPE_Q4_0:
41
- return ACL_INT4;
42
- case GGML_TYPE_Q8_0:
43
- return ACL_INT8;
44
- case GGML_TYPE_I64:
45
- return ACL_INT64;
46
- default:
47
- return ACL_DT_UNDEFINED;
48
- }
49
- return ACL_DT_UNDEFINED;
50
- }
51
-
52
- aclTensor* ggml_cann_create_tensor(const ggml_tensor* tensor, int64_t* ne,
53
- size_t* nb, int64_t dims, aclFormat format,
54
- size_t offset) {
55
- // If tensor is bcasted, Up to GGML_MAX_DIMS additional dimensions will be
56
- // added.
57
- int64_t acl_ne[GGML_MAX_DIMS * 2], acl_stride[GGML_MAX_DIMS * 2];
58
-
59
- if (ne == nullptr) {
60
- for (int i = 0; i < GGML_MAX_DIMS; i++) {
61
- acl_ne[i] = tensor->ne[i];
62
- // The step size of acl is in elements.
63
- acl_stride[i] = tensor->nb[i] / ggml_element_size(tensor);
64
- }
65
- } else {
66
- // With bcast
67
- for (int i = 0; i < dims; i++) {
68
- acl_ne[i] = ne[i];
69
- acl_stride[i] = nb[i] / ggml_element_size(tensor);
70
- }
71
- }
72
-
73
- int64_t final_dims = (dims == 0 ? GGML_MAX_DIMS : dims);
74
- int64_t acl_storage_len = 1;
75
- for (int i = 0; i < final_dims; i++) {
76
- acl_storage_len += (acl_ne[i] - 1) * acl_stride[i];
77
- }
78
-
79
- // Reverse ne and stride.
80
- std::reverse(acl_ne, acl_ne + final_dims);
81
- std::reverse(acl_stride, acl_stride + final_dims);
82
-
83
- aclTensor* acl_tensor = aclCreateTensor(
84
- acl_ne, final_dims, ggml_cann_type_mapping(tensor->type), acl_stride,
85
- offset / ggml_element_size(tensor), format, &acl_storage_len, 1,
86
- tensor->data);
87
-
88
- return acl_tensor;
89
- }
90
-
91
- bool ggml_cann_need_bcast(const ggml_tensor* t0, const ggml_tensor* t1) {
92
- for (int i = 0; i < GGML_MAX_DIMS; i++) {
93
- if (t1->ne[i] != t0->ne[i] && t1->ne[i] != 1) {
94
- return true;
95
- }
96
- }
97
- return false;
98
- }
99
-
100
- int64_t ggml_cann_get_bcast_shape(const ggml_tensor* src0,
101
- const ggml_tensor* src1,
102
- int64_t* bcast_src0_ne,
103
- int64_t* bcast_src1_ne, size_t* bcast_src0_nb,
104
- size_t* bcast_src1_nb) {
105
- GGML_ASSERT(ggml_can_repeat(src1, src0));
106
- int bcast_dim_cnt = 0;
107
- for (int i = 0; i < GGML_MAX_DIMS; i++) {
108
- int64_t nr = src0->ne[i] / src1->ne[i];
109
- bcast_src0_ne[bcast_dim_cnt] = src0->ne[i] / nr;
110
- bcast_src1_ne[bcast_dim_cnt] = src1->ne[i];
111
- bcast_src0_nb[bcast_dim_cnt] = src0->nb[i];
112
- bcast_src1_nb[bcast_dim_cnt] = src1->nb[i];
113
- bcast_dim_cnt++;
114
- if (nr != 1) {
115
- // Need to add an extra dim.
116
- bcast_src0_ne[bcast_dim_cnt] = nr;
117
- bcast_src1_ne[bcast_dim_cnt] = 1;
118
- bcast_src0_nb[bcast_dim_cnt] = bcast_src0_nb[bcast_dim_cnt - 1] *
119
- bcast_src0_ne[bcast_dim_cnt - 1];
120
- bcast_src1_nb[bcast_dim_cnt] = bcast_src1_nb[bcast_dim_cnt - 1] *
121
- bcast_src1_ne[bcast_dim_cnt - 1];
122
- bcast_dim_cnt++;
123
- }
124
- }
125
- return bcast_dim_cnt;
126
- }
127
-
128
- int64_t ggml_cann_get_mulmat_bcast_shape(
129
- const int64_t* input_ne, const int64_t* weight_ne, const int64_t* dst_ne,
130
- const size_t* input_nb, const size_t* weight_nb, const size_t* dst_nb,
131
- int64_t* bcast_input_ne, int64_t* bcast_weight_ne, int64_t* bcast_dst_ne,
132
- size_t* bcast_input_nb, size_t* bcast_weight_nb, size_t* bcast_dst_nb) {
133
- // input and dst shoule in same shape, except first two dims.
134
- GGML_ASSERT(input_ne[2] == dst_ne[2]);
135
- GGML_ASSERT(input_ne[3] == dst_ne[3]);
136
-
137
- int bcast_dim_cnt = 0;
138
-
139
- // For mul_mat, a dimension needs to be added before the dimension that
140
- // weight needs to be expanded to satisfy the bcast rule of matrix
141
- // multiplication.
142
- for (int i = 0; i < GGML_MAX_DIMS; i++) {
143
- int64_t nr = input_ne[i] / weight_ne[i];
144
- // Do not use bcast in the first two dimensions because we only support
145
- // the bcast batch dimension. Just copy them.
146
- if (i < 2 || nr == 1) {
147
- bcast_input_ne[bcast_dim_cnt] = input_ne[i];
148
- bcast_weight_ne[bcast_dim_cnt] = weight_ne[i];
149
- bcast_dst_ne[bcast_dim_cnt] = dst_ne[i];
150
-
151
- bcast_input_nb[bcast_dim_cnt] = input_nb[i];
152
- bcast_weight_nb[bcast_dim_cnt] = weight_nb[i];
153
- bcast_dst_nb[bcast_dim_cnt] = dst_nb[i];
154
- bcast_dim_cnt++;
155
- } else {
156
- // Need to add an extra dim.
157
- bcast_input_ne[bcast_dim_cnt] = nr;
158
- bcast_dst_ne[bcast_dim_cnt] = nr;
159
- bcast_weight_ne[bcast_dim_cnt] = 1;
160
- bcast_input_nb[bcast_dim_cnt] = input_nb[i];
161
- bcast_dst_nb[bcast_dim_cnt] = dst_nb[i];
162
- bcast_weight_nb[bcast_dim_cnt] = weight_nb[i];
163
- bcast_dim_cnt++;
164
-
165
- bcast_input_ne[bcast_dim_cnt] = input_ne[i] / nr;
166
- bcast_dst_ne[bcast_dim_cnt] = dst_ne[i] / nr;
167
- bcast_weight_ne[bcast_dim_cnt] = weight_ne[i];
168
- bcast_input_nb[bcast_dim_cnt] = bcast_input_nb[bcast_dim_cnt - 1] *
169
- bcast_input_ne[bcast_dim_cnt - 1];
170
- bcast_dst_nb[bcast_dim_cnt] = bcast_dst_nb[bcast_dim_cnt - 1] *
171
- bcast_dst_ne[bcast_dim_cnt - 1];
172
- bcast_weight_nb[bcast_dim_cnt] =
173
- bcast_weight_nb[bcast_dim_cnt - 1] *
174
- bcast_weight_ne[bcast_dim_cnt - 1];
175
- bcast_dim_cnt++;
176
- }
177
- }
178
- return bcast_dim_cnt;
179
- }
@@ -1,258 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2024 The ggml authors
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to
6
- * deal in the Software without restriction, including without limitation the
7
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
- * sell copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
- * IN THE SOFTWARE.
21
- */
22
-
23
- #ifndef CANN_ACL_TENSOR_H
24
- #define CANN_ACL_TENSOR_H
25
-
26
- #include <algorithm>
27
- #include <cstring>
28
-
29
- #include <aclnn/aclnn_base.h>
30
- #include "common.h"
31
-
32
- /**
33
- * @brief Maps a ggml_type to its corresponding aclDataType.
34
- *
35
- * @details This function takes a ggml_type as input and returns the corresponding
36
- * aclDataType. It supports mapping for various ggml_types. If the input type
37
- * does not match any of the predefined ggml_types, the function returns
38
- * ACL_DT_UNDEFINED.
39
- *
40
- * @param type The ggml_type to be mapped.
41
- * @return The corresponding aclDataType. If the input type is not recognized,
42
- * ACL_DT_UNDEFINED is returned.
43
- */
44
- aclDataType ggml_cann_type_mapping(ggml_type type);
45
-
46
- /**
47
- * @brief Creates an ACL tensor from a ggml_tensor with optional shape.
48
- *
49
- * @details This function creates an ACL tensor based on the properties of the
50
- * provided ggml_tensor. It supports customer shape by adjusting dimensions
51
- * and strides accordingly. If customer shape is applied, additional
52
- * dimensions and strides are calculated based on the provided parameters.
53
- *
54
- * @param tensor Pointer to the ggml_tensor to be converted to ACL tensor.
55
- * @param ne Pointer to an array containing dimensions. Defaults to nullptr
56
- * if no customer shape is applied.
57
- * @param nb Pointer to an array containing strides. Defaults to nullptr
58
- * if no customer shape is applied.
59
- * @param dims Number of dimensions in the tensor. Defaults to 0 if no customer
60
- * shape is applied.
61
- * @param format ACL tensor format. Defaults to ACL_FORMAT_ND.
62
- * @param offset Offset in bytes for the ACL tensor data. Defaults to 0.
63
- * @return Pointer to the created ACL tensor.
64
- */
65
- aclTensor* ggml_cann_create_tensor(const ggml_tensor* tensor, int64_t* ne = nullptr,
66
- size_t* nb = nullptr, int64_t dims = 0,
67
- aclFormat format = ACL_FORMAT_ND,
68
- size_t offset = 0);
69
-
70
- /**
71
- * @brief Template for creating an ACL tensor from provided parameters. typename TYPE
72
- * should be size_t or float.
73
- *
74
- * @details This function creates an ACL tensor using the provided data pointer,
75
- * data type, dimensions, strides, format, offset, and additional parameters.
76
- * It calculates necessary dimensions and strides based on the provided ne and nb
77
- * arrays, adjusting them for the ACL tensor creation. The ACL storage length
78
- * is also calculated based on the provided dimensions and strides.
79
- *
80
- * @param data_ptr Pointer to the data buffer for the ACL tensor.
81
- * @param dtype ACL data type of the tensor.
82
- * @param type_size Size of each element in the tensor data buffer.
83
- * @param ne Pointer to an array containing tensor dimensions.
84
- * @param nb Pointer to an array containing tensor strides.
85
- * @param dims Number of dimensions of the tensor.
86
- * @param format ACL tensor format. Defaults to ACL_FORMAT_ND.
87
- * @param offset Offset in bytes for the ACL tensor data. Defaults to 0.
88
- * @return Pointer to the created ACL tensor.
89
- */
90
- template<typename TYPE>
91
- aclTensor* ggml_cann_create_tensor(void* data_ptr, aclDataType dtype,
92
- TYPE type_size, int64_t* ne, TYPE* nb,
93
- int64_t dims,
94
- aclFormat format = ACL_FORMAT_ND,
95
- size_t offset = 0) {
96
- int64_t tmp_ne[GGML_MAX_DIMS * 2];
97
- int64_t tmp_stride[GGML_MAX_DIMS * 2];
98
-
99
- memcpy(tmp_ne, ne, dims * sizeof(int64_t));
100
- for (int i = 0; i < dims; i++) {
101
- tmp_stride[i] = nb[i] / type_size;
102
- }
103
-
104
- int64_t acl_storage_len = 1;
105
- for (int i = 0; i < dims; i++) {
106
- acl_storage_len += (tmp_ne[i] - 1) * tmp_stride[i];
107
- }
108
-
109
- std::reverse(tmp_ne, tmp_ne + dims);
110
- std::reverse(tmp_stride, tmp_stride + dims);
111
-
112
- aclTensor* acl_tensor =
113
- aclCreateTensor(tmp_ne, dims, dtype, tmp_stride, offset / type_size,
114
- format, &acl_storage_len, 1, data_ptr);
115
-
116
- return acl_tensor;
117
- }
118
-
119
- /**
120
- * @brief Checks if tensors require broadcasting based on their shapes.
121
- *
122
- * @details This function determines if two ggml_tensors need to be broadcasted for
123
- * element-wise operations. Broadcasting is necessary if the shapes of the
124
- * tensors are not identical and no dimension in either tensor equals 1.
125
- *
126
- * @param t0 Pointer to the first ggml_tensor.
127
- * @param t1 Pointer to the second ggml_tensor.
128
- * @return True if broadcasting is needed, False otherwise.
129
- *
130
- * @remarks This function iterates over the dimensions of t0 and t1. It checks if each
131
- * dimension in t1 differs from t0's corresponding dimension and is not equal
132
- * to 1. If such a dimension is found, broadcasting is required to align t1
133
- * with t0 for element-wise operations.
134
- */
135
- bool ggml_cann_need_bcast(const ggml_tensor* t0, const ggml_tensor* t1);
136
-
137
- /**
138
- * @brief Computes broadcast shapes and strides for two ggml_tensors.
139
- *
140
- * @details This function calculates the broadcast shapes and strides for two ggml_tensors,
141
- * following the broadcasting rules similar to numpy. It adjusts dimensions and
142
- * strides to ensure compatibility for element-wise operations where one tensor
143
- * can be broadcasted to match the shape of another tensor.
144
- *
145
- * @param src0 Pointer to the first ggml_tensor.
146
- * @param src1 Pointer to the second ggml_tensor.
147
- * @param bcast_ne_src0 Output array to store broadcasted dimensions for src0.
148
- * @param bcast_ne_src1 Output array to store broadcasted dimensions for src1.
149
- * @param bcast_nb_src0 Output array to store broadcasted strides for src0.
150
- * @param bcast_nb_src1 Output array to store broadcasted strides for src1.
151
- * @return Number of dimensions in the broadcasted shape.
152
- *
153
- * @pre ggml_can_repeat(src1, src0) must return true, indicating src1 can be broadcasted
154
- * to match src0.
155
- *
156
- * @remarks This function iterates over the dimensions of src0 and src1, calculating the
157
- * necessary broadcast dimensions and strides. If a dimension requires broadcasting
158
- * (i.e., its size in src1 is smaller than in src0), an additional dimension is
159
- * added with size calculated to match src0's dimension. This adjustment ensures
160
- * that src1 can be element-wise broadcasted to src0's shape.
161
- *
162
- * How it works:
163
- *
164
- * if dim0 has padding.
165
- * a -> (2, 2) padding = 2
166
- * a: [[1, 2, *, *]
167
- * [2, 3, *, *]]
168
- * nb = (8, 4, 2)
169
- *
170
- * if a should bcast with b -> (2, 4)
171
- * b' -> (2, 2, 2)
172
- * b : [[1, 2, 3, 4, *, *]
173
- * [5, 6, 7, 8, *, *]]
174
- * nb = (12, 6, 1)
175
- *
176
- * after bcast:
177
- * a' -> (2, 1, 2)
178
- * a': [[[1, 2], *, *]
179
- * [[2, 3], *, *]]
180
- * nb = (8, 4, 2, 1)
181
- *
182
- * b' : [[[1, 2], [3, 4], *, *]
183
- * [[5, 6], [7, 8], *, *]]
184
- * nb = (12, 6, 2, 1)
185
- * \endcode
186
- *
187
- * dim1 in a inserted dim, should add nb for dim1,
188
- * and all other nb moves to next in order.
189
- */
190
- int64_t ggml_cann_get_bcast_shape(const ggml_tensor* src0, const ggml_tensor* src1,
191
- int64_t* bcast_ne_src0, int64_t* bcast_ne_src1,
192
- size_t* bcast_nb_src0, size_t* bcast_nb_src1);
193
-
194
- // Bcast macro to avoid duplicate code.
195
- #define BCAST_SHAPE(src0, src1) \
196
- int64_t bcast_##src0##_ne[GGML_MAX_DIMS * 2]; \
197
- int64_t bcast_##src1##_ne[GGML_MAX_DIMS * 2]; \
198
- size_t bcast_##src0##_nb[GGML_MAX_DIMS * 2]; \
199
- size_t bcast_##src1##_nb[GGML_MAX_DIMS * 2]; \
200
- int64_t bcast_dims = ggml_cann_get_bcast_shape( \
201
- src0, src1, bcast_##src0##_ne, bcast_##src1##_ne, bcast_##src0##_nb, \
202
- bcast_##src1##_nb);
203
-
204
- #define BCAST_PARAM(tensor) bcast_##tensor##_ne, bcast_##tensor##_nb, bcast_dims
205
-
206
- /**
207
- * @brief Calculates broadcast shapes for matrix multiplication.
208
- *
209
- * @details This function computes the broadcast shapes required for matrix multiplication
210
- * based on the input, weight, and destination tensor shapes. It ensures that the
211
- * dimensions of weight tensors are expanded appropriately to satisfy matrix
212
- * multiplication broadcast rules.
213
- *
214
- * @param input_ne Array containing the dimensions of the input tensor.
215
- * @param weight_ne Array containing the dimensions of the weight tensor.
216
- * @param dst_ne Array containing the dimensions of the destination tensor.
217
- * @param input_nb Array containing the strides of the input tensor.
218
- * @param weight_nb Array containing the strides of the weight tensor.
219
- * @param dst_nb Array containing the strides of the destination tensor.
220
- * @param bcast_input_ne Output array for broadcasted input tensor dimensions.
221
- * @param bcast_weight_ne Output array for broadcasted weight tensor dimensions.
222
- * @param bcast_dst_ne Output array for broadcasted destination tensor dimensions.
223
- * @param bcast_input_nb Output array for broadcasted input tensor strides.
224
- * @param bcast_weight_nb Output array for broadcasted weight tensor strides.
225
- * @param bcast_dst_nb Output array for broadcasted destination tensor strides.
226
- * @return The number of dimensions in the broadcasted tensors.
227
- *
228
- * @remarks This function iterates over the tensor dimensions and calculates the broadcast
229
- * shapes needed for matrix multiplication. It ensures that dimensions where
230
- * weight tensor requires expansion are appropriately handled to conform with
231
- * broadcasting rules.
232
- * @note compare with ggml_cann_get_bcast_shape, mul_mat broadcast need add this new dim
233
- * before cast dim.
234
- * @sa ggml_cann_get_bcast_shape
235
- */
236
- int64_t ggml_cann_get_mulmat_bcast_shape(
237
- const int64_t* input_ne, const int64_t* weight_ne, const int64_t* dst_ne,
238
- const size_t* input_nb, const size_t* weight_nb, const size_t* dst_nb,
239
- int64_t* bcast_input_ne, int64_t* bcast_weight_ne, int64_t* bcast_dst_ne,
240
- size_t* bcast_input_nb, size_t* bcast_weight_nb, size_t* bcast_dst_nb);
241
-
242
- // Bcast macro to avoid duplicate code.
243
- #define BCAST_MUL_MAT_SHAPE(input, weight, dst) \
244
- int64_t bcast_##input##_ne[GGML_MAX_DIMS * 2]; \
245
- int64_t bcast_##weight##_ne[GGML_MAX_DIMS * 2]; \
246
- int64_t bcast_##dst##_ne[GGML_MAX_DIMS * 2]; \
247
- size_t bcast_##input##_nb[GGML_MAX_DIMS * 2]; \
248
- size_t bcast_##weight##_nb[GGML_MAX_DIMS * 2]; \
249
- size_t bcast_##dst##_nb[GGML_MAX_DIMS * 2]; \
250
- int64_t bcast_dims = ggml_cann_get_mulmat_bcast_shape( \
251
- input->ne, weight->ne, dst->ne, input->nb, weight->nb, dst->nb, \
252
- bcast_##input##_ne, bcast_##weight##_ne, bcast_##dst##_ne, \
253
- bcast_##input##_nb, bcast_##weight##_nb, bcast_##dst##_nb);
254
-
255
- #define BCAST_MUL_MAT_PARAM(tensor) \
256
- bcast_##tensor##_ne, bcast_##tensor##_nb, bcast_dims
257
-
258
- #endif // CANN_ACL_TENSOR_H