cactus-react-native 0.2.11 → 1.0.2

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