@fugood/llama.node 0.6.3 → 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 (377) 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 -7
  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/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
  27. package/src/llama.cpp/.github/workflows/build.yml +0 -1078
  28. package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
  29. package/src/llama.cpp/.github/workflows/docker.yml +0 -178
  30. package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
  31. package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
  32. package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
  33. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
  34. package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
  35. package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
  36. package/src/llama.cpp/.github/workflows/release.yml +0 -739
  37. package/src/llama.cpp/.github/workflows/server.yml +0 -237
  38. package/src/llama.cpp/.github/workflows/winget.yml +0 -42
  39. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
  40. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
  41. package/src/llama.cpp/cmake/build-info.cmake +0 -64
  42. package/src/llama.cpp/cmake/common.cmake +0 -35
  43. package/src/llama.cpp/cmake/git-vars.cmake +0 -22
  44. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
  45. package/src/llama.cpp/common/build-info.cpp.in +0 -4
  46. package/src/llama.cpp/docs/build.md +0 -561
  47. package/src/llama.cpp/examples/CMakeLists.txt +0 -43
  48. package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
  49. package/src/llama.cpp/examples/batched/batched.cpp +0 -246
  50. package/src/llama.cpp/examples/chat-13B.bat +0 -57
  51. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
  52. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
  53. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
  54. package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
  55. package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
  56. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
  57. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
  58. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
  59. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
  60. package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
  61. package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
  62. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
  63. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
  64. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
  65. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
  66. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
  67. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
  68. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
  69. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
  70. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
  71. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
  72. package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
  73. package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
  74. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
  75. package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
  76. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
  77. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
  78. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
  79. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
  80. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
  81. package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
  82. package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
  83. package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
  84. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
  85. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
  86. package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
  87. package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
  88. package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
  89. package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
  90. package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
  91. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
  92. package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
  93. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
  94. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
  95. package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
  96. package/src/llama.cpp/examples/simple/simple.cpp +0 -206
  97. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
  98. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
  99. package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
  100. package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
  101. package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
  102. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
  103. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
  104. package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
  105. package/src/llama.cpp/examples/sycl/build.sh +0 -23
  106. package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
  107. package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
  108. package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
  109. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
  110. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
  111. package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
  112. package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
  113. package/src/llama.cpp/examples/training/finetune.cpp +0 -96
  114. package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
  115. package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
  116. package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
  117. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
  118. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
  119. package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
  120. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
  121. package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
  122. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
  123. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
  124. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
  125. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
  126. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
  127. package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
  128. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
  129. package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
  130. package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
  131. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
  132. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
  133. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
  134. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
  135. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
  136. package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
  137. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  138. package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  139. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
  140. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
  141. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
  142. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
  143. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
  144. package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
  145. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
  146. package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
  147. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
  148. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
  149. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
  150. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
  151. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
  152. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
  153. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
  154. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
  155. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
  156. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
  157. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
  158. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
  159. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
  160. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
  161. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
  162. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
  163. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
  164. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
  165. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
  166. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
  167. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
  168. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
  169. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
  170. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
  171. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
  172. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
  173. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
  174. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
  175. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
  176. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
  177. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
  178. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
  179. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
  180. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
  181. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
  182. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
  183. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
  184. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
  185. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
  186. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
  187. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
  188. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
  189. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
  190. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
  191. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
  192. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
  193. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
  194. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
  195. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
  196. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
  197. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
  198. package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
  199. package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
  200. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
  201. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
  202. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
  203. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
  204. package/src/llama.cpp/ggml/src/ggml.c +0 -6550
  205. package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
  206. package/src/llama.cpp/models/.editorconfig +0 -1
  207. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  208. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  209. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  210. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
  211. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
  212. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
  213. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
  214. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  215. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
  216. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
  217. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  218. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
  219. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
  220. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  221. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
  222. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
  223. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
  225. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  226. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
  227. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
  228. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  229. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
  230. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
  231. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
  232. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
  233. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  234. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
  236. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
  237. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  238. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
  239. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
  240. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
  241. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
  242. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
  245. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  246. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
  248. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
  249. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
  250. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
  253. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
  256. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
  257. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
  258. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  259. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
  260. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
  261. package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
  262. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
  263. package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
  264. package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
  265. package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
  266. package/src/llama.cpp/prompts/alpaca.txt +0 -1
  267. package/src/llama.cpp/prompts/assistant.txt +0 -31
  268. package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
  269. package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
  270. package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
  271. package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
  272. package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
  273. package/src/llama.cpp/prompts/chat.txt +0 -28
  274. package/src/llama.cpp/prompts/dan-modified.txt +0 -1
  275. package/src/llama.cpp/prompts/dan.txt +0 -1
  276. package/src/llama.cpp/prompts/mnemonics.txt +0 -93
  277. package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
  278. package/src/llama.cpp/prompts/reason-act.txt +0 -18
  279. package/src/llama.cpp/requirements/requirements-all.txt +0 -15
  280. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
  281. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
  282. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
  283. package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
  284. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
  285. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
  286. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
  287. package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
  288. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
  289. package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
  290. package/src/llama.cpp/requirements.txt +0 -13
  291. package/src/llama.cpp/scripts/build-info.sh +0 -30
  292. package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
  293. package/src/llama.cpp/scripts/xxd.cmake +0 -16
  294. package/src/llama.cpp/tests/CMakeLists.txt +0 -177
  295. package/src/llama.cpp/tests/get-model.cpp +0 -21
  296. package/src/llama.cpp/tests/get-model.h +0 -2
  297. package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
  298. package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
  299. package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
  300. package/src/llama.cpp/tests/test-barrier.cpp +0 -94
  301. package/src/llama.cpp/tests/test-c.c +0 -7
  302. package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
  303. package/src/llama.cpp/tests/test-chat.cpp +0 -985
  304. package/src/llama.cpp/tests/test-double-float.cpp +0 -57
  305. package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
  306. package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
  307. package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
  308. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
  309. package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
  310. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
  311. package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
  312. package/src/llama.cpp/tests/test-log.cpp +0 -39
  313. package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
  314. package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
  315. package/src/llama.cpp/tests/test-opt.cpp +0 -904
  316. package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
  317. package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
  318. package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
  319. package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
  320. package/src/llama.cpp/tests/test-rope.cpp +0 -262
  321. package/src/llama.cpp/tests/test-sampling.cpp +0 -399
  322. package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
  323. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
  324. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
  325. package/src/llama.cpp/tools/CMakeLists.txt +0 -39
  326. package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
  327. package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
  328. package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
  329. package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
  330. package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
  331. package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
  332. package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
  333. package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
  334. package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
  335. package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
  336. package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
  337. package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
  338. package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
  339. package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
  340. package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
  341. package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
  342. package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
  343. package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
  344. package/src/llama.cpp/tools/main/main.cpp +0 -977
  345. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
  346. package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
  347. package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
  348. package/src/llama.cpp/tools/mtmd/clip.h +0 -101
  349. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
  350. package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
  351. package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
  352. package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
  353. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
  354. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
  355. package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
  356. package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
  357. package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
  358. package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
  359. package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
  360. package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
  361. package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
  362. package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
  363. package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
  364. package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
  365. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
  366. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
  367. package/src/llama.cpp/tools/run/run.cpp +0 -1261
  368. package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
  369. package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
  370. package/src/llama.cpp/tools/server/httplib.h +0 -10506
  371. package/src/llama.cpp/tools/server/server.cpp +0 -4966
  372. package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
  373. package/src/llama.cpp/tools/server/utils.hpp +0 -1337
  374. package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
  375. package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
  376. package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
  377. package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
@@ -1,58 +0,0 @@
1
- # mtmd
2
-
3
- # compile mtmd-audio separately to avoid long compile times with miniaudio.h
4
- # TODO @ngxson : move miniaudio.h and stb_image.h to mtmd-helper.cpp, then compile the helper as a separate library
5
- add_library(mtmd_audio STATIC mtmd-audio.cpp mtmd-audio.h)
6
- if (BUILD_SHARED_LIBS)
7
- set_target_properties(mtmd_audio PROPERTIES POSITION_INDEPENDENT_CODE ON)
8
- endif()
9
- target_link_libraries(mtmd_audio PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
10
- target_compile_features(mtmd_audio PRIVATE cxx_std_17)
11
- target_include_directories(mtmd_audio PRIVATE .)
12
-
13
- add_library(mtmd OBJECT
14
- mtmd.cpp
15
- mtmd-helper.cpp
16
- mtmd.h
17
- clip.cpp
18
- clip.h
19
- clip-impl.h
20
- )
21
-
22
- target_link_libraries(mtmd PRIVATE ggml llama mtmd_audio ${CMAKE_THREAD_LIBS_INIT})
23
-
24
- target_include_directories(mtmd PUBLIC .)
25
- target_include_directories(mtmd PRIVATE ../..)
26
- target_include_directories(mtmd PRIVATE ../../common) # for stb_image.h
27
-
28
- target_compile_features(mtmd PRIVATE cxx_std_17)
29
-
30
- add_library(mtmd_static STATIC $<TARGET_OBJECTS:mtmd>)
31
- if (BUILD_SHARED_LIBS)
32
- set_target_properties(mtmd PROPERTIES POSITION_INDEPENDENT_CODE ON)
33
- target_compile_definitions(mtmd PRIVATE LLAMA_SHARED LLAMA_BUILD)
34
- add_library(mtmd_shared SHARED $<TARGET_OBJECTS:mtmd>)
35
- target_link_libraries(mtmd_shared PRIVATE ggml llama mtmd_audio ${CMAKE_THREAD_LIBS_INIT})
36
- install(TARGETS mtmd_shared LIBRARY)
37
- endif()
38
-
39
- if (NOT MSVC)
40
- target_compile_options(mtmd PRIVATE -Wno-cast-qual) # stb_image.h
41
- target_compile_options(mtmd_audio PRIVATE -Wno-cast-qual) # miniaudio.h
42
- endif()
43
-
44
- if(TARGET BUILD_INFO)
45
- add_dependencies(mtmd BUILD_INFO)
46
- endif()
47
-
48
- add_executable(llama-llava-cli deprecation-warning.cpp)
49
- add_executable(llama-gemma3-cli deprecation-warning.cpp)
50
- add_executable(llama-minicpmv-cli deprecation-warning.cpp)
51
- add_executable(llama-qwen2vl-cli deprecation-warning.cpp)
52
-
53
- set(TARGET llama-mtmd-cli)
54
- add_executable(${TARGET} mtmd-cli.cpp)
55
- set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-mtmd-cli)
56
- install(TARGETS ${TARGET} RUNTIME)
57
- target_link_libraries(${TARGET} PRIVATE common mtmd ${CMAKE_THREAD_LIBS_INIT})
58
- target_compile_features(${TARGET} PRIVATE cxx_std_17)
@@ -1,462 +0,0 @@
1
- #include "ggml.h"
2
- #include "gguf.h"
3
- #include "clip.h"
4
-
5
- #include <climits>
6
- #include <cstdarg>
7
- #include <cinttypes>
8
- #include <string>
9
- #include <map>
10
- #include <sstream>
11
- #include <vector>
12
- #include <memory>
13
-
14
- // Internal header for clip.cpp
15
-
16
- #define KEY_FTYPE "general.file_type"
17
- #define KEY_NAME "general.name"
18
- #define KEY_DESCRIPTION "general.description"
19
- #define KEY_PROJ_TYPE "clip.projector_type"
20
- #define KEY_HAS_AUDIO_ENC "clip.has_audio_encoder"
21
- #define KEY_HAS_VISION_ENC "clip.has_vision_encoder"
22
- #define KEY_USE_GELU "clip.use_gelu"
23
- #define KEY_USE_SILU "clip.use_silu"
24
-
25
- #define KEY_N_EMBD "clip.%s.embedding_length"
26
- #define KEY_N_FF "clip.%s.feed_forward_length"
27
- #define KEY_N_BLOCK "clip.%s.block_count"
28
- #define KEY_PROJ_DIM "clip.%s.projection_dim"
29
- #define KEY_N_HEAD "clip.%s.attention.head_count"
30
- #define KEY_LAYER_NORM_EPS "clip.%s.attention.layer_norm_epsilon"
31
-
32
- // vision-specific
33
- #define KEY_IMAGE_SIZE "clip.vision.image_size"
34
- #define KEY_PATCH_SIZE "clip.vision.patch_size"
35
- #define KEY_IMAGE_MEAN "clip.vision.image_mean"
36
- #define KEY_IMAGE_STD "clip.vision.image_std"
37
- #define KEY_FEATURE_LAYER "clip.vision.feature_layer"
38
- #define KEY_PROJ_SCALE_FACTOR "clip.vision.projector.scale_factor"
39
- #define KEY_SPATIAL_MERGE_SIZE "clip.vision.spatial_merge_size"
40
-
41
- #define KEY_MM_PATCH_MERGE_TYPE "clip.vision.mm_patch_merge_type"
42
- #define KEY_IMAGE_GRID_PINPOINTS "clip.vision.image_grid_pinpoints"
43
- #define KEY_IMAGE_CROP_RESOLUTION "clip.vision.image_crop_resolution"
44
- #define KEY_WIN_ATTN_PATTERN "clip.vision.n_wa_pattern"
45
- #define KEY_ATTN_WINDOW_SIZE "clip.vision.window_size"
46
- #define KEY_MINICPMV_VERSION "clip.minicpmv_version"
47
-
48
- // audio-specific
49
- #define KEY_A_NUM_MEL_BINS "clip.audio.num_mel_bins"
50
- #define KEY_A_PROJ_STACK_FACTOR "clip.audio.projector.stack_factor"
51
-
52
-
53
- //
54
- // tensor name constants
55
- //
56
-
57
- #define TN_POS_EMBD "%s.position_embd.weight"
58
- #define TN_CLASS_EMBD "v.class_embd"
59
- #define TN_PATCH_EMBD "v.patch_embd.weight" // not rename tensor with ".0" postfix for backwrad compat
60
- #define TN_PATCH_EMBD_1 "v.patch_embd.weight.1"
61
- #define TN_PATCH_BIAS "v.patch_embd.bias"
62
- #define TN_ATTN_K "%s.blk.%d.attn_k.%s"
63
- #define TN_ATTN_Q "%s.blk.%d.attn_q.%s"
64
- #define TN_ATTN_V "%s.blk.%d.attn_v.%s"
65
- #define TN_ATTN_OUTPUT "%s.blk.%d.attn_out.%s"
66
- #define TN_ATTN_K_NORM "%s.blk.%d.attn_k_norm.%s"
67
- #define TN_ATTN_Q_NORM "%s.blk.%d.attn_q_norm.%s"
68
- #define TN_FFN_DOWN "%s.blk.%d.ffn_down.%s"
69
- #define TN_FFN_GATE "%s.blk.%d.ffn_gate.%s"
70
- #define TN_FFN_UP "%s.blk.%d.ffn_up.%s"
71
- #define TN_FFN_GATE "%s.blk.%d.ffn_gate.%s"
72
- #define TN_LN_1 "%s.blk.%d.ln1.%s" // layer norm
73
- #define TN_LN_2 "%s.blk.%d.ln2.%s" // layer norm
74
- #define TN_LS_1 "%s.blk.%d.ls1.%s" // layer scale
75
- #define TN_LS_2 "%s.blk.%d.ls2.%s" // layer scale
76
- #define TN_LN_PRE "%s.pre_ln.%s"
77
- #define TN_LN_POST "%s.post_ln.%s"
78
- #define TN_LLAVA_PROJ "mm.%d.%s"
79
- #define TN_MVLM_PROJ_MLP "mm.model.mlp.%d.%s"
80
- #define TN_MVLM_PROJ_BLOCK "mm.model.mb_block.%d.block.%d.%s"
81
- #define TN_MVLM_PROJ_PEG "mm.model.peg.%d.%s"
82
- #define TN_IMAGE_NEWLINE "model.image_newline"
83
- #define TN_MM_INP_NORM "mm.input_norm.weight"
84
- #define TN_MM_INP_PROJ "mm.input_projection.weight" // gemma3
85
- #define TN_MM_SOFT_EMB_N "mm.soft_emb_norm.weight" // gemma3
86
- #define TN_MM_PROJECTOR "mm.model.fc.weight" // idefics3
87
- #define TN_MM_PATCH_MERGER "mm.patch_merger.weight" // mistral small 3.1
88
- #define TN_TOK_IMG_BREAK "v.token_embd.img_break" // pixtral
89
- #define TN_TOK_GLM_BOI "adapter.boi" // glm-edge (these embeddings are not in text model)
90
- #define TN_TOK_GLM_EOI "adapter.eoi" // glm-edge (these embeddings are not in text model)
91
-
92
- // mimicpmv
93
- #define TN_MINICPMV_POS_EMBD_K "resampler.pos_embed_k"
94
- #define TN_MINICPMV_QUERY "resampler.query"
95
- #define TN_MINICPMV_PROJ "resampler.proj.weight"
96
- #define TN_MINICPMV_KV_PROJ "resampler.kv.weight"
97
- #define TN_MINICPMV_ATTN "resampler.attn.%s.%s"
98
- #define TN_MINICPMV_LN "resampler.ln_%s.%s"
99
-
100
- #define TN_GLM_ADAPER_CONV "adapter.conv.%s"
101
- #define TN_GLM_ADAPTER_LINEAR "adapter.linear.linear.%s"
102
- #define TN_GLM_ADAPTER_NORM_1 "adapter.linear.norm1.%s"
103
- #define TN_GLM_ADAPTER_D_H_2_4H "adapter.linear.dense_h_to_4h.%s"
104
- #define TN_GLM_ADAPTER_GATE "adapter.linear.gate.%s"
105
- #define TN_GLM_ADAPTER_D_4H_2_H "adapter.linear.dense_4h_to_h.%s"
106
-
107
- // ultravox
108
- #define TN_CONV1D "a.conv1d.%d.%s"
109
- #define TN_MM_AUDIO_MLP "mm.a.mlp.%d.%s"
110
- #define TN_MM_NORM_PRE "mm.a.norm_pre.%s"
111
- #define TN_MM_NORM_MID "mm.a.norm_mid.%s"
112
-
113
- // align x to upper multiple of n
114
- #define CLIP_ALIGN(x, n) ((((x) + (n) - 1) / (n)) * (n))
115
-
116
- enum projector_type {
117
- PROJECTOR_TYPE_MLP,
118
- PROJECTOR_TYPE_MLP_NORM,
119
- PROJECTOR_TYPE_LDP,
120
- PROJECTOR_TYPE_LDPV2,
121
- PROJECTOR_TYPE_MINICPMV,
122
- PROJECTOR_TYPE_GLM_EDGE,
123
- PROJECTOR_TYPE_QWEN2VL,
124
- PROJECTOR_TYPE_GEMMA3,
125
- PROJECTOR_TYPE_IDEFICS3,
126
- PROJECTOR_TYPE_PIXTRAL,
127
- PROJECTOR_TYPE_QWEN25VL,
128
- PROJECTOR_TYPE_ULTRAVOX,
129
- PROJECTOR_TYPE_INTERNVL,
130
- PROJECTOR_TYPE_LLAMA4,
131
- PROJECTOR_TYPE_UNKNOWN,
132
- };
133
-
134
- static std::map<projector_type, std::string> PROJECTOR_TYPE_NAMES = {
135
- { PROJECTOR_TYPE_MLP, "mlp" },
136
- { PROJECTOR_TYPE_LDP, "ldp" },
137
- { PROJECTOR_TYPE_LDPV2, "ldpv2"},
138
- { PROJECTOR_TYPE_MINICPMV, "resampler"},
139
- { PROJECTOR_TYPE_GLM_EDGE, "adapter"},
140
- { PROJECTOR_TYPE_QWEN2VL, "qwen2vl_merger"},
141
- { PROJECTOR_TYPE_QWEN25VL, "qwen2.5vl_merger"},
142
- { PROJECTOR_TYPE_GEMMA3, "gemma3"},
143
- { PROJECTOR_TYPE_IDEFICS3, "idefics3"},
144
- { PROJECTOR_TYPE_PIXTRAL, "pixtral"},
145
- { PROJECTOR_TYPE_ULTRAVOX, "ultravox"},
146
- { PROJECTOR_TYPE_INTERNVL, "internvl"},
147
- { PROJECTOR_TYPE_LLAMA4, "llama4"},
148
- };
149
-
150
- static projector_type clip_projector_type_from_string(const std::string & str) {
151
- for (const auto & pair : PROJECTOR_TYPE_NAMES) {
152
- if (pair.second == str) {
153
- return pair.first;
154
- }
155
- }
156
- return PROJECTOR_TYPE_UNKNOWN;
157
- }
158
-
159
- // RGB uint8 image
160
- struct clip_image_u8 {
161
- int nx;
162
- int ny;
163
-
164
- std::vector<uint8_t> buf;
165
- };
166
-
167
- // For images, buf.size() == nx*ny*3
168
- // Memory layout: RGBRGBRGB...
169
- // For audio, only one channel is used, buf.size() == nx*ny
170
- // nx will be n_frames and ny will be n_mel
171
- struct clip_image_f32 {
172
- int nx;
173
- int ny;
174
-
175
- std::vector<float> buf;
176
- };
177
-
178
- //
179
- // logging
180
- //
181
-
182
- static void clip_log_callback_default(enum ggml_log_level level, const char * text, void * user_data) {
183
- (void) level;
184
- (void) user_data;
185
- fputs(text, stderr);
186
- fflush(stderr);
187
- }
188
-
189
- struct clip_logger_state {
190
- ggml_log_level verbosity_thold;
191
- ggml_log_callback log_callback;
192
- void * log_callback_user_data;
193
- };
194
-
195
- extern struct clip_logger_state g_logger_state;
196
-
197
- static void clip_log_internal_v(enum ggml_log_level level, const char * format, va_list args) {
198
- if (format == NULL) {
199
- return;
200
- }
201
- va_list args_copy;
202
- va_copy(args_copy, args);
203
- char buffer[128];
204
- int len = vsnprintf(buffer, 128, format, args);
205
- if (len < 128) {
206
- g_logger_state.log_callback(level, buffer, g_logger_state.log_callback_user_data);
207
- } else {
208
- char * buffer2 = (char *) calloc(len + 1, sizeof(char));
209
- vsnprintf(buffer2, len + 1, format, args_copy);
210
- buffer2[len] = 0;
211
- g_logger_state.log_callback(level, buffer2, g_logger_state.log_callback_user_data);
212
- free(buffer2);
213
- }
214
- va_end(args_copy);
215
- }
216
-
217
- static void clip_log_internal(enum ggml_log_level level, const char * format, ...) {
218
- va_list args;
219
- va_start(args, format);
220
- clip_log_internal_v(level, format, args);
221
- va_end(args);
222
- }
223
-
224
- #define LOG_TMPL(level, ...) \
225
- do { \
226
- if ((level) >= g_logger_state.verbosity_thold) { \
227
- clip_log_internal((level), __VA_ARGS__); \
228
- } \
229
- } while (0)
230
- #define LOG_INF(...) LOG_TMPL(GGML_LOG_LEVEL_INFO, __VA_ARGS__)
231
- #define LOG_WRN(...) LOG_TMPL(GGML_LOG_LEVEL_WARN, __VA_ARGS__)
232
- #define LOG_ERR(...) LOG_TMPL(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
233
- #define LOG_DBG(...) LOG_TMPL(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
234
- #define LOG_CNT(...) LOG_TMPL(GGML_LOG_LEVEL_CONT, __VA_ARGS__)
235
-
236
- //
237
- // cpp wrappers
238
- //
239
-
240
- // wrapper for clip_image_size
241
- struct clip_image_size_deleter {
242
- void operator()(clip_image_size * val) { clip_image_size_free(val); }
243
- };
244
- typedef std::unique_ptr<clip_image_size, clip_image_size_deleter> clip_image_size_ptr;
245
-
246
- // wrapper for clip_image_u8
247
- struct clip_image_u8_deleter {
248
- void operator()(clip_image_u8 * val) { clip_image_u8_free(val); }
249
- };
250
- typedef std::unique_ptr<clip_image_u8, clip_image_u8_deleter> clip_image_u8_ptr;
251
-
252
- // wrapper for clip_image_f32
253
- struct clip_image_f32_deleter {
254
- void operator()(clip_image_f32 * val) { clip_image_f32_free(val); }
255
- };
256
- typedef std::unique_ptr<clip_image_f32, clip_image_f32_deleter> clip_image_f32_ptr;
257
-
258
- struct clip_image_u8_batch {
259
- std::vector<clip_image_u8_ptr> entries;
260
- };
261
-
262
- struct clip_image_f32_batch {
263
- std::vector<clip_image_f32_ptr> entries;
264
- bool is_audio = false;
265
-
266
- // for llava-uhd style models, we need to know the grid size
267
- // note: entries.size() == grid_x * grid_y + 1 (one overview image)
268
- int grid_x = 0;
269
- int grid_y = 0;
270
-
271
- clip_image_f32_batch clone() const {
272
- clip_image_f32_batch new_batch{
273
- /* entries */ {},
274
- /* is_audio */ is_audio,
275
- /* grid_x */ grid_x,
276
- /* grid_y */ grid_y,
277
- };
278
- new_batch.entries.reserve(entries.size());
279
- for (const auto & entry : entries) {
280
- new_batch.entries.emplace_back(new clip_image_f32(*entry));
281
- }
282
- return new_batch;
283
- }
284
- };
285
-
286
- //
287
- // common utils
288
- //
289
-
290
- static std::string string_format(const char * fmt, ...) {
291
- va_list ap;
292
- va_list ap2;
293
- va_start(ap, fmt);
294
- va_copy(ap2, ap);
295
- int size = vsnprintf(NULL, 0, fmt, ap);
296
- GGML_ASSERT(size >= 0 && size < INT_MAX); // NOLINT
297
- std::vector<char> buf(size + 1);
298
- int size2 = vsnprintf(buf.data(), size + 1, fmt, ap2);
299
- GGML_ASSERT(size2 == size);
300
- va_end(ap2);
301
- va_end(ap);
302
- return std::string(buf.data(), buf.size());
303
- }
304
-
305
- static void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
306
- if (search.empty()) {
307
- return;
308
- }
309
- std::string builder;
310
- builder.reserve(s.length());
311
- size_t pos = 0;
312
- size_t last_pos = 0;
313
- while ((pos = s.find(search, last_pos)) != std::string::npos) {
314
- builder.append(s, last_pos, pos - last_pos);
315
- builder.append(replace);
316
- last_pos = pos + search.length();
317
- }
318
- builder.append(s, last_pos, std::string::npos);
319
- s = std::move(builder);
320
- }
321
-
322
- // split string by a `std::string delim` instead of `char delim`
323
- static std::vector<std::string> string_split_str(std::string s, const std::string & delimiter) {
324
- std::vector<std::string> tokens;
325
- size_t pos = 0;
326
- std::string token;
327
- while ((pos = s.find(delimiter)) != std::string::npos) {
328
- token = s.substr(0, pos);
329
- tokens.push_back(token);
330
- s.erase(0, pos + delimiter.length());
331
- }
332
- tokens.push_back(s);
333
- return tokens;
334
- }
335
-
336
- //
337
- // gguf utils
338
- //
339
-
340
- static std::string gguf_data_to_str(enum gguf_type type, const void * data, int i) {
341
- switch (type) {
342
- case GGUF_TYPE_UINT8: return std::to_string(((const uint8_t *)data)[i]);
343
- case GGUF_TYPE_INT8: return std::to_string(((const int8_t *)data)[i]);
344
- case GGUF_TYPE_UINT16: return std::to_string(((const uint16_t *)data)[i]);
345
- case GGUF_TYPE_INT16: return std::to_string(((const int16_t *)data)[i]);
346
- case GGUF_TYPE_UINT32: return std::to_string(((const uint32_t *)data)[i]);
347
- case GGUF_TYPE_INT32: return std::to_string(((const int32_t *)data)[i]);
348
- case GGUF_TYPE_UINT64: return std::to_string(((const uint64_t *)data)[i]);
349
- case GGUF_TYPE_INT64: return std::to_string(((const int64_t *)data)[i]);
350
- case GGUF_TYPE_FLOAT32: return std::to_string(((const float *)data)[i]);
351
- case GGUF_TYPE_FLOAT64: return std::to_string(((const double *)data)[i]);
352
- case GGUF_TYPE_BOOL: return ((const bool *)data)[i] ? "true" : "false";
353
- default: return string_format("unknown type %d", type);
354
- }
355
- }
356
-
357
- static std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i) {
358
- const enum gguf_type type = gguf_get_kv_type(ctx_gguf, i);
359
-
360
- switch (type) {
361
- case GGUF_TYPE_STRING:
362
- return gguf_get_val_str(ctx_gguf, i);
363
- case GGUF_TYPE_ARRAY:
364
- {
365
- const enum gguf_type arr_type = gguf_get_arr_type(ctx_gguf, i);
366
- int arr_n = gguf_get_arr_n(ctx_gguf, i);
367
- const void * data = arr_type == GGUF_TYPE_STRING ? nullptr : gguf_get_arr_data(ctx_gguf, i);
368
- std::stringstream ss;
369
- ss << "[";
370
- for (int j = 0; j < arr_n; j++) {
371
- if (arr_type == GGUF_TYPE_STRING) {
372
- std::string val = gguf_get_arr_str(ctx_gguf, i, j);
373
- // escape quotes
374
- string_replace_all(val, "\\", "\\\\");
375
- string_replace_all(val, "\"", "\\\"");
376
- ss << '"' << val << '"';
377
- } else if (arr_type == GGUF_TYPE_ARRAY) {
378
- ss << "???";
379
- } else {
380
- ss << gguf_data_to_str(arr_type, data, j);
381
- }
382
- if (j < arr_n - 1) {
383
- ss << ", ";
384
- }
385
- }
386
- ss << "]";
387
- return ss.str();
388
- }
389
- default:
390
- return gguf_data_to_str(type, gguf_get_val_data(ctx_gguf, i), 0);
391
- }
392
- }
393
-
394
- //
395
- // debugging
396
- //
397
-
398
- static void print_tensor_shape(ggml_tensor * t) {
399
- printf("%s.shape = [", t->name);
400
- for (int i = 0; i < ggml_n_dims(t); ++i) {
401
- printf("%" PRId64, t->ne[i]);
402
- if (i < ggml_n_dims(t) - 1) {
403
- printf(", ");
404
- }
405
- }
406
- printf("]\n");
407
- }
408
-
409
- static void print_tensor_data(ggml_tensor * t, uint8_t * data, int64_t n) {
410
- ggml_type type = t->type;
411
- int64_t * ne = t->ne;
412
- size_t * nb = t->nb;
413
- for (int64_t i3 = 0; i3 < ne[3]; i3++) {
414
- printf("%s.data: [\n", t->name);
415
- for (int64_t i2 = 0; i2 < ne[2]; i2++) {
416
- if (i2 == n && ne[2] > 2*n) {
417
- printf(" ..., \n");
418
- i2 = ne[2] - n;
419
- }
420
- printf(" [\n");
421
- for (int64_t i1 = 0; i1 < ne[1]; i1++) {
422
- if (i1 == n && ne[1] > 2*n) {
423
- printf(" ..., \n");
424
- i1 = ne[1] - n;
425
- }
426
- printf(" [");
427
- for (int64_t i0 = 0; i0 < ne[0]; i0++) {
428
- if (i0 == n && ne[0] > 2*n) {
429
- printf("..., ");
430
- i0 = ne[0] - n;
431
- }
432
- size_t i = i3 * nb[3] + i2 * nb[2] + i1 * nb[1] + i0 * nb[0];
433
- float v;
434
- if (type == GGML_TYPE_F16) {
435
- v = ggml_fp16_to_fp32(*(ggml_fp16_t *) &data[i]);
436
- } else if (type == GGML_TYPE_F32) {
437
- v = *(float *) &data[i];
438
- } else if (type == GGML_TYPE_I32) {
439
- v = (float) *(int32_t *) &data[i];
440
- } else if (type == GGML_TYPE_I16) {
441
- v = (float) *(int16_t *) &data[i];
442
- } else if (type == GGML_TYPE_I8) {
443
- v = (float) *(int8_t *) &data[i];
444
- } else {
445
- GGML_ABORT("fatal error");
446
- }
447
- printf("%8.4f", v);
448
- if (i0 < ne[0] - 1) printf(", ");
449
- }
450
- printf("],\n");
451
- }
452
- printf(" ],\n");
453
- }
454
- printf(" ]\n");
455
- }
456
- }
457
-
458
- //
459
- // API used internally with mtmd
460
- //
461
-
462
- projector_type clip_get_projector_type(const struct clip_ctx * ctx);