@fugood/llama.node 0.2.3 → 0.3.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 (319) hide show
  1. package/CMakeLists.txt +6 -3
  2. package/bin/darwin/arm64/llama-node.node +0 -0
  3. package/bin/darwin/x64/llama-node.node +0 -0
  4. package/bin/linux/arm64/llama-node.node +0 -0
  5. package/bin/linux/x64/llama-node.node +0 -0
  6. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  7. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  8. package/bin/win32/arm64/llama-node.node +0 -0
  9. package/bin/win32/arm64/node.lib +0 -0
  10. package/bin/win32/x64/llama-node.node +0 -0
  11. package/bin/win32/x64/node.lib +0 -0
  12. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  13. package/bin/win32-vulkan/arm64/node.lib +0 -0
  14. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  15. package/bin/win32-vulkan/x64/node.lib +0 -0
  16. package/lib/binding.ts +8 -1
  17. package/package.json +3 -3
  18. package/patches/llama.patch +12 -12
  19. package/src/DetokenizeWorker.cpp +1 -1
  20. package/src/LlamaContext.cpp +33 -1
  21. package/src/LlamaContext.h +1 -0
  22. package/src/llama.cpp/.github/workflows/bench.yml +310 -0
  23. package/src/llama.cpp/.github/workflows/build.yml +1315 -0
  24. package/src/llama.cpp/.github/workflows/close-issue.yml +23 -0
  25. package/src/llama.cpp/.github/workflows/docker.yml +116 -0
  26. package/src/llama.cpp/.github/workflows/editorconfig.yml +27 -0
  27. package/src/llama.cpp/.github/workflows/gguf-publish.yml +44 -0
  28. package/src/llama.cpp/.github/workflows/labeler.yml +17 -0
  29. package/src/llama.cpp/.github/workflows/nix-ci-aarch64.yml +65 -0
  30. package/src/llama.cpp/.github/workflows/nix-ci.yml +72 -0
  31. package/src/llama.cpp/.github/workflows/nix-flake-update.yml +22 -0
  32. package/src/llama.cpp/.github/workflows/nix-publish-flake.yml +36 -0
  33. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +35 -0
  34. package/src/llama.cpp/.github/workflows/python-lint.yml +23 -0
  35. package/src/llama.cpp/.github/workflows/python-type-check.yml +38 -0
  36. package/src/llama.cpp/.github/workflows/server.yml +183 -0
  37. package/src/llama.cpp/CMakeLists.txt +91 -1245
  38. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +1 -1
  39. package/src/llama.cpp/cmake/build-info.cmake +58 -0
  40. package/src/llama.cpp/cmake/git-vars.cmake +22 -0
  41. package/src/llama.cpp/common/CMakeLists.txt +4 -3
  42. package/src/llama.cpp/common/build-info.cpp.in +4 -0
  43. package/src/llama.cpp/common/common.cpp +1116 -877
  44. package/src/llama.cpp/common/common.h +191 -77
  45. package/src/llama.cpp/common/grammar-parser.cpp +118 -31
  46. package/src/llama.cpp/common/json-schema-to-grammar.cpp +346 -65
  47. package/src/llama.cpp/common/log.h +1 -1
  48. package/src/llama.cpp/common/ngram-cache.h +10 -3
  49. package/src/llama.cpp/common/sampling.cpp +19 -10
  50. package/src/llama.cpp/docs/build.md +353 -0
  51. package/src/llama.cpp/examples/CMakeLists.txt +22 -22
  52. package/src/llama.cpp/examples/baby-llama/CMakeLists.txt +1 -1
  53. package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +6 -6
  54. package/src/llama.cpp/examples/batched/CMakeLists.txt +1 -1
  55. package/src/llama.cpp/examples/batched/batched.cpp +52 -55
  56. package/src/llama.cpp/examples/batched-bench/CMakeLists.txt +1 -1
  57. package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +20 -72
  58. package/src/llama.cpp/examples/benchmark/CMakeLists.txt +1 -1
  59. package/src/llama.cpp/examples/chat-13B.bat +57 -0
  60. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +1 -1
  61. package/src/llama.cpp/examples/{finetune → cvector-generator}/CMakeLists.txt +2 -2
  62. package/src/llama.cpp/examples/cvector-generator/completions.txt +582 -0
  63. package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +503 -0
  64. package/src/llama.cpp/examples/cvector-generator/mean.hpp +48 -0
  65. package/src/llama.cpp/examples/cvector-generator/negative.txt +4 -0
  66. package/src/llama.cpp/examples/cvector-generator/pca.hpp +325 -0
  67. package/src/llama.cpp/examples/cvector-generator/positive.txt +4 -0
  68. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +35 -0
  69. package/src/llama.cpp/examples/embedding/CMakeLists.txt +1 -1
  70. package/src/llama.cpp/examples/embedding/embedding.cpp +94 -46
  71. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +2 -2
  72. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +4 -6
  73. package/src/llama.cpp/examples/export-lora/CMakeLists.txt +1 -1
  74. package/src/llama.cpp/examples/export-lora/export-lora.cpp +344 -386
  75. package/src/llama.cpp/examples/gbnf-validator/CMakeLists.txt +2 -2
  76. package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +30 -25
  77. package/src/llama.cpp/examples/gguf/CMakeLists.txt +1 -1
  78. package/src/llama.cpp/examples/gguf/gguf.cpp +5 -0
  79. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +15 -0
  80. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +46 -0
  81. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +295 -0
  82. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +52 -0
  83. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +221 -0
  84. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +24 -0
  85. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +42 -0
  86. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +7093 -0
  87. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +693 -0
  88. package/src/llama.cpp/examples/gguf-split/CMakeLists.txt +1 -1
  89. package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +3 -3
  90. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +1 -1
  91. package/src/llama.cpp/examples/gritlm/gritlm.cpp +6 -2
  92. package/src/llama.cpp/examples/imatrix/CMakeLists.txt +1 -1
  93. package/src/llama.cpp/examples/imatrix/imatrix.cpp +137 -176
  94. package/src/llama.cpp/examples/infill/CMakeLists.txt +1 -1
  95. package/src/llama.cpp/examples/infill/infill.cpp +38 -153
  96. package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +175 -94
  97. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +65 -0
  98. package/src/llama.cpp/examples/llama.android/build.gradle.kts +6 -0
  99. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +68 -0
  100. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +11 -7
  101. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +2 -2
  102. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +18 -0
  103. package/src/llama.cpp/examples/llava/CMakeLists.txt +6 -5
  104. package/src/llama.cpp/examples/llava/android/build_64.sh +8 -0
  105. package/src/llama.cpp/examples/llava/clip.cpp +23 -14
  106. package/src/llama.cpp/examples/llava/llava-cli.cpp +8 -6
  107. package/src/llama.cpp/examples/llava/requirements.txt +3 -2
  108. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +1 -1
  109. package/src/llama.cpp/examples/lookahead/lookahead.cpp +2 -1
  110. package/src/llama.cpp/examples/lookup/CMakeLists.txt +4 -4
  111. package/src/llama.cpp/examples/lookup/lookup-create.cpp +2 -0
  112. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +4 -4
  113. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +2 -2
  114. package/src/llama.cpp/examples/lookup/lookup.cpp +1 -1
  115. package/src/llama.cpp/examples/main/CMakeLists.txt +1 -1
  116. package/src/llama.cpp/examples/main/main.cpp +98 -75
  117. package/src/llama.cpp/examples/main-cmake-pkg/CMakeLists.txt +4 -5
  118. package/src/llama.cpp/examples/parallel/CMakeLists.txt +1 -1
  119. package/src/llama.cpp/examples/parallel/parallel.cpp +2 -1
  120. package/src/llama.cpp/examples/passkey/CMakeLists.txt +1 -1
  121. package/src/llama.cpp/examples/passkey/passkey.cpp +23 -43
  122. package/src/llama.cpp/examples/perplexity/CMakeLists.txt +1 -1
  123. package/src/llama.cpp/examples/perplexity/perplexity.cpp +13 -10
  124. package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
  125. package/src/llama.cpp/examples/quantize/quantize.cpp +37 -34
  126. package/src/llama.cpp/examples/quantize-stats/CMakeLists.txt +1 -1
  127. package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +1 -1
  128. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +1 -1
  129. package/src/llama.cpp/examples/retrieval/retrieval.cpp +26 -77
  130. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +1 -1
  131. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +14 -7
  132. package/src/llama.cpp/examples/server/CMakeLists.txt +26 -2
  133. package/src/llama.cpp/examples/server/server.cpp +274 -671
  134. package/src/llama.cpp/examples/server/tests/requirements.txt +2 -2
  135. package/src/llama.cpp/examples/server/utils.hpp +28 -29
  136. package/src/llama.cpp/examples/simple/CMakeLists.txt +1 -1
  137. package/src/llama.cpp/examples/simple/simple.cpp +21 -29
  138. package/src/llama.cpp/examples/speculative/CMakeLists.txt +1 -1
  139. package/src/llama.cpp/examples/speculative/speculative.cpp +2 -1
  140. package/src/llama.cpp/examples/sycl/CMakeLists.txt +1 -1
  141. package/src/llama.cpp/examples/sycl/build.sh +23 -0
  142. package/src/llama.cpp/examples/sycl/run-llama2.sh +36 -0
  143. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +33 -0
  144. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +9 -0
  145. package/src/llama.cpp/examples/tokenize/CMakeLists.txt +1 -1
  146. package/src/llama.cpp/examples/tokenize/tokenize.cpp +16 -2
  147. package/src/llama.cpp/ggml/CMakeLists.txt +253 -0
  148. package/src/llama.cpp/{cmake → ggml/cmake}/FindSIMD.cmake +6 -6
  149. package/src/llama.cpp/{ggml-backend.h → ggml/include/ggml-backend.h} +22 -17
  150. package/src/llama.cpp/ggml/include/ggml-blas.h +23 -0
  151. package/src/llama.cpp/ggml/include/ggml-cann.h +125 -0
  152. package/src/llama.cpp/{ggml-cuda.h → ggml/include/ggml-cuda.h} +3 -0
  153. package/src/llama.cpp/{ggml-metal.h → ggml/include/ggml-metal.h} +1 -2
  154. package/src/llama.cpp/{ggml-sycl.h → ggml/include/ggml-sycl.h} +3 -10
  155. package/src/llama.cpp/{ggml.h → ggml/include/ggml.h} +80 -85
  156. package/src/llama.cpp/ggml/src/CMakeLists.txt +1329 -0
  157. package/src/llama.cpp/ggml/src/ggml-aarch64.c +2193 -0
  158. package/src/llama.cpp/ggml/src/ggml-aarch64.h +39 -0
  159. package/src/llama.cpp/{ggml-alloc.c → ggml/src/ggml-alloc.c} +100 -49
  160. package/src/llama.cpp/{ggml-backend-impl.h → ggml/src/ggml-backend-impl.h} +20 -8
  161. package/src/llama.cpp/{ggml-backend.c → ggml/src/ggml-backend.c} +307 -167
  162. package/src/llama.cpp/ggml/src/ggml-blas.cpp +367 -0
  163. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +198 -0
  164. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +230 -0
  165. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +2944 -0
  166. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +592 -0
  167. package/src/llama.cpp/ggml/src/ggml-cann/common.h +282 -0
  168. package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +32 -0
  169. package/src/llama.cpp/ggml/src/ggml-cann/kernels/ascendc_kernels.h +17 -0
  170. package/src/llama.cpp/ggml/src/ggml-cann/kernels/dup.cpp +223 -0
  171. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f16.cpp +186 -0
  172. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f32.cpp +180 -0
  173. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +193 -0
  174. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
  175. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +208 -0
  176. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +206 -0
  177. package/src/llama.cpp/ggml/src/ggml-cann.cpp +2023 -0
  178. package/src/llama.cpp/{ggml-common.h → ggml/src/ggml-common.h} +41 -7
  179. package/src/llama.cpp/{ggml-impl.h → ggml/src/ggml-impl.h} +113 -9
  180. package/src/llama.cpp/{ggml-kompute.cpp → ggml/src/ggml-kompute.cpp} +33 -18
  181. package/src/llama.cpp/{ggml-quants.c → ggml/src/ggml-quants.c} +1460 -940
  182. package/src/llama.cpp/{ggml-quants.h → ggml/src/ggml-quants.h} +19 -20
  183. package/src/llama.cpp/{ggml-rpc.cpp → ggml/src/ggml-rpc.cpp} +95 -72
  184. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +27 -0
  185. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +53 -0
  186. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +355 -0
  187. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +195 -0
  188. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +21 -0
  189. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +547 -0
  190. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +27 -0
  191. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +698 -0
  192. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
  193. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +27 -0
  194. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +3011 -0
  195. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +3031 -0
  196. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +33 -0
  197. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1027 -0
  198. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +27 -0
  199. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +374 -0
  200. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +35 -0
  201. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +66 -0
  202. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +275 -0
  203. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +22 -0
  204. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +251 -0
  205. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +24 -0
  206. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +1140 -0
  207. package/src/llama.cpp/ggml/src/ggml-sycl.cpp +5314 -0
  208. package/src/llama.cpp/{ggml-vulkan.cpp → ggml/src/ggml-vulkan.cpp} +1781 -1868
  209. package/src/llama.cpp/{ggml.c → ggml/src/ggml.c} +1245 -2087
  210. package/src/llama.cpp/{sgemm.cpp → ggml/src/llamafile/sgemm.cpp} +21 -24
  211. package/src/llama.cpp/{sgemm.h → ggml/src/llamafile/sgemm.h} +1 -1
  212. package/src/llama.cpp/ggml/src/vulkan-shaders/CMakeLists.txt +5 -0
  213. package/src/llama.cpp/ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp +552 -0
  214. package/src/llama.cpp/{llama.h → include/llama.h} +175 -100
  215. package/src/llama.cpp/models/.editorconfig +1 -0
  216. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  217. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  218. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  219. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +112 -0
  220. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +46 -0
  221. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  222. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +112 -0
  223. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +46 -0
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  225. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
  226. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +46 -0
  227. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  228. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
  229. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +46 -0
  230. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  231. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +112 -0
  232. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +46 -0
  233. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  234. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +112 -0
  235. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +46 -0
  236. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  237. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  238. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +112 -0
  239. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +46 -0
  240. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  241. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +112 -0
  242. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +46 -0
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +112 -0
  245. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +46 -0
  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 +112 -0
  248. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +46 -0
  249. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  250. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +112 -0
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +46 -0
  252. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  253. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +112 -0
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +46 -0
  255. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  256. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +112 -0
  257. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +46 -0
  258. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +2 -2
  259. package/src/llama.cpp/requirements/requirements-all.txt +12 -0
  260. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +2 -0
  261. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +3 -0
  262. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +3 -0
  263. package/src/llama.cpp/requirements/{requirements-convert.txt → requirements-convert_legacy_llama.txt} +1 -1
  264. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +1 -0
  265. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +2 -0
  266. package/src/llama.cpp/requirements/requirements-pydantic.txt +3 -0
  267. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +1 -0
  268. package/src/llama.cpp/requirements.txt +5 -4
  269. package/src/llama.cpp/scripts/build-info.sh +30 -0
  270. package/src/llama.cpp/scripts/install-oneapi.bat +19 -0
  271. package/src/llama.cpp/src/CMakeLists.txt +33 -0
  272. package/src/llama.cpp/src/llama-grammar.cpp +539 -0
  273. package/src/llama.cpp/src/llama-grammar.h +39 -0
  274. package/src/llama.cpp/src/llama-impl.h +26 -0
  275. package/src/llama.cpp/src/llama-sampling.cpp +635 -0
  276. package/src/llama.cpp/src/llama-sampling.h +56 -0
  277. package/src/llama.cpp/src/llama-vocab.cpp +1721 -0
  278. package/src/llama.cpp/src/llama-vocab.h +130 -0
  279. package/src/llama.cpp/{llama.cpp → src/llama.cpp} +5979 -5260
  280. package/src/llama.cpp/{unicode-data.cpp → src/unicode-data.cpp} +851 -802
  281. package/src/llama.cpp/{unicode.cpp → src/unicode.cpp} +52 -30
  282. package/src/llama.cpp/{unicode.h → src/unicode.h} +5 -1
  283. package/src/llama.cpp/tests/CMakeLists.txt +19 -20
  284. package/src/llama.cpp/tests/test-backend-ops.cpp +245 -67
  285. package/src/llama.cpp/tests/test-chat-template.cpp +57 -3
  286. package/src/llama.cpp/tests/test-double-float.cpp +2 -2
  287. package/src/llama.cpp/tests/test-grad0.cpp +2 -2
  288. package/src/llama.cpp/tests/test-grammar-integration.cpp +978 -31
  289. package/src/llama.cpp/tests/test-grammar-parser.cpp +423 -158
  290. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +508 -135
  291. package/src/llama.cpp/tests/test-llama-grammar.cpp +15 -9
  292. package/src/llama.cpp/tests/test-quantize-fns.cpp +1 -1
  293. package/src/llama.cpp/tests/test-quantize-perf.cpp +1 -1
  294. package/src/llama.cpp/tests/test-rope.cpp +3 -4
  295. package/src/llama.cpp/tests/test-sampling.cpp +5 -5
  296. package/src/llama.cpp/tests/test-tokenizer-0.cpp +6 -6
  297. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +20 -15
  298. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +22 -11
  299. package/bin/darwin/arm64/default.metallib +0 -0
  300. package/bin/darwin/x64/default.metallib +0 -0
  301. package/src/llama.cpp/examples/beam-search/CMakeLists.txt +0 -5
  302. package/src/llama.cpp/examples/beam-search/beam-search.cpp +0 -188
  303. package/src/llama.cpp/examples/finetune/finetune.cpp +0 -1862
  304. package/src/llama.cpp/examples/llama.android/llama/CMakeLists.txt +0 -55
  305. package/src/llama.cpp/examples/train-text-from-scratch/CMakeLists.txt +0 -5
  306. package/src/llama.cpp/examples/train-text-from-scratch/train-text-from-scratch.cpp +0 -1253
  307. package/src/llama.cpp/ggml-opencl.cpp +0 -2305
  308. package/src/llama.cpp/ggml-opencl.h +0 -36
  309. package/src/llama.cpp/ggml-sycl.cpp +0 -17340
  310. package/src/llama.cpp/ggml-vulkan-shaders.hpp +0 -81211
  311. package/src/llama.cpp/requirements/requirements-convert-hf-to-gguf-update.txt +0 -2
  312. package/src/llama.cpp/requirements/requirements-convert-hf-to-gguf.txt +0 -2
  313. package/src/llama.cpp/requirements/requirements-convert-llama-ggml-to-gguf.txt +0 -1
  314. package/src/llama.cpp/scripts/gen-build-info-cpp.cmake +0 -24
  315. /package/src/llama.cpp/{ggml-alloc.h → ggml/include/ggml-alloc.h} +0 -0
  316. /package/src/llama.cpp/{ggml-kompute.h → ggml/include/ggml-kompute.h} +0 -0
  317. /package/src/llama.cpp/{ggml-rpc.h → ggml/include/ggml-rpc.h} +0 -0
  318. /package/src/llama.cpp/{ggml-vulkan.h → ggml/include/ggml-vulkan.h} +0 -0
  319. /package/src/llama.cpp/{unicode-data.h → src/unicode-data.h} +0 -0
@@ -0,0 +1,353 @@
1
+ # Build llama.cpp locally
2
+
3
+ **To get the Code:**
4
+
5
+ ```bash
6
+ git clone https://github.com/ggerganov/llama.cpp
7
+ cd llama.cpp
8
+ ```
9
+
10
+ In order to build llama.cpp you have four different options.
11
+
12
+ - Using `make`:
13
+ - On Linux or MacOS:
14
+
15
+ ```bash
16
+ make
17
+ ```
18
+
19
+ - On Windows (x86/x64 only, arm64 requires cmake):
20
+
21
+ 1. Download the latest fortran version of [w64devkit](https://github.com/skeeto/w64devkit/releases).
22
+ 2. Extract `w64devkit` on your pc.
23
+ 3. Run `w64devkit.exe`.
24
+ 4. Use the `cd` command to reach the `llama.cpp` folder.
25
+ 5. From here you can run:
26
+ ```bash
27
+ make
28
+ ```
29
+
30
+ - Notes:
31
+ - For `Q4_0_4_4` quantization type build, add the `GGML_NO_LLAMAFILE=1` flag. For example, use `make GGML_NO_LLAMAFILE=1`.
32
+ - For faster compilation, add the `-j` argument to run multiple jobs in parallel. For example, `make -j 8` will run 8 jobs in parallel.
33
+ - For faster repeated compilation, install [ccache](https://ccache.dev/).
34
+ - For debug builds, run `make LLAMA_DEBUG=1`
35
+
36
+ - Using `CMake`:
37
+
38
+ ```bash
39
+ cmake -B build
40
+ cmake --build build --config Release
41
+ ```
42
+
43
+ **Notes**:
44
+
45
+ - For `Q4_0_4_4` quantization type build, add the `-DGGML_LLAMAFILE=OFF` cmake option. For example, use `cmake -B build -DGGML_LLAMAFILE=OFF`.
46
+ - For faster compilation, add the `-j` argument to run multiple jobs in parallel. For example, `cmake --build build --config Release -j 8` will run 8 jobs in parallel.
47
+ - For faster repeated compilation, install [ccache](https://ccache.dev/).
48
+ - For debug builds, there are two cases:
49
+
50
+ 1. Single-config generators (e.g. default = `Unix Makefiles`; note that they just ignore the `--config` flag):
51
+
52
+ ```bash
53
+ cmake -B build -DCMAKE_BUILD_TYPE=Debug
54
+ cmake --build build
55
+ ```
56
+
57
+ 2. Multi-config generators (`-G` param set to Visual Studio, XCode...):
58
+
59
+ ```bash
60
+ cmake -B build -G "Xcode"
61
+ cmake --build build --config Debug
62
+ ```
63
+ - Building for Windows (x86, x64 and arm64) with MSVC or clang as compilers:
64
+ - Install Visual Studio 2022, e.g. via the [Community Edition](https://visualstudio.microsoft.com/de/vs/community/). In the installer, select at least the following options (this also automatically installs the required additional tools like CMake,...):
65
+ - Tab Workload: Desktop-development with C++
66
+ - Tab Components (select quickly via search): C++-_CMake_ Tools for Windows, _Git_ for Windows, C++-_Clang_ Compiler for Windows, MS-Build Support for LLVM-Toolset (clang)
67
+ - Please remember to always use a Developer Command Prompt / PowerShell for VS2022 for git, build, test
68
+ - For Windows on ARM (arm64, WoA) build with:
69
+ ```bash
70
+ cmake --preset arm64-windows-llvm-release -D GGML_OPENMP=OFF
71
+ cmake --build build-arm64-windows-llvm-release
72
+ ```
73
+ Note: Building for arm64 could also be done just with MSVC (with the build-arm64-windows-MSVC preset, or the standard CMake build instructions). But MSVC does not support inline ARM assembly-code, used e.g. for the accelerated Q4_0_4_8 CPU kernels.
74
+
75
+ - Using `gmake` (FreeBSD):
76
+
77
+ 1. Install and activate [DRM in FreeBSD](https://wiki.freebsd.org/Graphics)
78
+ 2. Add your user to **video** group
79
+ 3. Install compilation dependencies.
80
+
81
+ ```bash
82
+ sudo pkg install gmake automake autoconf pkgconf llvm15 openblas
83
+
84
+ gmake CC=/usr/local/bin/clang15 CXX=/usr/local/bin/clang++15 -j4
85
+ ```
86
+
87
+ ## Metal Build
88
+
89
+ On MacOS, Metal is enabled by default. Using Metal makes the computation run on the GPU.
90
+ To disable the Metal build at compile time use the `GGML_NO_METAL=1` flag or the `GGML_METAL=OFF` cmake option.
91
+
92
+ When built with Metal support, you can explicitly disable GPU inference with the `--n-gpu-layers|-ngl 0` command-line
93
+ argument.
94
+
95
+ ## BLAS Build
96
+
97
+ Building the program with BLAS support may lead to some performance improvements in prompt processing using batch sizes higher than 32 (the default is 512). Support with CPU-only BLAS implementations doesn't affect the normal generation performance. We may see generation performance improvements with GPU-involved BLAS implementations, e.g. cuBLAS, hipBLAS. There are currently several different BLAS implementations available for build and use:
98
+
99
+ ### Accelerate Framework:
100
+
101
+ This is only available on Mac PCs and it's enabled by default. You can just build using the normal instructions.
102
+
103
+ ### OpenBLAS:
104
+
105
+ This provides BLAS acceleration using only the CPU. Make sure to have OpenBLAS installed on your machine.
106
+
107
+ - Using `make`:
108
+ - On Linux:
109
+ ```bash
110
+ make GGML_OPENBLAS=1
111
+ ```
112
+
113
+ - On Windows:
114
+
115
+ 1. Download the latest fortran version of [w64devkit](https://github.com/skeeto/w64devkit/releases).
116
+ 2. Download the latest version of [OpenBLAS for Windows](https://github.com/xianyi/OpenBLAS/releases).
117
+ 3. Extract `w64devkit` on your pc.
118
+ 4. From the OpenBLAS zip that you just downloaded copy `libopenblas.a`, located inside the `lib` folder, inside `w64devkit\x86_64-w64-mingw32\lib`.
119
+ 5. From the same OpenBLAS zip copy the content of the `include` folder inside `w64devkit\x86_64-w64-mingw32\include`.
120
+ 6. Run `w64devkit.exe`.
121
+ 7. Use the `cd` command to reach the `llama.cpp` folder.
122
+ 8. From here you can run:
123
+
124
+ ```bash
125
+ make GGML_OPENBLAS=1
126
+ ```
127
+
128
+ - Using `CMake` on Linux:
129
+
130
+ ```bash
131
+ cmake -B build -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS
132
+ cmake --build build --config Release
133
+ ```
134
+
135
+ ### BLIS
136
+
137
+ Check [BLIS.md](./backend/BLIS.md) for more information.
138
+
139
+ ### SYCL
140
+
141
+ SYCL is a higher-level programming model to improve programming productivity on various hardware accelerators.
142
+
143
+ llama.cpp based on SYCL is used to **support Intel GPU** (Data Center Max series, Flex series, Arc series, Built-in GPU and iGPU).
144
+
145
+ For detailed info, please refer to [llama.cpp for SYCL](./backend/SYCL.md).
146
+
147
+ ### Intel oneMKL
148
+
149
+ Building through oneAPI compilers will make avx_vnni instruction set available for intel processors that do not support avx512 and avx512_vnni. Please note that this build config **does not support Intel GPU**. For Intel GPU support, please refer to [llama.cpp for SYCL](./backend/SYCL.md).
150
+
151
+ - Using manual oneAPI installation:
152
+ By default, `GGML_BLAS_VENDOR` is set to `Generic`, so if you already sourced intel environment script and assign `-DGGML_BLAS=ON` in cmake, the mkl version of Blas will automatically been selected. Otherwise please install oneAPI and follow the below steps:
153
+ ```bash
154
+ source /opt/intel/oneapi/setvars.sh # You can skip this step if in oneapi-basekit docker image, only required for manual installation
155
+ cmake -B build -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_NATIVE=ON
156
+ cmake --build build --config Release
157
+ ```
158
+
159
+ - Using oneAPI docker image:
160
+ If you do not want to source the environment vars and install oneAPI manually, you can also build the code using intel docker container: [oneAPI-basekit](https://hub.docker.com/r/intel/oneapi-basekit). Then, you can use the commands given above.
161
+
162
+ Check [Optimizing and Running LLaMA2 on Intel® CPU](https://www.intel.com/content/www/us/en/content-details/791610/optimizing-and-running-llama2-on-intel-cpu.html) for more information.
163
+
164
+ ### CUDA
165
+
166
+ This provides GPU acceleration using the CUDA cores of your Nvidia GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager (e.g. `apt install nvidia-cuda-toolkit`) or from here: [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads).
167
+
168
+ For Jetson user, if you have Jetson Orin, you can try this: [Offical Support](https://www.jetson-ai-lab.com/tutorial_text-generation.html). If you are using an old model(nano/TX2), need some additional operations before compiling.
169
+
170
+ - Using `make`:
171
+ ```bash
172
+ make GGML_CUDA=1
173
+ ```
174
+ - Using `CMake`:
175
+
176
+ ```bash
177
+ cmake -B build -DGGML_CUDA=ON
178
+ cmake --build build --config Release
179
+ ```
180
+
181
+ The environment variable [`CUDA_VISIBLE_DEVICES`](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars) can be used to specify which GPU(s) will be used. The following compilation options are also available to tweak performance:
182
+
183
+ | Option | Legal values | Default | Description |
184
+ |-------------------------------|------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
185
+ | GGML_CUDA_FORCE_DMMV | Boolean | false | Force the use of dequantization + matrix vector multiplication kernels instead of using kernels that do matrix vector multiplication on quantized data. By default the decision is made based on compute capability (MMVQ for 6.1/Pascal/GTX 1000 or higher). Does not affect k-quants. |
186
+ | GGML_CUDA_DMMV_X | Positive integer >= 32 | 32 | Number of values in x direction processed by the CUDA dequantization + matrix vector multiplication kernel per iteration. Increasing this value can improve performance on fast GPUs. Power of 2 heavily recommended. Does not affect k-quants. |
187
+ | GGML_CUDA_MMV_Y | Positive integer | 1 | Block size in y direction for the CUDA mul mat vec kernels. Increasing this value can improve performance on fast GPUs. Power of 2 recommended. |
188
+ | GGML_CUDA_FORCE_MMQ | Boolean | false | Force the use of custom matrix multiplication kernels for quantized models instead of FP16 cuBLAS even if there is no int8 tensor core implementation available (affects V100, RDNA3). MMQ kernels are enabled by default on GPUs with int8 tensor core support. With MMQ force enabled, speed for large batch sizes will be worse but VRAM consumption will be lower. |
189
+ | GGML_CUDA_FORCE_CUBLAS | Boolean | false | Force the use of FP16 cuBLAS instead of custom matrix multiplication kernels for quantized models |
190
+ | GGML_CUDA_F16 | Boolean | false | If enabled, use half-precision floating point arithmetic for the CUDA dequantization + mul mat vec kernels and for the q4_1 and q5_1 matrix matrix multiplication kernels. Can improve performance on relatively recent GPUs. |
191
+ | GGML_CUDA_KQUANTS_ITER | 1 or 2 | 2 | Number of values processed per iteration and per CUDA thread for Q2_K and Q6_K quantization formats. Setting this value to 1 can improve performance for slow GPUs. |
192
+ | GGML_CUDA_PEER_MAX_BATCH_SIZE | Positive integer | 128 | Maximum batch size for which to enable peer access between multiple GPUs. Peer access requires either Linux or NVLink. When using NVLink enabling peer access for larger batch sizes is potentially beneficial. |
193
+ | GGML_CUDA_FA_ALL_QUANTS | Boolean | false | Compile support for all KV cache quantization type (combinations) for the FlashAttention CUDA kernels. More fine-grained control over KV cache size but compilation takes much longer. |
194
+
195
+ ### MUSA
196
+
197
+ - Using `make`:
198
+ ```bash
199
+ make GGML_MUSA=1
200
+ ```
201
+ - Using `CMake`:
202
+
203
+ ```bash
204
+ cmake -B build -DGGML_MUSA=ON
205
+ cmake --build build --config Release
206
+ ```
207
+
208
+ ### hipBLAS
209
+
210
+ This provides BLAS acceleration on HIP-supported AMD GPUs.
211
+ Make sure to have ROCm installed.
212
+ You can download it from your Linux distro's package manager or from here: [ROCm Quick Start (Linux)](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html#rocm-install-quick).
213
+
214
+ - Using `make`:
215
+ ```bash
216
+ make GGML_HIPBLAS=1
217
+ ```
218
+ - Using `CMake` for Linux (assuming a gfx1030-compatible AMD GPU):
219
+ ```bash
220
+ HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
221
+ cmake -S . -B build -DGGML_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
222
+ && cmake --build build --config Release -- -j 16
223
+ ```
224
+ On Linux it is also possible to use unified memory architecture (UMA) to share main memory between the CPU and integrated GPU by setting `-DGGML_HIP_UMA=ON`.
225
+ However, this hurts performance for non-integrated GPUs (but enables working with integrated GPUs).
226
+
227
+ Note that if you get the following error:
228
+ ```
229
+ clang: error: cannot find ROCm device library; provide its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build without ROCm device library
230
+ ```
231
+ Try searching for a directory under `HIP_PATH` that contains the file
232
+ `oclc_abi_version_400.bc`. Then, add the following to the start of the
233
+ command: `HIP_DEVICE_LIB_PATH=<directory-you-just-found>`, so something
234
+ like:
235
+ ```bash
236
+ HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -p)" \
237
+ HIP_DEVICE_LIB_PATH=<directory-you-just-found> \
238
+ cmake -S . -B build -DGGML_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
239
+ && cmake --build build -- -j 16
240
+ ```
241
+
242
+ - Using `make` (example for target gfx1030, build with 16 CPU threads):
243
+ ```bash
244
+ make -j16 GGML_HIPBLAS=1 GGML_HIP_UMA=1 AMDGPU_TARGETS=gfx1030
245
+ ```
246
+
247
+ - Using `CMake` for Windows (using x64 Native Tools Command Prompt for VS, and assuming a gfx1100-compatible AMD GPU):
248
+ ```bash
249
+ set PATH=%HIP_PATH%\bin;%PATH%
250
+ cmake -S . -B build -G Ninja -DAMDGPU_TARGETS=gfx1100 -DGGML_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
251
+ cmake --build build
252
+ ```
253
+ Make sure that `AMDGPU_TARGETS` is set to the GPU arch you want to compile for. The above example uses `gfx1100` that corresponds to Radeon RX 7900XTX/XT/GRE. You can find a list of targets [here](https://llvm.org/docs/AMDGPUUsage.html#processors)
254
+ Find your gpu version string by matching the most significant version information from `rocminfo | grep gfx | head -1 | awk '{print $2}'` with the list of processors, e.g. `gfx1035` maps to `gfx1030`.
255
+
256
+
257
+ The environment variable [`HIP_VISIBLE_DEVICES`](https://rocm.docs.amd.com/en/latest/understand/gpu_isolation.html#hip-visible-devices) can be used to specify which GPU(s) will be used.
258
+ If your GPU is not officially supported you can use the environment variable [`HSA_OVERRIDE_GFX_VERSION`] set to a similar GPU, for example 10.3.0 on RDNA2 (e.g. gfx1030, gfx1031, or gfx1035) or 11.0.0 on RDNA3.
259
+ The following compilation options are also available to tweak performance (yes, they refer to CUDA, not HIP, because it uses the same code as the cuBLAS version above):
260
+
261
+ | Option | Legal values | Default | Description |
262
+ |------------------------|------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
263
+ | GGML_CUDA_DMMV_X | Positive integer >= 32 | 32 | Number of values in x direction processed by the HIP dequantization + matrix vector multiplication kernel per iteration. Increasing this value can improve performance on fast GPUs. Power of 2 heavily recommended. Does not affect k-quants. |
264
+ | GGML_CUDA_MMV_Y | Positive integer | 1 | Block size in y direction for the HIP mul mat vec kernels. Increasing this value can improve performance on fast GPUs. Power of 2 recommended. Does not affect k-quants. |
265
+ | GGML_CUDA_KQUANTS_ITER | 1 or 2 | 2 | Number of values processed per iteration and per HIP thread for Q2_K and Q6_K quantization formats. Setting this value to 1 can improve performance for slow GPUs. |
266
+
267
+ ### Vulkan
268
+
269
+ **Windows**
270
+
271
+ #### w64devkit
272
+
273
+ Download and extract [w64devkit](https://github.com/skeeto/w64devkit/releases).
274
+
275
+ Download and install the [Vulkan SDK](https://vulkan.lunarg.com/sdk/home#windows). When selecting components, only the Vulkan SDK Core is required.
276
+
277
+ Launch `w64devkit.exe` and run the following commands to copy Vulkan dependencies:
278
+ ```sh
279
+ SDK_VERSION=1.3.283.0
280
+ cp /VulkanSDK/$SDK_VERSION/Bin/glslc.exe $W64DEVKIT_HOME/bin/
281
+ cp /VulkanSDK/$SDK_VERSION/Lib/vulkan-1.lib $W64DEVKIT_HOME/x86_64-w64-mingw32/lib/
282
+ cp -r /VulkanSDK/$SDK_VERSION/Include/* $W64DEVKIT_HOME/x86_64-w64-mingw32/include/
283
+ cat > $W64DEVKIT_HOME/x86_64-w64-mingw32/lib/pkgconfig/vulkan.pc <<EOF
284
+ Name: Vulkan-Loader
285
+ Description: Vulkan Loader
286
+ Version: $SDK_VERSION
287
+ Libs: -lvulkan-1
288
+ EOF
289
+
290
+ ```
291
+ Switch into the `llama.cpp` directory and run `make GGML_VULKAN=1`.
292
+
293
+ #### MSYS2
294
+ Install [MSYS2](https://www.msys2.org/) and then run the following commands in a UCRT terminal to install dependencies.
295
+ ```sh
296
+ pacman -S git \
297
+ mingw-w64-ucrt-x86_64-gcc \
298
+ mingw-w64-ucrt-x86_64-cmake \
299
+ mingw-w64-ucrt-x86_64-vulkan-devel \
300
+ mingw-w64-ucrt-x86_64-shaderc
301
+ ```
302
+ Switch into `llama.cpp` directory and build using CMake.
303
+ ```sh
304
+ cmake -B build -DGGML_VULKAN=ON
305
+ cmake --build build --config Release
306
+ ```
307
+
308
+ **With docker**:
309
+
310
+ You don't need to install Vulkan SDK. It will be installed inside the container.
311
+
312
+ ```sh
313
+ # Build the image
314
+ docker build -t llama-cpp-vulkan -f .devops/llama-cli-vulkan.Dockerfile .
315
+
316
+ # Then, use it:
317
+ docker run -it --rm -v "$(pwd):/app:Z" --device /dev/dri/renderD128:/dev/dri/renderD128 --device /dev/dri/card1:/dev/dri/card1 llama-cpp-vulkan -m "/app/models/YOUR_MODEL_FILE" -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33
318
+ ```
319
+
320
+ **Without docker**:
321
+
322
+ Firstly, you need to make sure you have installed [Vulkan SDK](https://vulkan.lunarg.com/doc/view/latest/linux/getting_started_ubuntu.html)
323
+
324
+ For example, on Ubuntu 22.04 (jammy), use the command below:
325
+
326
+ ```bash
327
+ wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key add -
328
+ wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
329
+ apt update -y
330
+ apt-get install -y vulkan-sdk
331
+ # To verify the installation, use the command below:
332
+ vulkaninfo
333
+ ```
334
+
335
+ Alternatively your package manager might be able to provide the appropriate libraries.
336
+ For example for Ubuntu 22.04 you can install `libvulkan-dev` instead.
337
+ For Fedora 40, you can install `vulkan-devel`, `glslc` and `glslang` packages.
338
+
339
+ Then, build llama.cpp using the cmake command below:
340
+
341
+ ```bash
342
+ cmake -B build -DGGML_VULKAN=1
343
+ cmake --build build --config Release
344
+ # Test the output binary (with "-ngl 33" to offload all layers to GPU)
345
+ ./bin/llama-cli -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4
346
+
347
+ # You should see in the output, ggml_vulkan detected your GPU. For example:
348
+ # ggml_vulkan: Using Intel(R) Graphics (ADL GT2) | uma: 1 | fp16: 1 | warp size: 32
349
+ ```
350
+
351
+ ### Android
352
+
353
+ To read documentation for how to build on Android, [click here](./android.md)
@@ -12,44 +12,44 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
12
12
 
13
13
  if (EMSCRIPTEN)
14
14
  else()
15
+ add_subdirectory(cvector-generator)
15
16
  add_subdirectory(baby-llama)
16
- add_subdirectory(batched)
17
17
  add_subdirectory(batched-bench)
18
- add_subdirectory(beam-search)
18
+ add_subdirectory(batched)
19
19
  add_subdirectory(benchmark)
20
20
  add_subdirectory(convert-llama2c-to-ggml)
21
21
  add_subdirectory(embedding)
22
22
  add_subdirectory(eval-callback)
23
- add_subdirectory(finetune)
24
- add_subdirectory(gritlm)
23
+ add_subdirectory(export-lora)
24
+ add_subdirectory(gbnf-validator)
25
+ add_subdirectory(gguf-hash)
25
26
  add_subdirectory(gguf-split)
27
+ add_subdirectory(gguf)
28
+ add_subdirectory(gritlm)
29
+ add_subdirectory(imatrix)
26
30
  add_subdirectory(infill)
27
31
  add_subdirectory(llama-bench)
28
32
  add_subdirectory(llava)
29
- if (LLAMA_SYCL)
30
- add_subdirectory(sycl)
31
- endif()
33
+ add_subdirectory(lookahead)
34
+ add_subdirectory(lookup)
32
35
  add_subdirectory(main)
33
- add_subdirectory(tokenize)
34
36
  add_subdirectory(parallel)
37
+ add_subdirectory(passkey)
35
38
  add_subdirectory(perplexity)
36
- add_subdirectory(quantize)
37
39
  add_subdirectory(quantize-stats)
40
+ add_subdirectory(quantize)
38
41
  add_subdirectory(retrieval)
39
- add_subdirectory(save-load-state)
40
- add_subdirectory(simple)
41
- add_subdirectory(passkey)
42
- add_subdirectory(speculative)
43
- add_subdirectory(lookahead)
44
- add_subdirectory(lookup)
45
- add_subdirectory(gguf)
46
- add_subdirectory(train-text-from-scratch)
47
- add_subdirectory(imatrix)
42
+ if (GGML_RPC)
43
+ add_subdirectory(rpc)
44
+ endif()
48
45
  if (LLAMA_BUILD_SERVER)
49
- add_subdirectory(server)
46
+ add_subdirectory(server)
50
47
  endif()
51
- add_subdirectory(export-lora)
52
- if (LLAMA_RPC)
53
- add_subdirectory(rpc)
48
+ if (GGML_SYCL)
49
+ add_subdirectory(sycl)
54
50
  endif()
51
+ add_subdirectory(save-load-state)
52
+ add_subdirectory(simple)
53
+ add_subdirectory(speculative)
54
+ add_subdirectory(tokenize)
55
55
  endif()
@@ -1,4 +1,4 @@
1
- set(TARGET baby-llama)
1
+ set(TARGET llama-baby-llama)
2
2
  add_executable(${TARGET} baby-llama.cpp)
3
3
  install(TARGETS ${TARGET} RUNTIME)
4
4
  target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
@@ -522,8 +522,8 @@ static struct ggml_tensor * forward(
522
522
  // wk shape [n_embd, n_embd, 1, 1]
523
523
  // Qcur shape [n_embd/n_head, n_head, N, 1]
524
524
  // Kcur shape [n_embd/n_head, n_head, N, 1]
525
- struct ggml_tensor * Qcur = ggml_rope(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wq, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0, 0);
526
- struct ggml_tensor * Kcur = ggml_rope(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wk, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0, 0);
525
+ struct ggml_tensor * Qcur = ggml_rope(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wq, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0);
526
+ struct ggml_tensor * Kcur = ggml_rope(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wk, cur), n_embd/n_head, n_head, N), KQ_pos, n_rot, 0);
527
527
 
528
528
  // store key and value to memory
529
529
  {
@@ -759,8 +759,8 @@ static struct ggml_tensor * forward_batch(
759
759
  // wk shape [n_embd, n_embd, 1, 1]
760
760
  // Qcur shape [n_embd/n_head, n_head, N, n_batch]
761
761
  // Kcur shape [n_embd/n_head, n_head, N, n_batch]
762
- struct ggml_tensor * Qcur = ggml_rope(ctx0, ggml_reshape_4d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wq, cur), n_embd/n_head, n_head, N, n_batch), KQ_pos, n_rot, 0, 0);
763
- struct ggml_tensor * Kcur = ggml_rope(ctx0, ggml_reshape_4d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wk, cur), n_embd/n_head, n_head, N, n_batch), KQ_pos, n_rot, 0, 0);
762
+ struct ggml_tensor * Qcur = ggml_rope(ctx0, ggml_reshape_4d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wq, cur), n_embd/n_head, n_head, N, n_batch), KQ_pos, n_rot, 0);
763
+ struct ggml_tensor * Kcur = ggml_rope(ctx0, ggml_reshape_4d(ctx0, ggml_mul_mat(ctx0, model->layers[il].wk, cur), n_embd/n_head, n_head, N, n_batch), KQ_pos, n_rot, 0);
764
764
  assert_shape_4d(Qcur, n_embd/n_head, n_head, N, n_batch);
765
765
  assert_shape_4d(Kcur, n_embd/n_head, n_head, N, n_batch);
766
766
 
@@ -1056,7 +1056,7 @@ static struct ggml_tensor * forward_lora(
1056
1056
  model->layers[il].wqb,
1057
1057
  cur)),
1058
1058
  n_embd/n_head, n_head, N),
1059
- KQ_pos, n_rot, 0, 0);
1059
+ KQ_pos, n_rot, 0);
1060
1060
  struct ggml_tensor * Kcur = ggml_rope(ctx0,
1061
1061
  ggml_reshape_3d(ctx0,
1062
1062
  ggml_mul_mat(ctx0,
@@ -1065,7 +1065,7 @@ static struct ggml_tensor * forward_lora(
1065
1065
  model->layers[il].wkb,
1066
1066
  cur)),
1067
1067
  n_embd/n_head, n_head, N),
1068
- KQ_pos, n_rot, 0, 0);
1068
+ KQ_pos, n_rot, 0);
1069
1069
 
1070
1070
  // store key and value to memory
1071
1071
  {
@@ -1,4 +1,4 @@
1
- set(TARGET batched)
1
+ set(TARGET llama-batched)
2
2
  add_executable(${TARGET} batched.cpp)
3
3
  install(TARGETS ${TARGET} RUNTIME)
4
4
  target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
@@ -7,48 +7,31 @@
7
7
  #include <string>
8
8
  #include <vector>
9
9
 
10
- int main(int argc, char ** argv) {
11
- gpt_params params;
10
+ static void print_usage(int argc, char ** argv, const gpt_params & params) {
11
+ gpt_params_print_usage(argc, argv, params);
12
12
 
13
- if (argc == 1 || argv[1][0] == '-') {
14
- printf("usage: %s MODEL_PATH [PROMPT] [PARALLEL] [LEN] [NGL]\n" , argv[0]);
15
- return 1 ;
16
- }
17
-
18
- // number of parallel batches
19
- int n_parallel = 1;
20
-
21
- // total length of the sequences including the prompt
22
- int n_len = 32;
23
-
24
- // number of layers to offload to the GPU
25
- int n_gpu_layers = 0;
13
+ LOG_TEE("\nexample usage:\n");
14
+ LOG_TEE("\n %s -m model.gguf -p \"Hello my name is\" -n 32 -np 4\n", argv[0]);
15
+ LOG_TEE("\n");
16
+ }
26
17
 
27
- if (argc >= 2) {
28
- params.model = argv[1];
29
- }
18
+ int main(int argc, char ** argv) {
19
+ gpt_params params;
30
20
 
31
- if (argc >= 3) {
32
- params.prompt = argv[2];
33
- }
21
+ params.prompt = "Hello my name is";
22
+ params.n_predict = 32;
34
23
 
35
- if (argc >= 4) {
36
- n_parallel = std::atoi(argv[3]);
24
+ if (!gpt_params_parse(argc, argv, params)) {
25
+ print_usage(argc, argv, params);
26
+ return 1;
37
27
  }
38
28
 
39
- if (argc >= 5) {
40
- n_len = std::atoi(argv[4]);
41
- }
42
29
 
43
- if (argc >= 6) {
44
- n_gpu_layers = std::atoi(argv[5]);
45
- }
46
-
47
- if (params.prompt.empty()) {
48
- params.prompt = "Hello my name is";
49
- }
30
+ // number of parallel batches
31
+ int n_parallel = params.n_parallel;
50
32
 
51
- string_process_escapes(params.prompt);
33
+ // total length of the sequences including the prompt
34
+ int n_predict = params.n_predict;
52
35
 
53
36
  // init LLM
54
37
 
@@ -57,9 +40,7 @@ int main(int argc, char ** argv) {
57
40
 
58
41
  // initialize the model
59
42
 
60
- llama_model_params model_params = llama_model_default_params();
61
-
62
- model_params.n_gpu_layers = n_gpu_layers;
43
+ llama_model_params model_params = llama_model_params_from_gpt_params(params);
63
44
 
64
45
  llama_model * model = llama_load_model_from_file(params.model.c_str(), model_params);
65
46
 
@@ -73,18 +54,14 @@ int main(int argc, char ** argv) {
73
54
  std::vector<llama_token> tokens_list;
74
55
  tokens_list = ::llama_tokenize(model, params.prompt, true);
75
56
 
76
- const int n_kv_req = tokens_list.size() + (n_len - tokens_list.size())*n_parallel;
57
+ const int n_kv_req = tokens_list.size() + (n_predict - tokens_list.size())*n_parallel;
77
58
 
78
59
  // initialize the context
79
60
 
80
- llama_context_params ctx_params = llama_context_default_params();
61
+ llama_context_params ctx_params = llama_context_params_from_gpt_params(params);
81
62
 
82
- ctx_params.seed = 1234;
83
63
  ctx_params.n_ctx = n_kv_req;
84
- ctx_params.n_batch = std::max(n_len, n_parallel);
85
- ctx_params.n_seq_max = n_parallel;
86
- ctx_params.n_threads = params.n_threads;
87
- ctx_params.n_threads_batch = params.n_threads_batch == -1 ? params.n_threads : params.n_threads_batch;
64
+ ctx_params.n_batch = std::max(n_predict, n_parallel);
88
65
 
89
66
  llama_context * ctx = llama_new_context_with_model(model, ctx_params);
90
67
 
@@ -93,9 +70,9 @@ int main(int argc, char ** argv) {
93
70
  return 1;
94
71
  }
95
72
 
96
- const int n_ctx = llama_n_ctx(ctx);
73
+ const int n_ctx = llama_n_ctx(ctx);
97
74
 
98
- LOG_TEE("\n%s: n_len = %d, n_ctx = %d, n_batch = %u, n_parallel = %d, n_kv_req = %d\n", __func__, n_len, n_ctx, ctx_params.n_batch, n_parallel, n_kv_req);
75
+ LOG_TEE("\n%s: n_predict = %d, n_ctx = %d, n_batch = %u, n_parallel = %d, n_kv_req = %d\n", __func__, n_predict, n_ctx, ctx_params.n_batch, n_parallel, n_kv_req);
99
76
 
100
77
  // make sure the KV cache is big enough to hold all the prompt and generated tokens
101
78
  if (n_kv_req > n_ctx) {
@@ -116,14 +93,34 @@ int main(int argc, char ** argv) {
116
93
 
117
94
  // create a llama_batch
118
95
  // we use this object to submit token data for decoding
119
- llama_batch batch = llama_batch_init(std::max(tokens_list.size(), (size_t)n_parallel), 0, 1);
96
+ llama_batch batch = llama_batch_init(std::max(tokens_list.size(), (size_t) n_parallel), 0, n_parallel);
97
+
98
+ std::vector<llama_seq_id> seq_ids(n_parallel, 0);
99
+ for (int32_t i = 0; i < n_parallel; ++i) {
100
+ seq_ids[i] = i;
101
+ }
120
102
 
121
103
  // evaluate the initial prompt
122
104
  for (size_t i = 0; i < tokens_list.size(); ++i) {
123
- llama_batch_add(batch, tokens_list[i], i, { 0 }, false);
105
+ llama_batch_add(batch, tokens_list[i], i, seq_ids, false);
124
106
  }
125
107
  GGML_ASSERT(batch.n_tokens == (int) tokens_list.size());
126
108
 
109
+ if (llama_model_has_encoder(model)) {
110
+ if (llama_encode(ctx, batch)) {
111
+ LOG_TEE("%s : failed to eval\n", __func__);
112
+ return 1;
113
+ }
114
+
115
+ llama_token decoder_start_token_id = llama_model_decoder_start_token(model);
116
+ if (decoder_start_token_id == -1) {
117
+ decoder_start_token_id = llama_token_bos(model);
118
+ }
119
+
120
+ llama_batch_clear(batch);
121
+ llama_batch_add(batch, decoder_start_token_id, 0, seq_ids, false);
122
+ }
123
+
127
124
  // llama_decode will output logits only for the last token of the prompt
128
125
  batch.logits[batch.n_tokens - 1] = true;
129
126
 
@@ -132,11 +129,11 @@ int main(int argc, char ** argv) {
132
129
  return 1;
133
130
  }
134
131
 
135
- // assign the system KV cache to all parallel sequences
136
- // this way, the parallel sequences will "reuse" the prompt tokens without having to copy them
137
- for (int32_t i = 1; i < n_parallel; ++i) {
138
- llama_kv_cache_seq_cp(ctx, 0, i, -1, -1);
139
- }
132
+ //// assign the system KV cache to all parallel sequences
133
+ //// this way, the parallel sequences will "reuse" the prompt tokens without having to copy them
134
+ //for (int32_t i = 1; i < n_parallel; ++i) {
135
+ // llama_kv_cache_seq_cp(ctx, 0, i, -1, -1);
136
+ //}
140
137
 
141
138
  if (n_parallel > 1) {
142
139
  LOG_TEE("\n\n%s: generating %d sequences ...\n", __func__, n_parallel);
@@ -156,7 +153,7 @@ int main(int argc, char ** argv) {
156
153
 
157
154
  const auto t_main_start = ggml_time_us();
158
155
 
159
- while (n_cur <= n_len) {
156
+ while (n_cur <= n_predict) {
160
157
  // prepare the next batch
161
158
  llama_batch_clear(batch);
162
159
 
@@ -192,7 +189,7 @@ int main(int argc, char ** argv) {
192
189
  //const llama_token new_token_id = llama_sample_token_greedy(ctx, &candidates_p);
193
190
 
194
191
  // is it an end of generation? -> mark the stream as finished
195
- if (llama_token_is_eog(model, new_token_id) || n_cur == n_len) {
192
+ if (llama_token_is_eog(model, new_token_id) || n_cur == n_predict) {
196
193
  i_batch[i] = -1;
197
194
  LOG_TEE("\n");
198
195
  if (n_parallel > 1) {
@@ -1,4 +1,4 @@
1
- set(TARGET batched-bench)
1
+ set(TARGET llama-batched-bench)
2
2
  add_executable(${TARGET} batched-bench.cpp)
3
3
  install(TARGETS ${TARGET} RUNTIME)
4
4
  target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})