@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,694 +0,0 @@
1
- #include "ggml.h"
2
- #include "gguf.h"
3
-
4
- #include <cstdlib> /* abort() */
5
- #include <cstddef>
6
- #include <cstdio>
7
- #include <string>
8
- #include <stdexcept>
9
- #include <algorithm>
10
- #include <cstring>
11
-
12
- #include <sstream>
13
- #include <fstream>
14
-
15
- #ifdef __cplusplus
16
- extern "C" {
17
- #endif
18
-
19
- #include "xxhash/xxhash.h"
20
- #include "sha1/sha1.h"
21
- #include "sha256/sha256.h"
22
-
23
- #ifdef __cplusplus
24
- }
25
- #endif
26
-
27
-
28
- // uuid.uuid5(uuid.NAMESPACE_URL, 'en.wikipedia.org/wiki/Llama.cpp')
29
- #define UUID_NAMESPACE_LLAMA_CPP "ef001206-dadc-5f6d-a15f-3359e577d4e5"
30
- #define UUID_NAMESPACE_LLAMA_CPP_HEX 0xef, 0x00, 0x12, 0x06, 0xda, 0xdc, 0x5f, 0x6d, 0xa1, 0x5f, 0x33, 0x59, 0xe5, 0x77, 0xd4, 0xe5
31
-
32
-
33
- #define HASH_TYPE_SHA256_STR "sha256"
34
- #define HASH_TYPE_SHA1_STR "sha1"
35
- #define HASH_TYPE_XXH64_STR "xxh64"
36
- #define HASH_TYPE_UUID_STR "uuid"
37
-
38
-
39
- typedef enum {
40
- HASH_EXIT_SUCCESS = 0, // All hash has been generated or validated
41
- HASH_EXIT_FAILURE = 1, // Generic Failure
42
- HASH_EXIT_MISMATCH = 2, // Hash mismatched during validation
43
- HASH_EXIT_MANIFEST_MISSING_ENTRY = 3, // Hash attempted validation but missing entry in manifest
44
- HASH_EXIT_MANIFEST_UNKNOWN_HASH = 4, // Manifest is present, but we do not know any hash format within it
45
- HASH_EXIT_MANIFEST_FILE_ERROR = 5 // Manifest is either missing or not a known format
46
- } hash_exit_code_t;
47
-
48
-
49
- typedef enum {
50
- HASH_MANIFEST_NOT_FOUND,
51
- HASH_MANIFEST_MISMATCH,
52
- HASH_MANIFEST_OK,
53
- } hash_manifest_result_t;
54
-
55
-
56
- struct hash_params {
57
- std::string input;
58
- bool xxh64 = false;
59
- bool sha1 = false;
60
- bool sha256 = false;
61
- bool uuid = false;
62
-
63
- bool no_layer = false;
64
-
65
- bool manifest_is_usable = false;
66
- std::string manifest_file;
67
- };
68
-
69
- struct manifest_check_params {
70
- bool xxh64 = false;
71
- bool sha1 = false;
72
- bool sha256 = false;
73
- bool uuid = false;
74
- };
75
-
76
- static char const * hash_manifest_result_to_str(hash_manifest_result_t value) {
77
- switch (value) {
78
- case HASH_MANIFEST_NOT_FOUND: return "Not Found";
79
- case HASH_MANIFEST_MISMATCH: return "Mismatch";
80
- case HASH_MANIFEST_OK: return "Ok";
81
- }
82
- return "?";
83
- }
84
-
85
- static char const * hash_exit_code_to_str(hash_exit_code_t value) {
86
- switch (value) {
87
- case HASH_EXIT_SUCCESS: return "Success";
88
- case HASH_EXIT_FAILURE: return "Failure";
89
- case HASH_EXIT_MISMATCH: return "Mismatch";
90
- case HASH_EXIT_MANIFEST_MISSING_ENTRY: return "Manifest Missing Entry";
91
- case HASH_EXIT_MANIFEST_UNKNOWN_HASH: return "Manifest Unknown Hash";
92
- case HASH_EXIT_MANIFEST_FILE_ERROR: return "Manifest File Error";
93
- }
94
- return "?";
95
- }
96
-
97
- static void hash_print_usage(const char * executable) {
98
- const hash_params default_params;
99
- printf("\n");
100
- printf("usage: %s [options] GGUF_IN\n", executable);
101
- printf("\n");
102
- printf("Hash a GGUF file");
103
- printf("\n");
104
- printf("options:\n");
105
- printf(" -h, --help show this help message and exit\n");
106
- printf(" --xxh64 use xxh64 hash\n");
107
- printf(" --sha1 use sha1 hash\n");
108
- printf(" --sha256 use sha256 hash\n");
109
- printf(" --all use all hash\n");
110
- printf(" --no-layer exclude per layer hash\n");
111
- printf(" --uuid generate UUIDv5 ID\n");
112
- printf(" -c, --check <manifest> verify against a manifest\n");
113
- printf("\n");
114
- }
115
-
116
- static void hash_params_parse_ex(int argc, const char ** argv, hash_params & params) {
117
- std::string arg;
118
- bool invalid_param = false;
119
- const std::string arg_prefix = "--";
120
-
121
- int arg_idx = 1;
122
- for (; arg_idx < argc && strncmp(argv[arg_idx], "--", 2) == 0; arg_idx++) {
123
- arg = argv[arg_idx];
124
- if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
125
- std::replace(arg.begin(), arg.end(), '_', '-');
126
- }
127
-
128
- bool arg_found = false;
129
- if (arg == "-h" || arg == "--help") {
130
- hash_print_usage(argv[0]);
131
- exit(0);
132
- }
133
-
134
- if (arg == "--xxh64") {
135
- arg_found = true;
136
- params.xxh64 = true;
137
- }
138
-
139
- if (arg == "--sha1") {
140
- arg_found = true;
141
- params.sha1 = true;
142
- }
143
-
144
- if (arg == "--uuid") {
145
- arg_found = true;
146
- params.uuid = true;
147
- }
148
-
149
- if (arg == "--sha256") {
150
- arg_found = true;
151
- params.sha256 = true;
152
- }
153
-
154
- if (arg == "--all") {
155
- arg_found = true;
156
- params.sha256 = true;
157
- params.sha1 = true;
158
- params.xxh64 = true;
159
- }
160
-
161
- if (arg == "--no-layer") {
162
- arg_found = true;
163
- params.no_layer = true;
164
- }
165
-
166
- if (arg == "-c" || arg == "--check") {
167
- if (++arg_idx >= argc) {
168
- invalid_param = true;
169
- break;
170
- }
171
- arg_found = true;
172
- params.manifest_file = argv[arg_idx];
173
- }
174
-
175
- if (!arg_found) {
176
- throw std::invalid_argument("error: unknown argument: " + arg);
177
- }
178
- }
179
-
180
- if (invalid_param) {
181
- throw std::invalid_argument("error: invalid parameter for argument:" + arg);
182
- }
183
-
184
- if (argc - arg_idx < 1) {
185
- throw std::invalid_argument("error: bad arguments");
186
- }
187
-
188
- params.input = argv[arg_idx++];
189
- }
190
-
191
- static bool hash_params_parse(int argc, const char ** argv, hash_params & params) {
192
- bool result = true;
193
- try {
194
- hash_params_parse_ex(argc, argv, params);
195
- }
196
- catch (const std::invalid_argument & ex) {
197
- fprintf(stderr, "%s\n", ex.what());
198
- hash_print_usage(argv[0]);
199
- exit(EXIT_FAILURE);
200
- }
201
- return result;
202
- }
203
-
204
- static bool manifest_type(const std::string & manifest_file, manifest_check_params & manifest_check) {
205
- if (manifest_file.empty()) {
206
- return false;
207
- }
208
-
209
- std::ifstream file(manifest_file);
210
- if (!file.is_open()) {
211
- return false;
212
- }
213
-
214
- std::string manifest_entry_line;
215
- while (getline(file, manifest_entry_line)) {
216
- // hash_type_str hash_str tensor_name
217
- // e.g. 'xxh64 f66e9cd66a4396a0 test.gguf:tensor_0'
218
- std::istringstream line_stream(manifest_entry_line);
219
- std::string file_hash_type;
220
- if (line_stream >> file_hash_type) {
221
- if (file_hash_type == HASH_TYPE_SHA256_STR) {
222
- manifest_check.sha256 = true;
223
- } else if (file_hash_type == HASH_TYPE_SHA1_STR) {
224
- manifest_check.sha1 = true;
225
- } else if (file_hash_type == HASH_TYPE_XXH64_STR) {
226
- manifest_check.xxh64 = true;
227
- } else if (file_hash_type == HASH_TYPE_UUID_STR) {
228
- manifest_check.uuid = true;
229
- }
230
- }
231
- }
232
-
233
- return true;
234
- }
235
-
236
- static hash_manifest_result_t manifest_verify(const std::string& manifest_file, const std::string& hash_type_str, const std::string& hash_str, const std::string& tensor_name) {
237
- if (manifest_file.empty()) {
238
- return HASH_MANIFEST_NOT_FOUND;
239
- }
240
-
241
- std::ifstream file(manifest_file);
242
- if (!file.is_open()) {
243
- return HASH_MANIFEST_NOT_FOUND;
244
- }
245
-
246
- std::string manifest_entry_line;
247
- while (getline(file, manifest_entry_line)) {
248
- std::istringstream line_stream(manifest_entry_line);
249
- std::string file_hash_type;
250
- std::string file_hash;
251
- std::string file_tensor_name;
252
- if (line_stream >> file_hash_type >> file_hash >> file_tensor_name) {
253
- // Line parsed. Check hash validity
254
-
255
- if (file_hash_type != hash_type_str) {
256
- continue;
257
- }
258
-
259
- if (file_tensor_name != tensor_name) {
260
- continue;
261
- }
262
-
263
- return (file_hash == hash_str) ? HASH_MANIFEST_OK : HASH_MANIFEST_MISMATCH;
264
- }
265
- }
266
-
267
- return HASH_MANIFEST_NOT_FOUND;
268
- }
269
-
270
- static void generate_uuidv5(const unsigned char sha1_digest[20], unsigned char uuid[16]) {
271
- // Ref: https://www.rfc-editor.org/rfc/rfc9562.html#section-5.5
272
- // Assumes that digest was processed correctly with the expected namespace
273
- for (int i = 0; i < 16; i++) {
274
- uuid[i] = sha1_digest[i];
275
- }
276
-
277
- // Set bits corresponding to UUID ver 5
278
- uuid[ 6] &= ~(0xF << 4);
279
- uuid[ 6] |= (5 << 4);
280
-
281
- // Set bits corresponding to UUID variant 0b10XX
282
- uuid[ 8] &= ~(0xc << 4);
283
- uuid[ 8] |= (0x8 << 4);
284
- }
285
-
286
- static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
287
- const std::string & fname = hash_params.input;
288
- struct ggml_context * ctx_data = NULL;
289
-
290
- struct gguf_init_params params = {
291
- /*.no_alloc = */ false,
292
- /*.ctx = */ &ctx_data,
293
- };
294
-
295
- // xxh64 init
296
- XXH64_state_t* xxh64_model_hash_state = NULL;
297
- if (hash_params.xxh64) {
298
- xxh64_model_hash_state = XXH64_createState();
299
- if (xxh64_model_hash_state==NULL) {
300
- abort();
301
- }
302
-
303
- XXH64_hash_t const seed = 0;
304
- if (XXH64_reset(xxh64_model_hash_state, seed) == XXH_ERROR) {
305
- abort();
306
- }
307
- }
308
-
309
- // sha1 init
310
- SHA1_CTX sha1_model_hash_ctx;
311
- if (hash_params.sha1) {
312
- SHA1Init(&sha1_model_hash_ctx);
313
- }
314
-
315
- // sha256 init
316
- sha256_t sha256_model_hash_ctx;
317
- if (hash_params.sha256) {
318
- sha256_init(&sha256_model_hash_ctx);
319
- }
320
-
321
- // sha1 for uuid init
322
- SHA1_CTX sha1_for_uuid_ctx;
323
- if (hash_params.uuid) {
324
- unsigned char const uuidv5_namespace[] = {UUID_NAMESPACE_LLAMA_CPP_HEX};
325
- SHA1Init(&sha1_for_uuid_ctx);
326
- SHA1Update( &sha1_for_uuid_ctx, (unsigned char const *)uuidv5_namespace, sizeof(uuidv5_namespace));
327
- }
328
-
329
- struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
330
- const int n_tensors = gguf_get_n_tensors(ctx);
331
- bool tensor_layer_in_manifest = false;
332
- bool model_in_manifest = false;
333
- bool tensor_layer_has_mismatch = false;
334
- bool model_has_mismatch = false;
335
- for (int i = 0; i < n_tensors; ++i) {
336
- const char * name = gguf_get_tensor_name(ctx, i);
337
- struct ggml_tensor * cur = ggml_get_tensor(ctx_data, name);
338
- auto n_bytes = ggml_nbytes(cur);
339
- auto *raw_data = cur->data;
340
- const std::string tensor_layer_name = fname + ":" + name;
341
-
342
- if (hash_params.xxh64) {
343
-
344
- if (!hash_params.no_layer) {
345
- // Per Layer Hash
346
- XXH64_hash_t hash = XXH64(raw_data, n_bytes, 0);
347
-
348
- char hex_result[17];
349
- for (int offset = 0; offset < 8; offset++) {
350
- unsigned int shift_bits_by = (8 * (8 - offset - 1));
351
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff);
352
- }
353
-
354
- if (hash_params.manifest_is_usable) {
355
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_XXH64_STR, hex_result, tensor_layer_name);
356
-
357
- switch (verify_result) {
358
- case HASH_MANIFEST_NOT_FOUND:
359
- break;
360
- case HASH_MANIFEST_MISMATCH:
361
- tensor_layer_in_manifest = true;
362
- tensor_layer_has_mismatch = true;
363
- break;
364
- case HASH_MANIFEST_OK:
365
- tensor_layer_in_manifest = true;
366
- break;
367
- }
368
-
369
- printf("%-8s %-s %s - %s\n", HASH_TYPE_XXH64_STR, hex_result, tensor_layer_name.c_str(), hash_manifest_result_to_str(verify_result));
370
- } else {
371
- printf("%-8s %-s %s\n", HASH_TYPE_XXH64_STR, hex_result, tensor_layer_name.c_str());
372
- }
373
- }
374
-
375
- // Overall Model Hash
376
- if (XXH64_update(xxh64_model_hash_state, raw_data, n_bytes) == XXH_ERROR) abort();
377
- }
378
-
379
- if (hash_params.sha1) {
380
-
381
- if (!hash_params.no_layer) {
382
- // Per Layer Hash
383
- char result[21]; // sha1 outputs 20 bytes
384
- SHA1( result, (const char *)raw_data, n_bytes);
385
-
386
- char hex_result[41] = {0};
387
- for (int offset = 0; offset < 20; offset++) {
388
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff);
389
- }
390
-
391
- if (hash_params.manifest_is_usable) {
392
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_SHA1_STR, hex_result, tensor_layer_name);
393
-
394
- switch (verify_result) {
395
- case HASH_MANIFEST_NOT_FOUND:
396
- break;
397
- case HASH_MANIFEST_MISMATCH:
398
- tensor_layer_in_manifest = true;
399
- tensor_layer_has_mismatch = true;
400
- break;
401
- case HASH_MANIFEST_OK:
402
- tensor_layer_in_manifest = true;
403
- break;
404
- }
405
-
406
- printf("%-8s %-s %s - %s\n", HASH_TYPE_SHA1_STR, hex_result, tensor_layer_name.c_str(), hash_manifest_result_to_str(verify_result));
407
- } else {
408
- printf("%-8s %-s %s\n", HASH_TYPE_SHA1_STR, hex_result, tensor_layer_name.c_str());
409
- }
410
- }
411
-
412
- // Overall Model Hash
413
- SHA1Update( &sha1_model_hash_ctx, (unsigned char const *)raw_data, n_bytes);
414
- }
415
-
416
- if (hash_params.sha256) {
417
-
418
- if (!hash_params.no_layer) {
419
- // Per Layer Hash
420
- unsigned char result[SHA256_DIGEST_SIZE]; // sha256 outputs 32 bytes
421
- sha256_hash((unsigned char*) result, (const unsigned char *)raw_data, n_bytes);
422
-
423
- char hex_result[SHA256_DIGEST_SIZE * 2 + 1] = {0};
424
- for (int offset = 0; offset < SHA256_DIGEST_SIZE; offset++) {
425
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff);
426
- }
427
-
428
- if (hash_params.manifest_is_usable) {
429
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_SHA256_STR, hex_result, tensor_layer_name);
430
-
431
- switch (verify_result) {
432
- case HASH_MANIFEST_NOT_FOUND:
433
- break;
434
- case HASH_MANIFEST_MISMATCH:
435
- tensor_layer_in_manifest = true;
436
- tensor_layer_has_mismatch = true;
437
- break;
438
- case HASH_MANIFEST_OK:
439
- tensor_layer_in_manifest = true;
440
- break;
441
- }
442
-
443
- printf("%-8s %-s %s - %s\n", HASH_TYPE_SHA256_STR, hex_result, tensor_layer_name.c_str(), hash_manifest_result_to_str(verify_result));
444
- } else {
445
- printf("%-8s %-s %s\n", HASH_TYPE_SHA256_STR, hex_result, tensor_layer_name.c_str());
446
- }
447
- }
448
-
449
- // Overall Model Hash
450
- sha256_update( &sha256_model_hash_ctx, (unsigned char const *)raw_data, n_bytes);
451
- }
452
-
453
- if (hash_params.uuid) {
454
- SHA1Update( &sha1_for_uuid_ctx, (unsigned char const *)raw_data, n_bytes);
455
- }
456
- }
457
-
458
- if (hash_params.xxh64) {
459
- XXH64_hash_t const hash = XXH64_digest(xxh64_model_hash_state);
460
-
461
- char hex_result[17];
462
- for (int offset = 0; offset < 8; offset++) {
463
- unsigned int shift_bits_by = (8 * (8 - offset - 1));
464
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff);
465
- }
466
-
467
- if (hash_params.manifest_is_usable) {
468
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_XXH64_STR, hex_result, fname);
469
-
470
- switch (verify_result) {
471
- case HASH_MANIFEST_NOT_FOUND:
472
- break;
473
- case HASH_MANIFEST_MISMATCH:
474
- model_in_manifest = true;
475
- model_has_mismatch = true;
476
- break;
477
- case HASH_MANIFEST_OK:
478
- model_in_manifest = true;
479
- break;
480
- }
481
-
482
- printf("%-8s %-s %s - %s\n", HASH_TYPE_XXH64_STR, hex_result, fname.c_str(), hash_manifest_result_to_str(verify_result));
483
- } else {
484
- printf("%-8s %-s %s\n", HASH_TYPE_XXH64_STR, hex_result, fname.c_str());
485
- }
486
- }
487
-
488
- if (hash_params.sha1) {
489
- unsigned char result[21];
490
- SHA1Final(result, &sha1_model_hash_ctx);
491
-
492
- char hex_result[41];
493
- for (int offset = 0; offset < 20; offset++) {
494
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff);
495
- }
496
-
497
- if (hash_params.manifest_is_usable) {
498
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_SHA1_STR, hex_result, fname);
499
-
500
- switch (verify_result) {
501
- case HASH_MANIFEST_NOT_FOUND:
502
- break;
503
- case HASH_MANIFEST_MISMATCH:
504
- model_in_manifest = true;
505
- model_has_mismatch = true;
506
- break;
507
- case HASH_MANIFEST_OK:
508
- model_in_manifest = true;
509
- break;
510
- }
511
-
512
- printf("%-8s %-s %s - %s\n", HASH_TYPE_SHA1_STR, hex_result, fname.c_str(), hash_manifest_result_to_str(verify_result));
513
- } else {
514
- printf("%-8s %-s %s\n", HASH_TYPE_SHA1_STR, hex_result, fname.c_str());
515
- }
516
- }
517
-
518
- if (hash_params.sha256) {
519
- unsigned char result[SHA256_DIGEST_SIZE]; // sha256 outputs 32 bytes
520
- sha256_final( &sha256_model_hash_ctx, result);
521
-
522
- char hex_result[SHA256_DIGEST_SIZE * 2 + 1] = {0};
523
- for (int offset = 0; offset < SHA256_DIGEST_SIZE; offset++) {
524
- snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff);
525
- }
526
-
527
- if (hash_params.manifest_is_usable) {
528
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_SHA256_STR, hex_result, fname);
529
-
530
- switch (verify_result) {
531
- case HASH_MANIFEST_NOT_FOUND:
532
- break;
533
- case HASH_MANIFEST_MISMATCH:
534
- model_in_manifest = true;
535
- model_has_mismatch = true;
536
- break;
537
- case HASH_MANIFEST_OK:
538
- model_in_manifest = true;
539
- break;
540
- }
541
-
542
- printf("%-8s %-s %s - %s\n", HASH_TYPE_SHA256_STR, hex_result, fname.c_str(), hash_manifest_result_to_str(verify_result));
543
- } else {
544
- printf("%-8s %-s %s\n", HASH_TYPE_SHA256_STR, hex_result, fname.c_str());
545
- }
546
- }
547
-
548
- if (hash_params.uuid) {
549
- unsigned char result[21];
550
- SHA1Final(result, &sha1_for_uuid_ctx);
551
-
552
- unsigned char uuid[16];
553
- generate_uuidv5(result, uuid);
554
-
555
- char string_buffer[37] = {0};
556
- snprintf(string_buffer, sizeof(string_buffer), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
557
- uuid[0], uuid[1], uuid[2], uuid[3],
558
- uuid[4], uuid[5], uuid[6], uuid[7],
559
- uuid[8], uuid[9], uuid[10], uuid[11],
560
- uuid[12], uuid[13], uuid[14], uuid[15]);
561
-
562
- if (hash_params.manifest_is_usable) {
563
- hash_manifest_result_t verify_result = manifest_verify(hash_params.manifest_file, HASH_TYPE_SHA256_STR, string_buffer, fname);
564
-
565
- switch (verify_result) {
566
- case HASH_MANIFEST_NOT_FOUND:
567
- break;
568
- case HASH_MANIFEST_MISMATCH:
569
- model_in_manifest = true;
570
- model_has_mismatch = true;
571
- break;
572
- case HASH_MANIFEST_OK:
573
- model_in_manifest = true;
574
- break;
575
- }
576
-
577
- printf("%-8s %-s %s - %s\n", HASH_TYPE_UUID_STR, string_buffer, fname.c_str(), hash_manifest_result_to_str(verify_result));
578
- } else {
579
- printf("%-8s %-s %s\n", HASH_TYPE_UUID_STR, string_buffer, fname.c_str());
580
- }
581
- }
582
-
583
-
584
- ggml_free(ctx_data);
585
- gguf_free(ctx);
586
-
587
-
588
- if (hash_params.manifest_is_usable) {
589
- // In hash verification mode
590
-
591
- if (!model_in_manifest) {
592
- // model missing in manifest?
593
-
594
- // Check tensor layer...
595
- if (!tensor_layer_in_manifest) {
596
- // Still missing? Maybe we are reading the wrong manifest.
597
- return HASH_EXIT_MANIFEST_MISSING_ENTRY;
598
- }
599
-
600
- if (tensor_layer_has_mismatch) {
601
- // Per tensor check found error
602
- return HASH_EXIT_FAILURE;
603
- }
604
-
605
- // All per tensor layer checks passed? Sounds good enough.
606
- return HASH_EXIT_SUCCESS;
607
- }
608
-
609
- // Overall model check passed, but let's check per layer just in case
610
- // If missing, we don't care too much as the overall model checked
611
- if (tensor_layer_in_manifest && tensor_layer_has_mismatch) {
612
- return HASH_EXIT_FAILURE;
613
- }
614
-
615
- if (model_has_mismatch) {
616
- // model has failed hash somewhere in the model
617
- return HASH_EXIT_FAILURE;
618
- }
619
-
620
- // All checks appears to be fine
621
- return HASH_EXIT_SUCCESS;
622
- }
623
-
624
- // In hash generation mode
625
- return HASH_EXIT_SUCCESS;
626
- }
627
-
628
- int main(int argc, const char ** argv) {
629
- hash_params params;
630
- manifest_check_params manifest_check;
631
- hash_params_parse(argc, argv, params);
632
-
633
- if (!params.manifest_file.empty()) {
634
- if (!manifest_type(params.manifest_file, manifest_check)) {
635
- printf("ERROR cannot open manifest %s", params.manifest_file.c_str());
636
- return HASH_EXIT_MANIFEST_FILE_ERROR;
637
- }
638
-
639
- if (!manifest_check.sha256 && !manifest_check.sha1 && !manifest_check.xxh64 && !manifest_check.uuid) {
640
- printf("ERROR manifest does not have any known hash format in %s", params.manifest_file.c_str());
641
- return HASH_EXIT_MANIFEST_UNKNOWN_HASH;
642
- }
643
-
644
- printf("manifest %s", params.manifest_file.c_str());
645
-
646
- if (manifest_check.sha256) {
647
- printf(" sha256");
648
- }
649
-
650
- if (manifest_check.sha1) {
651
- printf(" sha1");
652
- }
653
-
654
- if (manifest_check.xxh64) {
655
- printf(" xxh64");
656
- }
657
-
658
- if (manifest_check.uuid) {
659
- printf(" uuid");
660
- }
661
-
662
- printf("\n");
663
-
664
- // Autoselect the highest security hash if manifest is provided but
665
- // the user has not specifically defined the hash they care about
666
- if (!params.xxh64 && !params.sha1 && !params.uuid && !params.sha256) {
667
- // User has not selected a specific value, pick most secure hash
668
- if (manifest_check.sha256) {
669
- params.sha256 = true;
670
- } else if (manifest_check.sha1) {
671
- params.sha1 = true;
672
- } else if (manifest_check.xxh64) {
673
- params.xxh64 = true;
674
- } else if (manifest_check.uuid) {
675
- params.uuid = true;
676
- }
677
- }
678
-
679
- params.manifest_is_usable = true;
680
- }
681
-
682
- // By default if no swich argument provided, assume xxh64
683
- if (!params.xxh64 && !params.sha1 && !params.uuid && !params.sha256) {
684
- params.xxh64 = true;
685
- }
686
-
687
- hash_exit_code_t exit_code = gguf_hash(params);
688
-
689
- if (params.manifest_is_usable) {
690
- printf("\nVerification results for %s - %s\n", params.manifest_file.c_str(), hash_exit_code_to_str(exit_code));
691
- }
692
-
693
- return exit_code;
694
- }
@@ -1,5 +0,0 @@
1
- set(TARGET llama-gritlm)
2
- add_executable(${TARGET} gritlm.cpp)
3
- install(TARGETS ${TARGET} RUNTIME)
4
- target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
5
- target_compile_features(${TARGET} PRIVATE cxx_std_17)