cactus-react-native 0.0.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 (272) hide show
  1. package/README.md +230 -0
  2. package/android/build.gradle +104 -0
  3. package/android/gradle.properties +5 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/CMakeLists.txt +104 -0
  6. package/android/src/main/java/com/cactus/Cactus.java +646 -0
  7. package/android/src/main/java/com/cactus/CactusPackage.java +48 -0
  8. package/android/src/main/java/com/cactus/LlamaContext.java +579 -0
  9. package/android/src/main/jni-utils.h +100 -0
  10. package/android/src/main/jni.cpp +1254 -0
  11. package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
  12. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8.so +0 -0
  13. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
  14. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
  15. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
  16. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
  17. package/android/src/main/jniLibs/x86_64/libcactus.so +0 -0
  18. package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
  19. package/android/src/newarch/java/com/cactus/CactusModule.java +124 -0
  20. package/android/src/oldarch/java/com/cactus/CactusModule.java +125 -0
  21. package/cactus-react-native.podspec +45 -0
  22. package/ios/CMakeLists.txt +109 -0
  23. package/ios/Cactus.h +6 -0
  24. package/ios/Cactus.mm +405 -0
  25. package/ios/CactusContext.h +57 -0
  26. package/ios/CactusContext.mm +835 -0
  27. package/ios/cactus.xcframework/info.plist +74 -0
  28. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +133 -0
  29. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +143 -0
  30. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +683 -0
  31. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-alloc.h +76 -0
  32. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  33. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +354 -0
  34. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +1851 -0
  35. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +39 -0
  36. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  37. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  38. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  39. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  40. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +138 -0
  41. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +567 -0
  42. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  43. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal.h +66 -0
  44. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +216 -0
  45. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-quants.h +100 -0
  46. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-threading.h +14 -0
  47. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +2221 -0
  48. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gguf.h +202 -0
  49. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  50. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json.hpp +24766 -0
  51. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-adapter.h +76 -0
  52. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +421 -0
  53. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +88 -0
  54. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +53 -0
  55. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +265 -0
  56. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +38 -0
  57. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cpp.h +30 -0
  58. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-grammar.h +173 -0
  59. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +574 -0
  60. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +148 -0
  61. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-impl.h +61 -0
  62. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-io.h +35 -0
  63. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +287 -0
  64. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +21 -0
  65. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-mmap.h +68 -0
  66. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +167 -0
  67. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +403 -0
  68. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-sampling.h +32 -0
  69. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +125 -0
  70. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +1416 -0
  71. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/log.h +103 -0
  72. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  73. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +2915 -0
  74. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sampling.h +107 -0
  75. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sgemm.h +14 -0
  76. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode-data.h +20 -0
  77. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode.h +66 -0
  78. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
  79. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  80. package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
  81. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +133 -0
  82. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +143 -0
  83. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +683 -0
  84. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +76 -0
  85. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  86. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +354 -0
  87. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +1851 -0
  88. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +39 -0
  89. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  90. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  91. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  92. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  93. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +138 -0
  94. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +567 -0
  95. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  96. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +66 -0
  97. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +216 -0
  98. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +100 -0
  99. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +14 -0
  100. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +2221 -0
  101. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +202 -0
  102. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  103. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +24766 -0
  104. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +76 -0
  105. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +421 -0
  106. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +88 -0
  107. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +53 -0
  108. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +265 -0
  109. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +38 -0
  110. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +30 -0
  111. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +173 -0
  112. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +574 -0
  113. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +148 -0
  114. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +61 -0
  115. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +35 -0
  116. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +287 -0
  117. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +21 -0
  118. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +68 -0
  119. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +167 -0
  120. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +403 -0
  121. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +32 -0
  122. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +125 -0
  123. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +1416 -0
  124. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/log.h +103 -0
  125. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  126. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +2915 -0
  127. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +107 -0
  128. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +14 -0
  129. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +20 -0
  130. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +66 -0
  131. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  132. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +101 -0
  133. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  134. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  135. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +133 -0
  136. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +143 -0
  137. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +683 -0
  138. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-alloc.h +76 -0
  139. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  140. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +354 -0
  141. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +1851 -0
  142. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +39 -0
  143. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  144. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  145. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  146. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  147. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +138 -0
  148. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +567 -0
  149. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  150. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal.h +66 -0
  151. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +216 -0
  152. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-quants.h +100 -0
  153. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-threading.h +14 -0
  154. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +2221 -0
  155. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/gguf.h +202 -0
  156. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  157. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json.hpp +24766 -0
  158. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-adapter.h +76 -0
  159. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +421 -0
  160. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +88 -0
  161. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +53 -0
  162. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +265 -0
  163. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +38 -0
  164. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cpp.h +30 -0
  165. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-grammar.h +173 -0
  166. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +574 -0
  167. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +148 -0
  168. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-impl.h +61 -0
  169. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-io.h +35 -0
  170. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +287 -0
  171. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +21 -0
  172. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-mmap.h +68 -0
  173. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +167 -0
  174. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +403 -0
  175. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-sampling.h +32 -0
  176. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +125 -0
  177. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +1416 -0
  178. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/log.h +103 -0
  179. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  180. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +2915 -0
  181. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sampling.h +107 -0
  182. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sgemm.h +14 -0
  183. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode-data.h +20 -0
  184. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode.h +66 -0
  185. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
  186. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
  187. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
  188. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +133 -0
  189. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +143 -0
  190. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +683 -0
  191. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +76 -0
  192. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  193. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +354 -0
  194. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +1851 -0
  195. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +39 -0
  196. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  197. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  198. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  199. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  200. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +138 -0
  201. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +567 -0
  202. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  203. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +66 -0
  204. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +216 -0
  205. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +100 -0
  206. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +14 -0
  207. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +2221 -0
  208. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +202 -0
  209. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  210. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +24766 -0
  211. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +76 -0
  212. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +421 -0
  213. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +88 -0
  214. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +53 -0
  215. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +265 -0
  216. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +38 -0
  217. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +30 -0
  218. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +173 -0
  219. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +574 -0
  220. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +148 -0
  221. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +61 -0
  222. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +35 -0
  223. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +287 -0
  224. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +21 -0
  225. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +68 -0
  226. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +167 -0
  227. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +403 -0
  228. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +32 -0
  229. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +125 -0
  230. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +1416 -0
  231. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/log.h +103 -0
  232. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  233. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +2915 -0
  234. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +107 -0
  235. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +14 -0
  236. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +20 -0
  237. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +66 -0
  238. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  239. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +101 -0
  240. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  241. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  242. package/lib/commonjs/NativeCactus.js +9 -0
  243. package/lib/commonjs/NativeCactus.js.map +1 -0
  244. package/lib/commonjs/chat.js +37 -0
  245. package/lib/commonjs/chat.js.map +1 -0
  246. package/lib/commonjs/grammar.js +560 -0
  247. package/lib/commonjs/grammar.js.map +1 -0
  248. package/lib/commonjs/index.js +300 -0
  249. package/lib/commonjs/index.js.map +1 -0
  250. package/lib/commonjs/package.json +1 -0
  251. package/lib/module/NativeCactus.js +5 -0
  252. package/lib/module/NativeCactus.js.map +1 -0
  253. package/lib/module/chat.js +33 -0
  254. package/lib/module/chat.js.map +1 -0
  255. package/lib/module/grammar.js +553 -0
  256. package/lib/module/grammar.js.map +1 -0
  257. package/lib/module/index.js +277 -0
  258. package/lib/module/index.js.map +1 -0
  259. package/lib/module/package.json +1 -0
  260. package/lib/typescript/NativeCactus.d.ts +357 -0
  261. package/lib/typescript/NativeCactus.d.ts.map +1 -0
  262. package/lib/typescript/chat.d.ts +10 -0
  263. package/lib/typescript/chat.d.ts.map +1 -0
  264. package/lib/typescript/grammar.d.ts +37 -0
  265. package/lib/typescript/grammar.d.ts.map +1 -0
  266. package/lib/typescript/index.d.ts +96 -0
  267. package/lib/typescript/index.d.ts.map +1 -0
  268. package/package.json +223 -0
  269. package/src/NativeCactus.ts +418 -0
  270. package/src/chat.ts +44 -0
  271. package/src/grammar.ts +854 -0
  272. package/src/index.ts +482 -0
@@ -0,0 +1,683 @@
1
+ // Various helper functions and utilities
2
+
3
+ #pragma once
4
+
5
+ #include "llama-cpp.h"
6
+
7
+ #include <set>
8
+ #include <string>
9
+ #include <vector>
10
+ #include <sstream>
11
+
12
+ #ifdef _WIN32
13
+ #define DIRECTORY_SEPARATOR '\\'
14
+ #else
15
+ #define DIRECTORY_SEPARATOR '/'
16
+ #endif // _WIN32
17
+
18
+ #define die(msg) do { fputs("error: " msg "\n", stderr); exit(1); } while (0)
19
+ #define die_fmt(fmt, ...) do { fprintf(stderr, "error: " fmt "\n", __VA_ARGS__); exit(1); } while (0)
20
+
21
+ #define print_build_info() do { \
22
+ fprintf(stderr, "%s: build = %d (%s)\n", __func__, LLAMA_BUILD_NUMBER, LLAMA_COMMIT); \
23
+ fprintf(stderr, "%s: built with %s for %s\n", __func__, LLAMA_COMPILER, LLAMA_BUILD_TARGET); \
24
+ } while(0)
25
+
26
+ #define DEFAULT_MODEL_PATH "models/7B/ggml-model-f16.gguf"
27
+
28
+ struct common_adapter_lora_info {
29
+ std::string path;
30
+ float scale;
31
+
32
+ struct llama_adapter_lora * ptr;
33
+ };
34
+
35
+ using llama_tokens = std::vector<llama_token>;
36
+
37
+ // build info
38
+ extern int LLAMA_BUILD_NUMBER;
39
+ extern const char * LLAMA_COMMIT;
40
+ extern const char * LLAMA_COMPILER;
41
+ extern const char * LLAMA_BUILD_TARGET;
42
+
43
+ struct common_control_vector_load_info;
44
+
45
+ #define print_build_info() do { \
46
+ fprintf(stderr, "%s: build = %d (%s)\n", __func__, LLAMA_BUILD_NUMBER, LLAMA_COMMIT); \
47
+ fprintf(stderr, "%s: built with %s for %s\n", __func__, LLAMA_COMPILER, LLAMA_BUILD_TARGET); \
48
+ } while(0)
49
+
50
+ // build info
51
+ extern int LLAMA_BUILD_NUMBER;
52
+ extern char const *LLAMA_COMMIT;
53
+ extern char const *LLAMA_COMPILER;
54
+ extern char const *LLAMA_BUILD_TARGET;
55
+
56
+ //
57
+ // CPU utils
58
+ //
59
+
60
+ struct cpu_params {
61
+ int n_threads = -1;
62
+ bool cpumask[LM_GGML_MAX_N_THREADS] = {false}; // CPU affinity mask.
63
+ bool mask_valid = false; // Default: any CPU
64
+ enum lm_ggml_sched_priority priority = LM_GGML_SCHED_PRIO_NORMAL; // Scheduling prio : (0 - normal, 1 - medium, 2 - high, 3 - realtime)
65
+ bool strict_cpu = false; // Use strict CPU placement
66
+ uint32_t poll = 50; // Polling (busywait) level (0 - no polling, 100 - mostly polling)
67
+ };
68
+
69
+ int32_t cpu_get_num_physical_cores();
70
+ int32_t cpu_get_num_math();
71
+
72
+ //
73
+ // Common params
74
+ //
75
+
76
+ enum llama_example {
77
+ LLAMA_EXAMPLE_COMMON,
78
+ LLAMA_EXAMPLE_SPECULATIVE,
79
+ LLAMA_EXAMPLE_MAIN,
80
+ LLAMA_EXAMPLE_INFILL,
81
+ LLAMA_EXAMPLE_EMBEDDING,
82
+ LLAMA_EXAMPLE_PERPLEXITY,
83
+ LLAMA_EXAMPLE_RETRIEVAL,
84
+ LLAMA_EXAMPLE_PASSKEY,
85
+ LLAMA_EXAMPLE_IMATRIX,
86
+ LLAMA_EXAMPLE_BENCH,
87
+ LLAMA_EXAMPLE_SERVER,
88
+ LLAMA_EXAMPLE_CVECTOR_GENERATOR,
89
+ LLAMA_EXAMPLE_EXPORT_LORA,
90
+ LLAMA_EXAMPLE_LLAVA,
91
+ LLAMA_EXAMPLE_LOOKUP,
92
+ LLAMA_EXAMPLE_PARALLEL,
93
+ LLAMA_EXAMPLE_TTS,
94
+
95
+ LLAMA_EXAMPLE_COUNT,
96
+ };
97
+
98
+ enum common_sampler_type {
99
+ COMMON_SAMPLER_TYPE_NONE = 0,
100
+ COMMON_SAMPLER_TYPE_DRY = 1,
101
+ COMMON_SAMPLER_TYPE_TOP_K = 2,
102
+ COMMON_SAMPLER_TYPE_TOP_P = 3,
103
+ COMMON_SAMPLER_TYPE_MIN_P = 4,
104
+ //COMMON_SAMPLER_TYPE_TFS_Z = 5,
105
+ COMMON_SAMPLER_TYPE_TYPICAL_P = 6,
106
+ COMMON_SAMPLER_TYPE_TEMPERATURE = 7,
107
+ COMMON_SAMPLER_TYPE_XTC = 8,
108
+ COMMON_SAMPLER_TYPE_INFILL = 9,
109
+ COMMON_SAMPLER_TYPE_PENALTIES = 10,
110
+ };
111
+
112
+ // dimensionality reduction methods, used by cvector-generator
113
+ enum dimre_method {
114
+ DIMRE_METHOD_PCA,
115
+ DIMRE_METHOD_MEAN,
116
+ };
117
+
118
+ enum common_conversation_mode {
119
+ COMMON_CONVERSATION_MODE_DISABLED = 0,
120
+ COMMON_CONVERSATION_MODE_ENABLED = 1,
121
+ COMMON_CONVERSATION_MODE_AUTO = 2,
122
+ };
123
+
124
+ enum common_grammar_trigger_type {
125
+ COMMON_GRAMMAR_TRIGGER_TYPE_TOKEN,
126
+ COMMON_GRAMMAR_TRIGGER_TYPE_WORD,
127
+ COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN,
128
+ COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN_START,
129
+ };
130
+
131
+ struct common_grammar_trigger {
132
+ common_grammar_trigger_type type;
133
+ std::string value;
134
+ llama_token token = LLAMA_TOKEN_NULL;
135
+
136
+ // T can only be nlohmann::ordered_json
137
+ template <class T> T to_json() const;
138
+ template <class T> static common_grammar_trigger from_json(const T & in);
139
+ };
140
+
141
+ // sampling parameters
142
+ struct common_params_sampling {
143
+ uint32_t seed = LLAMA_DEFAULT_SEED; // the seed used to initialize llama_sampler
144
+
145
+ int32_t n_prev = 64; // number of previous tokens to remember
146
+ int32_t n_probs = 0; // if greater than 0, output the probabilities of top n_probs tokens.
147
+ int32_t min_keep = 0; // 0 = disabled, otherwise samplers should return at least min_keep tokens
148
+ int32_t top_k = 40; // <= 0 to use vocab size
149
+ float top_p = 0.95f; // 1.0 = disabled
150
+ float min_p = 0.05f; // 0.0 = disabled
151
+ float xtc_probability = 0.00f; // 0.0 = disabled
152
+ float xtc_threshold = 0.10f; // > 0.5 disables XTC
153
+ float typ_p = 1.00f; // typical_p, 1.0 = disabled
154
+ float temp = 0.80f; // <= 0.0 to sample greedily, 0.0 to not output probabilities
155
+ float dynatemp_range = 0.00f; // 0.0 = disabled
156
+ float dynatemp_exponent = 1.00f; // controls how entropy maps to temperature in dynamic temperature sampler
157
+ int32_t penalty_last_n = 64; // last n tokens to penalize (0 = disable penalty, -1 = context size)
158
+ float penalty_repeat = 1.00f; // 1.0 = disabled
159
+ float penalty_freq = 0.00f; // 0.0 = disabled
160
+ float penalty_present = 0.00f; // 0.0 = disabled
161
+ float dry_multiplier = 0.0f; // 0.0 = disabled; DRY repetition penalty for tokens extending repetition:
162
+ float dry_base = 1.75f; // 0.0 = disabled; multiplier * base ^ (length of sequence before token - allowed length)
163
+ int32_t dry_allowed_length = 2; // tokens extending repetitions beyond this receive penalty
164
+ int32_t dry_penalty_last_n = -1; // how many tokens to scan for repetitions (0 = disable penalty, -1 = context size)
165
+ int32_t mirostat = 0; // 0 = disabled, 1 = mirostat, 2 = mirostat 2.0
166
+ float top_n_sigma = -1.00f;// -1.0 = disabled
167
+ float mirostat_tau = 5.00f; // target entropy
168
+ float mirostat_eta = 0.10f; // learning rate
169
+ bool ignore_eos = false;
170
+ bool no_perf = false; // disable performance metrics
171
+ bool timing_per_token = false;
172
+
173
+ std::vector<std::string> dry_sequence_breakers = {"\n", ":", "\"", "*"}; // default sequence breakers for DRY
174
+
175
+
176
+ std::vector<enum common_sampler_type> samplers = {
177
+ COMMON_SAMPLER_TYPE_PENALTIES,
178
+ COMMON_SAMPLER_TYPE_DRY,
179
+ COMMON_SAMPLER_TYPE_TOP_K,
180
+ COMMON_SAMPLER_TYPE_TYPICAL_P,
181
+ COMMON_SAMPLER_TYPE_TOP_P,
182
+ COMMON_SAMPLER_TYPE_MIN_P,
183
+ COMMON_SAMPLER_TYPE_XTC,
184
+ COMMON_SAMPLER_TYPE_TEMPERATURE,
185
+ };
186
+
187
+ std::string grammar; // optional BNF-like grammar to constrain sampling
188
+ bool grammar_lazy = false;
189
+ std::vector<common_grammar_trigger> grammar_triggers; // optional triggers (for lazy grammars)
190
+ std::set<llama_token> preserved_tokens;
191
+
192
+ std::vector<llama_logit_bias> logit_bias; // logit biases to apply
193
+
194
+ // print the parameters into a string
195
+ std::string print() const;
196
+ };
197
+
198
+ struct common_params_speculative {
199
+ std::vector<lm_ggml_backend_dev_t> devices; // devices to use for offloading
200
+
201
+ int32_t n_ctx = 0; // draft context size
202
+ int32_t n_max = 16; // maximum number of tokens to draft during speculative decoding
203
+ int32_t n_min = 0; // minimum number of draft tokens to use for speculative decoding
204
+ int32_t n_gpu_layers = -1; // number of layers to store in VRAM for the draft model (-1 - use default)
205
+ float p_split = 0.1f; // speculative decoding split probability
206
+ float p_min = 0.75f; // minimum speculative decoding probability (greedy)
207
+
208
+ struct cpu_params cpuparams;
209
+ struct cpu_params cpuparams_batch;
210
+
211
+ std::string hf_repo = ""; // HF repo // NOLINT
212
+ std::string hf_file = ""; // HF file // NOLINT
213
+
214
+ std::string model = ""; // draft model for speculative decoding // NOLINT
215
+ std::string model_url = ""; // model url to download // NOLINT
216
+ };
217
+
218
+ struct common_params_vocoder {
219
+ std::string hf_repo = ""; // HF repo // NOLINT
220
+ std::string hf_file = ""; // HF file // NOLINT
221
+
222
+ std::string model = ""; // model path // NOLINT
223
+ std::string model_url = ""; // model url to download // NOLINT
224
+
225
+ std::string speaker_file = ""; // speaker file path // NOLINT
226
+
227
+ bool use_guide_tokens = false; // enable guide tokens to improve TTS accuracy // NOLINT
228
+ };
229
+
230
+ enum common_reasoning_format {
231
+ COMMON_REASONING_FORMAT_NONE,
232
+ COMMON_REASONING_FORMAT_DEEPSEEK, // Extract thinking tag contents and return as `message.reasoning_content`
233
+ };
234
+
235
+ struct common_params {
236
+ bool vocab_only = false;
237
+ int32_t n_predict = -1; // new tokens to predict
238
+ int32_t n_ctx = 4096; // context size
239
+ int32_t n_batch = 2048; // logical batch size for prompt processing (must be >=32 to use BLAS)
240
+ int32_t n_ubatch = 512; // physical batch size for prompt processing (must be >=32 to use BLAS)
241
+ int32_t n_keep = 0; // number of tokens to keep from initial prompt
242
+ int32_t n_chunks = -1; // max number of chunks to process (-1 = unlimited)
243
+ int32_t n_parallel = 1; // number of parallel sequences to decode
244
+ int32_t n_sequences = 1; // number of sequences to decode
245
+ int32_t grp_attn_n = 1; // group-attention factor
246
+ int32_t grp_attn_w = 512; // group-attention width
247
+ int32_t n_print = -1; // print token count every n tokens (-1 = disabled)
248
+ float rope_freq_base = 0.0f; // RoPE base frequency
249
+ float rope_freq_scale = 0.0f; // RoPE frequency scaling factor
250
+ float yarn_ext_factor = -1.0f; // YaRN extrapolation mix factor
251
+ float yarn_attn_factor = 1.0f; // YaRN magnitude scaling factor
252
+ float yarn_beta_fast = 32.0f; // YaRN low correction dim
253
+ float yarn_beta_slow = 1.0f; // YaRN high correction dim
254
+ int32_t yarn_orig_ctx = 0; // YaRN original context length
255
+ float defrag_thold = 0.1f; // KV cache defragmentation threshold
256
+
257
+ // offload params
258
+ std::vector<lm_ggml_backend_dev_t> devices; // devices to use for offloading
259
+
260
+ int32_t n_gpu_layers = -1; // number of layers to store in VRAM (-1 - use default)
261
+ int32_t main_gpu = 0; // the GPU that is used for scratch and small tensors
262
+ float tensor_split[128] = {0}; // how split tensors should be distributed across GPUs
263
+
264
+ enum llama_split_mode split_mode = LLAMA_SPLIT_MODE_LAYER; // how to split the model across GPUs
265
+
266
+ struct cpu_params cpuparams;
267
+ struct cpu_params cpuparams_batch;
268
+
269
+ lm_ggml_backend_sched_eval_callback cb_eval = nullptr;
270
+ void * cb_eval_user_data = nullptr;
271
+
272
+ lm_ggml_numa_strategy numa = LM_GGML_NUMA_STRATEGY_DISABLED;
273
+
274
+ enum llama_rope_scaling_type rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_UNSPECIFIED;
275
+ enum llama_pooling_type pooling_type = LLAMA_POOLING_TYPE_UNSPECIFIED; // pooling type for embeddings
276
+ enum llama_attention_type attention_type = LLAMA_ATTENTION_TYPE_UNSPECIFIED; // attention type for embeddings
277
+
278
+ struct common_params_sampling sampling;
279
+ struct common_params_speculative speculative;
280
+ struct common_params_vocoder vocoder;
281
+
282
+ std::string model = ""; // model path // NOLINT
283
+ std::string model_alias = ""; // model alias // NOLINT
284
+ std::string model_url = ""; // model url to download // NOLINT
285
+ std::string hf_token = ""; // HF token // NOLINT
286
+ std::string hf_repo = ""; // HF repo // NOLINT
287
+ std::string hf_file = ""; // HF file // NOLINT
288
+ std::string prompt = ""; // NOLINT
289
+ std::string system_prompt = ""; // NOLINT
290
+ std::string prompt_file = ""; // store the external prompt file name // NOLINT
291
+ std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state // NOLINT
292
+ std::string input_prefix = ""; // string to prefix user inputs with // NOLINT
293
+ std::string input_suffix = ""; // string to suffix user inputs with // NOLINT
294
+ std::string lookup_cache_static = ""; // path of static ngram cache file for lookup decoding // NOLINT
295
+ std::string lookup_cache_dynamic = ""; // path of dynamic ngram cache file for lookup decoding // NOLINT
296
+ std::string logits_file = ""; // file for saving *all* logits // NOLINT
297
+
298
+ std::vector<std::string> in_files; // all input files
299
+ std::vector<std::string> antiprompt; // strings upon which more user input is prompted (a.k.a. reverse prompts)
300
+ std::vector<llama_model_kv_override> kv_overrides;
301
+
302
+ bool lora_init_without_apply = false; // only load lora to memory, but do not apply it to ctx (user can manually apply lora later using llama_adapter_lora_apply)
303
+ std::vector<common_adapter_lora_info> lora_adapters; // lora adapter path with user defined scale
304
+
305
+ std::vector<common_control_vector_load_info> control_vectors; // control vector with user defined scale
306
+
307
+ int32_t verbosity = 0;
308
+ int32_t control_vector_layer_start = -1; // layer range for control vector
309
+ int32_t control_vector_layer_end = -1; // layer range for control vector
310
+
311
+ int32_t ppl_stride = 0; // stride for perplexity calculations. If left at 0, the pre-existing approach will be used.
312
+ int32_t ppl_output_type = 0; // = 0 -> ppl output is as usual, = 1 -> ppl output is num_tokens, ppl, one per line
313
+ // (which is more convenient to use for plotting)
314
+ //
315
+ bool hellaswag = false; // compute HellaSwag score over random tasks from datafile supplied in prompt
316
+ size_t hellaswag_tasks = 400; // number of tasks to use when computing the HellaSwag score
317
+
318
+ bool winogrande = false; // compute Winogrande score over random tasks from datafile supplied in prompt
319
+ size_t winogrande_tasks = 0; // number of tasks to use when computing the Winogrande score. If 0, all tasks will be computed
320
+
321
+ bool multiple_choice = false; // compute TruthfulQA score over random tasks from datafile supplied in prompt
322
+ size_t multiple_choice_tasks = 0; // number of tasks to use when computing the TruthfulQA score. If 0, all tasks will be computed
323
+
324
+ bool kl_divergence = false; // compute KL divergence
325
+
326
+ bool usage = false; // print usage
327
+ bool completion = false; // print source-able completion script
328
+ bool use_color = false; // use color to distinguish generations and inputs
329
+ bool special = false; // enable special token output
330
+ bool interactive = false; // interactive mode
331
+ bool interactive_first = false; // wait for user input immediately
332
+ bool prompt_cache_all = false; // save user input and generations to prompt cache
333
+ bool prompt_cache_ro = false; // open the prompt cache read-only and do not update it
334
+
335
+ bool escape = true; // escape "\n", "\r", "\t", "\'", "\"", and "\\"
336
+ bool multiline_input = false; // reverse the usage of `\`
337
+ bool simple_io = false; // improves compatibility with subprocesses and limited consoles
338
+ bool cont_batching = true; // insert new sequences for decoding on-the-fly
339
+ bool flash_attn = false; // flash attention
340
+ bool no_perf = false; // disable performance metrics
341
+ bool ctx_shift = true; // context shift on inifinite text generation
342
+
343
+ bool input_prefix_bos = false; // prefix BOS to user inputs, preceding input_prefix
344
+ bool logits_all = false; // return logits for all tokens in the batch
345
+ bool use_mmap = true; // use mmap for faster loads
346
+ bool use_mlock = false; // use mlock to keep model in memory
347
+ bool verbose_prompt = false; // print prompt tokens before generation
348
+ bool display_prompt = true; // print prompt before generation
349
+ bool dump_kv_cache = false; // dump the KV cache contents for debugging purposes
350
+ bool no_kv_offload = false; // disable KV offloading
351
+ bool warmup = true; // warmup run
352
+ bool check_tensors = false; // validate tensor data
353
+
354
+ bool single_turn = false; // single turn chat conversation
355
+
356
+ llama_progress_callback progress_callback = nullptr;
357
+ void * progress_callback_user_data = nullptr;
358
+
359
+ lm_ggml_type cache_type_k = LM_GGML_TYPE_F16; // KV cache data type for the K
360
+ lm_ggml_type cache_type_v = LM_GGML_TYPE_F16; // KV cache data type for the V
361
+
362
+ common_conversation_mode conversation_mode = COMMON_CONVERSATION_MODE_AUTO;
363
+
364
+ // multimodal models (see examples/llava)
365
+ std::string mmproj = ""; // path to multimodal projector // NOLINT
366
+ std::vector<std::string> image; // path to image file(s)
367
+
368
+ // embedding
369
+ bool embedding = false; // get only sentence embedding
370
+ int32_t embd_normalize = 2; // normalisation for embeddings (-1=none, 0=max absolute int16, 1=taxicab, 2=euclidean, >2=p-norm)
371
+ std::string embd_out = ""; // empty = default, "array" = [[],[]...], "json" = openai style, "json+" = same "json" + cosine similarity matrix
372
+ std::string embd_sep = "\n"; // separator of embeddings
373
+ bool reranking = false; // enable reranking support on server
374
+
375
+ // server params
376
+ int32_t port = 8080; // server listens on this network port
377
+ int32_t timeout_read = 600; // http read timeout in seconds
378
+ int32_t timeout_write = timeout_read; // http write timeout in seconds
379
+ int32_t n_threads_http = -1; // number of threads to process HTTP requests (TODO: support threadpool)
380
+ int32_t n_cache_reuse = 0; // min chunk size to reuse from the cache via KV shifting
381
+
382
+ std::string hostname = "127.0.0.1";
383
+ std::string public_path = ""; // NOLINT
384
+ std::string chat_template = ""; // NOLINT
385
+ bool use_jinja = false; // NOLINT
386
+ bool enable_chat_template = true;
387
+ common_reasoning_format reasoning_format = COMMON_REASONING_FORMAT_DEEPSEEK;
388
+
389
+ std::vector<std::string> api_keys;
390
+
391
+ std::string ssl_file_key = ""; // NOLINT
392
+ std::string ssl_file_cert = ""; // NOLINT
393
+
394
+ // "advanced" endpoints are disabled by default for better security
395
+ bool webui = true;
396
+ bool endpoint_slots = false;
397
+ bool endpoint_props = false; // only control POST requests, not GET
398
+ bool endpoint_metrics = false;
399
+
400
+ bool log_json = false;
401
+
402
+ std::string slot_save_path;
403
+
404
+ float slot_prompt_similarity = 0.5f;
405
+
406
+ // batched-bench params
407
+ bool is_pp_shared = false;
408
+
409
+ std::vector<int32_t> n_pp;
410
+ std::vector<int32_t> n_tg;
411
+ std::vector<int32_t> n_pl;
412
+
413
+ // retrieval params
414
+ std::vector<std::string> context_files; // context files to embed
415
+
416
+ int32_t chunk_size = 64; // chunk size for context embedding
417
+
418
+ std::string chunk_separator = "\n"; // chunk separator for context embedding
419
+
420
+ // passkey params
421
+ int32_t n_junk = 250; // number of times to repeat the junk text
422
+ int32_t i_pos = -1; // position of the passkey in the junk text
423
+
424
+ // imatrix params
425
+ int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations
426
+ int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations
427
+ int32_t i_chunk = 0; // start processing from this chunk
428
+
429
+ bool process_output = false; // collect data for the output tensor
430
+ bool compute_ppl = true; // whether to compute perplexity
431
+
432
+ // cvector-generator params
433
+ int n_pca_batch = 100;
434
+ int n_pca_iterations = 1000;
435
+ dimre_method cvector_dimre_method = DIMRE_METHOD_PCA;
436
+ std::string cvector_positive_file = "examples/cvector-generator/positive.txt";
437
+ std::string cvector_negative_file = "examples/cvector-generator/negative.txt";
438
+
439
+ bool spm_infill = false; // suffix/prefix/middle pattern for infill
440
+
441
+ // batched-bench params
442
+ bool batched_bench_output_jsonl = false;
443
+
444
+ // common params
445
+ std::string out_file; // output filename for all example programs
446
+ };
447
+
448
+ // call once at the start of a program if it uses libcommon
449
+ // initializes the logging system and prints info about the build
450
+ void common_init();
451
+
452
+ std::string common_params_get_system_info(const common_params & params);
453
+
454
+ bool parse_cpu_range(const std::string & range, bool(&boolmask)[LM_GGML_MAX_N_THREADS]);
455
+ bool parse_cpu_mask(const std::string & mask, bool(&boolmask)[LM_GGML_MAX_N_THREADS]);
456
+ void postprocess_cpu_params(cpu_params & cpuparams, const cpu_params * role_model = nullptr);
457
+ bool set_process_priority(enum lm_ggml_sched_priority prio);
458
+
459
+ //
460
+ // String utils
461
+ //
462
+
463
+ #ifdef __GNUC__
464
+ # if defined(__MINGW32__) && !defined(__clang__)
465
+ # define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
466
+ # else
467
+ # define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
468
+ # endif
469
+ #else
470
+ # define LLAMA_COMMON_ATTRIBUTE_FORMAT(...)
471
+ #endif
472
+
473
+ LLAMA_COMMON_ATTRIBUTE_FORMAT(1, 2)
474
+ std::string string_format(const char * fmt, ...);
475
+
476
+ std::string string_strip(const std::string & str);
477
+ std::string string_get_sortable_timestamp();
478
+
479
+ std::string string_join(const std::vector<std::string> & values, const std::string & separator);
480
+ std::vector<std::string> string_split(const std::string & str, const std::string & delimiter);
481
+ std::string string_repeat(const std::string & str, size_t n);
482
+
483
+ void string_replace_all(std::string & s, const std::string & search, const std::string & replace);
484
+
485
+ std::string regex_escape(const std::string & s);
486
+
487
+ template<class T>
488
+ static std::vector<T> string_split(const std::string & str, char delim) {
489
+ static_assert(!std::is_same<T, std::string>::value, "Please use the specialized version for std::string");
490
+ std::vector<T> values;
491
+ std::istringstream str_stream(str);
492
+ std::string token;
493
+ while (std::getline(str_stream, token, delim)) {
494
+ T value;
495
+ std::istringstream token_stream(token);
496
+ token_stream >> value;
497
+ values.push_back(value);
498
+ }
499
+ return values;
500
+ }
501
+
502
+ template<>
503
+ std::vector<std::string> string_split<std::string>(const std::string & input, char separator)
504
+ {
505
+ std::vector<std::string> parts;
506
+ size_t begin_pos = 0;
507
+ size_t separator_pos = input.find(separator);
508
+ while (separator_pos != std::string::npos) {
509
+ std::string part = input.substr(begin_pos, separator_pos - begin_pos);
510
+ parts.emplace_back(part);
511
+ begin_pos = separator_pos + 1;
512
+ separator_pos = input.find(separator, begin_pos);
513
+ }
514
+ parts.emplace_back(input.substr(begin_pos, separator_pos - begin_pos));
515
+ return parts;
516
+ }
517
+
518
+ static bool string_starts_with(const std::string & str,
519
+ const std::string & prefix) { // While we wait for C++20's std::string::starts_with...
520
+ return str.rfind(prefix, 0) == 0;
521
+ }
522
+
523
+ static bool string_ends_with(const std::string & str,
524
+ const std::string & suffix) { // While we wait for C++20's std::string::ends_with...
525
+ return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0;
526
+ }
527
+
528
+ bool string_parse_kv_override(const char * data, std::vector<llama_model_kv_override> & overrides);
529
+ void string_process_escapes(std::string & input);
530
+
531
+ std::string string_from(bool value);
532
+ std::string string_from(const std::vector<int> & values);
533
+ std::string string_from(const struct llama_context * ctx, const std::vector<llama_token> & tokens);
534
+ std::string string_from(const struct llama_context * ctx, const struct llama_batch & batch);
535
+
536
+ //
537
+ // Filesystem utils
538
+ //
539
+
540
+ bool fs_validate_filename(const std::string & filename);
541
+ bool fs_create_directory_with_parents(const std::string & path);
542
+
543
+ std::string fs_get_cache_directory();
544
+ std::string fs_get_cache_file(const std::string & filename);
545
+
546
+ //
547
+ // Model utils
548
+ //
549
+
550
+ // note: defines object's lifetime
551
+ struct common_init_result {
552
+ llama_model_ptr model;
553
+ llama_context_ptr context;
554
+
555
+ std::vector<llama_adapter_lora_ptr> lora;
556
+ };
557
+
558
+ struct common_init_result common_init_from_params(common_params & params);
559
+
560
+ struct llama_model_params common_model_params_to_llama ( common_params & params);
561
+ struct llama_context_params common_context_params_to_llama(const common_params & params);
562
+ struct lm_ggml_threadpool_params lm_ggml_threadpool_params_from_cpu_params(const cpu_params & params);
563
+
564
+ // clear LoRA adapters from context, then apply new list of adapters
565
+ void common_set_adapter_lora(struct llama_context * ctx, std::vector<common_adapter_lora_info> & lora);
566
+
567
+ //
568
+ // Batch utils
569
+ //
570
+
571
+ void common_batch_clear(struct llama_batch & batch);
572
+
573
+ void common_batch_add(
574
+ struct llama_batch & batch,
575
+ llama_token id,
576
+ llama_pos pos,
577
+ const std::vector<llama_seq_id> & seq_ids,
578
+ bool logits);
579
+
580
+ //
581
+ // Token utils
582
+ //
583
+
584
+ // longest common prefix
585
+ size_t common_lcp(const llama_tokens & a, const llama_tokens & b);
586
+
587
+ // longet common subsequence
588
+ size_t common_lcs(const llama_tokens & a, const llama_tokens & b);
589
+
590
+ //
591
+ // Vocab utils
592
+ //
593
+
594
+ // tokenizes a string into a vector of tokens
595
+ // should work similar to Python's `tokenizer.encode`
596
+ std::vector<llama_token> common_tokenize(
597
+ const struct llama_context * ctx,
598
+ const std::string & text,
599
+ bool add_special,
600
+ bool parse_special = false);
601
+
602
+ std::vector<llama_token> common_tokenize(
603
+ const struct llama_vocab * vocab,
604
+ const std::string & text,
605
+ bool add_special,
606
+ bool parse_special = false);
607
+
608
+ // tokenizes a token into a piece, optionally renders special/control tokens
609
+ // should work similar to Python's `tokenizer.id_to_piece`
610
+ std::string common_token_to_piece(
611
+ const struct llama_context * ctx,
612
+ llama_token token,
613
+ bool special = true);
614
+
615
+ std::string common_token_to_piece(
616
+ const struct llama_vocab * vocab,
617
+ llama_token token,
618
+ bool special = true);
619
+
620
+ // detokenizes a vector of tokens into a string
621
+ // should work similar to Python's `tokenizer.decode`
622
+ // optionally renders special/control tokens
623
+ std::string common_detokenize(
624
+ const struct llama_context * ctx,
625
+ const std::vector<llama_token> & tokens,
626
+ bool special = true);
627
+
628
+ std::string common_detokenize(
629
+ const struct llama_vocab * vocab,
630
+ const std::vector<llama_token> & tokens,
631
+ bool special = true);
632
+
633
+ //
634
+ // KV cache utils
635
+ //
636
+
637
+ // Dump the KV cache view with the number of sequences per cell.
638
+ void common_kv_cache_dump_view(const llama_kv_cache_view & view, int row_size = 80);
639
+
640
+ // Dump the KV cache view showing individual sequences in each cell (long output).
641
+ void common_kv_cache_dump_view_seqs(const llama_kv_cache_view & view, int row_size = 40);
642
+
643
+ //
644
+ // Embedding utils
645
+ //
646
+
647
+ // TODO: repace embd_norm with an enum
648
+ void common_embd_normalize(const float * inp, float * out, int n, int embd_norm);
649
+
650
+ float common_embd_similarity_cos(const float * embd1, const float * embd2, int n);
651
+
652
+ //
653
+ // Control vector utils
654
+ //
655
+
656
+ struct common_control_vector_data {
657
+ int n_embd;
658
+
659
+ // stores data for layers [1, n_layer] where n_layer = data.size() / n_embd
660
+ std::vector<float> data;
661
+ };
662
+
663
+ struct common_control_vector_load_info {
664
+ float strength;
665
+
666
+ std::string fname;
667
+ };
668
+
669
+ // Load control vectors, scale each by strength, and add them together.
670
+ // On error, returns {-1, empty}
671
+ common_control_vector_data common_control_vector_load(const std::vector<common_control_vector_load_info> & load_infos);
672
+
673
+ //
674
+ // Split utils
675
+ //
676
+
677
+ namespace {
678
+
679
+ const char * const LLM_KV_SPLIT_NO = "split.no";
680
+ const char * const LLM_KV_SPLIT_COUNT = "split.count";
681
+ const char * const LLM_KV_SPLIT_TENSORS_COUNT = "split.tensors.count";
682
+
683
+ }