@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,1201 +0,0 @@
1
- #ifdef NDEBUG
2
- # undef NDEBUG
3
- #endif
4
-
5
- #include "sampling.h"
6
-
7
- #include <cassert>
8
- #include <string>
9
- #include <vector>
10
-
11
- static const llama_vocab * vocab;
12
-
13
- static bool match_string(const std::string & input, llama_sampler * grammar) {
14
- llama_sampler_reset(grammar);
15
- auto tokens = common_tokenize(vocab, input, false, false);
16
-
17
- auto n_vocab = llama_vocab_n_tokens(vocab);
18
-
19
- std::vector<llama_token_data> cur;
20
- cur.reserve(n_vocab);
21
- for (llama_token token_id = 0; token_id < (llama_token) n_vocab; token_id++) {
22
- cur.emplace_back(llama_token_data{ token_id, 0.0f, 0.0f });
23
- }
24
- auto tok_arr = llama_token_data_array{ cur.data(), cur.size(), -1, false };
25
-
26
- for (const auto token : tokens) {
27
- for (llama_token token_id = 0; token_id < (llama_token) n_vocab; token_id++) {
28
- cur[token_id].logit = 0.0f;
29
- }
30
- llama_sampler_apply(grammar, &tok_arr);
31
- if (cur[token].logit < 0.0f) {
32
- return false;
33
- }
34
- llama_sampler_accept(grammar, token);
35
- }
36
-
37
- // do we allow EOS at the end? if so the grammar is accepting
38
-
39
- auto tok_eos = llama_vocab_eot(vocab);
40
- if (tok_eos == LLAMA_TOKEN_NULL) {
41
- tok_eos = llama_vocab_eos(vocab);
42
- }
43
-
44
- cur[tok_eos].logit = 0.0f;
45
- llama_sampler_apply(grammar, &tok_arr);
46
-
47
- return cur[tok_eos].logit >= 0.0f;
48
- }
49
-
50
- static void test(const std::string & test_desc, const std::string & grammar_str,
51
- const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
52
- fprintf(stderr, "⚫ Testing %s\n%s\n", test_desc.c_str(), grammar_str.c_str());
53
- fflush(stderr);
54
-
55
- auto * grammar = llama_sampler_init_llg(vocab, "lark", grammar_str.c_str());
56
-
57
- fprintf(stderr, " 🔵 Valid strings:\n");
58
-
59
- // Passing strings
60
- for (const auto & test_string : passing_strings) {
61
- fprintf(stderr, " \"%s\" ", test_string.c_str());
62
- fflush(stderr);
63
-
64
- bool matched = match_string(test_string, grammar);
65
-
66
- if (!matched) {
67
- fprintf(stderr, "❌ (failed to match)\n");
68
-
69
- // DEBUG: Write strings to files so that we can analyze more easily with gbnf-validator program to see exactly where things failed.
70
- // DEBUG: Write the grammar_str to test-grammar-integration.grammar.gbnf
71
- FILE * grammar_file = fopen("test-grammar-integration.grammar.gbnf", "w");
72
- if (grammar_file) {
73
- fprintf(grammar_file, "%s", grammar_str.c_str());
74
- fclose(grammar_file);
75
- }
76
-
77
- // DEBUG: Write the test string to test-grammar-integration.string.txt
78
- FILE * string_file = fopen("test-grammar-integration.string.txt", "w");
79
- if (string_file) {
80
- fprintf(string_file, "%s", test_string.c_str());
81
- fclose(string_file);
82
- }
83
-
84
- fprintf(stderr,
85
- "\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following "
86
- "command: ./test-gbnf-validator test-grammar-integration.grammar.gbnf "
87
- "test-grammar-integration.string.txt\n\n");
88
- } else {
89
- fprintf(stdout, "✅︎\n");
90
- }
91
-
92
- assert(matched);
93
- }
94
-
95
- fprintf(stderr, " 🟠 Invalid strings:\n");
96
-
97
- // Failing strings
98
- for (const auto & test_string : failing_strings) {
99
- fprintf(stderr, " \"%s\" ", test_string.c_str());
100
- fflush(stderr);
101
-
102
- bool matched = match_string(test_string, grammar);
103
-
104
- if (matched) {
105
- fprintf(stderr, "❌ (incorrectly matched)\n");
106
- } else {
107
- fprintf(stdout, "✅︎\n");
108
- }
109
- assert(!matched);
110
- }
111
-
112
- llama_sampler_free(grammar);
113
- }
114
-
115
- static void test_grammar(const std::string & test_desc, const std::string & grammar_str,
116
- const std::vector<std::string> & passing_strings,
117
- const std::vector<std::string> & failing_strings) {
118
- test(test_desc + ". Grammar: " + grammar_str, grammar_str, passing_strings, failing_strings);
119
- }
120
-
121
- static void test_schema(const std::string & test_desc, const std::string & schema_str,
122
- const std::vector<std::string> & passing_strings,
123
- const std::vector<std::string> & failing_strings) {
124
- test(test_desc + ". Schema: " + schema_str, "%llguidance {}\nstart: %json " + schema_str, passing_strings,
125
- failing_strings);
126
- }
127
-
128
- static void test_simple_grammar() {
129
- test_schema("min 0",
130
- R"""({
131
- "type": "integer",
132
- "minimum": 0
133
- })""",
134
- // Passing strings
135
- {
136
- "0",
137
- "10",
138
- "12",
139
- "10000",
140
- },
141
- // Failing strings
142
- {
143
- "-1",
144
- "-10",
145
- "-10000",
146
- "-100000000000000000000000000000000",
147
- // "100000000000000000000000000000000",
148
- "00",
149
- "01",
150
- "-0",
151
- });
152
- test_schema("min 2",
153
- // Schema
154
- R"""({
155
- "type": "integer",
156
- "minimum": 2
157
- })""",
158
- // Passing strings
159
- {
160
- "2",
161
- "3",
162
- "4",
163
- "10",
164
- "20",
165
- "1234567890000000",
166
- },
167
- // Failing strings
168
- {
169
- "0", "1", "-1", "-100", "0", "1", "01", "02",
170
- // "12345678900000000",
171
- });
172
- test_schema("min 456",
173
- R"""({
174
- "type": "integer",
175
- "minimum": 456
176
- })""",
177
- // Passing strings
178
- {
179
- "456",
180
- "4560",
181
- "457",
182
- "460",
183
- "500",
184
- },
185
- // Failing strings
186
- {
187
- "455",
188
- "356",
189
- "50",
190
- "050",
191
- "-1",
192
- "-456",
193
- });
194
- test_schema("min -123",
195
- R"""({
196
- "type": "integer",
197
- "minimum": -123
198
- })""",
199
- // Passing strings
200
- {
201
- "-123",
202
- "-122",
203
- "-11",
204
- "-1",
205
- "0",
206
- "1",
207
- "123",
208
- "1234",
209
- "2345",
210
- },
211
- // Failing strings
212
- {
213
- "-1234",
214
- "-124",
215
- });
216
-
217
- test_schema("max 9999",
218
- // Schema
219
- R"""({
220
- "type": "integer",
221
- "maximum": 9999
222
- })""",
223
- // Passing strings
224
- {
225
- "-99999",
226
- "0",
227
- "9999",
228
- },
229
- // Failing strings
230
- {
231
- "10000",
232
- "99991",
233
- });
234
- test_schema("max -9999",
235
- // Schema
236
- R"""({
237
- "type": "integer",
238
- "maximum": -9999
239
- })""",
240
- // Passing strings
241
- {
242
- "-10000",
243
- "-9999",
244
- },
245
- // Failing strings
246
- {
247
- "-9998",
248
- "0",
249
- "9999",
250
- });
251
- test_schema("min 5 max 30",
252
- // Schema
253
- R"""({
254
- "type": "integer",
255
- "minimum": 5,
256
- "maximum": 30
257
- })""",
258
- // Passing strings
259
- {
260
- "5",
261
- "10",
262
- "30",
263
- },
264
- // Failing strings
265
- {
266
- "05",
267
- "4",
268
- "-1",
269
- "31",
270
- "123",
271
- "0123",
272
- });
273
- test_schema("min -1 max 1",
274
- R"""({
275
- "type": "integer",
276
- "minimum": -1,
277
- "maximum": 1
278
- })""",
279
- // Passing strings
280
- {
281
- "-1",
282
- "0",
283
- "1",
284
- },
285
- // Failing strings
286
- {
287
- "-11",
288
- "-10",
289
- "-2",
290
- "2",
291
- "10",
292
- "11",
293
- });
294
- test_schema("min -123 max 42",
295
- R"""({
296
- "type": "integer",
297
- "minimum": -123,
298
- "maximum": 42
299
- })""",
300
- // Passing strings
301
- {
302
- "-123",
303
- "-122",
304
- "-13",
305
- "-11",
306
- "-2",
307
- "-1",
308
- "0",
309
- "1",
310
- "5",
311
- "10",
312
- "39",
313
- "40",
314
- "42",
315
- },
316
- // Failing strings
317
- {
318
- "-0123",
319
- "-124",
320
- "-1123",
321
- "-200",
322
- "43",
323
- "123",
324
- "0123",
325
- });
326
- test_schema("exclusive min / max",
327
- // Schema
328
- R"""({
329
- "type": "integer",
330
- "exclusiveMinimum": 0,
331
- "exclusiveMaximum": 10000
332
- })""",
333
- // Passing strings
334
- {
335
- "1",
336
- "9999",
337
- },
338
- // Failing strings
339
- {
340
- "0",
341
- "01",
342
- "10000",
343
- "99999",
344
- });
345
-
346
- // Test case for a simple grammar
347
- test_grammar("simple grammar",
348
- R"""(
349
- start: expr
350
- expr: term ("+" term)*
351
- term: number
352
- number: /[0-9]+/ )""",
353
- // Passing strings
354
- {
355
- "42",
356
- "1+2+3+4+5",
357
- "123+456",
358
- },
359
- // Failing strings
360
- {
361
- "+",
362
- "/ 3",
363
- "1+2+3+4+5+",
364
- "12a45",
365
- });
366
- }
367
-
368
- static void test_complex_grammar() {
369
- // Test case for a more complex grammar, with both failure strings and success strings
370
- test_grammar("medium complexity grammar",
371
- // Grammar
372
- R"""(
373
- start: expression
374
- expression: term ws (("+"|"-") ws term)*
375
- term: factor ws (("*"|"/") ws factor)*
376
- factor: number | variable | "(" expression ")" | function-call
377
- number: /[0-9]+/
378
- variable: /[a-zA-Z_][a-zA-Z0-9_]*/
379
- function-call: variable ws "(" (expression ("," ws expression)*)? ")"
380
- ws: /[ \t\n\r]?/ )""",
381
- // Passing strings
382
- { "42",
383
- "1*2*3*4*5",
384
- "x",
385
- "x+10",
386
- "x1+y2",
387
- "(a+b)*(c-d)",
388
- "func()",
389
- "func(x,y+2)",
390
- "a*(b+c)-d/e",
391
- "f(g(x),h(y,z))",
392
- "x + 10",
393
- "x1 + y2",
394
- "(a + b) * (c - d)",
395
- "func()",
396
- "func(x, y + 2)",
397
- "a * (b + c) - d / e",
398
- "f(g(x), h(y, z))",
399
- "123+456",
400
- "123*456*789-123/456+789*123",
401
- "123+456*789-123/456+789*123-456/789+123*456-789/123+456*789-123/456+789*123-456" },
402
- // Failing strings
403
- {
404
- "+",
405
- "/ 3x",
406
- "x + + y",
407
- "a * / b",
408
- "func(,)",
409
- "func(x y)",
410
- "(a + b",
411
- "x + y)",
412
- "a + b * (c - d",
413
- "42 +",
414
- "x +",
415
- "x + 10 +",
416
- "(a + b) * (c - d",
417
- "func(",
418
- "func(x, y + 2",
419
- "a * (b + c) - d /",
420
- "f(g(x), h(y, z)",
421
- "123+456*789-123/456+789*123-456/789+123*456-789/123+456*789-123/456+789*123-456/",
422
- });
423
- }
424
-
425
- static void test_special_chars() {
426
- // A collection of tests to exercise special characters such as "."
427
- test_grammar("special characters",
428
- // Grammar
429
- R"""(
430
- start: /.../ "abc" /.../
431
- )""",
432
- // Passing strings
433
- { "abcabcabc", "aaaabcccc",
434
- // NOTE: Also ensures that multi-byte characters still count as a single character
435
- "🔵🟠✅abc❌🟠🔵" },
436
- // Failing strings
437
- { "aaabcccc", "aaaaabcccc", "aaaabccc", "aaaabccccc", "🔵🟠✅❌abc❌✅🟠🔵", "🔵🟠abc🟠🔵" });
438
- }
439
-
440
- static void test_quantifiers() {
441
- // A collection of tests to exercise * + and ? quantifiers
442
-
443
- test_grammar(
444
- "* quantifier",
445
- // Grammar
446
- R"""(start: "a"*)""",
447
- // Passing strings
448
- { "", "a", "aaaaa", "aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" },
449
- // Failing strings
450
- { "b", "ab", "aab", "ba", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" });
451
- test_grammar(
452
- "+ quantifier",
453
- // Grammar
454
- R"""(start: "a"+)""",
455
- // Passing strings
456
- { "a", "aaaaa", "aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" },
457
- // Failing strings
458
- { "", "b", "ab", "aab", "ba", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" });
459
- test_grammar("? quantifier",
460
- // Grammar
461
- R"""(start: "a"?)""",
462
- // Passing strings
463
- { "", "a" },
464
- // Failing strings
465
- {
466
- "b",
467
- "ab",
468
- "aa",
469
- "ba",
470
- });
471
- test_grammar("mixed quantifiers",
472
- // Grammar
473
- R"""(
474
- start: cons+ vowel* cons? (vowel cons)*
475
- vowel: /[aeiouy]/
476
- cons: /[bcdfghjklmnpqrstvwxyz]/
477
- )""",
478
- // Passing strings
479
- {
480
- "yes",
481
- "no",
482
- "noyes",
483
- "crwth",
484
- "four",
485
- "bryyyy",
486
- },
487
- // Failing strings
488
- {
489
- "yess",
490
- "yesno",
491
- "forty",
492
- "catyyy",
493
- });
494
- test_grammar("simple exact repetition",
495
- // Grammar
496
- R"""(
497
- start: /[ab]{4}/
498
- )""",
499
- // Passing strings
500
- {
501
- "aaaa",
502
- "bbbb",
503
- "abab",
504
- },
505
- // Failing strings
506
- {
507
- "a",
508
- "b",
509
- "aaaaa",
510
- });
511
- test_grammar("simple min repetition",
512
- // Grammar
513
- R"""(
514
- start: /[ab]{4,}/
515
- )""",
516
- // Passing strings
517
- {
518
- "aaaa",
519
- "aaaaab",
520
- "bbbb",
521
- "ababab",
522
- },
523
- // Failing strings
524
- {
525
- "",
526
- "aba",
527
- });
528
- test_grammar("simple max repetition",
529
- // Grammar
530
- R"""(
531
- start: /[ab]{0,4}/
532
- )""",
533
- // Passing strings
534
- {
535
- "",
536
- "a",
537
- "aa",
538
- "aaa",
539
- "aaab",
540
- },
541
- // Failing strings
542
- {
543
- "aaaaa",
544
- });
545
- // test_grammar("min / max repetition",
546
- // // Grammar
547
- // R"""(
548
- // start: ("0x" /[A-F0-9]{2}/ " "?){3,5}
549
- // )""",
550
- // // Passing strings
551
- // {
552
- // "0xFF 0x12 0xAB",
553
- // "0xFF 0x12 0xAB 0x00 0x00",
554
- // },
555
- // // Failing strings
556
- // {
557
- // "",
558
- // "0xFF",
559
- // "0xFF 0x12",
560
- // "0xFF 0x12 0xAB 0x00 0x00 0x00",
561
- // });
562
- }
563
-
564
- static void test_json_schema() {
565
- // Note that this is similar to the regular grammar tests,
566
- // but we convert each json schema to a grammar before parsing.
567
- // Otherwise, this test structure is the same.
568
-
569
- test_schema("empty schema (object)",
570
- // Schema
571
- R"""(
572
- {"type":"object"}
573
- )""",
574
- // Passing strings
575
- {
576
- R"""({})""",
577
- R"""({"foo": "bar"})""",
578
- },
579
- // Failing strings
580
- {
581
- "",
582
- "[]",
583
- "null",
584
- R"""("")""",
585
- "true",
586
- });
587
-
588
- test_schema(
589
- "exotic formats (list)",
590
- // Schema
591
- R"""({
592
- "items": [
593
- { "format": "date" },
594
- { "format": "uuid" },
595
- { "format": "time" },
596
- { "format": "date-time" }
597
- ]
598
- })""",
599
- // Passing strings
600
- {
601
- // "{}", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
602
- // "[]", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
603
- R"""(["2012-04-23", "12345678-1234-1234-1234-1234567890ab", "18:25:43.511Z", "2012-04-23T18:25:43.511Z"])""",
604
- //R"""(["2012-04-23","12345678-1234-1234-1234-1234567890ab"])""", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
605
- //R"""({"foo": "bar"})""", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
606
- },
607
- // Failing strings
608
- {
609
- R"""(["foo", "bar"])""",
610
- R"""(["12345678-1234-1234-1234-1234567890ab"])""",
611
- });
612
-
613
- test_schema("string",
614
- // Schema
615
- R"""({
616
- "type": "string"
617
- })""",
618
- // Passing strings
619
- {
620
- R"""("foo")""",
621
- R"""("bar")""",
622
- R"""("")""",
623
- },
624
- // Failing strings
625
- {
626
- R"""({})""",
627
- R"""("foo": "bar")""",
628
- });
629
-
630
- test_schema("string w/ min length 1",
631
- // Schema
632
- R"""({
633
- "type": "string",
634
- "minLength": 1
635
- })""",
636
- // Passing strings
637
- {
638
- R"""("foo")""",
639
- R"""("bar")""",
640
- },
641
- // Failing strings
642
- {
643
- R"""("")""",
644
- R"""({})""",
645
- R"""("foo": "bar")""",
646
- });
647
-
648
- test_schema("string w/ min length 3",
649
- // Schema
650
- R"""({
651
- "type": "string",
652
- "minLength": 3
653
- })""",
654
- // Passing strings
655
- {
656
- R"""("foo")""",
657
- R"""("bar")""",
658
- R"""("foobar")""",
659
- },
660
- // Failing strings
661
- {
662
- R"""("")""",
663
- R"""("f")""",
664
- R"""("fo")""",
665
- });
666
-
667
- test_schema("string w/ max length",
668
- // Schema
669
- R"""({
670
- "type": "string",
671
- "maxLength": 3
672
- })""",
673
- // Passing strings
674
- {
675
- R"""("foo")""",
676
- R"""("bar")""",
677
- R"""("")""",
678
- R"""("f")""",
679
- R"""("fo")""",
680
- },
681
- // Failing strings
682
- {
683
- R"""("foobar")""",
684
- });
685
-
686
- test_schema("string w/ min & max length",
687
- // Schema
688
- R"""({
689
- "type": "string",
690
- "minLength": 1,
691
- "maxLength": 4
692
- })""",
693
- // Passing strings
694
- {
695
- R"""("foo")""",
696
- R"""("bar")""",
697
- R"""("f")""",
698
- R"""("barf")""",
699
- },
700
- // Failing strings
701
- {
702
- R"""("")""",
703
- R"""("barfo")""",
704
- R"""("foobar")""",
705
- });
706
-
707
- test_schema("boolean",
708
- // Schema
709
- R"""({
710
- "type": "boolean"
711
- })""",
712
- // Passing strings
713
- {
714
- "true",
715
- "false",
716
- },
717
- // Failing strings
718
- {
719
- R"""("")""",
720
- R"""("true")""",
721
- R"""(True)""",
722
- R"""(FALSE)""",
723
- });
724
-
725
- test_schema("integer",
726
- // Schema
727
- R"""({
728
- "type": "integer"
729
- })""",
730
- // Passing strings
731
- {
732
- R"""(0)""",
733
- R"""(12345)""",
734
- R"""(1234567890123456)""",
735
- },
736
- // Failing strings
737
- {
738
- R"""()""",
739
- R"""(01)""",
740
- R"""(007)""",
741
- R"""(12345678901234567 )""",
742
- });
743
-
744
- test_schema("string const",
745
- // Schema
746
- R"""({
747
- "const": "foo"
748
- })""",
749
- // Passing strings
750
- {
751
- R"""("foo")""",
752
- },
753
- // Failing strings
754
- {
755
- R"""(foo)""",
756
- R"""("bar")""",
757
- });
758
-
759
- test_schema("non-string const",
760
- // Schema
761
- R"""({
762
- "const": true
763
- })""",
764
- // Passing strings
765
- {
766
- R"""(true)""",
767
- },
768
- // Failing strings
769
- {
770
- R"""()""",
771
- R"""(foo)""",
772
- R"""("true")""",
773
- });
774
-
775
- test_schema("non-string const",
776
- // Schema
777
- R"""({
778
- "enum": ["red", "amber", "green", null, 42, ["foo"]]
779
- })""",
780
- // Passing strings
781
- {
782
- R"""("red")""",
783
- R"""(null)""",
784
- R"""(42)""",
785
- R"""(["foo"])""",
786
- },
787
- // Failing strings
788
- {
789
- R"""()""",
790
- R"""(420)""",
791
- R"""(true)""",
792
- R"""(foo)""",
793
- });
794
-
795
- test_schema("simple pattern",
796
- // Schema
797
- R"""({
798
- "pattern": "^[a-zA-Z0-9_-]*$"
799
- })""",
800
- // Passing strings
801
- {
802
- R"""("")""",
803
- R"""("He_llo-12")""",
804
- },
805
- // Failing strings
806
- {
807
- R"""("!")""",
808
- R"""("Hello World")""",
809
- });
810
-
811
- test_schema("pattern with escapes",
812
- // Schema
813
- R"""({
814
- "pattern": "^a\\^\\$\\.\\[\\]\\(\\)\\|\\{\\}\\*\\+\\?b$"
815
- })""",
816
- // Passing strings
817
- {
818
- R"""("a^$.[]()|{}*+?b")""",
819
- },
820
- // Failing strings
821
- {
822
- R"""("ab")""",
823
- });
824
-
825
- test_schema("",
826
- // Schema
827
- R"""(
828
- {
829
- "type": ["array", "null"],
830
- "items": { "type": "string" }
831
- }
832
- )""",
833
- // Passing strings
834
- {
835
- "null",
836
- "[]",
837
- "[\"123\"]",
838
- "[\"foo\", \"bar\"]",
839
- },
840
- // Failing strings
841
- {
842
- "",
843
- "[123]",
844
- "\"foo\"",
845
- "[\"foo\", 42]",
846
- });
847
-
848
- test_schema("min+max items",
849
- // Schema
850
- R"""({
851
- "items": {
852
- "type": ["number", "integer"]
853
- },
854
- "minItems": 3,
855
- "maxItems": 5
856
- })""",
857
- // Passing strings
858
- {
859
- R"""([1, 2, 3])""",
860
- R"""([1, 2, 3, 4])""",
861
- R"""([1, 2, 3, 4, 5])""",
862
- // this is in fact correct; keyword do not apply if the type is wrong
863
- R"""(1)""",
864
- },
865
- // Failing strings
866
- {
867
- R"""([1, 2])""",
868
- R"""([1, 2, 3, 4, 5, 6])""",
869
- });
870
-
871
- // Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties)
872
- test_schema("object properties",
873
- // Schema
874
- R"""({
875
- "type": "object",
876
- "properties": {
877
- "number": { "type": "number" },
878
- "street_name": { "type": "string" },
879
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
880
- },
881
- "additionalProperties": false
882
- })""",
883
- // Passing strings
884
- {
885
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue"})""",
886
- // "By default, leaving out properties is valid"
887
- R"""({ "street_name": "Pennsylvania" })""",
888
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
889
- // "By extension, even an empty object is valid"
890
- R"""({})""",
891
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
892
- },
893
- // Failing strings
894
- {
895
- // Change datatype from number to string
896
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
897
- // Reorder properties
898
- R"""({ "street_name": "Pennsylvania", "number": 1600 })""",
899
- // Reorder properties
900
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
901
- // Additional properties set to false
902
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue", "direction":"NW"})""",
903
-
904
- });
905
-
906
- test_schema("additional properties can't override other properties",
907
- R"""({
908
- "properties": {
909
- "a": {"type": "integer"},
910
- "b": {"type": "integer"}
911
- },
912
- "additionalProperties": true
913
- })""",
914
- // Passing strings
915
- {
916
- R"""({"a": 42})""",
917
- R"""({"c": ""})""",
918
- R"""({"a": 42, "c": ""})""",
919
- R"""({"a_": ""})""",
920
- },
921
- // Failing strings
922
- {
923
- R"""()""",
924
- R"""({"a": ""})""",
925
- R"""({"a": "", "b": ""})""",
926
- });
927
-
928
- // Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties)
929
- test_schema("object properties, additionalProperties: true",
930
- // Schema
931
- R"""({
932
- "type": "object",
933
- "properties": {
934
- "number": { "type": "number" },
935
- "street_name": { "type": "string" },
936
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
937
- },
938
- "additionalProperties": true
939
- })""",
940
- // Passing strings
941
- {
942
- // "By extension, even an empty object is valid"
943
- R"""({})""",
944
- R"""({"number":1600,"street_name":"Pennsylvania","street_type":"Avenue"})""",
945
- // "By default, leaving out properties is valid"
946
- R"""({ "street_name": "Pennsylvania" })""",
947
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
948
- // "By default, providing additional properties is valid"
949
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue", "direction":"NW"})""",
950
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
951
- },
952
- // Failing strings
953
- {
954
- // Change datatype from number to string
955
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
956
- // Reorder properties
957
- R"""({ "street_name": "Pennsylvania", "number": 1600, "street_type":"Avenue"})""",
958
- });
959
-
960
- // Additional properties: false
961
- test_schema(
962
- "required + optional props each in original order",
963
- // Schema
964
- R"""({
965
- "type": "object",
966
- "properties": {
967
- "number": { "type": "number" },
968
- "street_name": { "type": "string" },
969
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
970
- },
971
- "additionalProperties": false
972
- })""",
973
- // Passing strings
974
- {
975
- R"""({ "street_name": "Pennsylvania" })""",
976
- R"""({ "number": 1600, "street_type":"Avenue"})""",
977
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
978
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue"})""",
979
- // Spaces are permitted around enum values
980
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
981
- },
982
- // Failing strings
983
- {
984
- // Reorder properties
985
- R"""({ "street_type": "Avenue", "number": 1600 })""",
986
- // Add "direction"
987
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue", "direction": "NW" })""",
988
- });
989
-
990
- test_schema("required + optional props each in original order",
991
- // Schema
992
- R"""({
993
- "properties": {
994
- "b": {"type": "string"},
995
- "a": {"type": "string"},
996
- "d": {"type": "string"},
997
- "c": {"type": "string"}
998
- },
999
- "required": ["a", "b"],
1000
- "additionalProperties": false
1001
- })""",
1002
- // Passing strings
1003
- {
1004
- R"""({"b": "foo", "a": "bar"})""",
1005
- R"""({"b":"foo","a":"bar","d":"qux"})""",
1006
- R"""({"b":"foo", "a":"bar", "d":"qux", "c":"baz"})""",
1007
- },
1008
- // Failing strings
1009
- {
1010
- R"""({"a": "foo", "b": "bar"})""",
1011
- R"""({"b": "bar"})""",
1012
- R"""({"a": "foo", "c": "baz"})""",
1013
- R"""({"a":"foo", "b":"bar", "c":"baz", "d":"qux"})""",
1014
- });
1015
-
1016
- // NOTE: Example from https://json-schema.org/learn/getting-started-step-by-step#define-required-properties
1017
- test_schema(
1018
- "required props",
1019
- // Schema
1020
- R"""({
1021
- "$schema": "https://json-schema.org/draft/2020-12/schema",
1022
- "$id": "https://example.com/product.schema.json",
1023
- "title": "Product",
1024
- "description": "A product from Acme's catalog",
1025
- "type": "object",
1026
- "properties": {
1027
- "productId": {
1028
- "description": "The unique identifier for a product",
1029
- "type": "integer"
1030
- },
1031
- "productName": {
1032
- "description": "Name of the product",
1033
- "type": "string"
1034
- },
1035
- "price": {
1036
- "description": "The price of the product",
1037
- "type": "number",
1038
- "exclusiveMinimum": 0
1039
- },
1040
- "tags": {
1041
- "description": "Tags for the product",
1042
- "type": "array",
1043
- "items": {
1044
- "type": "string"
1045
- },
1046
- "minItems": 1,
1047
- "DISABLED_uniqueItems": true
1048
- },
1049
- "dimensions": {
1050
- "type": "object",
1051
- "properties": {
1052
- "length": {
1053
- "type": "number"
1054
- },
1055
- "width": {
1056
- "type": "number"
1057
- },
1058
- "height": {
1059
- "type": "number"
1060
- }
1061
- },
1062
- "required": [ "length", "width", "height" ]
1063
- }
1064
- },
1065
- "required": [ "productId", "productName", "price" ]
1066
- })""",
1067
- // Passing strings
1068
- {
1069
- R"""({"productId": 1, "productName": "A green door", "price": 12.50})""",
1070
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"]})""",
1071
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"], "dimensions": {"length": 785, "width": 250.5, "height": -0.359}})""",
1072
- },
1073
- // Failing strings
1074
- {
1075
- R"""({})""", // Missing all required properties
1076
- R"""({"productName": "A green door", "price": 12.50, "productId": 1})""", // Out of order properties
1077
- // `exclusiveMinimum` is OK for llg
1078
- R"""({"productId": 1, "productName": "A green door", "price": -12.50})""",
1079
- R"""({"productId": 1, "productName": "A green door"})""", // Missing required property (price)
1080
- R"""({"productName": "A green door", "price": 12.50})""", // Missing required property (productId)
1081
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": []})""", // tags is empty, but minItems is 1
1082
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "dimensions": {"length": 785, "width": 250.5, "height": -0.359}, "tags": ["home", "green"]})""", // Tags and dimensions are out of order
1083
- // TODO: The following line should fail, but currently it passes. `uniqueItems` is not supported, as it would likely be too difficult to implement.
1084
- // R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green", "home"]})""",
1085
- });
1086
- }
1087
-
1088
- static void one_hot(llama_token_data_array & tok_arr, llama_token selected) {
1089
- auto n_vocab = tok_arr.size;
1090
-
1091
- tok_arr.selected = -1;
1092
- tok_arr.sorted = false;
1093
- for (llama_token token_id = 0; token_id < (llama_token) n_vocab; token_id++) {
1094
- tok_arr.data[token_id].id = token_id;
1095
- tok_arr.data[token_id].logit = 0.0f;
1096
- }
1097
-
1098
- tok_arr.data[selected].logit = 100.0f;
1099
- }
1100
-
1101
- static void test_sampler_chain(void) {
1102
- auto sparams = llama_sampler_chain_default_params();
1103
- sparams.no_perf = false;
1104
- llama_sampler * sampler = llama_sampler_chain_init(sparams);
1105
-
1106
- const auto grammar_data = R"(%llguidance {}
1107
- start: /[A-Z ]*/)";
1108
-
1109
- llama_sampler_chain_add(sampler, llama_sampler_init_llg(vocab, "lark", grammar_data));
1110
- llama_sampler_chain_add(sampler, llama_sampler_init_dist(42));
1111
-
1112
- auto input = "ALL YOUR BASE ARE BELONG TO US";
1113
- auto tokens = common_tokenize(vocab, input, false, false);
1114
-
1115
- auto n_vocab = llama_vocab_n_tokens(vocab);
1116
-
1117
- std::vector<llama_token_data> cur;
1118
- cur.reserve(n_vocab);
1119
- for (llama_token token_id = 0; token_id < (llama_token) n_vocab; token_id++) {
1120
- cur.emplace_back(llama_token_data{ token_id, 0.0f, 0.0f });
1121
- }
1122
- auto tok_arr = llama_token_data_array{ cur.data(), cur.size(), -1, false };
1123
-
1124
- for (const auto token : tokens) {
1125
- one_hot(tok_arr, token);
1126
-
1127
- fprintf(stderr, "applying token: %d\n", token);
1128
- llama_sampler_apply(sampler, &tok_arr);
1129
-
1130
- auto idx = tok_arr.selected;
1131
- fprintf(stderr, " -> %d %f\n", cur[idx].id, cur[idx].logit);
1132
- assert(cur[tok_arr.selected].id == token);
1133
- llama_sampler_accept(sampler, token);
1134
- }
1135
-
1136
- auto tok_eos = llama_vocab_eot(vocab);
1137
- if (tok_eos == LLAMA_TOKEN_NULL) {
1138
- tok_eos = llama_vocab_eos(vocab);
1139
- }
1140
-
1141
- one_hot(tok_arr, tok_eos);
1142
-
1143
- llama_sampler_apply(sampler, &tok_arr);
1144
- assert(cur[tok_arr.selected].id == tok_eos);
1145
- }
1146
-
1147
- int main(int argc, const char ** argv) {
1148
- fprintf(stdout, "Running llguidance integration tests...\n");
1149
-
1150
- if (argc != 2) {
1151
- fprintf(stderr, "Usage: %s <vocab-file>\n", argv[0]);
1152
- return 1;
1153
- }
1154
-
1155
- const char * vocab_file = argv[1];
1156
-
1157
- fprintf(stderr, "reading vocab from: '%s'\n", vocab_file);
1158
-
1159
- llama_model * model;
1160
- llama_context * ctx;
1161
-
1162
- llama_backend_init();
1163
-
1164
- // load the vocab
1165
- {
1166
- auto mparams = llama_model_default_params();
1167
-
1168
- mparams.vocab_only = true;
1169
-
1170
- model = llama_model_load_from_file(vocab_file, mparams);
1171
-
1172
- if (model == NULL) {
1173
- fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, vocab_file);
1174
- return 1;
1175
- }
1176
-
1177
- // needed?
1178
- auto cparams = llama_context_default_params();
1179
-
1180
- ctx = llama_init_from_model(model, cparams);
1181
-
1182
- if (ctx == NULL) {
1183
- fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, vocab_file);
1184
- llama_model_free(model);
1185
- return 1;
1186
- }
1187
- }
1188
-
1189
- vocab = llama_model_get_vocab(model);
1190
-
1191
- test_simple_grammar();
1192
- test_complex_grammar();
1193
- test_special_chars();
1194
- test_quantifiers();
1195
- test_json_schema();
1196
-
1197
- test_sampler_chain();
1198
-
1199
- fprintf(stdout, "All tests passed.\n");
1200
- return 0;
1201
- }