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,2221 @@
1
+ #pragma once
2
+
3
+ //
4
+ // GGML Tensor Library
5
+ //
6
+ // This documentation is still a work in progress.
7
+ // If you wish some specific topics to be covered, feel free to drop a comment:
8
+ //
9
+ // https://github.com/ggerganov/whisper.cpp/issues/40
10
+ //
11
+ // ## Overview
12
+ //
13
+ // This library implements:
14
+ //
15
+ // - a set of tensor operations
16
+ // - automatic differentiation
17
+ // - basic optimization algorithms
18
+ //
19
+ // The aim of this library is to provide a minimalistic approach for various machine learning tasks. This includes,
20
+ // but is not limited to, the following:
21
+ //
22
+ // - linear regression
23
+ // - support vector machines
24
+ // - neural networks
25
+ //
26
+ // The library allows the user to define a certain function using the available tensor operations. This function
27
+ // definition is represented internally via a computation graph. Each tensor operation in the function definition
28
+ // corresponds to a node in the graph. Having the computation graph defined, the user can choose to compute the
29
+ // function's value and/or its gradient with respect to the input variables. Optionally, the function can be optimized
30
+ // using one of the available optimization algorithms.
31
+ //
32
+ // For example, here we define the function: f(x) = a*x^2 + b
33
+ //
34
+ // {
35
+ // struct lm_ggml_init_params params = {
36
+ // .mem_size = 16*1024*1024,
37
+ // .mem_buffer = NULL,
38
+ // };
39
+ //
40
+ // // memory allocation happens here
41
+ // struct lm_ggml_context * ctx = lm_ggml_init(params);
42
+ //
43
+ // struct lm_ggml_tensor * x = lm_ggml_new_tensor_1d(ctx, LM_GGML_TYPE_F32, 1);
44
+ //
45
+ // lm_ggml_set_param(ctx, x); // x is an input variable
46
+ //
47
+ // struct lm_ggml_tensor * a = lm_ggml_new_tensor_1d(ctx, LM_GGML_TYPE_F32, 1);
48
+ // struct lm_ggml_tensor * b = lm_ggml_new_tensor_1d(ctx, LM_GGML_TYPE_F32, 1);
49
+ // struct lm_ggml_tensor * x2 = lm_ggml_mul(ctx, x, x);
50
+ // struct lm_ggml_tensor * f = lm_ggml_add(ctx, lm_ggml_mul(ctx, a, x2), b);
51
+ //
52
+ // ...
53
+ // }
54
+ //
55
+ // Notice that the function definition above does not involve any actual computation. The computation is performed only
56
+ // when the user explicitly requests it. For example, to compute the function's value at x = 2.0:
57
+ //
58
+ // {
59
+ // ...
60
+ //
61
+ // struct lm_ggml_cgraph * gf = lm_ggml_new_graph(ctx);
62
+ // lm_ggml_build_forward_expand(gf, f);
63
+ //
64
+ // // set the input variable and parameter values
65
+ // lm_ggml_set_f32(x, 2.0f);
66
+ // lm_ggml_set_f32(a, 3.0f);
67
+ // lm_ggml_set_f32(b, 4.0f);
68
+ //
69
+ // lm_ggml_graph_compute_with_ctx(ctx, &gf, n_threads);
70
+ //
71
+ // printf("f = %f\n", lm_ggml_get_f32_1d(f, 0));
72
+ //
73
+ // ...
74
+ // }
75
+ //
76
+ // The actual computation is performed in the lm_ggml_graph_compute() function.
77
+ //
78
+ // The lm_ggml_new_tensor_...() functions create new tensors. They are allocated in the memory buffer provided to the
79
+ // lm_ggml_init() function. You have to be careful not to exceed the memory buffer size. Therefore, you have to know
80
+ // in advance how much memory you need for your computation. Alternatively, you can allocate a large enough memory
81
+ // and after defining the computation graph, call the lm_ggml_used_mem() function to find out how much memory was
82
+ // actually needed.
83
+ //
84
+ // The lm_ggml_set_param() function marks a tensor as an input variable. This is used by the automatic
85
+ // differentiation and optimization algorithms.
86
+ //
87
+ // The described approach allows to define the function graph once and then compute its forward or backward graphs
88
+ // multiple times. All computations will use the same memory buffer allocated in the lm_ggml_init() function. This way
89
+ // the user can avoid the memory allocation overhead at runtime.
90
+ //
91
+ // The library supports multi-dimensional tensors - up to 4 dimensions. The FP16 and FP32 data types are first class
92
+ // citizens, but in theory the library can be extended to support FP8 and integer data types.
93
+ //
94
+ // Each tensor operation produces a new tensor. Initially the library was envisioned to support only the use of unary
95
+ // and binary operations. Most of the available operations fall into one of these two categories. With time, it became
96
+ // clear that the library needs to support more complex operations. The way to support these operations is not clear
97
+ // yet, but a few examples are demonstrated in the following operations:
98
+ //
99
+ // - lm_ggml_permute()
100
+ // - lm_ggml_conv_1d_1s()
101
+ // - lm_ggml_conv_1d_2s()
102
+ //
103
+ // For each tensor operator, the library implements a forward and backward computation function. The forward function
104
+ // computes the output tensor value given the input tensor values. The backward function computes the adjoint of the
105
+ // input tensors given the adjoint of the output tensor. For a detailed explanation of what this means, take a
106
+ // calculus class, or watch the following video:
107
+ //
108
+ // What is Automatic Differentiation?
109
+ // https://www.youtube.com/watch?v=wG_nF1awSSY
110
+ //
111
+ //
112
+ // ## Tensor data (struct lm_ggml_tensor)
113
+ //
114
+ // The tensors are stored in memory via the lm_ggml_tensor struct. The structure provides information about the size of
115
+ // the tensor, the data type, and the memory buffer where the tensor data is stored. Additionally, it contains
116
+ // pointers to the "source" tensors - i.e. the tensors that were used to compute the current tensor. For example:
117
+ //
118
+ // {
119
+ // struct lm_ggml_tensor * c = lm_ggml_add(ctx, a, b);
120
+ //
121
+ // assert(c->src[0] == a);
122
+ // assert(c->src[1] == b);
123
+ // }
124
+ //
125
+ // The multi-dimensional tensors are stored in row-major order. The lm_ggml_tensor struct contains fields for the
126
+ // number of elements in each dimension ("ne") as well as the number of bytes ("nb", a.k.a. stride). This allows
127
+ // to store tensors that are not contiguous in memory, which is useful for operations such as transposition and
128
+ // permutation. All tensor operations have to take the stride into account and not assume that the tensor is
129
+ // contiguous in memory.
130
+ //
131
+ // The data of the tensor is accessed via the "data" pointer. For example:
132
+ //
133
+ // {
134
+ // const int nx = 2;
135
+ // const int ny = 3;
136
+ //
137
+ // struct lm_ggml_tensor * a = lm_ggml_new_tensor_2d(ctx, LM_GGML_TYPE_F32, nx, ny);
138
+ //
139
+ // for (int y = 0; y < ny; y++) {
140
+ // for (int x = 0; x < nx; x++) {
141
+ // *(float *) ((char *) a->data + y*a->nb[1] + x*a->nb[0]) = x + y;
142
+ // }
143
+ // }
144
+ //
145
+ // ...
146
+ // }
147
+ //
148
+ // Alternatively, there are helper functions, such as lm_ggml_get_f32_1d() and lm_ggml_set_f32_1d() that can be used.
149
+ //
150
+ // ## The matrix multiplication operator (lm_ggml_mul_mat)
151
+ //
152
+ // TODO
153
+ //
154
+ //
155
+ // ## Multi-threading
156
+ //
157
+ // TODO
158
+ //
159
+ //
160
+ // ## Overview of ggml.c
161
+ //
162
+ // TODO
163
+ //
164
+ //
165
+ // ## SIMD optimizations
166
+ //
167
+ // TODO
168
+ //
169
+ //
170
+ // ## Debugging ggml
171
+ //
172
+ // TODO
173
+ //
174
+ //
175
+
176
+ #ifdef LM_GGML_SHARED
177
+ # if defined(_WIN32) && !defined(__MINGW32__)
178
+ # ifdef LM_GGML_BUILD
179
+ # define LM_GGML_API __declspec(dllexport) extern
180
+ # else
181
+ # define LM_GGML_API __declspec(dllimport) extern
182
+ # endif
183
+ # else
184
+ # define LM_GGML_API __attribute__ ((visibility ("default"))) extern
185
+ # endif
186
+ #else
187
+ # define LM_GGML_API extern
188
+ #endif
189
+
190
+ // TODO: support for clang
191
+ #ifdef __GNUC__
192
+ # define LM_GGML_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
193
+ #elif defined(_MSC_VER)
194
+ # define LM_GGML_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
195
+ #else
196
+ # define LM_GGML_DEPRECATED(func, hint) func
197
+ #endif
198
+
199
+ #ifndef __GNUC__
200
+ # define LM_GGML_ATTRIBUTE_FORMAT(...)
201
+ #elif defined(__MINGW32__) && !defined(__clang__)
202
+ # define LM_GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
203
+ #else
204
+ # define LM_GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
205
+ #endif
206
+
207
+ #include <stdbool.h>
208
+ #include <stddef.h>
209
+ #include <stdint.h>
210
+ #include <stdio.h>
211
+
212
+ #define LM_GGML_FILE_MAGIC 0x67676d6c // "ggml"
213
+ #define LM_GGML_FILE_VERSION 2
214
+
215
+ #define LM_GGML_QNT_VERSION 2 // bump this on quantization format changes
216
+ #define LM_GGML_QNT_VERSION_FACTOR 1000 // do not change this
217
+
218
+ #define LM_GGML_MAX_DIMS 4
219
+ #define LM_GGML_MAX_PARAMS 2048
220
+ #define LM_GGML_MAX_SRC 10
221
+ #define LM_GGML_MAX_N_THREADS 512
222
+ #define LM_GGML_MAX_OP_PARAMS 64
223
+
224
+ #ifndef LM_GGML_MAX_NAME
225
+ # define LM_GGML_MAX_NAME 64
226
+ #endif
227
+
228
+ #define LM_GGML_DEFAULT_N_THREADS 4
229
+ #define LM_GGML_DEFAULT_GRAPH_SIZE 2048
230
+
231
+ #if UINTPTR_MAX == 0xFFFFFFFF
232
+ #define LM_GGML_MEM_ALIGN 4
233
+ #else
234
+ #define LM_GGML_MEM_ALIGN 16
235
+ #endif
236
+
237
+ #define LM_GGML_EXIT_SUCCESS 0
238
+ #define LM_GGML_EXIT_ABORTED 1
239
+
240
+ #define LM_GGML_ROPE_TYPE_NEOX 2
241
+ #define LM_GGML_ROPE_TYPE_MROPE 8
242
+ #define LM_GGML_ROPE_TYPE_VISION 24
243
+
244
+ #define LM_GGML_UNUSED(x) (void)(x)
245
+
246
+ #define LM_GGML_PAD(x, n) (((x) + (n) - 1) & ~((n) - 1))
247
+
248
+ #ifndef NDEBUG
249
+ # define LM_GGML_UNREACHABLE() do { fprintf(stderr, "statement should be unreachable\n"); abort(); } while(0)
250
+ #elif defined(__GNUC__)
251
+ # define LM_GGML_UNREACHABLE() __builtin_unreachable()
252
+ #elif defined(_MSC_VER)
253
+ # define LM_GGML_UNREACHABLE() __assume(0)
254
+ #else
255
+ # define LM_GGML_UNREACHABLE() ((void) 0)
256
+ #endif
257
+
258
+ #ifdef __cplusplus
259
+ # define LM_GGML_NORETURN [[noreturn]]
260
+ #elif defined(_MSC_VER)
261
+ # define LM_GGML_NORETURN __declspec(noreturn)
262
+ #else
263
+ # define LM_GGML_NORETURN _Noreturn
264
+ #endif
265
+
266
+ #define LM_GGML_ABORT(...) lm_ggml_abort(__FILE__, __LINE__, __VA_ARGS__)
267
+ #define LM_GGML_ASSERT(x) if (!(x)) LM_GGML_ABORT("LM_GGML_ASSERT(%s) failed", #x)
268
+
269
+ // used to copy the number of elements and stride in bytes of tensors into local variables.
270
+ // main purpose is to reduce code duplication and improve readability.
271
+ //
272
+ // example:
273
+ //
274
+ // LM_GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne);
275
+ // LM_GGML_TENSOR_LOCALS(size_t, nb1, src1, nb);
276
+ //
277
+ #define LM_GGML_TENSOR_LOCALS_1(type, prefix, pointer, array) \
278
+ const type prefix##0 = (pointer)->array[0]; \
279
+ LM_GGML_UNUSED(prefix##0);
280
+ #define LM_GGML_TENSOR_LOCALS_2(type, prefix, pointer, array) \
281
+ LM_GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array) \
282
+ const type prefix##1 = (pointer)->array[1]; \
283
+ LM_GGML_UNUSED(prefix##1);
284
+ #define LM_GGML_TENSOR_LOCALS_3(type, prefix, pointer, array) \
285
+ LM_GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array) \
286
+ const type prefix##2 = (pointer)->array[2]; \
287
+ LM_GGML_UNUSED(prefix##2);
288
+ #define LM_GGML_TENSOR_LOCALS(type, prefix, pointer, array) \
289
+ LM_GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array) \
290
+ const type prefix##3 = (pointer)->array[3]; \
291
+ LM_GGML_UNUSED(prefix##3);
292
+
293
+ #define LM_GGML_TENSOR_UNARY_OP_LOCALS \
294
+ LM_GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
295
+ LM_GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
296
+ LM_GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
297
+ LM_GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
298
+
299
+ #define LM_GGML_TENSOR_BINARY_OP_LOCALS \
300
+ LM_GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
301
+ LM_GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
302
+ LM_GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
303
+ LM_GGML_TENSOR_LOCALS(size_t, nb1, src1, nb) \
304
+ LM_GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
305
+ LM_GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
306
+
307
+ #define LM_GGML_TENSOR_BINARY_OP_LOCALS01 \
308
+ LM_GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
309
+ LM_GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
310
+ LM_GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
311
+ LM_GGML_TENSOR_LOCALS(size_t, nb1, src1, nb)
312
+
313
+ #ifdef __cplusplus
314
+ extern "C" {
315
+ #endif
316
+
317
+ LM_GGML_NORETURN LM_GGML_ATTRIBUTE_FORMAT(3, 4)
318
+ LM_GGML_API void lm_ggml_abort(const char * file, int line, const char * fmt, ...);
319
+
320
+ enum lm_ggml_status {
321
+ LM_GGML_STATUS_ALLOC_FAILED = -2,
322
+ LM_GGML_STATUS_FAILED = -1,
323
+ LM_GGML_STATUS_SUCCESS = 0,
324
+ LM_GGML_STATUS_ABORTED = 1,
325
+ };
326
+
327
+ // get lm_ggml_status name string
328
+ LM_GGML_API const char * lm_ggml_status_to_string(enum lm_ggml_status status);
329
+
330
+ // ieee 754-2008 half-precision float16
331
+ // todo: make this not an integral type
332
+ typedef uint16_t lm_ggml_fp16_t;
333
+ LM_GGML_API float lm_ggml_fp16_to_fp32(lm_ggml_fp16_t);
334
+ LM_GGML_API lm_ggml_fp16_t lm_ggml_fp32_to_fp16(float);
335
+ LM_GGML_API void lm_ggml_fp16_to_fp32_row(const lm_ggml_fp16_t *, float *, int64_t);
336
+ LM_GGML_API void lm_ggml_fp32_to_fp16_row(const float *, lm_ggml_fp16_t *, int64_t);
337
+
338
+ // google brain half-precision bfloat16
339
+ typedef struct { uint16_t bits; } lm_ggml_bf16_t;
340
+ LM_GGML_API lm_ggml_bf16_t lm_ggml_fp32_to_bf16(float);
341
+ LM_GGML_API float lm_ggml_bf16_to_fp32(lm_ggml_bf16_t); // consider just doing << 16
342
+ LM_GGML_API void lm_ggml_bf16_to_fp32_row(const lm_ggml_bf16_t *, float *, int64_t);
343
+ LM_GGML_API void lm_ggml_fp32_to_bf16_row_ref(const float *, lm_ggml_bf16_t *, int64_t);
344
+ LM_GGML_API void lm_ggml_fp32_to_bf16_row(const float *, lm_ggml_bf16_t *, int64_t);
345
+
346
+ struct lm_ggml_object;
347
+ struct lm_ggml_context;
348
+ struct lm_ggml_cgraph;
349
+
350
+ // NOTE: always add types at the end of the enum to keep backward compatibility
351
+ enum lm_ggml_type {
352
+ LM_GGML_TYPE_F32 = 0,
353
+ LM_GGML_TYPE_F16 = 1,
354
+ LM_GGML_TYPE_Q4_0 = 2,
355
+ LM_GGML_TYPE_Q4_1 = 3,
356
+ // LM_GGML_TYPE_Q4_2 = 4, support has been removed
357
+ // LM_GGML_TYPE_Q4_3 = 5, support has been removed
358
+ LM_GGML_TYPE_Q5_0 = 6,
359
+ LM_GGML_TYPE_Q5_1 = 7,
360
+ LM_GGML_TYPE_Q8_0 = 8,
361
+ LM_GGML_TYPE_Q8_1 = 9,
362
+ LM_GGML_TYPE_Q2_K = 10,
363
+ LM_GGML_TYPE_Q3_K = 11,
364
+ LM_GGML_TYPE_Q4_K = 12,
365
+ LM_GGML_TYPE_Q5_K = 13,
366
+ LM_GGML_TYPE_Q6_K = 14,
367
+ LM_GGML_TYPE_Q8_K = 15,
368
+ LM_GGML_TYPE_IQ2_XXS = 16,
369
+ LM_GGML_TYPE_IQ2_XS = 17,
370
+ LM_GGML_TYPE_IQ3_XXS = 18,
371
+ LM_GGML_TYPE_IQ1_S = 19,
372
+ LM_GGML_TYPE_IQ4_NL = 20,
373
+ LM_GGML_TYPE_IQ3_S = 21,
374
+ LM_GGML_TYPE_IQ2_S = 22,
375
+ LM_GGML_TYPE_IQ4_XS = 23,
376
+ LM_GGML_TYPE_I8 = 24,
377
+ LM_GGML_TYPE_I16 = 25,
378
+ LM_GGML_TYPE_I32 = 26,
379
+ LM_GGML_TYPE_I64 = 27,
380
+ LM_GGML_TYPE_F64 = 28,
381
+ LM_GGML_TYPE_IQ1_M = 29,
382
+ LM_GGML_TYPE_BF16 = 30,
383
+ // LM_GGML_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files
384
+ // LM_GGML_TYPE_Q4_0_4_8 = 32,
385
+ // LM_GGML_TYPE_Q4_0_8_8 = 33,
386
+ LM_GGML_TYPE_TQ1_0 = 34,
387
+ LM_GGML_TYPE_TQ2_0 = 35,
388
+ // LM_GGML_TYPE_IQ4_NL_4_4 = 36,
389
+ // LM_GGML_TYPE_IQ4_NL_4_8 = 37,
390
+ // LM_GGML_TYPE_IQ4_NL_8_8 = 38,
391
+ LM_GGML_TYPE_COUNT = 39,
392
+ };
393
+
394
+ // precision
395
+ enum lm_ggml_prec {
396
+ LM_GGML_PREC_DEFAULT,
397
+ LM_GGML_PREC_F32,
398
+ };
399
+
400
+ // model file types
401
+ enum lm_ggml_ftype {
402
+ LM_GGML_FTYPE_UNKNOWN = -1,
403
+ LM_GGML_FTYPE_ALL_F32 = 0,
404
+ LM_GGML_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
405
+ LM_GGML_FTYPE_MOSTLY_Q4_0 = 2, // except 1d tensors
406
+ LM_GGML_FTYPE_MOSTLY_Q4_1 = 3, // except 1d tensors
407
+ LM_GGML_FTYPE_MOSTLY_Q4_1_SOME_F16 = 4, // tok_embeddings.weight and output.weight are F16
408
+ LM_GGML_FTYPE_MOSTLY_Q8_0 = 7, // except 1d tensors
409
+ LM_GGML_FTYPE_MOSTLY_Q5_0 = 8, // except 1d tensors
410
+ LM_GGML_FTYPE_MOSTLY_Q5_1 = 9, // except 1d tensors
411
+ LM_GGML_FTYPE_MOSTLY_Q2_K = 10, // except 1d tensors
412
+ LM_GGML_FTYPE_MOSTLY_Q3_K = 11, // except 1d tensors
413
+ LM_GGML_FTYPE_MOSTLY_Q4_K = 12, // except 1d tensors
414
+ LM_GGML_FTYPE_MOSTLY_Q5_K = 13, // except 1d tensors
415
+ LM_GGML_FTYPE_MOSTLY_Q6_K = 14, // except 1d tensors
416
+ LM_GGML_FTYPE_MOSTLY_IQ2_XXS = 15, // except 1d tensors
417
+ LM_GGML_FTYPE_MOSTLY_IQ2_XS = 16, // except 1d tensors
418
+ LM_GGML_FTYPE_MOSTLY_IQ3_XXS = 17, // except 1d tensors
419
+ LM_GGML_FTYPE_MOSTLY_IQ1_S = 18, // except 1d tensors
420
+ LM_GGML_FTYPE_MOSTLY_IQ4_NL = 19, // except 1d tensors
421
+ LM_GGML_FTYPE_MOSTLY_IQ3_S = 20, // except 1d tensors
422
+ LM_GGML_FTYPE_MOSTLY_IQ2_S = 21, // except 1d tensors
423
+ LM_GGML_FTYPE_MOSTLY_IQ4_XS = 22, // except 1d tensors
424
+ LM_GGML_FTYPE_MOSTLY_IQ1_M = 23, // except 1d tensors
425
+ LM_GGML_FTYPE_MOSTLY_BF16 = 24, // except 1d tensors
426
+ };
427
+
428
+ // available tensor operations:
429
+ enum lm_ggml_op {
430
+ LM_GGML_OP_NONE = 0,
431
+
432
+ LM_GGML_OP_DUP,
433
+ LM_GGML_OP_ADD,
434
+ LM_GGML_OP_ADD1,
435
+ LM_GGML_OP_ACC,
436
+ LM_GGML_OP_SUB,
437
+ LM_GGML_OP_MUL,
438
+ LM_GGML_OP_DIV,
439
+ LM_GGML_OP_SQR,
440
+ LM_GGML_OP_SQRT,
441
+ LM_GGML_OP_LOG,
442
+ LM_GGML_OP_SIN,
443
+ LM_GGML_OP_COS,
444
+ LM_GGML_OP_SUM,
445
+ LM_GGML_OP_SUM_ROWS,
446
+ LM_GGML_OP_MEAN,
447
+ LM_GGML_OP_ARGMAX,
448
+ LM_GGML_OP_COUNT_EQUAL,
449
+ LM_GGML_OP_REPEAT,
450
+ LM_GGML_OP_REPEAT_BACK,
451
+ LM_GGML_OP_CONCAT,
452
+ LM_GGML_OP_SILU_BACK,
453
+ LM_GGML_OP_NORM, // normalize
454
+ LM_GGML_OP_RMS_NORM,
455
+ LM_GGML_OP_RMS_NORM_BACK,
456
+ LM_GGML_OP_GROUP_NORM,
457
+ LM_GGML_OP_L2_NORM,
458
+
459
+ LM_GGML_OP_MUL_MAT,
460
+ LM_GGML_OP_MUL_MAT_ID,
461
+ LM_GGML_OP_OUT_PROD,
462
+
463
+ LM_GGML_OP_SCALE,
464
+ LM_GGML_OP_SET,
465
+ LM_GGML_OP_CPY,
466
+ LM_GGML_OP_CONT,
467
+ LM_GGML_OP_RESHAPE,
468
+ LM_GGML_OP_VIEW,
469
+ LM_GGML_OP_PERMUTE,
470
+ LM_GGML_OP_TRANSPOSE,
471
+ LM_GGML_OP_GET_ROWS,
472
+ LM_GGML_OP_GET_ROWS_BACK,
473
+ LM_GGML_OP_DIAG,
474
+ LM_GGML_OP_DIAG_MASK_INF,
475
+ LM_GGML_OP_DIAG_MASK_ZERO,
476
+ LM_GGML_OP_SOFT_MAX,
477
+ LM_GGML_OP_SOFT_MAX_BACK,
478
+ LM_GGML_OP_ROPE,
479
+ LM_GGML_OP_ROPE_BACK,
480
+ LM_GGML_OP_CLAMP,
481
+ LM_GGML_OP_CONV_TRANSPOSE_1D,
482
+ LM_GGML_OP_IM2COL,
483
+ LM_GGML_OP_IM2COL_BACK,
484
+ LM_GGML_OP_CONV_TRANSPOSE_2D,
485
+ LM_GGML_OP_POOL_1D,
486
+ LM_GGML_OP_POOL_2D,
487
+ LM_GGML_OP_POOL_2D_BACK,
488
+ LM_GGML_OP_UPSCALE, // nearest interpolate
489
+ LM_GGML_OP_PAD,
490
+ LM_GGML_OP_PAD_REFLECT_1D,
491
+ LM_GGML_OP_ARANGE,
492
+ LM_GGML_OP_TIMESTEP_EMBEDDING,
493
+ LM_GGML_OP_ARGSORT,
494
+ LM_GGML_OP_LEAKY_RELU,
495
+
496
+ LM_GGML_OP_FLASH_ATTN_EXT,
497
+ LM_GGML_OP_FLASH_ATTN_BACK,
498
+ LM_GGML_OP_SSM_CONV,
499
+ LM_GGML_OP_SSM_SCAN,
500
+ LM_GGML_OP_WIN_PART,
501
+ LM_GGML_OP_WIN_UNPART,
502
+ LM_GGML_OP_GET_REL_POS,
503
+ LM_GGML_OP_ADD_REL_POS,
504
+ LM_GGML_OP_RWKV_WKV6,
505
+ LM_GGML_OP_GATED_LINEAR_ATTN,
506
+ LM_GGML_OP_RWKV_WKV7,
507
+
508
+ LM_GGML_OP_UNARY,
509
+
510
+ LM_GGML_OP_MAP_UNARY,
511
+ LM_GGML_OP_MAP_BINARY,
512
+
513
+ LM_GGML_OP_MAP_CUSTOM1_F32,
514
+ LM_GGML_OP_MAP_CUSTOM2_F32,
515
+ LM_GGML_OP_MAP_CUSTOM3_F32,
516
+
517
+ LM_GGML_OP_MAP_CUSTOM1,
518
+ LM_GGML_OP_MAP_CUSTOM2,
519
+ LM_GGML_OP_MAP_CUSTOM3,
520
+
521
+ LM_GGML_OP_CROSS_ENTROPY_LOSS,
522
+ LM_GGML_OP_CROSS_ENTROPY_LOSS_BACK,
523
+ LM_GGML_OP_OPT_STEP_ADAMW,
524
+
525
+ LM_GGML_OP_COUNT,
526
+ };
527
+
528
+ enum lm_ggml_unary_op {
529
+ LM_GGML_UNARY_OP_ABS,
530
+ LM_GGML_UNARY_OP_SGN,
531
+ LM_GGML_UNARY_OP_NEG,
532
+ LM_GGML_UNARY_OP_STEP,
533
+ LM_GGML_UNARY_OP_TANH,
534
+ LM_GGML_UNARY_OP_ELU,
535
+ LM_GGML_UNARY_OP_RELU,
536
+ LM_GGML_UNARY_OP_SIGMOID,
537
+ LM_GGML_UNARY_OP_GELU,
538
+ LM_GGML_UNARY_OP_GELU_QUICK,
539
+ LM_GGML_UNARY_OP_SILU,
540
+ LM_GGML_UNARY_OP_HARDSWISH,
541
+ LM_GGML_UNARY_OP_HARDSIGMOID,
542
+ LM_GGML_UNARY_OP_EXP,
543
+
544
+ LM_GGML_UNARY_OP_COUNT,
545
+ };
546
+
547
+ enum lm_ggml_object_type {
548
+ LM_GGML_OBJECT_TYPE_TENSOR,
549
+ LM_GGML_OBJECT_TYPE_GRAPH,
550
+ LM_GGML_OBJECT_TYPE_WORK_BUFFER
551
+ };
552
+
553
+ enum lm_ggml_log_level {
554
+ LM_GGML_LOG_LEVEL_NONE = 0,
555
+ LM_GGML_LOG_LEVEL_DEBUG = 1,
556
+ LM_GGML_LOG_LEVEL_INFO = 2,
557
+ LM_GGML_LOG_LEVEL_WARN = 3,
558
+ LM_GGML_LOG_LEVEL_ERROR = 4,
559
+ LM_GGML_LOG_LEVEL_CONT = 5, // continue previous log
560
+ };
561
+
562
+ // this tensor...
563
+ enum lm_ggml_tensor_flag {
564
+ LM_GGML_TENSOR_FLAG_INPUT = 1, // ...is an input for the GGML compute graph
565
+ LM_GGML_TENSOR_FLAG_OUTPUT = 2, // ...is an output for the GGML compute graph
566
+ LM_GGML_TENSOR_FLAG_PARAM = 4, // ...contains trainable parameters
567
+ LM_GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
568
+ };
569
+
570
+ struct lm_ggml_init_params {
571
+ // memory pool
572
+ size_t mem_size; // bytes
573
+ void * mem_buffer; // if NULL, memory will be allocated internally
574
+ bool no_alloc; // don't allocate memory for the tensor data
575
+ };
576
+
577
+ // n-dimensional tensor
578
+ struct lm_ggml_tensor {
579
+ enum lm_ggml_type type;
580
+
581
+ struct lm_ggml_backend_buffer * buffer;
582
+
583
+ int64_t ne[LM_GGML_MAX_DIMS]; // number of elements
584
+ size_t nb[LM_GGML_MAX_DIMS]; // stride in bytes:
585
+ // nb[0] = lm_ggml_type_size(type)
586
+ // nb[1] = nb[0] * (ne[0] / lm_ggml_blck_size(type)) + padding
587
+ // nb[i] = nb[i-1] * ne[i-1]
588
+
589
+ // compute data
590
+ enum lm_ggml_op op;
591
+
592
+ // op params - allocated as int32_t for alignment
593
+ int32_t op_params[LM_GGML_MAX_OP_PARAMS / sizeof(int32_t)];
594
+
595
+ int32_t flags;
596
+
597
+ struct lm_ggml_tensor * src[LM_GGML_MAX_SRC];
598
+
599
+ // source tensor and offset for views
600
+ struct lm_ggml_tensor * view_src;
601
+ size_t view_offs;
602
+
603
+ void * data;
604
+
605
+ char name[LM_GGML_MAX_NAME];
606
+
607
+ void * extra; // extra things e.g. for ggml-cuda.cu
608
+
609
+ char padding[8];
610
+ };
611
+
612
+ static const size_t LM_GGML_TENSOR_SIZE = sizeof(struct lm_ggml_tensor);
613
+
614
+ // Abort callback
615
+ // If not NULL, called before ggml computation
616
+ // If it returns true, the computation is aborted
617
+ typedef bool (*lm_ggml_abort_callback)(void * data);
618
+
619
+
620
+ //
621
+ // GUID
622
+ //
623
+
624
+ // GUID types
625
+ typedef uint8_t lm_ggml_guid[16];
626
+ typedef lm_ggml_guid * lm_ggml_guid_t;
627
+
628
+ LM_GGML_API bool lm_ggml_guid_matches(lm_ggml_guid_t guid_a, lm_ggml_guid_t guid_b);
629
+
630
+ // misc
631
+
632
+ LM_GGML_API void lm_ggml_time_init(void); // call this once at the beginning of the program
633
+ LM_GGML_API int64_t lm_ggml_time_ms(void);
634
+ LM_GGML_API int64_t lm_ggml_time_us(void);
635
+ LM_GGML_API int64_t lm_ggml_cycles(void);
636
+ LM_GGML_API int64_t lm_ggml_cycles_per_ms(void);
637
+
638
+ // accepts a UTF-8 path, even on Windows
639
+ LM_GGML_API FILE * lm_ggml_fopen(const char * fname, const char * mode);
640
+
641
+ LM_GGML_API void lm_ggml_print_object (const struct lm_ggml_object * obj);
642
+ LM_GGML_API void lm_ggml_print_objects(const struct lm_ggml_context * ctx);
643
+
644
+ LM_GGML_API int64_t lm_ggml_nelements (const struct lm_ggml_tensor * tensor);
645
+ LM_GGML_API int64_t lm_ggml_nrows (const struct lm_ggml_tensor * tensor);
646
+ LM_GGML_API size_t lm_ggml_nbytes (const struct lm_ggml_tensor * tensor);
647
+ LM_GGML_API size_t lm_ggml_nbytes_pad(const struct lm_ggml_tensor * tensor); // same as lm_ggml_nbytes() but padded to LM_GGML_MEM_ALIGN
648
+
649
+ LM_GGML_API int64_t lm_ggml_blck_size(enum lm_ggml_type type);
650
+ LM_GGML_API size_t lm_ggml_type_size(enum lm_ggml_type type); // size in bytes for all elements in a block
651
+ LM_GGML_API size_t lm_ggml_row_size (enum lm_ggml_type type, int64_t ne); // size in bytes for all elements in a row
652
+
653
+ LM_GGML_DEPRECATED(
654
+ LM_GGML_API double lm_ggml_type_sizef(enum lm_ggml_type type), // lm_ggml_type_size()/lm_ggml_blck_size() as float
655
+ "use lm_ggml_row_size() instead");
656
+
657
+ LM_GGML_API const char * lm_ggml_type_name(enum lm_ggml_type type);
658
+ LM_GGML_API const char * lm_ggml_op_name (enum lm_ggml_op op);
659
+ LM_GGML_API const char * lm_ggml_op_symbol(enum lm_ggml_op op);
660
+
661
+ LM_GGML_API const char * lm_ggml_unary_op_name(enum lm_ggml_unary_op op);
662
+ LM_GGML_API const char * lm_ggml_op_desc(const struct lm_ggml_tensor * t); // unary or op name
663
+
664
+ LM_GGML_API size_t lm_ggml_element_size(const struct lm_ggml_tensor * tensor);
665
+
666
+ LM_GGML_API bool lm_ggml_is_quantized(enum lm_ggml_type type);
667
+
668
+ // TODO: temporary until model loading of ggml examples is refactored
669
+ LM_GGML_API enum lm_ggml_type lm_ggml_ftype_to_lm_ggml_type(enum lm_ggml_ftype ftype);
670
+
671
+ LM_GGML_API bool lm_ggml_is_transposed(const struct lm_ggml_tensor * tensor);
672
+ LM_GGML_API bool lm_ggml_is_permuted (const struct lm_ggml_tensor * tensor);
673
+ LM_GGML_API bool lm_ggml_is_empty (const struct lm_ggml_tensor * tensor);
674
+ LM_GGML_API bool lm_ggml_is_scalar (const struct lm_ggml_tensor * tensor);
675
+ LM_GGML_API bool lm_ggml_is_vector (const struct lm_ggml_tensor * tensor);
676
+ LM_GGML_API bool lm_ggml_is_matrix (const struct lm_ggml_tensor * tensor);
677
+ LM_GGML_API bool lm_ggml_is_3d (const struct lm_ggml_tensor * tensor);
678
+ LM_GGML_API int lm_ggml_n_dims (const struct lm_ggml_tensor * tensor); // returns 1 for scalars
679
+
680
+ LM_GGML_API bool lm_ggml_is_contiguous (const struct lm_ggml_tensor * tensor);
681
+ LM_GGML_API bool lm_ggml_is_contiguous_0(const struct lm_ggml_tensor * tensor); // same as lm_ggml_is_contiguous()
682
+ LM_GGML_API bool lm_ggml_is_contiguous_1(const struct lm_ggml_tensor * tensor); // contiguous for dims >= 1
683
+ LM_GGML_API bool lm_ggml_is_contiguous_2(const struct lm_ggml_tensor * tensor); // contiguous for dims >= 2
684
+
685
+ LM_GGML_API bool lm_ggml_are_same_shape (const struct lm_ggml_tensor * t0, const struct lm_ggml_tensor * t1);
686
+ LM_GGML_API bool lm_ggml_are_same_stride(const struct lm_ggml_tensor * t0, const struct lm_ggml_tensor * t1);
687
+
688
+ LM_GGML_API bool lm_ggml_can_repeat(const struct lm_ggml_tensor * t0, const struct lm_ggml_tensor * t1);
689
+
690
+ // use this to compute the memory overhead of a tensor
691
+ LM_GGML_API size_t lm_ggml_tensor_overhead(void);
692
+
693
+ LM_GGML_API bool lm_ggml_validate_row_data(enum lm_ggml_type type, const void * data, size_t nbytes);
694
+
695
+ // main
696
+
697
+ LM_GGML_API struct lm_ggml_context * lm_ggml_init (struct lm_ggml_init_params params);
698
+ LM_GGML_API void lm_ggml_reset(struct lm_ggml_context * ctx);
699
+ LM_GGML_API void lm_ggml_free (struct lm_ggml_context * ctx);
700
+
701
+ LM_GGML_API size_t lm_ggml_used_mem(const struct lm_ggml_context * ctx);
702
+
703
+ LM_GGML_API bool lm_ggml_get_no_alloc(struct lm_ggml_context * ctx);
704
+ LM_GGML_API void lm_ggml_set_no_alloc(struct lm_ggml_context * ctx, bool no_alloc);
705
+
706
+ LM_GGML_API void * lm_ggml_get_mem_buffer (const struct lm_ggml_context * ctx);
707
+ LM_GGML_API size_t lm_ggml_get_mem_size (const struct lm_ggml_context * ctx);
708
+ LM_GGML_API size_t lm_ggml_get_max_tensor_size(const struct lm_ggml_context * ctx);
709
+
710
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_new_tensor(
711
+ struct lm_ggml_context * ctx,
712
+ enum lm_ggml_type type,
713
+ int n_dims,
714
+ const int64_t *ne);
715
+
716
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_new_tensor_1d(
717
+ struct lm_ggml_context * ctx,
718
+ enum lm_ggml_type type,
719
+ int64_t ne0);
720
+
721
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_new_tensor_2d(
722
+ struct lm_ggml_context * ctx,
723
+ enum lm_ggml_type type,
724
+ int64_t ne0,
725
+ int64_t ne1);
726
+
727
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_new_tensor_3d(
728
+ struct lm_ggml_context * ctx,
729
+ enum lm_ggml_type type,
730
+ int64_t ne0,
731
+ int64_t ne1,
732
+ int64_t ne2);
733
+
734
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_new_tensor_4d(
735
+ struct lm_ggml_context * ctx,
736
+ enum lm_ggml_type type,
737
+ int64_t ne0,
738
+ int64_t ne1,
739
+ int64_t ne2,
740
+ int64_t ne3);
741
+
742
+ LM_GGML_API void * lm_ggml_new_buffer(struct lm_ggml_context * ctx, size_t nbytes);
743
+
744
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_dup_tensor (struct lm_ggml_context * ctx, const struct lm_ggml_tensor * src);
745
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_view_tensor(struct lm_ggml_context * ctx, struct lm_ggml_tensor * src);
746
+
747
+ // Context tensor enumeration and lookup
748
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_first_tensor(const struct lm_ggml_context * ctx);
749
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_next_tensor (const struct lm_ggml_context * ctx, struct lm_ggml_tensor * tensor);
750
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_tensor(struct lm_ggml_context * ctx, const char * name);
751
+
752
+ // Converts a flat index into coordinates
753
+ LM_GGML_API void lm_ggml_unravel_index(const struct lm_ggml_tensor * tensor, int64_t i, int64_t * i0, int64_t * i1, int64_t * i2, int64_t * i3);
754
+
755
+ LM_GGML_API enum lm_ggml_unary_op lm_ggml_get_unary_op(const struct lm_ggml_tensor * tensor);
756
+
757
+ LM_GGML_API void * lm_ggml_get_data (const struct lm_ggml_tensor * tensor);
758
+ LM_GGML_API float * lm_ggml_get_data_f32(const struct lm_ggml_tensor * tensor);
759
+
760
+ LM_GGML_API const char * lm_ggml_get_name (const struct lm_ggml_tensor * tensor);
761
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_name ( struct lm_ggml_tensor * tensor, const char * name);
762
+ LM_GGML_ATTRIBUTE_FORMAT(2, 3)
763
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_format_name( struct lm_ggml_tensor * tensor, const char * fmt, ...);
764
+
765
+ // Tensor flags
766
+ LM_GGML_API void lm_ggml_set_input(struct lm_ggml_tensor * tensor);
767
+ LM_GGML_API void lm_ggml_set_output(struct lm_ggml_tensor * tensor);
768
+ LM_GGML_API void lm_ggml_set_param(struct lm_ggml_context * ctx, struct lm_ggml_tensor * tensor);
769
+ LM_GGML_API void lm_ggml_set_loss(struct lm_ggml_tensor * tensor);
770
+
771
+ //
772
+ // operations on tensors with backpropagation
773
+ //
774
+
775
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_dup(
776
+ struct lm_ggml_context * ctx,
777
+ struct lm_ggml_tensor * a);
778
+
779
+ // in-place, returns view(a)
780
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_dup_inplace(
781
+ struct lm_ggml_context * ctx,
782
+ struct lm_ggml_tensor * a);
783
+
784
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add(
785
+ struct lm_ggml_context * ctx,
786
+ struct lm_ggml_tensor * a,
787
+ struct lm_ggml_tensor * b);
788
+
789
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add_inplace(
790
+ struct lm_ggml_context * ctx,
791
+ struct lm_ggml_tensor * a,
792
+ struct lm_ggml_tensor * b);
793
+
794
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add_cast(
795
+ struct lm_ggml_context * ctx,
796
+ struct lm_ggml_tensor * a,
797
+ struct lm_ggml_tensor * b,
798
+ enum lm_ggml_type type);
799
+
800
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add1(
801
+ struct lm_ggml_context * ctx,
802
+ struct lm_ggml_tensor * a,
803
+ struct lm_ggml_tensor * b);
804
+
805
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add1_inplace(
806
+ struct lm_ggml_context * ctx,
807
+ struct lm_ggml_tensor * a,
808
+ struct lm_ggml_tensor * b);
809
+
810
+ // dst = a
811
+ // view(dst, nb1, nb2, nb3, offset) += b
812
+ // return dst
813
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_acc(
814
+ struct lm_ggml_context * ctx,
815
+ struct lm_ggml_tensor * a,
816
+ struct lm_ggml_tensor * b,
817
+ size_t nb1,
818
+ size_t nb2,
819
+ size_t nb3,
820
+ size_t offset);
821
+
822
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_acc_inplace(
823
+ struct lm_ggml_context * ctx,
824
+ struct lm_ggml_tensor * a,
825
+ struct lm_ggml_tensor * b,
826
+ size_t nb1,
827
+ size_t nb2,
828
+ size_t nb3,
829
+ size_t offset);
830
+
831
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sub(
832
+ struct lm_ggml_context * ctx,
833
+ struct lm_ggml_tensor * a,
834
+ struct lm_ggml_tensor * b);
835
+
836
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sub_inplace(
837
+ struct lm_ggml_context * ctx,
838
+ struct lm_ggml_tensor * a,
839
+ struct lm_ggml_tensor * b);
840
+
841
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_mul(
842
+ struct lm_ggml_context * ctx,
843
+ struct lm_ggml_tensor * a,
844
+ struct lm_ggml_tensor * b);
845
+
846
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_mul_inplace(
847
+ struct lm_ggml_context * ctx,
848
+ struct lm_ggml_tensor * a,
849
+ struct lm_ggml_tensor * b);
850
+
851
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_div(
852
+ struct lm_ggml_context * ctx,
853
+ struct lm_ggml_tensor * a,
854
+ struct lm_ggml_tensor * b);
855
+
856
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_div_inplace(
857
+ struct lm_ggml_context * ctx,
858
+ struct lm_ggml_tensor * a,
859
+ struct lm_ggml_tensor * b);
860
+
861
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sqr(
862
+ struct lm_ggml_context * ctx,
863
+ struct lm_ggml_tensor * a);
864
+
865
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sqr_inplace(
866
+ struct lm_ggml_context * ctx,
867
+ struct lm_ggml_tensor * a);
868
+
869
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sqrt(
870
+ struct lm_ggml_context * ctx,
871
+ struct lm_ggml_tensor * a);
872
+
873
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sqrt_inplace(
874
+ struct lm_ggml_context * ctx,
875
+ struct lm_ggml_tensor * a);
876
+
877
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_log(
878
+ struct lm_ggml_context * ctx,
879
+ struct lm_ggml_tensor * a);
880
+
881
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_log_inplace(
882
+ struct lm_ggml_context * ctx,
883
+ struct lm_ggml_tensor * a);
884
+
885
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sin(
886
+ struct lm_ggml_context * ctx,
887
+ struct lm_ggml_tensor * a);
888
+
889
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sin_inplace(
890
+ struct lm_ggml_context * ctx,
891
+ struct lm_ggml_tensor * a);
892
+
893
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cos(
894
+ struct lm_ggml_context * ctx,
895
+ struct lm_ggml_tensor * a);
896
+
897
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cos_inplace(
898
+ struct lm_ggml_context * ctx,
899
+ struct lm_ggml_tensor * a);
900
+
901
+ // return scalar
902
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sum(
903
+ struct lm_ggml_context * ctx,
904
+ struct lm_ggml_tensor * a);
905
+
906
+ // sums along rows, with input shape [a,b,c,d] return shape [1,b,c,d]
907
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sum_rows(
908
+ struct lm_ggml_context * ctx,
909
+ struct lm_ggml_tensor * a);
910
+
911
+ // mean along rows
912
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_mean(
913
+ struct lm_ggml_context * ctx,
914
+ struct lm_ggml_tensor * a);
915
+
916
+ // argmax along rows
917
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_argmax(
918
+ struct lm_ggml_context * ctx,
919
+ struct lm_ggml_tensor * a);
920
+
921
+ // count number of equal elements in a and b
922
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_count_equal(
923
+ struct lm_ggml_context * ctx,
924
+ struct lm_ggml_tensor * a,
925
+ struct lm_ggml_tensor * b);
926
+
927
+ // if a is the same shape as b, and a is not parameter, return a
928
+ // otherwise, return a new tensor: repeat(a) to fit in b
929
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_repeat(
930
+ struct lm_ggml_context * ctx,
931
+ struct lm_ggml_tensor * a,
932
+ struct lm_ggml_tensor * b);
933
+
934
+ // sums repetitions in a into shape of b
935
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_repeat_back(
936
+ struct lm_ggml_context * ctx,
937
+ struct lm_ggml_tensor * a,
938
+ struct lm_ggml_tensor * b);
939
+
940
+ // concat a and b along dim
941
+ // used in stable-diffusion
942
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_concat(
943
+ struct lm_ggml_context * ctx,
944
+ struct lm_ggml_tensor * a,
945
+ struct lm_ggml_tensor * b,
946
+ int dim);
947
+
948
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_abs(
949
+ struct lm_ggml_context * ctx,
950
+ struct lm_ggml_tensor * a);
951
+
952
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_abs_inplace(
953
+ struct lm_ggml_context * ctx,
954
+ struct lm_ggml_tensor * a);
955
+
956
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sgn(
957
+ struct lm_ggml_context * ctx,
958
+ struct lm_ggml_tensor * a);
959
+
960
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sgn_inplace(
961
+ struct lm_ggml_context * ctx,
962
+ struct lm_ggml_tensor * a);
963
+
964
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_neg(
965
+ struct lm_ggml_context * ctx,
966
+ struct lm_ggml_tensor * a);
967
+
968
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_neg_inplace(
969
+ struct lm_ggml_context * ctx,
970
+ struct lm_ggml_tensor * a);
971
+
972
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_step(
973
+ struct lm_ggml_context * ctx,
974
+ struct lm_ggml_tensor * a);
975
+
976
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_step_inplace(
977
+ struct lm_ggml_context * ctx,
978
+ struct lm_ggml_tensor * a);
979
+
980
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_tanh(
981
+ struct lm_ggml_context * ctx,
982
+ struct lm_ggml_tensor * a);
983
+
984
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_tanh_inplace(
985
+ struct lm_ggml_context * ctx,
986
+ struct lm_ggml_tensor * a);
987
+
988
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_elu(
989
+ struct lm_ggml_context * ctx,
990
+ struct lm_ggml_tensor * a);
991
+
992
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_elu_inplace(
993
+ struct lm_ggml_context * ctx,
994
+ struct lm_ggml_tensor * a);
995
+
996
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_relu(
997
+ struct lm_ggml_context * ctx,
998
+ struct lm_ggml_tensor * a);
999
+
1000
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_leaky_relu(
1001
+ struct lm_ggml_context * ctx,
1002
+ struct lm_ggml_tensor * a, float negative_slope, bool inplace);
1003
+
1004
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_relu_inplace(
1005
+ struct lm_ggml_context * ctx,
1006
+ struct lm_ggml_tensor * a);
1007
+
1008
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sigmoid(
1009
+ struct lm_ggml_context * ctx,
1010
+ struct lm_ggml_tensor * a);
1011
+
1012
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_sigmoid_inplace(
1013
+ struct lm_ggml_context * ctx,
1014
+ struct lm_ggml_tensor * a);
1015
+
1016
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_gelu(
1017
+ struct lm_ggml_context * ctx,
1018
+ struct lm_ggml_tensor * a);
1019
+
1020
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_gelu_inplace(
1021
+ struct lm_ggml_context * ctx,
1022
+ struct lm_ggml_tensor * a);
1023
+
1024
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_gelu_quick(
1025
+ struct lm_ggml_context * ctx,
1026
+ struct lm_ggml_tensor * a);
1027
+
1028
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_gelu_quick_inplace(
1029
+ struct lm_ggml_context * ctx,
1030
+ struct lm_ggml_tensor * a);
1031
+
1032
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_silu(
1033
+ struct lm_ggml_context * ctx,
1034
+ struct lm_ggml_tensor * a);
1035
+
1036
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_silu_inplace(
1037
+ struct lm_ggml_context * ctx,
1038
+ struct lm_ggml_tensor * a);
1039
+
1040
+ // a - x
1041
+ // b - dy
1042
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_silu_back(
1043
+ struct lm_ggml_context * ctx,
1044
+ struct lm_ggml_tensor * a,
1045
+ struct lm_ggml_tensor * b);
1046
+
1047
+ // hardswish(x) = x * relu6(x + 3) / 6
1048
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_hardswish(
1049
+ struct lm_ggml_context * ctx,
1050
+ struct lm_ggml_tensor * a);
1051
+
1052
+ // hardsigmoid(x) = relu6(x + 3) / 6
1053
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_hardsigmoid(
1054
+ struct lm_ggml_context * ctx,
1055
+ struct lm_ggml_tensor * a);
1056
+
1057
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_exp(
1058
+ struct lm_ggml_context * ctx,
1059
+ struct lm_ggml_tensor * a);
1060
+
1061
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_exp_inplace(
1062
+ struct lm_ggml_context * ctx,
1063
+ struct lm_ggml_tensor * a);
1064
+
1065
+ // normalize along rows
1066
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_norm(
1067
+ struct lm_ggml_context * ctx,
1068
+ struct lm_ggml_tensor * a,
1069
+ float eps);
1070
+
1071
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_norm_inplace(
1072
+ struct lm_ggml_context * ctx,
1073
+ struct lm_ggml_tensor * a,
1074
+ float eps);
1075
+
1076
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rms_norm(
1077
+ struct lm_ggml_context * ctx,
1078
+ struct lm_ggml_tensor * a,
1079
+ float eps);
1080
+
1081
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rms_norm_inplace(
1082
+ struct lm_ggml_context * ctx,
1083
+ struct lm_ggml_tensor * a,
1084
+ float eps);
1085
+
1086
+ // group normalize along ne0*ne1*n_groups
1087
+ // used in stable-diffusion
1088
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_group_norm(
1089
+ struct lm_ggml_context * ctx,
1090
+ struct lm_ggml_tensor * a,
1091
+ int n_groups,
1092
+ float eps);
1093
+
1094
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_group_norm_inplace(
1095
+ struct lm_ggml_context * ctx,
1096
+ struct lm_ggml_tensor * a,
1097
+ int n_groups,
1098
+ float eps);
1099
+
1100
+ // l2 normalize along rows
1101
+ // used in rwkv v7
1102
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_l2_norm(
1103
+ struct lm_ggml_context * ctx,
1104
+ struct lm_ggml_tensor * a,
1105
+ float eps);
1106
+
1107
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_l2_norm_inplace(
1108
+ struct lm_ggml_context * ctx,
1109
+ struct lm_ggml_tensor * a,
1110
+ float eps);
1111
+
1112
+ // a - x
1113
+ // b - dy
1114
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rms_norm_back(
1115
+ struct lm_ggml_context * ctx,
1116
+ struct lm_ggml_tensor * a,
1117
+ struct lm_ggml_tensor * b,
1118
+ float eps);
1119
+
1120
+ // A: k columns, n rows => [ne03, ne02, n, k]
1121
+ // B: k columns, m rows (i.e. we transpose it internally) => [ne03 * x, ne02 * y, m, k]
1122
+ // result is n columns, m rows => [ne03 * x, ne02 * y, m, n]
1123
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_mul_mat(
1124
+ struct lm_ggml_context * ctx,
1125
+ struct lm_ggml_tensor * a,
1126
+ struct lm_ggml_tensor * b);
1127
+
1128
+ // change the precision of a matrix multiplication
1129
+ // set to LM_GGML_PREC_F32 for higher precision (useful for phi-2)
1130
+ LM_GGML_API void lm_ggml_mul_mat_set_prec(
1131
+ struct lm_ggml_tensor * a,
1132
+ enum lm_ggml_prec prec);
1133
+
1134
+ // indirect matrix multiplication
1135
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_mul_mat_id(
1136
+ struct lm_ggml_context * ctx,
1137
+ struct lm_ggml_tensor * as,
1138
+ struct lm_ggml_tensor * b,
1139
+ struct lm_ggml_tensor * ids);
1140
+
1141
+ // A: m columns, n rows,
1142
+ // B: p columns, n rows,
1143
+ // result is m columns, p rows
1144
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_out_prod(
1145
+ struct lm_ggml_context * ctx,
1146
+ struct lm_ggml_tensor * a,
1147
+ struct lm_ggml_tensor * b);
1148
+
1149
+ //
1150
+ // operations on tensors without backpropagation
1151
+ //
1152
+
1153
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_scale(
1154
+ struct lm_ggml_context * ctx,
1155
+ struct lm_ggml_tensor * a,
1156
+ float s);
1157
+
1158
+ // in-place, returns view(a)
1159
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_scale_inplace(
1160
+ struct lm_ggml_context * ctx,
1161
+ struct lm_ggml_tensor * a,
1162
+ float s);
1163
+
1164
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1165
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set(
1166
+ struct lm_ggml_context * ctx,
1167
+ struct lm_ggml_tensor * a,
1168
+ struct lm_ggml_tensor * b,
1169
+ size_t nb1,
1170
+ size_t nb2,
1171
+ size_t nb3,
1172
+ size_t offset); // in bytes
1173
+
1174
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1175
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_inplace(
1176
+ struct lm_ggml_context * ctx,
1177
+ struct lm_ggml_tensor * a,
1178
+ struct lm_ggml_tensor * b,
1179
+ size_t nb1,
1180
+ size_t nb2,
1181
+ size_t nb3,
1182
+ size_t offset); // in bytes
1183
+
1184
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_1d(
1185
+ struct lm_ggml_context * ctx,
1186
+ struct lm_ggml_tensor * a,
1187
+ struct lm_ggml_tensor * b,
1188
+ size_t offset); // in bytes
1189
+
1190
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_1d_inplace(
1191
+ struct lm_ggml_context * ctx,
1192
+ struct lm_ggml_tensor * a,
1193
+ struct lm_ggml_tensor * b,
1194
+ size_t offset); // in bytes
1195
+
1196
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1197
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_2d(
1198
+ struct lm_ggml_context * ctx,
1199
+ struct lm_ggml_tensor * a,
1200
+ struct lm_ggml_tensor * b,
1201
+ size_t nb1,
1202
+ size_t offset); // in bytes
1203
+
1204
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1205
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_2d_inplace(
1206
+ struct lm_ggml_context * ctx,
1207
+ struct lm_ggml_tensor * a,
1208
+ struct lm_ggml_tensor * b,
1209
+ size_t nb1,
1210
+ size_t offset); // in bytes
1211
+
1212
+ // a -> b, return view(b)
1213
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cpy(
1214
+ struct lm_ggml_context * ctx,
1215
+ struct lm_ggml_tensor * a,
1216
+ struct lm_ggml_tensor * b);
1217
+
1218
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cast(
1219
+ struct lm_ggml_context * ctx,
1220
+ struct lm_ggml_tensor * a,
1221
+ enum lm_ggml_type type);
1222
+
1223
+ // make contiguous
1224
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cont(
1225
+ struct lm_ggml_context * ctx,
1226
+ struct lm_ggml_tensor * a);
1227
+
1228
+ // make contiguous, with new shape
1229
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cont_1d(
1230
+ struct lm_ggml_context * ctx,
1231
+ struct lm_ggml_tensor * a,
1232
+ int64_t ne0);
1233
+
1234
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cont_2d(
1235
+ struct lm_ggml_context * ctx,
1236
+ struct lm_ggml_tensor * a,
1237
+ int64_t ne0,
1238
+ int64_t ne1);
1239
+
1240
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cont_3d(
1241
+ struct lm_ggml_context * ctx,
1242
+ struct lm_ggml_tensor * a,
1243
+ int64_t ne0,
1244
+ int64_t ne1,
1245
+ int64_t ne2);
1246
+
1247
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cont_4d(
1248
+ struct lm_ggml_context * ctx,
1249
+ struct lm_ggml_tensor * a,
1250
+ int64_t ne0,
1251
+ int64_t ne1,
1252
+ int64_t ne2,
1253
+ int64_t ne3);
1254
+
1255
+ // return view(a), b specifies the new shape
1256
+ // TODO: when we start computing gradient, make a copy instead of view
1257
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_reshape(
1258
+ struct lm_ggml_context * ctx,
1259
+ struct lm_ggml_tensor * a,
1260
+ struct lm_ggml_tensor * b);
1261
+
1262
+ // return view(a)
1263
+ // TODO: when we start computing gradient, make a copy instead of view
1264
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_reshape_1d(
1265
+ struct lm_ggml_context * ctx,
1266
+ struct lm_ggml_tensor * a,
1267
+ int64_t ne0);
1268
+
1269
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_reshape_2d(
1270
+ struct lm_ggml_context * ctx,
1271
+ struct lm_ggml_tensor * a,
1272
+ int64_t ne0,
1273
+ int64_t ne1);
1274
+
1275
+ // return view(a)
1276
+ // TODO: when we start computing gradient, make a copy instead of view
1277
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_reshape_3d(
1278
+ struct lm_ggml_context * ctx,
1279
+ struct lm_ggml_tensor * a,
1280
+ int64_t ne0,
1281
+ int64_t ne1,
1282
+ int64_t ne2);
1283
+
1284
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_reshape_4d(
1285
+ struct lm_ggml_context * ctx,
1286
+ struct lm_ggml_tensor * a,
1287
+ int64_t ne0,
1288
+ int64_t ne1,
1289
+ int64_t ne2,
1290
+ int64_t ne3);
1291
+
1292
+ // offset in bytes
1293
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_view_1d(
1294
+ struct lm_ggml_context * ctx,
1295
+ struct lm_ggml_tensor * a,
1296
+ int64_t ne0,
1297
+ size_t offset);
1298
+
1299
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_view_2d(
1300
+ struct lm_ggml_context * ctx,
1301
+ struct lm_ggml_tensor * a,
1302
+ int64_t ne0,
1303
+ int64_t ne1,
1304
+ size_t nb1, // row stride in bytes
1305
+ size_t offset);
1306
+
1307
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_view_3d(
1308
+ struct lm_ggml_context * ctx,
1309
+ struct lm_ggml_tensor * a,
1310
+ int64_t ne0,
1311
+ int64_t ne1,
1312
+ int64_t ne2,
1313
+ size_t nb1, // row stride in bytes
1314
+ size_t nb2, // slice stride in bytes
1315
+ size_t offset);
1316
+
1317
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_view_4d(
1318
+ struct lm_ggml_context * ctx,
1319
+ struct lm_ggml_tensor * a,
1320
+ int64_t ne0,
1321
+ int64_t ne1,
1322
+ int64_t ne2,
1323
+ int64_t ne3,
1324
+ size_t nb1, // row stride in bytes
1325
+ size_t nb2, // slice stride in bytes
1326
+ size_t nb3,
1327
+ size_t offset);
1328
+
1329
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_permute(
1330
+ struct lm_ggml_context * ctx,
1331
+ struct lm_ggml_tensor * a,
1332
+ int axis0,
1333
+ int axis1,
1334
+ int axis2,
1335
+ int axis3);
1336
+
1337
+ // alias for lm_ggml_permute(ctx, a, 1, 0, 2, 3)
1338
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_transpose(
1339
+ struct lm_ggml_context * ctx,
1340
+ struct lm_ggml_tensor * a);
1341
+
1342
+ // supports 3D: a->ne[2] == b->ne[1]
1343
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_rows(
1344
+ struct lm_ggml_context * ctx,
1345
+ struct lm_ggml_tensor * a, // data
1346
+ struct lm_ggml_tensor * b); // row indices
1347
+
1348
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_rows_back(
1349
+ struct lm_ggml_context * ctx,
1350
+ struct lm_ggml_tensor * a, // gradients of lm_ggml_get_rows result
1351
+ struct lm_ggml_tensor * b, // row indices
1352
+ struct lm_ggml_tensor * c); // data for lm_ggml_get_rows, only used for its shape
1353
+
1354
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_diag(
1355
+ struct lm_ggml_context * ctx,
1356
+ struct lm_ggml_tensor * a);
1357
+
1358
+ // set elements above the diagonal to -INF
1359
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_diag_mask_inf(
1360
+ struct lm_ggml_context * ctx,
1361
+ struct lm_ggml_tensor * a,
1362
+ int n_past);
1363
+
1364
+ // in-place, returns view(a)
1365
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_diag_mask_inf_inplace(
1366
+ struct lm_ggml_context * ctx,
1367
+ struct lm_ggml_tensor * a,
1368
+ int n_past);
1369
+
1370
+ // set elements above the diagonal to 0
1371
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_diag_mask_zero(
1372
+ struct lm_ggml_context * ctx,
1373
+ struct lm_ggml_tensor * a,
1374
+ int n_past);
1375
+
1376
+ // in-place, returns view(a)
1377
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_diag_mask_zero_inplace(
1378
+ struct lm_ggml_context * ctx,
1379
+ struct lm_ggml_tensor * a,
1380
+ int n_past);
1381
+
1382
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_soft_max(
1383
+ struct lm_ggml_context * ctx,
1384
+ struct lm_ggml_tensor * a);
1385
+
1386
+ // in-place, returns view(a)
1387
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_soft_max_inplace(
1388
+ struct lm_ggml_context * ctx,
1389
+ struct lm_ggml_tensor * a);
1390
+
1391
+ // fused soft_max(a*scale + mask*(ALiBi slope))
1392
+ // mask is optional
1393
+ // max_bias = 0.0f for no ALiBi
1394
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_soft_max_ext(
1395
+ struct lm_ggml_context * ctx,
1396
+ struct lm_ggml_tensor * a,
1397
+ struct lm_ggml_tensor * mask,
1398
+ float scale,
1399
+ float max_bias);
1400
+
1401
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_soft_max_ext_back(
1402
+ struct lm_ggml_context * ctx,
1403
+ struct lm_ggml_tensor * a,
1404
+ struct lm_ggml_tensor * b,
1405
+ float scale,
1406
+ float max_bias);
1407
+
1408
+ // in-place, returns view(a)
1409
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_soft_max_ext_back_inplace(
1410
+ struct lm_ggml_context * ctx,
1411
+ struct lm_ggml_tensor * a,
1412
+ struct lm_ggml_tensor * b,
1413
+ float scale,
1414
+ float max_bias);
1415
+
1416
+ // rotary position embedding
1417
+ // if (mode & 1) - skip n_past elements (NOT SUPPORTED)
1418
+ // if (mode & LM_GGML_ROPE_TYPE_NEOX) - GPT-NeoX style
1419
+ //
1420
+ // b is an int32 vector with size a->ne[2], it contains the positions
1421
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope(
1422
+ struct lm_ggml_context * ctx,
1423
+ struct lm_ggml_tensor * a,
1424
+ struct lm_ggml_tensor * b,
1425
+ int n_dims,
1426
+ int mode);
1427
+
1428
+ // in-place, returns view(a)
1429
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_inplace(
1430
+ struct lm_ggml_context * ctx,
1431
+ struct lm_ggml_tensor * a,
1432
+ struct lm_ggml_tensor * b,
1433
+ int n_dims,
1434
+ int mode);
1435
+
1436
+ // custom RoPE
1437
+ // c is freq factors (e.g. phi3-128k), (optional)
1438
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_ext(
1439
+ struct lm_ggml_context * ctx,
1440
+ struct lm_ggml_tensor * a,
1441
+ struct lm_ggml_tensor * b,
1442
+ struct lm_ggml_tensor * c,
1443
+ int n_dims,
1444
+ int mode,
1445
+ int n_ctx_orig,
1446
+ float freq_base,
1447
+ float freq_scale,
1448
+ float ext_factor,
1449
+ float attn_factor,
1450
+ float beta_fast,
1451
+ float beta_slow);
1452
+
1453
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_multi(
1454
+ struct lm_ggml_context * ctx,
1455
+ struct lm_ggml_tensor * a,
1456
+ struct lm_ggml_tensor * b,
1457
+ struct lm_ggml_tensor * c,
1458
+ int n_dims,
1459
+ int sections[4],
1460
+ int mode,
1461
+ int n_ctx_orig,
1462
+ float freq_base,
1463
+ float freq_scale,
1464
+ float ext_factor,
1465
+ float attn_factor,
1466
+ float beta_fast,
1467
+ float beta_slow);
1468
+
1469
+ // in-place, returns view(a)
1470
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_ext_inplace(
1471
+ struct lm_ggml_context * ctx,
1472
+ struct lm_ggml_tensor * a,
1473
+ struct lm_ggml_tensor * b,
1474
+ struct lm_ggml_tensor * c,
1475
+ int n_dims,
1476
+ int mode,
1477
+ int n_ctx_orig,
1478
+ float freq_base,
1479
+ float freq_scale,
1480
+ float ext_factor,
1481
+ float attn_factor,
1482
+ float beta_fast,
1483
+ float beta_slow);
1484
+
1485
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_custom(
1486
+ struct lm_ggml_context * ctx,
1487
+ struct lm_ggml_tensor * a,
1488
+ struct lm_ggml_tensor * b,
1489
+ int n_dims,
1490
+ int mode,
1491
+ int n_ctx_orig,
1492
+ float freq_base,
1493
+ float freq_scale,
1494
+ float ext_factor,
1495
+ float attn_factor,
1496
+ float beta_fast,
1497
+ float beta_slow),
1498
+ "use lm_ggml_rope_ext instead");
1499
+
1500
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_custom_inplace(
1501
+ struct lm_ggml_context * ctx,
1502
+ struct lm_ggml_tensor * a,
1503
+ struct lm_ggml_tensor * b,
1504
+ int n_dims,
1505
+ int mode,
1506
+ int n_ctx_orig,
1507
+ float freq_base,
1508
+ float freq_scale,
1509
+ float ext_factor,
1510
+ float attn_factor,
1511
+ float beta_fast,
1512
+ float beta_slow),
1513
+ "use lm_ggml_rope_ext_inplace instead");
1514
+
1515
+ // compute correction dims for YaRN RoPE scaling
1516
+ LM_GGML_API void lm_ggml_rope_yarn_corr_dims(
1517
+ int n_dims, int n_ctx_orig, float freq_base, float beta_fast, float beta_slow, float dims[2]);
1518
+
1519
+ // rotary position embedding backward, i.e compute dx from dy
1520
+ // a - dy
1521
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_ext_back(
1522
+ struct lm_ggml_context * ctx,
1523
+ struct lm_ggml_tensor * a, // gradients of lm_ggml_rope result
1524
+ struct lm_ggml_tensor * b, // positions
1525
+ struct lm_ggml_tensor * c, // freq factors
1526
+ int n_dims,
1527
+ int mode,
1528
+ int n_ctx_orig,
1529
+ float freq_base,
1530
+ float freq_scale,
1531
+ float ext_factor,
1532
+ float attn_factor,
1533
+ float beta_fast,
1534
+ float beta_slow);
1535
+
1536
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rope_multi_back(
1537
+ struct lm_ggml_context * ctx,
1538
+ struct lm_ggml_tensor * a,
1539
+ struct lm_ggml_tensor * b,
1540
+ struct lm_ggml_tensor * c,
1541
+ int n_dims,
1542
+ int sections[4],
1543
+ int mode,
1544
+ int n_ctx_orig,
1545
+ float freq_base,
1546
+ float freq_scale,
1547
+ float ext_factor,
1548
+ float attn_factor,
1549
+ float beta_fast,
1550
+ float beta_slow);
1551
+
1552
+
1553
+ // clamp
1554
+ // in-place, returns view(a)
1555
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_clamp(
1556
+ struct lm_ggml_context * ctx,
1557
+ struct lm_ggml_tensor * a,
1558
+ float min,
1559
+ float max);
1560
+
1561
+ // im2col
1562
+ // converts data into a format that effectively results in a convolution when combined with matrix multiplication
1563
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_im2col(
1564
+ struct lm_ggml_context * ctx,
1565
+ struct lm_ggml_tensor * a, // convolution kernel
1566
+ struct lm_ggml_tensor * b, // data
1567
+ int s0, // stride dimension 0
1568
+ int s1, // stride dimension 1
1569
+ int p0, // padding dimension 0
1570
+ int p1, // padding dimension 1
1571
+ int d0, // dilation dimension 0
1572
+ int d1, // dilation dimension 1
1573
+ bool is_2D,
1574
+ enum lm_ggml_type dst_type);
1575
+
1576
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_im2col_back(
1577
+ struct lm_ggml_context * ctx,
1578
+ struct lm_ggml_tensor * a, // convolution kernel
1579
+ struct lm_ggml_tensor * b, // gradient of im2col output
1580
+ int64_t * ne, // shape of im2col input
1581
+ int s0, // stride dimension 0
1582
+ int s1, // stride dimension 1
1583
+ int p0, // padding dimension 0
1584
+ int p1, // padding dimension 1
1585
+ int d0, // dilation dimension 0
1586
+ int d1, // dilation dimension 1
1587
+ bool is_2D);
1588
+
1589
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_1d(
1590
+ struct lm_ggml_context * ctx,
1591
+ struct lm_ggml_tensor * a, // convolution kernel
1592
+ struct lm_ggml_tensor * b, // data
1593
+ int s0, // stride
1594
+ int p0, // padding
1595
+ int d0); // dilation
1596
+
1597
+ // conv_1d with padding = half
1598
+ // alias for lm_ggml_conv_1d(a, b, s, a->ne[0]/2, d)
1599
+ LM_GGML_API struct lm_ggml_tensor* lm_ggml_conv_1d_ph(
1600
+ struct lm_ggml_context * ctx,
1601
+ struct lm_ggml_tensor * a, // convolution kernel
1602
+ struct lm_ggml_tensor * b, // data
1603
+ int s, // stride
1604
+ int d); // dilation
1605
+
1606
+ // depthwise
1607
+ // TODO: this is very likely wrong for some cases! - needs more testing
1608
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_1d_dw(
1609
+ struct lm_ggml_context * ctx,
1610
+ struct lm_ggml_tensor * a, // convolution kernel
1611
+ struct lm_ggml_tensor * b, // data
1612
+ int s0, // stride
1613
+ int p0, // padding
1614
+ int d0); // dilation
1615
+
1616
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_1d_dw_ph(
1617
+ struct lm_ggml_context * ctx,
1618
+ struct lm_ggml_tensor * a, // convolution kernel
1619
+ struct lm_ggml_tensor * b, // data
1620
+ int s0, // stride
1621
+ int d0); // dilation
1622
+
1623
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_transpose_1d(
1624
+ struct lm_ggml_context * ctx,
1625
+ struct lm_ggml_tensor * a, // convolution kernel
1626
+ struct lm_ggml_tensor * b, // data
1627
+ int s0, // stride
1628
+ int p0, // padding
1629
+ int d0); // dilation
1630
+
1631
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_2d(
1632
+ struct lm_ggml_context * ctx,
1633
+ struct lm_ggml_tensor * a, // convolution kernel
1634
+ struct lm_ggml_tensor * b, // data
1635
+ int s0, // stride dimension 0
1636
+ int s1, // stride dimension 1
1637
+ int p0, // padding dimension 0
1638
+ int p1, // padding dimension 1
1639
+ int d0, // dilation dimension 0
1640
+ int d1); // dilation dimension 1
1641
+
1642
+ // kernel size is a->ne[0] x a->ne[1]
1643
+ // stride is equal to kernel size
1644
+ // padding is zero
1645
+ // example:
1646
+ // a: 16 16 3 768
1647
+ // b: 1024 1024 3 1
1648
+ // res: 64 64 768 1
1649
+ // used in sam
1650
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_2d_sk_p0(
1651
+ struct lm_ggml_context * ctx,
1652
+ struct lm_ggml_tensor * a,
1653
+ struct lm_ggml_tensor * b);
1654
+
1655
+ // kernel size is a->ne[0] x a->ne[1]
1656
+ // stride is 1
1657
+ // padding is half
1658
+ // example:
1659
+ // a: 3 3 256 256
1660
+ // b: 64 64 256 1
1661
+ // res: 64 64 256 1
1662
+ // used in sam
1663
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_2d_s1_ph(
1664
+ struct lm_ggml_context * ctx,
1665
+ struct lm_ggml_tensor * a,
1666
+ struct lm_ggml_tensor * b);
1667
+
1668
+ // depthwise
1669
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_2d_dw(
1670
+ struct lm_ggml_context * ctx,
1671
+ struct lm_ggml_tensor * a, // convolution kernel
1672
+ struct lm_ggml_tensor * b, // data
1673
+ int s0, // stride dimension 0
1674
+ int s1, // stride dimension 1
1675
+ int p0, // padding dimension 0
1676
+ int p1, // padding dimension 1
1677
+ int d0, // dilation dimension 0
1678
+ int d1); // dilation dimension 1
1679
+
1680
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_conv_transpose_2d_p0(
1681
+ struct lm_ggml_context * ctx,
1682
+ struct lm_ggml_tensor * a,
1683
+ struct lm_ggml_tensor * b,
1684
+ int stride);
1685
+
1686
+ enum lm_ggml_op_pool {
1687
+ LM_GGML_OP_POOL_MAX,
1688
+ LM_GGML_OP_POOL_AVG,
1689
+ LM_GGML_OP_POOL_COUNT,
1690
+ };
1691
+
1692
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_pool_1d(
1693
+ struct lm_ggml_context * ctx,
1694
+ struct lm_ggml_tensor * a,
1695
+ enum lm_ggml_op_pool op,
1696
+ int k0, // kernel size
1697
+ int s0, // stride
1698
+ int p0); // padding
1699
+
1700
+ // the result will have 2*p0 padding for the first dimension
1701
+ // and 2*p1 padding for the second dimension
1702
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_pool_2d(
1703
+ struct lm_ggml_context * ctx,
1704
+ struct lm_ggml_tensor * a,
1705
+ enum lm_ggml_op_pool op,
1706
+ int k0,
1707
+ int k1,
1708
+ int s0,
1709
+ int s1,
1710
+ float p0,
1711
+ float p1);
1712
+
1713
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_pool_2d_back(
1714
+ struct lm_ggml_context * ctx,
1715
+ struct lm_ggml_tensor * a,
1716
+ struct lm_ggml_tensor * af, // "a"/input used in forward pass
1717
+ enum lm_ggml_op_pool op,
1718
+ int k0,
1719
+ int k1,
1720
+ int s0,
1721
+ int s1,
1722
+ float p0,
1723
+ float p1);
1724
+
1725
+ // nearest interpolate
1726
+ // multiplies ne0 and ne1 by scale factor
1727
+ // used in stable-diffusion
1728
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_upscale(
1729
+ struct lm_ggml_context * ctx,
1730
+ struct lm_ggml_tensor * a,
1731
+ int scale_factor);
1732
+
1733
+ // nearest interpolate
1734
+ // nearest interpolate to specified dimensions
1735
+ // used in tortoise.cpp
1736
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_upscale_ext(
1737
+ struct lm_ggml_context * ctx,
1738
+ struct lm_ggml_tensor * a,
1739
+ int ne0,
1740
+ int ne1,
1741
+ int ne2,
1742
+ int ne3);
1743
+
1744
+ // pad each dimension with zeros: [x, ..., x] -> [x, ..., x, 0, ..., 0]
1745
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_pad(
1746
+ struct lm_ggml_context * ctx,
1747
+ struct lm_ggml_tensor * a,
1748
+ int p0,
1749
+ int p1,
1750
+ int p2,
1751
+ int p3);
1752
+
1753
+ // pad each dimension with reflection: [a, b, c, d] -> [b, a, b, c, d, c]
1754
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_pad_reflect_1d(
1755
+ struct lm_ggml_context * ctx,
1756
+ struct lm_ggml_tensor * a,
1757
+ int p0,
1758
+ int p1);
1759
+
1760
+ // Ref: https://github.com/CompVis/stable-diffusion/blob/main/ldm/modules/diffusionmodules/util.py#L151
1761
+ // timesteps: [N,]
1762
+ // return: [N, dim]
1763
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_timestep_embedding(
1764
+ struct lm_ggml_context * ctx,
1765
+ struct lm_ggml_tensor * timesteps,
1766
+ int dim,
1767
+ int max_period);
1768
+
1769
+ // sort rows
1770
+ enum lm_ggml_sort_order {
1771
+ LM_GGML_SORT_ORDER_ASC,
1772
+ LM_GGML_SORT_ORDER_DESC,
1773
+ };
1774
+
1775
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_argsort(
1776
+ struct lm_ggml_context * ctx,
1777
+ struct lm_ggml_tensor * a,
1778
+ enum lm_ggml_sort_order order);
1779
+
1780
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_arange(
1781
+ struct lm_ggml_context * ctx,
1782
+ float start,
1783
+ float stop,
1784
+ float step);
1785
+
1786
+ // top k elements per row
1787
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_top_k(
1788
+ struct lm_ggml_context * ctx,
1789
+ struct lm_ggml_tensor * a,
1790
+ int k);
1791
+
1792
+ #define LM_GGML_KQ_MASK_PAD 64
1793
+
1794
+ // q: [n_embd, n_batch, n_head, 1]
1795
+ // k: [n_embd, n_kv, n_head_kv, 1]
1796
+ // v: [n_embd, n_kv, n_head_kv, 1] !! not transposed !!
1797
+ // mask: [n_kv, n_batch_pad, 1, 1] !! n_batch_pad = LM_GGML_PAD(n_batch, LM_GGML_KQ_MASK_PAD) !!
1798
+ // res: [n_embd, n_head, n_batch, 1] !! permuted !!
1799
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_flash_attn_ext(
1800
+ struct lm_ggml_context * ctx,
1801
+ struct lm_ggml_tensor * q,
1802
+ struct lm_ggml_tensor * k,
1803
+ struct lm_ggml_tensor * v,
1804
+ struct lm_ggml_tensor * mask,
1805
+ float scale,
1806
+ float max_bias,
1807
+ float logit_softcap);
1808
+
1809
+ LM_GGML_API void lm_ggml_flash_attn_ext_set_prec(
1810
+ struct lm_ggml_tensor * a,
1811
+ enum lm_ggml_prec prec);
1812
+
1813
+ LM_GGML_API enum lm_ggml_prec lm_ggml_flash_attn_ext_get_prec(
1814
+ const struct lm_ggml_tensor * a);
1815
+
1816
+ // TODO: needs to be adapted to lm_ggml_flash_attn_ext
1817
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_flash_attn_back(
1818
+ struct lm_ggml_context * ctx,
1819
+ struct lm_ggml_tensor * q,
1820
+ struct lm_ggml_tensor * k,
1821
+ struct lm_ggml_tensor * v,
1822
+ struct lm_ggml_tensor * d,
1823
+ bool masked);
1824
+
1825
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_ssm_conv(
1826
+ struct lm_ggml_context * ctx,
1827
+ struct lm_ggml_tensor * sx,
1828
+ struct lm_ggml_tensor * c);
1829
+
1830
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_ssm_scan(
1831
+ struct lm_ggml_context * ctx,
1832
+ struct lm_ggml_tensor * s,
1833
+ struct lm_ggml_tensor * x,
1834
+ struct lm_ggml_tensor * dt,
1835
+ struct lm_ggml_tensor * A,
1836
+ struct lm_ggml_tensor * B,
1837
+ struct lm_ggml_tensor * C);
1838
+
1839
+ // partition into non-overlapping windows with padding if needed
1840
+ // example:
1841
+ // a: 768 64 64 1
1842
+ // w: 14
1843
+ // res: 768 14 14 25
1844
+ // used in sam
1845
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_win_part(
1846
+ struct lm_ggml_context * ctx,
1847
+ struct lm_ggml_tensor * a,
1848
+ int w);
1849
+
1850
+ // reverse of lm_ggml_win_part
1851
+ // used in sam
1852
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_win_unpart(
1853
+ struct lm_ggml_context * ctx,
1854
+ struct lm_ggml_tensor * a,
1855
+ int w0,
1856
+ int h0,
1857
+ int w);
1858
+
1859
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_unary(
1860
+ struct lm_ggml_context * ctx,
1861
+ struct lm_ggml_tensor * a,
1862
+ enum lm_ggml_unary_op op);
1863
+
1864
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_unary_inplace(
1865
+ struct lm_ggml_context * ctx,
1866
+ struct lm_ggml_tensor * a,
1867
+ enum lm_ggml_unary_op op);
1868
+
1869
+ // used in sam
1870
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_get_rel_pos(
1871
+ struct lm_ggml_context * ctx,
1872
+ struct lm_ggml_tensor * a,
1873
+ int qh,
1874
+ int kh);
1875
+
1876
+ // used in sam
1877
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add_rel_pos(
1878
+ struct lm_ggml_context * ctx,
1879
+ struct lm_ggml_tensor * a,
1880
+ struct lm_ggml_tensor * pw,
1881
+ struct lm_ggml_tensor * ph);
1882
+
1883
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_add_rel_pos_inplace(
1884
+ struct lm_ggml_context * ctx,
1885
+ struct lm_ggml_tensor * a,
1886
+ struct lm_ggml_tensor * pw,
1887
+ struct lm_ggml_tensor * ph);
1888
+
1889
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rwkv_wkv6(
1890
+ struct lm_ggml_context * ctx,
1891
+ struct lm_ggml_tensor * k,
1892
+ struct lm_ggml_tensor * v,
1893
+ struct lm_ggml_tensor * r,
1894
+ struct lm_ggml_tensor * tf,
1895
+ struct lm_ggml_tensor * td,
1896
+ struct lm_ggml_tensor * state);
1897
+
1898
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_gated_linear_attn(
1899
+ struct lm_ggml_context * ctx,
1900
+ struct lm_ggml_tensor * k,
1901
+ struct lm_ggml_tensor * v,
1902
+ struct lm_ggml_tensor * q,
1903
+ struct lm_ggml_tensor * g,
1904
+ struct lm_ggml_tensor * state,
1905
+ float scale);
1906
+
1907
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_rwkv_wkv7(
1908
+ struct lm_ggml_context * ctx,
1909
+ struct lm_ggml_tensor * r,
1910
+ struct lm_ggml_tensor * w,
1911
+ struct lm_ggml_tensor * k,
1912
+ struct lm_ggml_tensor * v,
1913
+ struct lm_ggml_tensor * a,
1914
+ struct lm_ggml_tensor * b,
1915
+ struct lm_ggml_tensor * state);
1916
+
1917
+ // custom operators
1918
+
1919
+ typedef void (*lm_ggml_unary_op_f32_t) (const int, float *, const float *);
1920
+ typedef void (*lm_ggml_binary_op_f32_t)(const int, float *, const float *, const float *);
1921
+
1922
+ typedef void (*lm_ggml_custom1_op_f32_t)(struct lm_ggml_tensor *, const struct lm_ggml_tensor *);
1923
+ typedef void (*lm_ggml_custom2_op_f32_t)(struct lm_ggml_tensor *, const struct lm_ggml_tensor *, const struct lm_ggml_tensor *);
1924
+ typedef void (*lm_ggml_custom3_op_f32_t)(struct lm_ggml_tensor *, const struct lm_ggml_tensor *, const struct lm_ggml_tensor *, const struct lm_ggml_tensor *);
1925
+
1926
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_unary_f32(
1927
+ struct lm_ggml_context * ctx,
1928
+ struct lm_ggml_tensor * a,
1929
+ lm_ggml_unary_op_f32_t fun),
1930
+ "use lm_ggml_map_custom1 instead");
1931
+
1932
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_unary_inplace_f32(
1933
+ struct lm_ggml_context * ctx,
1934
+ struct lm_ggml_tensor * a,
1935
+ lm_ggml_unary_op_f32_t fun),
1936
+ "use lm_ggml_map_custom1_inplace instead");
1937
+
1938
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_binary_f32(
1939
+ struct lm_ggml_context * ctx,
1940
+ struct lm_ggml_tensor * a,
1941
+ struct lm_ggml_tensor * b,
1942
+ lm_ggml_binary_op_f32_t fun),
1943
+ "use lm_ggml_map_custom2 instead");
1944
+
1945
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_binary_inplace_f32(
1946
+ struct lm_ggml_context * ctx,
1947
+ struct lm_ggml_tensor * a,
1948
+ struct lm_ggml_tensor * b,
1949
+ lm_ggml_binary_op_f32_t fun),
1950
+ "use lm_ggml_map_custom2_inplace instead");
1951
+
1952
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom1_f32(
1953
+ struct lm_ggml_context * ctx,
1954
+ struct lm_ggml_tensor * a,
1955
+ lm_ggml_custom1_op_f32_t fun),
1956
+ "use lm_ggml_map_custom1 instead");
1957
+
1958
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom1_inplace_f32(
1959
+ struct lm_ggml_context * ctx,
1960
+ struct lm_ggml_tensor * a,
1961
+ lm_ggml_custom1_op_f32_t fun),
1962
+ "use lm_ggml_map_custom1_inplace instead");
1963
+
1964
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom2_f32(
1965
+ struct lm_ggml_context * ctx,
1966
+ struct lm_ggml_tensor * a,
1967
+ struct lm_ggml_tensor * b,
1968
+ lm_ggml_custom2_op_f32_t fun),
1969
+ "use lm_ggml_map_custom2 instead");
1970
+
1971
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom2_inplace_f32(
1972
+ struct lm_ggml_context * ctx,
1973
+ struct lm_ggml_tensor * a,
1974
+ struct lm_ggml_tensor * b,
1975
+ lm_ggml_custom2_op_f32_t fun),
1976
+ "use lm_ggml_map_custom2_inplace instead");
1977
+
1978
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom3_f32(
1979
+ struct lm_ggml_context * ctx,
1980
+ struct lm_ggml_tensor * a,
1981
+ struct lm_ggml_tensor * b,
1982
+ struct lm_ggml_tensor * c,
1983
+ lm_ggml_custom3_op_f32_t fun),
1984
+ "use lm_ggml_map_custom3 instead");
1985
+
1986
+ LM_GGML_DEPRECATED(LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom3_inplace_f32(
1987
+ struct lm_ggml_context * ctx,
1988
+ struct lm_ggml_tensor * a,
1989
+ struct lm_ggml_tensor * b,
1990
+ struct lm_ggml_tensor * c,
1991
+ lm_ggml_custom3_op_f32_t fun),
1992
+ "use lm_ggml_map_custom3_inplace instead");
1993
+
1994
+ // custom operators v2
1995
+
1996
+ typedef void (*lm_ggml_custom1_op_t)(struct lm_ggml_tensor * dst , const struct lm_ggml_tensor * a, int ith, int nth, void * userdata);
1997
+ typedef void (*lm_ggml_custom2_op_t)(struct lm_ggml_tensor * dst , const struct lm_ggml_tensor * a, const struct lm_ggml_tensor * b, int ith, int nth, void * userdata);
1998
+ typedef void (*lm_ggml_custom3_op_t)(struct lm_ggml_tensor * dst , const struct lm_ggml_tensor * a, const struct lm_ggml_tensor * b, const struct lm_ggml_tensor * c, int ith, int nth, void * userdata);
1999
+
2000
+ #define LM_GGML_N_TASKS_MAX (-1)
2001
+ // n_tasks == LM_GGML_N_TASKS_MAX means to use max number of tasks
2002
+
2003
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom1(
2004
+ struct lm_ggml_context * ctx,
2005
+ struct lm_ggml_tensor * a,
2006
+ lm_ggml_custom1_op_t fun,
2007
+ int n_tasks,
2008
+ void * userdata);
2009
+
2010
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom1_inplace(
2011
+ struct lm_ggml_context * ctx,
2012
+ struct lm_ggml_tensor * a,
2013
+ lm_ggml_custom1_op_t fun,
2014
+ int n_tasks,
2015
+ void * userdata);
2016
+
2017
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom2(
2018
+ struct lm_ggml_context * ctx,
2019
+ struct lm_ggml_tensor * a,
2020
+ struct lm_ggml_tensor * b,
2021
+ lm_ggml_custom2_op_t fun,
2022
+ int n_tasks,
2023
+ void * userdata);
2024
+
2025
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom2_inplace(
2026
+ struct lm_ggml_context * ctx,
2027
+ struct lm_ggml_tensor * a,
2028
+ struct lm_ggml_tensor * b,
2029
+ lm_ggml_custom2_op_t fun,
2030
+ int n_tasks,
2031
+ void * userdata);
2032
+
2033
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom3(
2034
+ struct lm_ggml_context * ctx,
2035
+ struct lm_ggml_tensor * a,
2036
+ struct lm_ggml_tensor * b,
2037
+ struct lm_ggml_tensor * c,
2038
+ lm_ggml_custom3_op_t fun,
2039
+ int n_tasks,
2040
+ void * userdata);
2041
+
2042
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_map_custom3_inplace(
2043
+ struct lm_ggml_context * ctx,
2044
+ struct lm_ggml_tensor * a,
2045
+ struct lm_ggml_tensor * b,
2046
+ struct lm_ggml_tensor * c,
2047
+ lm_ggml_custom3_op_t fun,
2048
+ int n_tasks,
2049
+ void * userdata);
2050
+
2051
+ // loss function
2052
+
2053
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cross_entropy_loss(
2054
+ struct lm_ggml_context * ctx,
2055
+ struct lm_ggml_tensor * a, // logits
2056
+ struct lm_ggml_tensor * b); // labels
2057
+
2058
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_cross_entropy_loss_back(
2059
+ struct lm_ggml_context * ctx,
2060
+ struct lm_ggml_tensor * a, // logits
2061
+ struct lm_ggml_tensor * b, // labels
2062
+ struct lm_ggml_tensor * c); // gradients of cross_entropy_loss result
2063
+
2064
+ // AdamW optimizer step
2065
+ // Paper: https://arxiv.org/pdf/1711.05101v3.pdf
2066
+ // PyTorch: https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html
2067
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_opt_step_adamw(
2068
+ struct lm_ggml_context * ctx,
2069
+ struct lm_ggml_tensor * a,
2070
+ struct lm_ggml_tensor * grad,
2071
+ struct lm_ggml_tensor * m,
2072
+ struct lm_ggml_tensor * v,
2073
+ struct lm_ggml_tensor * adamw_params); // parameters such a the learning rate
2074
+
2075
+ //
2076
+ // automatic differentiation
2077
+ //
2078
+
2079
+ LM_GGML_API void lm_ggml_build_forward_expand(struct lm_ggml_cgraph * cgraph, struct lm_ggml_tensor * tensor);
2080
+ LM_GGML_API void lm_ggml_build_backward_expand(
2081
+ struct lm_ggml_context * ctx_static, // context for static gradients (loss + gradient accumulation)
2082
+ struct lm_ggml_context * ctx_compute, // context for gradient computation
2083
+ struct lm_ggml_cgraph * cgraph,
2084
+ bool accumulate); // whether or not gradients should be accumulated, requires static allocation of tensors in ctx_static
2085
+
2086
+ // graph allocation in a context
2087
+ LM_GGML_API struct lm_ggml_cgraph * lm_ggml_new_graph (struct lm_ggml_context * ctx); // size = LM_GGML_DEFAULT_GRAPH_SIZE, grads = false
2088
+ LM_GGML_API struct lm_ggml_cgraph * lm_ggml_new_graph_custom(struct lm_ggml_context * ctx, size_t size, bool grads);
2089
+ LM_GGML_API struct lm_ggml_cgraph * lm_ggml_graph_dup (struct lm_ggml_context * ctx, struct lm_ggml_cgraph * cgraph);
2090
+ LM_GGML_API void lm_ggml_graph_cpy (struct lm_ggml_cgraph * src, struct lm_ggml_cgraph * dst);
2091
+ LM_GGML_API void lm_ggml_graph_reset (struct lm_ggml_cgraph * cgraph); // set regular grads + optimizer momenta to 0, set loss grad to 1
2092
+ LM_GGML_API void lm_ggml_graph_clear (struct lm_ggml_cgraph * cgraph);
2093
+
2094
+ LM_GGML_API int lm_ggml_graph_size (struct lm_ggml_cgraph * cgraph);
2095
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_graph_node (struct lm_ggml_cgraph * cgraph, int i); // if i < 0, returns nodes[n_nodes + i]
2096
+ LM_GGML_API struct lm_ggml_tensor ** lm_ggml_graph_nodes (struct lm_ggml_cgraph * cgraph);
2097
+ LM_GGML_API int lm_ggml_graph_n_nodes(struct lm_ggml_cgraph * cgraph);
2098
+
2099
+ LM_GGML_API void lm_ggml_graph_add_node(struct lm_ggml_cgraph * cgraph, struct lm_ggml_tensor * tensor);
2100
+
2101
+ LM_GGML_API size_t lm_ggml_graph_overhead(void);
2102
+ LM_GGML_API size_t lm_ggml_graph_overhead_custom(size_t size, bool grads);
2103
+
2104
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_graph_get_tensor (const struct lm_ggml_cgraph * cgraph, const char * name);
2105
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_graph_get_grad (const struct lm_ggml_cgraph * cgraph, const struct lm_ggml_tensor * node);
2106
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_graph_get_grad_acc(const struct lm_ggml_cgraph * cgraph, const struct lm_ggml_tensor * node);
2107
+
2108
+ LM_GGML_API void lm_ggml_graph_export(const struct lm_ggml_cgraph * cgraph, const char * fname);
2109
+ LM_GGML_API struct lm_ggml_cgraph * lm_ggml_graph_import(const char * fname, struct lm_ggml_context ** ctx_data, struct lm_ggml_context ** ctx_eval);
2110
+
2111
+ // print info and performance information for the graph
2112
+ LM_GGML_API void lm_ggml_graph_print(const struct lm_ggml_cgraph * cgraph);
2113
+
2114
+ // dump the graph into a file using the dot format
2115
+ LM_GGML_API void lm_ggml_graph_dump_dot(const struct lm_ggml_cgraph * gb, const struct lm_ggml_cgraph * gf, const char * filename);
2116
+
2117
+ // TODO these functions were sandwiched in the old optimization interface, is there a better place for them?
2118
+ typedef void (*lm_ggml_log_callback)(enum lm_ggml_log_level level, const char * text, void * user_data);
2119
+
2120
+ // Set callback for all future logging events.
2121
+ // If this is not called, or NULL is supplied, everything is output on stderr.
2122
+ LM_GGML_API void lm_ggml_log_set(lm_ggml_log_callback log_callback, void * user_data);
2123
+
2124
+ LM_GGML_API struct lm_ggml_tensor * lm_ggml_set_zero(struct lm_ggml_tensor * tensor);
2125
+
2126
+ //
2127
+ // quantization
2128
+ //
2129
+
2130
+ // - lm_ggml_quantize_init can be called multiple times with the same type
2131
+ // it will only initialize the quantization tables for the first call or after lm_ggml_quantize_free
2132
+ // automatically called by lm_ggml_quantize_chunk for convenience
2133
+ //
2134
+ // - lm_ggml_quantize_free will free any memory allocated by lm_ggml_quantize_init
2135
+ // call this at the end of the program to avoid memory leaks
2136
+ //
2137
+ // note: these are thread-safe
2138
+ //
2139
+ LM_GGML_API void lm_ggml_quantize_init(enum lm_ggml_type type);
2140
+ LM_GGML_API void lm_ggml_quantize_free(void);
2141
+
2142
+ // some quantization type cannot be used without an importance matrix
2143
+ LM_GGML_API bool lm_ggml_quantize_requires_imatrix(enum lm_ggml_type type);
2144
+
2145
+ // calls lm_ggml_quantize_init internally (i.e. can allocate memory)
2146
+ LM_GGML_API size_t lm_ggml_quantize_chunk(
2147
+ enum lm_ggml_type type,
2148
+ const float * src,
2149
+ void * dst,
2150
+ int64_t start,
2151
+ int64_t nrows,
2152
+ int64_t n_per_row,
2153
+ const float * imatrix);
2154
+
2155
+ #ifdef __cplusplus
2156
+ // restrict not standard in C++
2157
+ # if defined(__GNUC__)
2158
+ # define LM_GGML_RESTRICT __restrict__
2159
+ # elif defined(__clang__)
2160
+ # define LM_GGML_RESTRICT __restrict
2161
+ # elif defined(_MSC_VER)
2162
+ # define LM_GGML_RESTRICT __restrict
2163
+ # else
2164
+ # define LM_GGML_RESTRICT
2165
+ # endif
2166
+ #else
2167
+ # if defined (_MSC_VER) && (__STDC_VERSION__ < 201112L)
2168
+ # define LM_GGML_RESTRICT __restrict
2169
+ # else
2170
+ # define LM_GGML_RESTRICT restrict
2171
+ # endif
2172
+ #endif
2173
+ typedef void (*lm_ggml_to_float_t) (const void * LM_GGML_RESTRICT x, float * LM_GGML_RESTRICT y, int64_t k);
2174
+ typedef void (*lm_ggml_from_float_t)(const float * LM_GGML_RESTRICT x, void * LM_GGML_RESTRICT y, int64_t k);
2175
+
2176
+ struct lm_ggml_type_traits {
2177
+ const char * type_name;
2178
+ int64_t blck_size;
2179
+ int64_t blck_size_interleave; // interleave elements in blocks
2180
+ size_t type_size;
2181
+ bool is_quantized;
2182
+ lm_ggml_to_float_t to_float;
2183
+ lm_ggml_from_float_t from_float_ref;
2184
+ };
2185
+
2186
+ LM_GGML_API const struct lm_ggml_type_traits * lm_ggml_get_type_traits(enum lm_ggml_type type);
2187
+
2188
+ // ggml threadpool
2189
+ // TODO: currently, only a few functions are in the base ggml API, while the rest are in the CPU backend
2190
+ // the goal should be to create an API that other backends can use move everything to the ggml base
2191
+
2192
+ // scheduling priorities
2193
+ enum lm_ggml_sched_priority {
2194
+ LM_GGML_SCHED_PRIO_NORMAL,
2195
+ LM_GGML_SCHED_PRIO_MEDIUM,
2196
+ LM_GGML_SCHED_PRIO_HIGH,
2197
+ LM_GGML_SCHED_PRIO_REALTIME
2198
+ };
2199
+
2200
+ // threadpool params
2201
+ // Use lm_ggml_threadpool_params_default() or lm_ggml_threadpool_params_init() to populate the defaults
2202
+ struct lm_ggml_threadpool_params {
2203
+ bool cpumask[LM_GGML_MAX_N_THREADS]; // mask of cpu cores (all-zeros means use default affinity settings)
2204
+ int n_threads; // number of threads
2205
+ enum lm_ggml_sched_priority prio; // thread priority
2206
+ uint32_t poll; // polling level (0 - no polling, 100 - aggressive polling)
2207
+ bool strict_cpu; // strict cpu placement
2208
+ bool paused; // start in paused state
2209
+ };
2210
+
2211
+ struct lm_ggml_threadpool; // forward declaration, see ggml.c
2212
+
2213
+ typedef struct lm_ggml_threadpool * lm_ggml_threadpool_t;
2214
+
2215
+ LM_GGML_API struct lm_ggml_threadpool_params lm_ggml_threadpool_params_default(int n_threads);
2216
+ LM_GGML_API void lm_ggml_threadpool_params_init (struct lm_ggml_threadpool_params * p, int n_threads);
2217
+ LM_GGML_API bool lm_ggml_threadpool_params_match (const struct lm_ggml_threadpool_params * p0, const struct lm_ggml_threadpool_params * p1);
2218
+
2219
+ #ifdef __cplusplus
2220
+ }
2221
+ #endif