cohere-transcribe 0.1.0

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 (480) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE.txt +201 -0
  4. data/NOTICE +5 -0
  5. data/README.md +265 -0
  6. data/THIRD_PARTY_NOTICES.md +67 -0
  7. data/exe/cohere-transcribe +8 -0
  8. data/exe/cohere-transcribe-doctor +8 -0
  9. data/ext/cohere_transcribe_native/CMakeLists.txt +262 -0
  10. data/ext/cohere_transcribe_native/README.md +26 -0
  11. data/ext/cohere_transcribe_native/audio_abi.cpp +1416 -0
  12. data/ext/cohere_transcribe_native/audio_exports.macos +5 -0
  13. data/ext/cohere_transcribe_native/audio_exports.map +10 -0
  14. data/ext/cohere_transcribe_native/cohere_abi.cpp +1209 -0
  15. data/ext/cohere_transcribe_native/exports.macos +40 -0
  16. data/ext/cohere_transcribe_native/exports.map +45 -0
  17. data/ext/cohere_transcribe_native/extconf.rb +89 -0
  18. data/ext/cohere_transcribe_native/test/abi_smoke.rb +232 -0
  19. data/ext/cohere_transcribe_native/test/audio_matrix_smoke.cpp +121 -0
  20. data/ext/cohere_transcribe_native/test/audio_reliability_smoke.cpp +198 -0
  21. data/ext/cohere_transcribe_native/test/native_abi_reliability_smoke.cpp +186 -0
  22. data/ext/cohere_transcribe_native/test/native_batch_projection_probe.rb +81 -0
  23. data/ext/cohere_transcribe_native/test/native_cancellation_smoke.cpp +194 -0
  24. data/lib/cohere/transcribe/alignment/ATTRIBUTION.md +23 -0
  25. data/lib/cohere/transcribe/alignment/LICENSE.ctc-forced-aligner +407 -0
  26. data/lib/cohere/transcribe/alignment/LICENSE.torchaudio +25 -0
  27. data/lib/cohere/transcribe/alignment/LICENSE.uroman +26 -0
  28. data/lib/cohere/transcribe/alignment/aligner.rb +476 -0
  29. data/lib/cohere/transcribe/alignment/ctc.rb +224 -0
  30. data/lib/cohere/transcribe/alignment/text.rb +237 -0
  31. data/lib/cohere/transcribe/alignment/uroman_data.rb +4950 -0
  32. data/lib/cohere/transcribe/api.rb +173 -0
  33. data/lib/cohere/transcribe/asr/batching.rb +472 -0
  34. data/lib/cohere/transcribe/asr/failure_policy.rb +112 -0
  35. data/lib/cohere/transcribe/asr/native.rb +676 -0
  36. data/lib/cohere/transcribe/audio/ATTRIBUTION.md +8 -0
  37. data/lib/cohere/transcribe/audio/LICENSE.auditok +21 -0
  38. data/lib/cohere/transcribe/audio/decoder.rb +315 -0
  39. data/lib/cohere/transcribe/audio/ffmpeg_native.rb +248 -0
  40. data/lib/cohere/transcribe/audio/segmentation.rb +260 -0
  41. data/lib/cohere/transcribe/cli.rb +727 -0
  42. data/lib/cohere/transcribe/configuration.rb +282 -0
  43. data/lib/cohere/transcribe/constants.rb +14 -0
  44. data/lib/cohere/transcribe/dense_converter.rb +548 -0
  45. data/lib/cohere/transcribe/doctor.rb +576 -0
  46. data/lib/cohere/transcribe/errors.rb +57 -0
  47. data/lib/cohere/transcribe/gguf_writer.rb +268 -0
  48. data/lib/cohere/transcribe/hub.rb +436 -0
  49. data/lib/cohere/transcribe/input.rb +110 -0
  50. data/lib/cohere/transcribe/licenses/crispasr.txt +21 -0
  51. data/lib/cohere/transcribe/loader.rb +128 -0
  52. data/lib/cohere/transcribe/model_identity.rb +440 -0
  53. data/lib/cohere/transcribe/output/publication.rb +1118 -0
  54. data/lib/cohere/transcribe/output/rendering.rb +105 -0
  55. data/lib/cohere/transcribe/output/timing.rb +86 -0
  56. data/lib/cohere/transcribe/python_text.rb +70 -0
  57. data/lib/cohere/transcribe/pytorch_checkpoint.rb +1180 -0
  58. data/lib/cohere/transcribe/runtime/engine.rb +1676 -0
  59. data/lib/cohere/transcribe/runtime/model_provider.rb +390 -0
  60. data/lib/cohere/transcribe/runtime/precision.rb +57 -0
  61. data/lib/cohere/transcribe/runtime/preparation.rb +215 -0
  62. data/lib/cohere/transcribe/runtime/resources.rb +165 -0
  63. data/lib/cohere/transcribe/runtime/word_pipeline.rb +364 -0
  64. data/lib/cohere/transcribe/safetensors.rb +579 -0
  65. data/lib/cohere/transcribe/state/checkpoint.rb +224 -0
  66. data/lib/cohere/transcribe/state/contracts.rb +141 -0
  67. data/lib/cohere/transcribe/state/io.rb +727 -0
  68. data/lib/cohere/transcribe/state/locking.rb +211 -0
  69. data/lib/cohere/transcribe/state/manifest.rb +155 -0
  70. data/lib/cohere/transcribe/state.rb +7 -0
  71. data/lib/cohere/transcribe/types.rb +535 -0
  72. data/lib/cohere/transcribe/vad/ATTRIBUTION.md +14 -0
  73. data/lib/cohere/transcribe/vad/LICENSE.faster-whisper +21 -0
  74. data/lib/cohere/transcribe/vad/LICENSE.silero-vad +21 -0
  75. data/lib/cohere/transcribe/vad/silero.rb +344 -0
  76. data/lib/cohere/transcribe/vad/silero_vad_v6.onnx +0 -0
  77. data/lib/cohere/transcribe/vad/timestamps.rb +219 -0
  78. data/lib/cohere/transcribe/version.rb +7 -0
  79. data/lib/cohere/transcribe.rb +26 -0
  80. data/sig/cohere/transcribe.rbs +250 -0
  81. data/vendor/crispasr/AUTHORS +510 -0
  82. data/vendor/crispasr/LICENSE +21 -0
  83. data/vendor/crispasr/UPSTREAM.md +9 -0
  84. data/vendor/crispasr/VERSION +1 -0
  85. data/vendor/crispasr/ggml/AUTHORS +335 -0
  86. data/vendor/crispasr/ggml/CMakeLists.txt +512 -0
  87. data/vendor/crispasr/ggml/LICENSE +21 -0
  88. data/vendor/crispasr/ggml/README.md +49 -0
  89. data/vendor/crispasr/ggml/cmake/FindNCCL.cmake +36 -0
  90. data/vendor/crispasr/ggml/cmake/GitVars.cmake +22 -0
  91. data/vendor/crispasr/ggml/cmake/common.cmake +50 -0
  92. data/vendor/crispasr/ggml/cmake/ggml-config.cmake.in +191 -0
  93. data/vendor/crispasr/ggml/ggml.pc.in +10 -0
  94. data/vendor/crispasr/ggml/include/ggml-alloc.h +85 -0
  95. data/vendor/crispasr/ggml/include/ggml-backend.h +431 -0
  96. data/vendor/crispasr/ggml/include/ggml-blas.h +25 -0
  97. data/vendor/crispasr/ggml/include/ggml-cann.h +123 -0
  98. data/vendor/crispasr/ggml/include/ggml-cpp.h +39 -0
  99. data/vendor/crispasr/ggml/include/ggml-cpu.h +151 -0
  100. data/vendor/crispasr/ggml/include/ggml-cuda.h +50 -0
  101. data/vendor/crispasr/ggml/include/ggml-hexagon.h +19 -0
  102. data/vendor/crispasr/ggml/include/ggml-metal.h +61 -0
  103. data/vendor/crispasr/ggml/include/ggml-opencl.h +26 -0
  104. data/vendor/crispasr/ggml/include/ggml-openvino.h +37 -0
  105. data/vendor/crispasr/ggml/include/ggml-opt.h +256 -0
  106. data/vendor/crispasr/ggml/include/ggml-rpc.h +35 -0
  107. data/vendor/crispasr/ggml/include/ggml-sycl.h +49 -0
  108. data/vendor/crispasr/ggml/include/ggml-virtgpu.h +14 -0
  109. data/vendor/crispasr/ggml/include/ggml-vulkan.h +29 -0
  110. data/vendor/crispasr/ggml/include/ggml-webgpu.h +19 -0
  111. data/vendor/crispasr/ggml/include/ggml-zdnn.h +17 -0
  112. data/vendor/crispasr/ggml/include/ggml-zendnn.h +22 -0
  113. data/vendor/crispasr/ggml/include/ggml.h +2887 -0
  114. data/vendor/crispasr/ggml/include/gguf.h +204 -0
  115. data/vendor/crispasr/ggml/src/CMakeLists.txt +493 -0
  116. data/vendor/crispasr/ggml/src/ggml-alloc.c +1323 -0
  117. data/vendor/crispasr/ggml/src/ggml-backend-dl.cpp +48 -0
  118. data/vendor/crispasr/ggml/src/ggml-backend-dl.h +44 -0
  119. data/vendor/crispasr/ggml/src/ggml-backend-impl.h +275 -0
  120. data/vendor/crispasr/ggml/src/ggml-backend-meta.cpp +2145 -0
  121. data/vendor/crispasr/ggml/src/ggml-backend-reg.cpp +586 -0
  122. data/vendor/crispasr/ggml/src/ggml-backend.cpp +2437 -0
  123. data/vendor/crispasr/ggml/src/ggml-common.h +1900 -0
  124. data/vendor/crispasr/ggml/src/ggml-cpu/CMakeLists.txt +718 -0
  125. data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.cpp +249 -0
  126. data/vendor/crispasr/ggml/src/ggml-cpu/amx/amx.h +8 -0
  127. data/vendor/crispasr/ggml/src/ggml-cpu/amx/common.h +115 -0
  128. data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.cpp +2512 -0
  129. data/vendor/crispasr/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  130. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp +98 -0
  131. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/quants.c +4244 -0
  132. data/vendor/crispasr/ggml/src/ggml-cpu/arch/arm/repack.cpp +5156 -0
  133. data/vendor/crispasr/ggml/src/ggml-cpu/arch/loongarch/quants.c +2158 -0
  134. data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
  135. data/vendor/crispasr/ggml/src/ggml-cpu/arch/powerpc/quants.c +2304 -0
  136. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp +38 -0
  137. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/quants.c +4455 -0
  138. data/vendor/crispasr/ggml/src/ggml-cpu/arch/riscv/repack.cpp +1703 -0
  139. data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp +50 -0
  140. data/vendor/crispasr/ggml/src/ggml-cpu/arch/s390/quants.c +1465 -0
  141. data/vendor/crispasr/ggml/src/ggml-cpu/arch/wasm/quants.c +1220 -0
  142. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
  143. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/quants.c +3970 -0
  144. data/vendor/crispasr/ggml/src/ggml-cpu/arch/x86/repack.cpp +6407 -0
  145. data/vendor/crispasr/ggml/src/ggml-cpu/arch-fallback.h +349 -0
  146. data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.cpp +154 -0
  147. data/vendor/crispasr/ggml/src/ggml-cpu/binary-ops.h +16 -0
  148. data/vendor/crispasr/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
  149. data/vendor/crispasr/ggml/src/ggml-cpu/common.h +95 -0
  150. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu-impl.h +539 -0
  151. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.c +3791 -0
  152. data/vendor/crispasr/ggml/src/ggml-cpu/ggml-cpu.cpp +703 -0
  153. data/vendor/crispasr/ggml/src/ggml-cpu/hbm.cpp +55 -0
  154. data/vendor/crispasr/ggml/src/ggml-cpu/hbm.h +8 -0
  155. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.cpp +939 -0
  156. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kernels.h +90 -0
  157. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +1513 -0
  158. data/vendor/crispasr/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
  159. data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.cpp +4051 -0
  160. data/vendor/crispasr/ggml/src/ggml-cpu/llamafile/sgemm.h +25 -0
  161. data/vendor/crispasr/ggml/src/ggml-cpu/ops.cpp +11662 -0
  162. data/vendor/crispasr/ggml/src/ggml-cpu/ops.h +121 -0
  163. data/vendor/crispasr/ggml/src/ggml-cpu/quants.c +1288 -0
  164. data/vendor/crispasr/ggml/src/ggml-cpu/quants.h +103 -0
  165. data/vendor/crispasr/ggml/src/ggml-cpu/repack.cpp +4836 -0
  166. data/vendor/crispasr/ggml/src/ggml-cpu/repack.h +245 -0
  167. data/vendor/crispasr/ggml/src/ggml-cpu/simd-gemm.h +226 -0
  168. data/vendor/crispasr/ggml/src/ggml-cpu/simd-mappings.h +1329 -0
  169. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.cpp +1025 -0
  170. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime.h +13 -0
  171. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime1_kernels.cpp +3196 -0
  172. data/vendor/crispasr/ggml/src/ggml-cpu/spacemit/ime_kernels.h +26 -0
  173. data/vendor/crispasr/ggml/src/ggml-cpu/traits.cpp +36 -0
  174. data/vendor/crispasr/ggml/src/ggml-cpu/traits.h +38 -0
  175. data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.cpp +336 -0
  176. data/vendor/crispasr/ggml/src/ggml-cpu/unary-ops.h +35 -0
  177. data/vendor/crispasr/ggml/src/ggml-cpu/vec.cpp +681 -0
  178. data/vendor/crispasr/ggml/src/ggml-cpu/vec.h +1606 -0
  179. data/vendor/crispasr/ggml/src/ggml-cuda/CMakeLists.txt +272 -0
  180. data/vendor/crispasr/ggml/src/ggml-cuda/acc.cu +61 -0
  181. data/vendor/crispasr/ggml/src/ggml-cuda/acc.cuh +5 -0
  182. data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cu +58 -0
  183. data/vendor/crispasr/ggml/src/ggml-cuda/add-id.cuh +3 -0
  184. data/vendor/crispasr/ggml/src/ggml-cuda/arange.cu +34 -0
  185. data/vendor/crispasr/ggml/src/ggml-cuda/arange.cuh +5 -0
  186. data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cu +91 -0
  187. data/vendor/crispasr/ggml/src/ggml-cuda/argmax.cuh +3 -0
  188. data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cu +265 -0
  189. data/vendor/crispasr/ggml/src/ggml-cuda/argsort.cuh +19 -0
  190. data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cu +534 -0
  191. data/vendor/crispasr/ggml/src/ggml-cuda/binbcast.cuh +12 -0
  192. data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cu +45 -0
  193. data/vendor/crispasr/ggml/src/ggml-cuda/clamp.cuh +5 -0
  194. data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cu +81 -0
  195. data/vendor/crispasr/ggml/src/ggml-cuda/col2im-1d.cuh +3 -0
  196. data/vendor/crispasr/ggml/src/ggml-cuda/common.cuh +1489 -0
  197. data/vendor/crispasr/ggml/src/ggml-cuda/concat.cu +204 -0
  198. data/vendor/crispasr/ggml/src/ggml-cuda/concat.cuh +5 -0
  199. data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cu +97 -0
  200. data/vendor/crispasr/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
  201. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
  202. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
  203. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cu +115 -0
  204. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d-transpose.cuh +5 -0
  205. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cu +166 -0
  206. data/vendor/crispasr/ggml/src/ggml-cuda/conv2d.cuh +5 -0
  207. data/vendor/crispasr/ggml/src/ggml-cuda/convert.cu +892 -0
  208. data/vendor/crispasr/ggml/src/ggml-cuda/convert.cuh +66 -0
  209. data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cu +64 -0
  210. data/vendor/crispasr/ggml/src/ggml-cuda/count-equal.cuh +5 -0
  211. data/vendor/crispasr/ggml/src/ggml-cuda/cp-async.cuh +57 -0
  212. data/vendor/crispasr/ggml/src/ggml-cuda/cpy-utils.cuh +217 -0
  213. data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cu +581 -0
  214. data/vendor/crispasr/ggml/src/ggml-cuda/cpy.cuh +7 -0
  215. data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cu +177 -0
  216. data/vendor/crispasr/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
  217. data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cu +307 -0
  218. data/vendor/crispasr/ggml/src/ggml-cuda/cumsum.cuh +5 -0
  219. data/vendor/crispasr/ggml/src/ggml-cuda/dequantize.cuh +99 -0
  220. data/vendor/crispasr/ggml/src/ggml-cuda/diag.cu +77 -0
  221. data/vendor/crispasr/ggml/src/ggml-cuda/diag.cuh +5 -0
  222. data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cu +40 -0
  223. data/vendor/crispasr/ggml/src/ggml-cuda/diagmask.cuh +5 -0
  224. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-common.cuh +1212 -0
  225. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1860 -0
  226. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cu +57 -0
  227. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-tile.cuh +1309 -0
  228. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-vec.cuh +600 -0
  229. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cu +696 -0
  230. data/vendor/crispasr/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +51 -0
  231. data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cu +620 -0
  232. data/vendor/crispasr/ggml/src/ggml-cuda/fattn.cuh +5 -0
  233. data/vendor/crispasr/ggml/src/ggml-cuda/fill.cu +37 -0
  234. data/vendor/crispasr/ggml/src/ggml-cuda/fill.cuh +3 -0
  235. data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cu +273 -0
  236. data/vendor/crispasr/ggml/src/ggml-cuda/gated_delta_net.cuh +4 -0
  237. data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cu +332 -0
  238. data/vendor/crispasr/ggml/src/ggml-cuda/getrows.cuh +15 -0
  239. data/vendor/crispasr/ggml/src/ggml-cuda/ggml-cuda.cu +5580 -0
  240. data/vendor/crispasr/ggml/src/ggml-cuda/gla.cu +93 -0
  241. data/vendor/crispasr/ggml/src/ggml-cuda/gla.cuh +3 -0
  242. data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cu +274 -0
  243. data/vendor/crispasr/ggml/src/ggml-cuda/im2col.cuh +6 -0
  244. data/vendor/crispasr/ggml/src/ggml-cuda/mean.cu +75 -0
  245. data/vendor/crispasr/ggml/src/ggml-cuda/mean.cuh +3 -0
  246. data/vendor/crispasr/ggml/src/ggml-cuda/mma.cuh +1333 -0
  247. data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cu +191 -0
  248. data/vendor/crispasr/ggml/src/ggml-cuda/mmf.cuh +908 -0
  249. data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cu +164 -0
  250. data/vendor/crispasr/ggml/src/ggml-cuda/mmid.cuh +5 -0
  251. data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cu +372 -0
  252. data/vendor/crispasr/ggml/src/ggml-cuda/mmq.cuh +4175 -0
  253. data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cu +862 -0
  254. data/vendor/crispasr/ggml/src/ggml-cuda/mmvf.cuh +14 -0
  255. data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cu +1161 -0
  256. data/vendor/crispasr/ggml/src/ggml-cuda/mmvq.cuh +16 -0
  257. data/vendor/crispasr/ggml/src/ggml-cuda/norm.cu +756 -0
  258. data/vendor/crispasr/ggml/src/ggml-cuda/norm.cuh +20 -0
  259. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
  260. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
  261. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cu +49 -0
  262. data/vendor/crispasr/ggml/src/ggml-cuda/opt-step-sgd.cuh +5 -0
  263. data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cu +68 -0
  264. data/vendor/crispasr/ggml/src/ggml-cuda/out-prod.cuh +3 -0
  265. data/vendor/crispasr/ggml/src/ggml-cuda/pad.cu +106 -0
  266. data/vendor/crispasr/ggml/src/ggml-cuda/pad.cuh +5 -0
  267. data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cu +91 -0
  268. data/vendor/crispasr/ggml/src/ggml-cuda/pad_reflect_1d.cuh +5 -0
  269. data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cu +94 -0
  270. data/vendor/crispasr/ggml/src/ggml-cuda/pool2d.cuh +5 -0
  271. data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cu +443 -0
  272. data/vendor/crispasr/ggml/src/ggml-cuda/quantize.cuh +41 -0
  273. data/vendor/crispasr/ggml/src/ggml-cuda/reduce_rows.cuh +39 -0
  274. data/vendor/crispasr/ggml/src/ggml-cuda/roll.cu +67 -0
  275. data/vendor/crispasr/ggml/src/ggml-cuda/roll.cuh +5 -0
  276. data/vendor/crispasr/ggml/src/ggml-cuda/rope.cu +665 -0
  277. data/vendor/crispasr/ggml/src/ggml-cuda/rope.cuh +9 -0
  278. data/vendor/crispasr/ggml/src/ggml-cuda/scale.cu +34 -0
  279. data/vendor/crispasr/ggml/src/ggml-cuda/scale.cuh +5 -0
  280. data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cu +330 -0
  281. data/vendor/crispasr/ggml/src/ggml-cuda/set-rows.cuh +7 -0
  282. data/vendor/crispasr/ggml/src/ggml-cuda/set.cu +39 -0
  283. data/vendor/crispasr/ggml/src/ggml-cuda/set.cuh +7 -0
  284. data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cu +34 -0
  285. data/vendor/crispasr/ggml/src/ggml-cuda/softcap.cuh +5 -0
  286. data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cu +472 -0
  287. data/vendor/crispasr/ggml/src/ggml-cuda/softmax.cuh +7 -0
  288. data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cu +275 -0
  289. data/vendor/crispasr/ggml/src/ggml-cuda/solve_tri.cuh +3 -0
  290. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cu +197 -0
  291. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
  292. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cu +342 -0
  293. data/vendor/crispasr/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
  294. data/vendor/crispasr/ggml/src/ggml-cuda/sum.cu +41 -0
  295. data/vendor/crispasr/ggml/src/ggml-cuda/sum.cuh +5 -0
  296. data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cu +43 -0
  297. data/vendor/crispasr/ggml/src/ggml-cuda/sumrows.cuh +4 -0
  298. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
  299. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_32.cu +6 -0
  300. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +11 -0
  301. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
  302. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
  303. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +12 -0
  304. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
  305. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_32.cu +6 -0
  306. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +12 -0
  307. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +11 -0
  308. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
  309. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
  310. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
  311. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
  312. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +12 -0
  313. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +11 -0
  314. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
  315. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
  316. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
  317. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +12 -0
  318. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +11 -0
  319. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq112-dv112.cu +5 -0
  320. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq128-dv128.cu +5 -0
  321. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq256-dv256.cu +5 -0
  322. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq320-dv256.cu +5 -0
  323. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq40-dv40.cu +5 -0
  324. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq512-dv512.cu +5 -0
  325. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq576-dv512.cu +5 -0
  326. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq64-dv64.cu +5 -0
  327. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq72-dv72.cu +5 -0
  328. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq80-dv80.cu +5 -0
  329. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-tile-instance-dkq96-dv96.cu +5 -0
  330. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-bf16.cu +7 -0
  331. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-f16.cu +7 -0
  332. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_0.cu +7 -0
  333. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q4_1.cu +7 -0
  334. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_0.cu +7 -0
  335. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q5_1.cu +7 -0
  336. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-bf16-q8_0.cu +7 -0
  337. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-bf16.cu +7 -0
  338. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-f16.cu +7 -0
  339. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_0.cu +7 -0
  340. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q4_1.cu +7 -0
  341. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_0.cu +7 -0
  342. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q5_1.cu +7 -0
  343. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-f16-q8_0.cu +7 -0
  344. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-bf16.cu +7 -0
  345. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-f16.cu +7 -0
  346. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_0.cu +7 -0
  347. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q4_1.cu +7 -0
  348. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_0.cu +7 -0
  349. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q5_1.cu +7 -0
  350. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_0-q8_0.cu +7 -0
  351. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-bf16.cu +7 -0
  352. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-f16.cu +7 -0
  353. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_0.cu +7 -0
  354. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q4_1.cu +7 -0
  355. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_0.cu +7 -0
  356. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q5_1.cu +7 -0
  357. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q4_1-q8_0.cu +7 -0
  358. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-bf16.cu +7 -0
  359. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-f16.cu +7 -0
  360. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_0.cu +7 -0
  361. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q4_1.cu +7 -0
  362. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_0.cu +7 -0
  363. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q5_1.cu +7 -0
  364. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_0-q8_0.cu +7 -0
  365. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-bf16.cu +7 -0
  366. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-f16.cu +7 -0
  367. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_0.cu +7 -0
  368. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q4_1.cu +7 -0
  369. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_0.cu +7 -0
  370. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q5_1.cu +7 -0
  371. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q5_1-q8_0.cu +7 -0
  372. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-bf16.cu +7 -0
  373. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-f16.cu +7 -0
  374. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_0.cu +7 -0
  375. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q4_1.cu +7 -0
  376. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_0.cu +7 -0
  377. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q5_1.cu +7 -0
  378. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/fattn-vec-instance-q8_0-q8_0.cu +7 -0
  379. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_1.cu +5 -0
  380. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_10.cu +5 -0
  381. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_11.cu +5 -0
  382. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_12.cu +5 -0
  383. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_13.cu +5 -0
  384. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_14.cu +5 -0
  385. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_15.cu +5 -0
  386. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_16.cu +5 -0
  387. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_2.cu +5 -0
  388. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_3.cu +5 -0
  389. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_4.cu +5 -0
  390. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_5.cu +5 -0
  391. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_6.cu +5 -0
  392. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_7.cu +5 -0
  393. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_8.cu +5 -0
  394. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmf-instance-ncols_9.cu +5 -0
  395. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
  396. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
  397. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
  398. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
  399. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
  400. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
  401. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
  402. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
  403. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-mxfp4.cu +5 -0
  404. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-nvfp4.cu +5 -0
  405. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q1_0.cu +5 -0
  406. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
  407. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
  408. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
  409. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
  410. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
  411. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
  412. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
  413. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
  414. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
  415. data/vendor/crispasr/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
  416. data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cu +95 -0
  417. data/vendor/crispasr/ggml/src/ggml-cuda/top-k.cuh +3 -0
  418. data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cu +415 -0
  419. data/vendor/crispasr/ggml/src/ggml-cuda/topk-moe.cuh +27 -0
  420. data/vendor/crispasr/ggml/src/ggml-cuda/tri.cu +136 -0
  421. data/vendor/crispasr/ggml/src/ggml-cuda/tri.cuh +5 -0
  422. data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cu +47 -0
  423. data/vendor/crispasr/ggml/src/ggml-cuda/tsembd.cuh +5 -0
  424. data/vendor/crispasr/ggml/src/ggml-cuda/unary.cu +644 -0
  425. data/vendor/crispasr/ggml/src/ggml-cuda/unary.cuh +116 -0
  426. data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cu +293 -0
  427. data/vendor/crispasr/ggml/src/ggml-cuda/upscale.cuh +5 -0
  428. data/vendor/crispasr/ggml/src/ggml-cuda/vecdotq.cuh +1317 -0
  429. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/cuda.h +28 -0
  430. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/hip.h +306 -0
  431. data/vendor/crispasr/ggml/src/ggml-cuda/vendors/musa.h +148 -0
  432. data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cu +199 -0
  433. data/vendor/crispasr/ggml/src/ggml-cuda/wkv.cuh +7 -0
  434. data/vendor/crispasr/ggml/src/ggml-impl.h +783 -0
  435. data/vendor/crispasr/ggml/src/ggml-metal/CMakeLists.txt +124 -0
  436. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.cpp +457 -0
  437. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-common.h +52 -0
  438. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.h +41 -0
  439. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-context.m +778 -0
  440. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.cpp +2117 -0
  441. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.h +299 -0
  442. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-device.m +2093 -0
  443. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-impl.h +1267 -0
  444. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.cpp +5023 -0
  445. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal-ops.h +111 -0
  446. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.cpp +954 -0
  447. data/vendor/crispasr/ggml/src/ggml-metal/ggml-metal.metal +11756 -0
  448. data/vendor/crispasr/ggml/src/ggml-opt.cpp +1094 -0
  449. data/vendor/crispasr/ggml/src/ggml-quants.c +5491 -0
  450. data/vendor/crispasr/ggml/src/ggml-quants.h +112 -0
  451. data/vendor/crispasr/ggml/src/ggml-threading.cpp +12 -0
  452. data/vendor/crispasr/ggml/src/ggml-threading.h +14 -0
  453. data/vendor/crispasr/ggml/src/ggml.c +7925 -0
  454. data/vendor/crispasr/ggml/src/ggml.cpp +26 -0
  455. data/vendor/crispasr/ggml/src/gguf.cpp +1556 -0
  456. data/vendor/crispasr/src/cohere-arch.h +137 -0
  457. data/vendor/crispasr/src/cohere.cpp +5642 -0
  458. data/vendor/crispasr/src/cohere.h +327 -0
  459. data/vendor/crispasr/src/cohere_batch_planner.h +82 -0
  460. data/vendor/crispasr/src/cohere_chunking.h +64 -0
  461. data/vendor/crispasr/src/cohere_decoder_batch_layout.h +60 -0
  462. data/vendor/crispasr/src/cohere_encoder_padded_layout.h +27 -0
  463. data/vendor/crispasr/src/cohere_frontend.cpp +189 -0
  464. data/vendor/crispasr/src/cohere_frontend.h +31 -0
  465. data/vendor/crispasr/src/cohere_ragged_controller.h +149 -0
  466. data/vendor/crispasr/src/cohere_token_renderer.h +181 -0
  467. data/vendor/crispasr/src/core/attention.h +924 -0
  468. data/vendor/crispasr/src/core/audio_chunking.h +97 -0
  469. data/vendor/crispasr/src/core/beam_decode.h +486 -0
  470. data/vendor/crispasr/src/core/cpu_ops.h +135 -0
  471. data/vendor/crispasr/src/core/gguf_loader.cpp +1021 -0
  472. data/vendor/crispasr/src/core/gguf_loader.h +216 -0
  473. data/vendor/crispasr/src/core/gpu_backend_pref.h +119 -0
  474. data/vendor/crispasr/src/core/mel.cpp +519 -0
  475. data/vendor/crispasr/src/core/mel.h +265 -0
  476. data/vendor/crispasr/src/core/ngram_loop_fix.h +173 -0
  477. data/vendor/crispasr/src/core/repetition_loop_guard.h +54 -0
  478. data/vendor/crispasr/src/crispasr_imatrix.cpp +255 -0
  479. data/vendor/crispasr/src/crispasr_imatrix.h +38 -0
  480. metadata +596 -0
@@ -0,0 +1,2887 @@
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/ggml-org/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 ggml_init_params params = {
36
+ // .mem_size = 16*1024*1024,
37
+ // .mem_buffer = NULL,
38
+ // };
39
+ //
40
+ // // memory allocation happens here
41
+ // struct ggml_context * ctx = ggml_init(params);
42
+ //
43
+ // struct ggml_tensor * x = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
44
+ //
45
+ // ggml_set_param(ctx, x); // x is an input variable
46
+ //
47
+ // struct ggml_tensor * a = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
48
+ // struct ggml_tensor * b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
49
+ // struct ggml_tensor * x2 = ggml_mul(ctx, x, x);
50
+ // struct ggml_tensor * f = ggml_add(ctx, 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 ggml_cgraph * gf = ggml_new_graph(ctx);
62
+ // ggml_build_forward_expand(gf, f);
63
+ //
64
+ // // set the input variable and parameter values
65
+ // ggml_set_f32(x, 2.0f);
66
+ // ggml_set_f32(a, 3.0f);
67
+ // ggml_set_f32(b, 4.0f);
68
+ //
69
+ // ggml_graph_compute_with_ctx(ctx, &gf, n_threads);
70
+ //
71
+ // printf("f = %f\n", ggml_get_f32_1d(f, 0));
72
+ //
73
+ // ...
74
+ // }
75
+ //
76
+ // The actual computation is performed in the ggml_graph_compute() function.
77
+ //
78
+ // The ggml_new_tensor_...() functions create new tensors. They are allocated in the memory buffer provided to the
79
+ // 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 ggml_used_mem() function to find out how much memory was
82
+ // actually needed.
83
+ //
84
+ // The 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 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
+ // - ggml_permute()
100
+ // - ggml_conv_1d_1s()
101
+ // - 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 ggml_tensor)
113
+ //
114
+ // The tensors are stored in memory via the 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 ggml_tensor * c = 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 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 ggml_tensor * a = ggml_new_tensor_2d(ctx, 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 ggml_get_f32_1d() and ggml_set_f32_1d() that can be used.
149
+ //
150
+ // ## The matrix multiplication operator (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 GGML_SHARED
177
+ # if defined(_WIN32) && !defined(__MINGW32__)
178
+ # ifdef GGML_BUILD
179
+ # define GGML_API __declspec(dllexport) extern
180
+ # else
181
+ # define GGML_API __declspec(dllimport) extern
182
+ # endif
183
+ # else
184
+ # define GGML_API __attribute__ ((visibility ("default"))) extern
185
+ # endif
186
+ #else
187
+ # define GGML_API extern
188
+ #endif
189
+
190
+ // TODO: support for clang
191
+ #ifdef __GNUC__
192
+ # define GGML_DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
193
+ #elif defined(_MSC_VER)
194
+ # define GGML_DEPRECATED(func, hint) __declspec(deprecated(hint)) func
195
+ #else
196
+ # define GGML_DEPRECATED(func, hint) func
197
+ #endif
198
+
199
+ #ifndef __GNUC__
200
+ # define GGML_ATTRIBUTE_FORMAT(...)
201
+ #elif defined(__MINGW32__) && !defined(__clang__)
202
+ # define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
203
+ #else
204
+ # define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
205
+ #endif
206
+
207
+ #if defined(_WIN32) && !defined(_WIN32_WINNT)
208
+ # define _WIN32_WINNT 0x0A00
209
+ #endif
210
+
211
+ #include <stdbool.h>
212
+ #include <stddef.h>
213
+ #include <stdint.h>
214
+ #include <stdio.h>
215
+
216
+ #define GGML_FILE_MAGIC 0x67676d6c // "ggml"
217
+ #define GGML_FILE_VERSION 2
218
+
219
+ #define GGML_QNT_VERSION 2 // bump this on quantization format changes
220
+ #define GGML_QNT_VERSION_FACTOR 1000 // do not change this
221
+
222
+ #define GGML_MAX_DIMS 4
223
+ #define GGML_MAX_PARAMS 2048
224
+ #define GGML_MAX_SRC 10
225
+ #define GGML_MAX_N_THREADS 512
226
+ #define GGML_MAX_OP_PARAMS 64
227
+
228
+ #ifndef GGML_MAX_NAME
229
+ # define GGML_MAX_NAME 64
230
+ #endif
231
+
232
+ #define GGML_DEFAULT_N_THREADS 4
233
+ #define GGML_DEFAULT_GRAPH_SIZE 2048
234
+
235
+ #if UINTPTR_MAX == 0xFFFFFFFF
236
+ #define GGML_MEM_ALIGN 4
237
+ #elif defined(__EMSCRIPTEN__)
238
+ // emscripten uses max_align_t == 8, so we need GGML_MEM_ALIGN == 8 for 64-bit wasm.
239
+ // (for 32-bit wasm, the first conditional is true and GGML_MEM_ALIGN stays 4.)
240
+ // ref: https://github.com/ggml-org/llama.cpp/pull/18628
241
+ #define GGML_MEM_ALIGN 8
242
+ #else
243
+ #define GGML_MEM_ALIGN 16
244
+ #endif
245
+
246
+ #define GGML_EXIT_SUCCESS 0
247
+ #define GGML_EXIT_ABORTED 1
248
+
249
+ // TODO: convert to enum https://github.com/ggml-org/llama.cpp/pull/16187#discussion_r2388538726
250
+ #define GGML_ROPE_TYPE_NORMAL 0
251
+ #define GGML_ROPE_TYPE_NEOX 2
252
+ #define GGML_ROPE_TYPE_MROPE 8
253
+ #define GGML_ROPE_TYPE_VISION 24
254
+ #define GGML_ROPE_TYPE_IMROPE 40 // binary: 101000
255
+
256
+ #define GGML_MROPE_SECTIONS 4
257
+
258
+ #define GGML_UNUSED(x) (void)(x)
259
+ #ifdef __CUDACC__
260
+ template<typename... Args>
261
+ __host__ __device__ constexpr inline void ggml_unused_vars_impl(Args&&...) noexcept {}
262
+ #define GGML_UNUSED_VARS(...) ggml_unused_vars_impl(__VA_ARGS__)
263
+ #else
264
+ #define GGML_UNUSED_VARS(...) do { (void)sizeof((__VA_ARGS__, 0)); } while(0)
265
+ #endif // __CUDACC__
266
+
267
+ #define GGML_PAD(x, n) (((x) + (n) - 1) & ~((n) - 1))
268
+
269
+ #ifndef NDEBUG
270
+ # define GGML_UNREACHABLE() do { fprintf(stderr, "statement should be unreachable\n"); abort(); } while(0)
271
+ #elif defined(__GNUC__)
272
+ # define GGML_UNREACHABLE() __builtin_unreachable()
273
+ #elif defined(_MSC_VER)
274
+ # define GGML_UNREACHABLE() __assume(0)
275
+ #else
276
+ # define GGML_UNREACHABLE() ((void) 0)
277
+ #endif
278
+
279
+ #ifdef __cplusplus
280
+ # define GGML_NORETURN [[noreturn]]
281
+ #elif defined(_MSC_VER)
282
+ # define GGML_NORETURN __declspec(noreturn)
283
+ #else
284
+ # define GGML_NORETURN _Noreturn
285
+ #endif
286
+
287
+ #define GGML_ABORT(...) ggml_abort(__FILE__, __LINE__, __VA_ARGS__)
288
+ #define GGML_ASSERT(x) if (!(x)) GGML_ABORT("GGML_ASSERT(%s) failed", #x)
289
+
290
+ // used to copy the number of elements and stride in bytes of tensors into local variables.
291
+ // main purpose is to reduce code duplication and improve readability.
292
+ //
293
+ // example:
294
+ //
295
+ // GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne);
296
+ // GGML_TENSOR_LOCALS(size_t, nb1, src1, nb);
297
+ //
298
+ #define GGML_TENSOR_LOCALS_1(type, prefix, pointer, array) \
299
+ const type prefix##0 = (pointer) ? (pointer)->array[0] : 0; \
300
+ GGML_UNUSED(prefix##0);
301
+ #define GGML_TENSOR_LOCALS_2(type, prefix, pointer, array) \
302
+ GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array) \
303
+ const type prefix##1 = (pointer) ? (pointer)->array[1] : 0; \
304
+ GGML_UNUSED(prefix##1);
305
+ #define GGML_TENSOR_LOCALS_3(type, prefix, pointer, array) \
306
+ GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array) \
307
+ const type prefix##2 = (pointer) ? (pointer)->array[2] : 0; \
308
+ GGML_UNUSED(prefix##2);
309
+ #define GGML_TENSOR_LOCALS(type, prefix, pointer, array) \
310
+ GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array) \
311
+ const type prefix##3 = (pointer) ? (pointer)->array[3] : 0; \
312
+ GGML_UNUSED(prefix##3);
313
+
314
+ #define GGML_TENSOR_UNARY_OP_LOCALS \
315
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
316
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
317
+ GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
318
+ GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
319
+
320
+ #define GGML_TENSOR_BINARY_OP_LOCALS \
321
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
322
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
323
+ GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
324
+ GGML_TENSOR_LOCALS(size_t, nb1, src1, nb) \
325
+ GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
326
+ GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
327
+
328
+ #define GGML_TENSOR_TERNARY_OP_LOCALS \
329
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
330
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
331
+ GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
332
+ GGML_TENSOR_LOCALS(size_t, nb1, src1, nb) \
333
+ GGML_TENSOR_LOCALS(int64_t, ne2, src2, ne) \
334
+ GGML_TENSOR_LOCALS(size_t, nb2, src2, nb) \
335
+ GGML_TENSOR_LOCALS(int64_t, ne, dst, ne) \
336
+ GGML_TENSOR_LOCALS(size_t, nb, dst, nb)
337
+
338
+ #define GGML_TENSOR_BINARY_OP_LOCALS01 \
339
+ GGML_TENSOR_LOCALS(int64_t, ne0, src0, ne) \
340
+ GGML_TENSOR_LOCALS(size_t, nb0, src0, nb) \
341
+ GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) \
342
+ GGML_TENSOR_LOCALS(size_t, nb1, src1, nb)
343
+
344
+ #ifdef __cplusplus
345
+ extern "C" {
346
+ #endif
347
+
348
+ // Function type used in fatal error callbacks
349
+ typedef void (*ggml_abort_callback_t)(const char * error_message);
350
+
351
+ // Set the abort callback (passing null will restore original abort functionality: printing a message to stdout)
352
+ // Returns the old callback for chaining
353
+ GGML_API ggml_abort_callback_t ggml_set_abort_callback(ggml_abort_callback_t callback);
354
+
355
+ GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
356
+ GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
357
+
358
+ enum ggml_status {
359
+ GGML_STATUS_ALLOC_FAILED = -2,
360
+ GGML_STATUS_FAILED = -1,
361
+ GGML_STATUS_SUCCESS = 0,
362
+ GGML_STATUS_ABORTED = 1,
363
+ };
364
+
365
+ // get ggml_status name string
366
+ GGML_API const char * ggml_status_to_string(enum ggml_status status);
367
+
368
+ // ieee 754-2008 half-precision float16
369
+ // todo: make this not an integral type
370
+ typedef uint16_t ggml_fp16_t;
371
+ GGML_API float ggml_fp16_to_fp32(ggml_fp16_t);
372
+ GGML_API ggml_fp16_t ggml_fp32_to_fp16(float);
373
+ GGML_API void ggml_fp16_to_fp32_row(const ggml_fp16_t *, float *, int64_t);
374
+ GGML_API void ggml_fp32_to_fp16_row(const float *, ggml_fp16_t *, int64_t);
375
+
376
+ // google brain half-precision bfloat16
377
+ typedef struct { uint16_t bits; } ggml_bf16_t;
378
+ GGML_API ggml_bf16_t ggml_fp32_to_bf16(float);
379
+ GGML_API float ggml_bf16_to_fp32(ggml_bf16_t); // consider just doing << 16
380
+ GGML_API void ggml_bf16_to_fp32_row(const ggml_bf16_t *, float *, int64_t);
381
+ GGML_API void ggml_fp32_to_bf16_row_ref(const float *, ggml_bf16_t *, int64_t);
382
+ GGML_API void ggml_fp32_to_bf16_row(const float *, ggml_bf16_t *, int64_t);
383
+
384
+ struct ggml_object;
385
+ struct ggml_context;
386
+ struct ggml_cgraph;
387
+
388
+ // NOTE: always add types at the end of the enum to keep backward compatibility
389
+ enum ggml_type {
390
+ GGML_TYPE_F32 = 0,
391
+ GGML_TYPE_F16 = 1,
392
+ GGML_TYPE_Q4_0 = 2,
393
+ GGML_TYPE_Q4_1 = 3,
394
+ // GGML_TYPE_Q4_2 = 4, support has been removed
395
+ // GGML_TYPE_Q4_3 = 5, support has been removed
396
+ GGML_TYPE_Q5_0 = 6,
397
+ GGML_TYPE_Q5_1 = 7,
398
+ GGML_TYPE_Q8_0 = 8,
399
+ GGML_TYPE_Q8_1 = 9,
400
+ GGML_TYPE_Q2_K = 10,
401
+ GGML_TYPE_Q3_K = 11,
402
+ GGML_TYPE_Q4_K = 12,
403
+ GGML_TYPE_Q5_K = 13,
404
+ GGML_TYPE_Q6_K = 14,
405
+ GGML_TYPE_Q8_K = 15,
406
+ GGML_TYPE_IQ2_XXS = 16,
407
+ GGML_TYPE_IQ2_XS = 17,
408
+ GGML_TYPE_IQ3_XXS = 18,
409
+ GGML_TYPE_IQ1_S = 19,
410
+ GGML_TYPE_IQ4_NL = 20,
411
+ GGML_TYPE_IQ3_S = 21,
412
+ GGML_TYPE_IQ2_S = 22,
413
+ GGML_TYPE_IQ4_XS = 23,
414
+ GGML_TYPE_I8 = 24,
415
+ GGML_TYPE_I16 = 25,
416
+ GGML_TYPE_I32 = 26,
417
+ GGML_TYPE_I64 = 27,
418
+ GGML_TYPE_F64 = 28,
419
+ GGML_TYPE_IQ1_M = 29,
420
+ GGML_TYPE_BF16 = 30,
421
+ // GGML_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files
422
+ // GGML_TYPE_Q4_0_4_8 = 32,
423
+ // GGML_TYPE_Q4_0_8_8 = 33,
424
+ GGML_TYPE_TQ1_0 = 34,
425
+ GGML_TYPE_TQ2_0 = 35,
426
+ // GGML_TYPE_IQ4_NL_4_4 = 36,
427
+ // GGML_TYPE_IQ4_NL_4_8 = 37,
428
+ // GGML_TYPE_IQ4_NL_8_8 = 38,
429
+ GGML_TYPE_MXFP4 = 39, // MXFP4 (1 block)
430
+ GGML_TYPE_NVFP4 = 40, // NVFP4 (4 blocks, E4M3 scale)
431
+ GGML_TYPE_Q1_0 = 41,
432
+ GGML_TYPE_COUNT = 42,
433
+ };
434
+
435
+ // precision
436
+ enum ggml_prec {
437
+ GGML_PREC_DEFAULT = 0, // stored as ggml_tensor.op_params, 0 by default
438
+ GGML_PREC_F32 = 10,
439
+ };
440
+
441
+ // model file types
442
+ enum ggml_ftype {
443
+ GGML_FTYPE_UNKNOWN = -1,
444
+ GGML_FTYPE_ALL_F32 = 0,
445
+ GGML_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
446
+ GGML_FTYPE_MOSTLY_Q4_0 = 2, // except 1d tensors
447
+ GGML_FTYPE_MOSTLY_Q4_1 = 3, // except 1d tensors
448
+ GGML_FTYPE_MOSTLY_Q4_1_SOME_F16 = 4, // tok_embeddings.weight and output.weight are F16
449
+ GGML_FTYPE_MOSTLY_Q8_0 = 7, // except 1d tensors
450
+ GGML_FTYPE_MOSTLY_Q5_0 = 8, // except 1d tensors
451
+ GGML_FTYPE_MOSTLY_Q5_1 = 9, // except 1d tensors
452
+ GGML_FTYPE_MOSTLY_Q2_K = 10, // except 1d tensors
453
+ GGML_FTYPE_MOSTLY_Q3_K = 11, // except 1d tensors
454
+ GGML_FTYPE_MOSTLY_Q4_K = 12, // except 1d tensors
455
+ GGML_FTYPE_MOSTLY_Q5_K = 13, // except 1d tensors
456
+ GGML_FTYPE_MOSTLY_Q6_K = 14, // except 1d tensors
457
+ GGML_FTYPE_MOSTLY_IQ2_XXS = 15, // except 1d tensors
458
+ GGML_FTYPE_MOSTLY_IQ2_XS = 16, // except 1d tensors
459
+ GGML_FTYPE_MOSTLY_IQ3_XXS = 17, // except 1d tensors
460
+ GGML_FTYPE_MOSTLY_IQ1_S = 18, // except 1d tensors
461
+ GGML_FTYPE_MOSTLY_IQ4_NL = 19, // except 1d tensors
462
+ GGML_FTYPE_MOSTLY_IQ3_S = 20, // except 1d tensors
463
+ GGML_FTYPE_MOSTLY_IQ2_S = 21, // except 1d tensors
464
+ GGML_FTYPE_MOSTLY_IQ4_XS = 22, // except 1d tensors
465
+ GGML_FTYPE_MOSTLY_IQ1_M = 23, // except 1d tensors
466
+ GGML_FTYPE_MOSTLY_BF16 = 24, // except 1d tensors
467
+ GGML_FTYPE_MOSTLY_MXFP4 = 25, // except 1d tensors
468
+ GGML_FTYPE_MOSTLY_NVFP4 = 26, // except 1d tensors
469
+ GGML_FTYPE_MOSTLY_Q1_0 = 27, // except 1d tensors
470
+ };
471
+
472
+ // available tensor operations:
473
+ enum ggml_op {
474
+ GGML_OP_NONE = 0,
475
+
476
+ GGML_OP_DUP,
477
+ GGML_OP_ADD,
478
+ GGML_OP_ADD_ID,
479
+ GGML_OP_ADD1,
480
+ GGML_OP_ACC,
481
+ GGML_OP_SUB,
482
+ GGML_OP_MUL,
483
+ GGML_OP_DIV,
484
+ GGML_OP_SQR,
485
+ GGML_OP_SQRT,
486
+ GGML_OP_LOG,
487
+ GGML_OP_SIN,
488
+ GGML_OP_COS,
489
+ GGML_OP_SUM,
490
+ GGML_OP_SUM_ROWS,
491
+ GGML_OP_CUMSUM,
492
+ GGML_OP_MEAN,
493
+ GGML_OP_ARGMAX,
494
+ GGML_OP_COUNT_EQUAL,
495
+ GGML_OP_REPEAT,
496
+ GGML_OP_REPEAT_BACK,
497
+ GGML_OP_CONCAT,
498
+ GGML_OP_SILU_BACK,
499
+ GGML_OP_NORM, // normalize
500
+ GGML_OP_NORM_AFFINE, // fused normalize + affine (w*norm(x)+b)
501
+ GGML_OP_RMS_NORM,
502
+ GGML_OP_RMS_NORM_BACK,
503
+ GGML_OP_GROUP_NORM,
504
+ GGML_OP_L2_NORM,
505
+
506
+ GGML_OP_MUL_MAT,
507
+ GGML_OP_MUL_MAT_ID,
508
+ GGML_OP_OUT_PROD,
509
+
510
+ GGML_OP_SCALE,
511
+ GGML_OP_SET,
512
+ GGML_OP_CPY,
513
+ GGML_OP_CONT,
514
+ GGML_OP_RESHAPE,
515
+ GGML_OP_VIEW,
516
+ GGML_OP_PERMUTE,
517
+ GGML_OP_TRANSPOSE,
518
+ GGML_OP_GET_ROWS,
519
+ GGML_OP_GET_ROWS_BACK,
520
+ GGML_OP_SET_ROWS,
521
+ GGML_OP_DIAG,
522
+ GGML_OP_DIAG_MASK_INF,
523
+ GGML_OP_DIAG_MASK_ZERO,
524
+ GGML_OP_SOFT_MAX,
525
+ GGML_OP_SOFT_MAX_BACK,
526
+ GGML_OP_ROPE,
527
+ GGML_OP_ROPE_BACK,
528
+ GGML_OP_CLAMP,
529
+ GGML_OP_CONV_TRANSPOSE_1D,
530
+ GGML_OP_COL2IM_1D,
531
+ GGML_OP_IM2COL,
532
+ GGML_OP_IM2COL_BACK,
533
+ GGML_OP_IM2COL_3D,
534
+ GGML_OP_CONV_2D,
535
+ GGML_OP_CONV_3D,
536
+ GGML_OP_CONV_2D_DW,
537
+ GGML_OP_CONV_TRANSPOSE_2D,
538
+ GGML_OP_POOL_1D,
539
+ GGML_OP_POOL_2D,
540
+ GGML_OP_POOL_2D_BACK,
541
+ GGML_OP_UPSCALE,
542
+ GGML_OP_PAD,
543
+ GGML_OP_PAD_REFLECT_1D,
544
+ GGML_OP_ROLL,
545
+ GGML_OP_ARANGE,
546
+ GGML_OP_TIMESTEP_EMBEDDING,
547
+ GGML_OP_ARGSORT,
548
+ GGML_OP_TOP_K,
549
+ GGML_OP_LEAKY_RELU,
550
+ GGML_OP_TRI,
551
+ GGML_OP_FILL,
552
+
553
+ GGML_OP_FLASH_ATTN_EXT,
554
+ GGML_OP_FLASH_ATTN_BACK,
555
+ GGML_OP_SSM_CONV,
556
+ GGML_OP_SSM_SCAN,
557
+ GGML_OP_WIN_PART,
558
+ GGML_OP_WIN_UNPART,
559
+ GGML_OP_GET_REL_POS,
560
+ GGML_OP_ADD_REL_POS,
561
+ GGML_OP_RWKV_WKV6,
562
+ GGML_OP_GATED_LINEAR_ATTN,
563
+ GGML_OP_RWKV_WKV7,
564
+ GGML_OP_SOLVE_TRI,
565
+ GGML_OP_GATED_DELTA_NET,
566
+
567
+ GGML_OP_UNARY,
568
+
569
+ GGML_OP_MAP_CUSTOM1,
570
+ GGML_OP_MAP_CUSTOM2,
571
+ GGML_OP_MAP_CUSTOM3,
572
+
573
+ GGML_OP_CUSTOM,
574
+
575
+ GGML_OP_CROSS_ENTROPY_LOSS,
576
+ GGML_OP_CROSS_ENTROPY_LOSS_BACK,
577
+ GGML_OP_OPT_STEP_ADAMW,
578
+ GGML_OP_OPT_STEP_SGD,
579
+
580
+ GGML_OP_GLU,
581
+
582
+ // CrispASR patch (PR #07-metal-aa-snake-beta): fused BigVGAN v2
583
+ // anti-aliased SnakeBeta (upsample 2× + sin²(α·x)/β + downsample 2×).
584
+ // MUST RE-APPLY after every ggml bump.
585
+ GGML_OP_AA_SNAKE_BETA,
586
+
587
+ GGML_OP_COUNT,
588
+ };
589
+
590
+ enum ggml_unary_op {
591
+ GGML_UNARY_OP_ABS,
592
+ GGML_UNARY_OP_SGN,
593
+ GGML_UNARY_OP_NEG,
594
+ GGML_UNARY_OP_STEP,
595
+ GGML_UNARY_OP_TANH,
596
+ GGML_UNARY_OP_ELU,
597
+ GGML_UNARY_OP_RELU,
598
+ GGML_UNARY_OP_SIGMOID,
599
+ GGML_UNARY_OP_GELU,
600
+ GGML_UNARY_OP_GELU_QUICK,
601
+ GGML_UNARY_OP_SILU,
602
+ GGML_UNARY_OP_HARDSWISH,
603
+ GGML_UNARY_OP_HARDSIGMOID,
604
+ GGML_UNARY_OP_EXP,
605
+ GGML_UNARY_OP_EXPM1,
606
+ GGML_UNARY_OP_SOFTPLUS,
607
+ GGML_UNARY_OP_GELU_ERF,
608
+ GGML_UNARY_OP_XIELU,
609
+ GGML_UNARY_OP_FLOOR,
610
+ GGML_UNARY_OP_CEIL,
611
+ GGML_UNARY_OP_ROUND,
612
+ GGML_UNARY_OP_TRUNC,
613
+
614
+ GGML_UNARY_OP_COUNT,
615
+ };
616
+
617
+ enum ggml_glu_op {
618
+ GGML_GLU_OP_REGLU,
619
+ GGML_GLU_OP_GEGLU,
620
+ GGML_GLU_OP_SWIGLU,
621
+ GGML_GLU_OP_SWIGLU_OAI,
622
+ GGML_GLU_OP_GEGLU_ERF,
623
+ GGML_GLU_OP_GEGLU_QUICK,
624
+ GGML_GLU_OP_SIGLU,
625
+
626
+ GGML_GLU_OP_COUNT,
627
+ };
628
+
629
+ enum ggml_object_type {
630
+ GGML_OBJECT_TYPE_TENSOR,
631
+ GGML_OBJECT_TYPE_GRAPH,
632
+ GGML_OBJECT_TYPE_WORK_BUFFER
633
+ };
634
+
635
+ enum ggml_log_level {
636
+ GGML_LOG_LEVEL_NONE = 0,
637
+ GGML_LOG_LEVEL_DEBUG = 1,
638
+ GGML_LOG_LEVEL_INFO = 2,
639
+ GGML_LOG_LEVEL_WARN = 3,
640
+ GGML_LOG_LEVEL_ERROR = 4,
641
+ GGML_LOG_LEVEL_CONT = 5, // continue previous log
642
+ };
643
+
644
+ // this tensor...
645
+ enum ggml_tensor_flag {
646
+ GGML_TENSOR_FLAG_INPUT = 1, // ...is an input for the GGML compute graph
647
+ GGML_TENSOR_FLAG_OUTPUT = 2, // ...is an output for the GGML compute graph
648
+ GGML_TENSOR_FLAG_PARAM = 4, // ...contains trainable parameters
649
+ GGML_TENSOR_FLAG_LOSS = 8, // ...defines loss for numerical optimization (multiple loss tensors add up)
650
+ GGML_TENSOR_FLAG_COMPUTE = 16, // ...must be computed
651
+ };
652
+
653
+ enum ggml_tri_type {
654
+ GGML_TRI_TYPE_UPPER_DIAG = 0,
655
+ GGML_TRI_TYPE_UPPER = 1,
656
+ GGML_TRI_TYPE_LOWER_DIAG = 2,
657
+ GGML_TRI_TYPE_LOWER = 3
658
+ };
659
+
660
+ struct ggml_init_params {
661
+ // memory pool
662
+ size_t mem_size; // bytes
663
+ void * mem_buffer; // if NULL, memory will be allocated internally
664
+ bool no_alloc; // don't allocate memory for the tensor data
665
+ };
666
+
667
+ // n-dimensional tensor
668
+ struct ggml_tensor {
669
+ enum ggml_type type;
670
+
671
+ struct ggml_backend_buffer * buffer;
672
+
673
+ int64_t ne[GGML_MAX_DIMS]; // number of elements
674
+ size_t nb[GGML_MAX_DIMS]; // stride in bytes:
675
+ // nb[0] = ggml_type_size(type)
676
+ // nb[1] = nb[0] * (ne[0] / ggml_blck_size(type)) + padding
677
+ // nb[i] = nb[i-1] * ne[i-1]
678
+
679
+ // compute data
680
+ enum ggml_op op;
681
+
682
+ // op params - allocated as int32_t for alignment
683
+ int32_t op_params[GGML_MAX_OP_PARAMS / sizeof(int32_t)];
684
+
685
+ int32_t flags;
686
+
687
+ struct ggml_tensor * src[GGML_MAX_SRC];
688
+
689
+ // source tensor and offset for views
690
+ struct ggml_tensor * view_src;
691
+ size_t view_offs;
692
+
693
+ void * data;
694
+
695
+ char name[GGML_MAX_NAME];
696
+
697
+ void * extra; // extra things e.g. for ggml-cuda.cu
698
+
699
+ char padding[8];
700
+ };
701
+
702
+ static const size_t GGML_TENSOR_SIZE = sizeof(struct ggml_tensor);
703
+
704
+ // Abort callback
705
+ // If not NULL, called before ggml computation
706
+ // If it returns true, the computation is aborted
707
+ typedef bool (*ggml_abort_callback)(void * data);
708
+
709
+
710
+ //
711
+ // GUID
712
+ //
713
+
714
+ // GUID types
715
+ typedef uint8_t ggml_guid[16];
716
+ typedef ggml_guid * ggml_guid_t;
717
+
718
+ GGML_API bool ggml_guid_matches(ggml_guid_t guid_a, ggml_guid_t guid_b);
719
+
720
+ // misc
721
+
722
+ GGML_API const char * ggml_version(void);
723
+ GGML_API const char * ggml_commit(void);
724
+
725
+ GGML_API void ggml_time_init(void); // call this once at the beginning of the program
726
+ GGML_API int64_t ggml_time_ms(void);
727
+ GGML_API int64_t ggml_time_us(void);
728
+ GGML_API int64_t ggml_cycles(void);
729
+ GGML_API int64_t ggml_cycles_per_ms(void);
730
+
731
+ // accepts a UTF-8 path, even on Windows
732
+ GGML_API FILE * ggml_fopen(const char * fname, const char * mode);
733
+
734
+ GGML_API void ggml_print_object (const struct ggml_object * obj);
735
+ GGML_API void ggml_print_objects(const struct ggml_context * ctx);
736
+
737
+ GGML_API int64_t ggml_nelements (const struct ggml_tensor * tensor);
738
+ GGML_API int64_t ggml_nrows (const struct ggml_tensor * tensor);
739
+ GGML_API size_t ggml_nbytes (const struct ggml_tensor * tensor);
740
+ GGML_API size_t ggml_nbytes_pad(const struct ggml_tensor * tensor); // same as ggml_nbytes() but padded to GGML_MEM_ALIGN
741
+
742
+ GGML_API int64_t ggml_blck_size(enum ggml_type type);
743
+ GGML_API size_t ggml_type_size(enum ggml_type type); // size in bytes for all elements in a block
744
+ GGML_API size_t ggml_row_size (enum ggml_type type, int64_t ne); // size in bytes for all elements in a row
745
+
746
+ GGML_DEPRECATED(
747
+ GGML_API double ggml_type_sizef(enum ggml_type type), // ggml_type_size()/ggml_blck_size() as float
748
+ "use ggml_row_size() instead");
749
+
750
+ GGML_API const char * ggml_type_name(enum ggml_type type);
751
+ GGML_API const char * ggml_op_name (enum ggml_op op);
752
+ GGML_API const char * ggml_op_symbol(enum ggml_op op);
753
+
754
+ GGML_API const char * ggml_unary_op_name(enum ggml_unary_op op);
755
+ GGML_API const char * ggml_glu_op_name(enum ggml_glu_op op);
756
+ GGML_API const char * ggml_op_desc(const struct ggml_tensor * t); // unary or op name
757
+
758
+ GGML_API size_t ggml_element_size(const struct ggml_tensor * tensor);
759
+
760
+ GGML_API bool ggml_is_quantized(enum ggml_type type);
761
+
762
+ // TODO: temporary until model loading of ggml examples is refactored
763
+ GGML_API enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype);
764
+
765
+ GGML_API bool ggml_is_transposed(const struct ggml_tensor * tensor);
766
+ GGML_API bool ggml_is_permuted (const struct ggml_tensor * tensor);
767
+ GGML_API bool ggml_is_empty (const struct ggml_tensor * tensor);
768
+ GGML_API bool ggml_is_view (const struct ggml_tensor * tensor);
769
+ GGML_API bool ggml_is_scalar (const struct ggml_tensor * tensor);
770
+ GGML_API bool ggml_is_vector (const struct ggml_tensor * tensor);
771
+ GGML_API bool ggml_is_matrix (const struct ggml_tensor * tensor);
772
+ GGML_API bool ggml_is_3d (const struct ggml_tensor * tensor);
773
+ GGML_API int ggml_n_dims (const struct ggml_tensor * tensor); // returns 1 for scalars
774
+
775
+ // returns whether the tensor elements can be iterated over with a flattened index (no gaps, no permutation)
776
+ GGML_API bool ggml_is_contiguous (const struct ggml_tensor * tensor);
777
+ GGML_API bool ggml_is_contiguous_0(const struct ggml_tensor * tensor); // same as ggml_is_contiguous()
778
+ GGML_API bool ggml_is_contiguous_1(const struct ggml_tensor * tensor); // contiguous for dims >= 1
779
+ GGML_API bool ggml_is_contiguous_2(const struct ggml_tensor * tensor); // contiguous for dims >= 2
780
+
781
+ // returns whether the tensor elements are allocated as one contiguous block of memory (no gaps, but permutation ok)
782
+ GGML_API bool ggml_is_contiguously_allocated(const struct ggml_tensor * tensor);
783
+
784
+ // true for tensor that is stored in memory as CxWxHxN and has been permuted to WxHxCxN
785
+ GGML_API bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor);
786
+
787
+ // true if the elements in dimension 0 are contiguous, or there is just 1 block of elements
788
+ GGML_API bool ggml_is_contiguous_rows(const struct ggml_tensor * tensor);
789
+
790
+ GGML_API bool ggml_are_same_shape (const struct ggml_tensor * t0, const struct ggml_tensor * t1);
791
+ GGML_API bool ggml_are_same_stride(const struct ggml_tensor * t0, const struct ggml_tensor * t1);
792
+
793
+ GGML_API bool ggml_can_repeat(const struct ggml_tensor * t0, const struct ggml_tensor * t1);
794
+
795
+ // use this to compute the memory overhead of a tensor
796
+ GGML_API size_t ggml_tensor_overhead(void);
797
+
798
+ GGML_API bool ggml_validate_row_data(enum ggml_type type, const void * data, size_t nbytes);
799
+
800
+ // main
801
+
802
+ GGML_API struct ggml_context * ggml_init (struct ggml_init_params params);
803
+ GGML_API void ggml_reset(struct ggml_context * ctx);
804
+ GGML_API void ggml_free (struct ggml_context * ctx);
805
+
806
+ GGML_API size_t ggml_used_mem(const struct ggml_context * ctx);
807
+
808
+ GGML_API bool ggml_get_no_alloc(struct ggml_context * ctx);
809
+ GGML_API void ggml_set_no_alloc(struct ggml_context * ctx, bool no_alloc);
810
+
811
+ GGML_API void * ggml_get_mem_buffer (const struct ggml_context * ctx);
812
+ GGML_API size_t ggml_get_mem_size (const struct ggml_context * ctx);
813
+ GGML_API size_t ggml_get_max_tensor_size(const struct ggml_context * ctx);
814
+
815
+ GGML_API struct ggml_tensor * ggml_new_tensor(
816
+ struct ggml_context * ctx,
817
+ enum ggml_type type,
818
+ int n_dims,
819
+ const int64_t *ne);
820
+
821
+ GGML_API struct ggml_tensor * ggml_new_tensor_1d(
822
+ struct ggml_context * ctx,
823
+ enum ggml_type type,
824
+ int64_t ne0);
825
+
826
+ GGML_API struct ggml_tensor * ggml_new_tensor_2d(
827
+ struct ggml_context * ctx,
828
+ enum ggml_type type,
829
+ int64_t ne0,
830
+ int64_t ne1);
831
+
832
+ GGML_API struct ggml_tensor * ggml_new_tensor_3d(
833
+ struct ggml_context * ctx,
834
+ enum ggml_type type,
835
+ int64_t ne0,
836
+ int64_t ne1,
837
+ int64_t ne2);
838
+
839
+ GGML_API struct ggml_tensor * ggml_new_tensor_4d(
840
+ struct ggml_context * ctx,
841
+ enum ggml_type type,
842
+ int64_t ne0,
843
+ int64_t ne1,
844
+ int64_t ne2,
845
+ int64_t ne3);
846
+
847
+ GGML_API void * ggml_new_buffer(struct ggml_context * ctx, size_t nbytes);
848
+
849
+ GGML_API struct ggml_tensor * ggml_dup_tensor (struct ggml_context * ctx, const struct ggml_tensor * src);
850
+ GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, struct ggml_tensor * src);
851
+
852
+ // Context tensor enumeration and lookup
853
+ GGML_API struct ggml_tensor * ggml_get_first_tensor(const struct ggml_context * ctx);
854
+ GGML_API struct ggml_tensor * ggml_get_next_tensor (const struct ggml_context * ctx, struct ggml_tensor * tensor);
855
+ GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);
856
+
857
+ // Converts a flat index into coordinates
858
+ GGML_API void ggml_unravel_index(const struct ggml_tensor * tensor, int64_t i, int64_t * i0, int64_t * i1, int64_t * i2, int64_t * i3);
859
+
860
+ GGML_API enum ggml_unary_op ggml_get_unary_op(const struct ggml_tensor * tensor);
861
+ GGML_API enum ggml_glu_op ggml_get_glu_op(const struct ggml_tensor * tensor);
862
+
863
+ GGML_API void * ggml_get_data (const struct ggml_tensor * tensor);
864
+ GGML_API float * ggml_get_data_f32(const struct ggml_tensor * tensor);
865
+
866
+ GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
867
+ GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
868
+ GGML_ATTRIBUTE_FORMAT(2, 3)
869
+ GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
870
+
871
+ // Tensor flags
872
+ GGML_API void ggml_set_input(struct ggml_tensor * tensor);
873
+ GGML_API void ggml_set_output(struct ggml_tensor * tensor);
874
+ GGML_API void ggml_set_param(struct ggml_tensor * tensor);
875
+ GGML_API void ggml_set_loss(struct ggml_tensor * tensor);
876
+
877
+ //
878
+ // operations on tensors with backpropagation
879
+ //
880
+
881
+ GGML_API struct ggml_tensor * ggml_dup(
882
+ struct ggml_context * ctx,
883
+ struct ggml_tensor * a);
884
+
885
+ // in-place, returns view(a)
886
+ GGML_API struct ggml_tensor * ggml_dup_inplace(
887
+ struct ggml_context * ctx,
888
+ struct ggml_tensor * a);
889
+
890
+ GGML_API struct ggml_tensor * ggml_add(
891
+ struct ggml_context * ctx,
892
+ struct ggml_tensor * a,
893
+ struct ggml_tensor * b);
894
+
895
+ GGML_API struct ggml_tensor * ggml_add_inplace(
896
+ struct ggml_context * ctx,
897
+ struct ggml_tensor * a,
898
+ struct ggml_tensor * b);
899
+
900
+ GGML_API struct ggml_tensor * ggml_add_cast(
901
+ struct ggml_context * ctx,
902
+ struct ggml_tensor * a,
903
+ struct ggml_tensor * b,
904
+ enum ggml_type type);
905
+
906
+ // dst[i0, i1, i2] = a[i0, i1, i2] + b[i0, ids[i1, i2]]
907
+ GGML_API struct ggml_tensor * ggml_add_id(
908
+ struct ggml_context * ctx,
909
+ struct ggml_tensor * a,
910
+ struct ggml_tensor * b,
911
+ struct ggml_tensor * ids);
912
+
913
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_add1(
914
+ struct ggml_context * ctx,
915
+ struct ggml_tensor * a,
916
+ struct ggml_tensor * b),
917
+ "use ggml_add instead");
918
+
919
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_add1_inplace(
920
+ struct ggml_context * ctx,
921
+ struct ggml_tensor * a,
922
+ struct ggml_tensor * b),
923
+ "use ggml_add_inplace instead");
924
+
925
+ // dst = a
926
+ // view(dst, nb1, nb2, nb3, offset) += b
927
+ // return dst
928
+ GGML_API struct ggml_tensor * ggml_acc(
929
+ struct ggml_context * ctx,
930
+ struct ggml_tensor * a,
931
+ struct ggml_tensor * b,
932
+ size_t nb1,
933
+ size_t nb2,
934
+ size_t nb3,
935
+ size_t offset);
936
+
937
+ GGML_API struct ggml_tensor * ggml_acc_inplace(
938
+ struct ggml_context * ctx,
939
+ struct ggml_tensor * a,
940
+ struct ggml_tensor * b,
941
+ size_t nb1,
942
+ size_t nb2,
943
+ size_t nb3,
944
+ size_t offset);
945
+
946
+ GGML_API struct ggml_tensor * ggml_sub(
947
+ struct ggml_context * ctx,
948
+ struct ggml_tensor * a,
949
+ struct ggml_tensor * b);
950
+
951
+ GGML_API struct ggml_tensor * ggml_sub_inplace(
952
+ struct ggml_context * ctx,
953
+ struct ggml_tensor * a,
954
+ struct ggml_tensor * b);
955
+
956
+ GGML_API struct ggml_tensor * ggml_mul(
957
+ struct ggml_context * ctx,
958
+ struct ggml_tensor * a,
959
+ struct ggml_tensor * b);
960
+
961
+ GGML_API struct ggml_tensor * ggml_mul_inplace(
962
+ struct ggml_context * ctx,
963
+ struct ggml_tensor * a,
964
+ struct ggml_tensor * b);
965
+
966
+ GGML_API struct ggml_tensor * ggml_div(
967
+ struct ggml_context * ctx,
968
+ struct ggml_tensor * a,
969
+ struct ggml_tensor * b);
970
+
971
+ GGML_API struct ggml_tensor * ggml_div_inplace(
972
+ struct ggml_context * ctx,
973
+ struct ggml_tensor * a,
974
+ struct ggml_tensor * b);
975
+
976
+ GGML_API struct ggml_tensor * ggml_sqr(
977
+ struct ggml_context * ctx,
978
+ struct ggml_tensor * a);
979
+
980
+ GGML_API struct ggml_tensor * ggml_sqr_inplace(
981
+ struct ggml_context * ctx,
982
+ struct ggml_tensor * a);
983
+
984
+ GGML_API struct ggml_tensor * ggml_sqrt(
985
+ struct ggml_context * ctx,
986
+ struct ggml_tensor * a);
987
+
988
+ GGML_API struct ggml_tensor * ggml_sqrt_inplace(
989
+ struct ggml_context * ctx,
990
+ struct ggml_tensor * a);
991
+
992
+ GGML_API struct ggml_tensor * ggml_log(
993
+ struct ggml_context * ctx,
994
+ struct ggml_tensor * a);
995
+
996
+ GGML_API struct ggml_tensor * ggml_log_inplace(
997
+ struct ggml_context * ctx,
998
+ struct ggml_tensor * a);
999
+
1000
+ GGML_API struct ggml_tensor * ggml_expm1(
1001
+ struct ggml_context * ctx,
1002
+ struct ggml_tensor * a);
1003
+
1004
+ GGML_API struct ggml_tensor * ggml_expm1_inplace(
1005
+ struct ggml_context * ctx,
1006
+ struct ggml_tensor * a);
1007
+
1008
+ GGML_API struct ggml_tensor * ggml_softplus(
1009
+ struct ggml_context * ctx,
1010
+ struct ggml_tensor * a);
1011
+
1012
+ GGML_API struct ggml_tensor * ggml_softplus_inplace(
1013
+ struct ggml_context * ctx,
1014
+ struct ggml_tensor * a);
1015
+
1016
+ GGML_API struct ggml_tensor * ggml_sin(
1017
+ struct ggml_context * ctx,
1018
+ struct ggml_tensor * a);
1019
+
1020
+ GGML_API struct ggml_tensor * ggml_sin_inplace(
1021
+ struct ggml_context * ctx,
1022
+ struct ggml_tensor * a);
1023
+
1024
+ GGML_API struct ggml_tensor * ggml_cos(
1025
+ struct ggml_context * ctx,
1026
+ struct ggml_tensor * a);
1027
+
1028
+ GGML_API struct ggml_tensor * ggml_cos_inplace(
1029
+ struct ggml_context * ctx,
1030
+ struct ggml_tensor * a);
1031
+
1032
+ // return scalar
1033
+ GGML_API struct ggml_tensor * ggml_sum(
1034
+ struct ggml_context * ctx,
1035
+ struct ggml_tensor * a);
1036
+
1037
+ // sums along rows, with input shape [a,b,c,d] return shape [1,b,c,d]
1038
+ GGML_API struct ggml_tensor * ggml_sum_rows(
1039
+ struct ggml_context * ctx,
1040
+ struct ggml_tensor * a);
1041
+
1042
+ GGML_API struct ggml_tensor * ggml_cumsum(
1043
+ struct ggml_context * ctx,
1044
+ struct ggml_tensor * a);
1045
+
1046
+ // mean along rows
1047
+ GGML_API struct ggml_tensor * ggml_mean(
1048
+ struct ggml_context * ctx,
1049
+ struct ggml_tensor * a);
1050
+
1051
+ // argmax along rows
1052
+ GGML_API struct ggml_tensor * ggml_argmax(
1053
+ struct ggml_context * ctx,
1054
+ struct ggml_tensor * a);
1055
+
1056
+ // count number of equal elements in a and b
1057
+ GGML_API struct ggml_tensor * ggml_count_equal(
1058
+ struct ggml_context * ctx,
1059
+ struct ggml_tensor * a,
1060
+ struct ggml_tensor * b);
1061
+
1062
+ // if a is the same shape as b, and a is not parameter, return a
1063
+ // otherwise, return a new tensor: repeat(a) to fit in b
1064
+ GGML_API struct ggml_tensor * ggml_repeat(
1065
+ struct ggml_context * ctx,
1066
+ struct ggml_tensor * a,
1067
+ struct ggml_tensor * b);
1068
+
1069
+ // repeat a to the specified shape
1070
+ GGML_API struct ggml_tensor * ggml_repeat_4d(
1071
+ struct ggml_context * ctx,
1072
+ struct ggml_tensor * a,
1073
+ int64_t ne0,
1074
+ int64_t ne1,
1075
+ int64_t ne2,
1076
+ int64_t ne3);
1077
+
1078
+ // sums repetitions in a into shape of b
1079
+ GGML_API struct ggml_tensor * ggml_repeat_back(
1080
+ struct ggml_context * ctx,
1081
+ struct ggml_tensor * a,
1082
+ struct ggml_tensor * b); // sum up values that are adjacent in dims > 0 instead of repeated with same stride
1083
+
1084
+ // concat a and b along dim
1085
+ // used in stable-diffusion
1086
+ GGML_API struct ggml_tensor * ggml_concat(
1087
+ struct ggml_context * ctx,
1088
+ struct ggml_tensor * a,
1089
+ struct ggml_tensor * b,
1090
+ int dim);
1091
+
1092
+ GGML_API struct ggml_tensor * ggml_abs(
1093
+ struct ggml_context * ctx,
1094
+ struct ggml_tensor * a);
1095
+
1096
+ GGML_API struct ggml_tensor * ggml_abs_inplace(
1097
+ struct ggml_context * ctx,
1098
+ struct ggml_tensor * a);
1099
+
1100
+ GGML_API struct ggml_tensor * ggml_sgn(
1101
+ struct ggml_context * ctx,
1102
+ struct ggml_tensor * a);
1103
+
1104
+ GGML_API struct ggml_tensor * ggml_sgn_inplace(
1105
+ struct ggml_context * ctx,
1106
+ struct ggml_tensor * a);
1107
+
1108
+ GGML_API struct ggml_tensor * ggml_neg(
1109
+ struct ggml_context * ctx,
1110
+ struct ggml_tensor * a);
1111
+
1112
+ GGML_API struct ggml_tensor * ggml_neg_inplace(
1113
+ struct ggml_context * ctx,
1114
+ struct ggml_tensor * a);
1115
+
1116
+ GGML_API struct ggml_tensor * ggml_step(
1117
+ struct ggml_context * ctx,
1118
+ struct ggml_tensor * a);
1119
+
1120
+ GGML_API struct ggml_tensor * ggml_step_inplace(
1121
+ struct ggml_context * ctx,
1122
+ struct ggml_tensor * a);
1123
+
1124
+ GGML_API struct ggml_tensor * ggml_tanh(
1125
+ struct ggml_context * ctx,
1126
+ struct ggml_tensor * a);
1127
+
1128
+ GGML_API struct ggml_tensor * ggml_tanh_inplace(
1129
+ struct ggml_context * ctx,
1130
+ struct ggml_tensor * a);
1131
+
1132
+ GGML_API struct ggml_tensor * ggml_elu(
1133
+ struct ggml_context * ctx,
1134
+ struct ggml_tensor * a);
1135
+
1136
+ GGML_API struct ggml_tensor * ggml_elu_inplace(
1137
+ struct ggml_context * ctx,
1138
+ struct ggml_tensor * a);
1139
+
1140
+ GGML_API struct ggml_tensor * ggml_relu(
1141
+ struct ggml_context * ctx,
1142
+ struct ggml_tensor * a);
1143
+
1144
+ GGML_API struct ggml_tensor * ggml_leaky_relu(
1145
+ struct ggml_context * ctx,
1146
+ struct ggml_tensor * a, float negative_slope, bool inplace);
1147
+
1148
+ GGML_API struct ggml_tensor * ggml_relu_inplace(
1149
+ struct ggml_context * ctx,
1150
+ struct ggml_tensor * a);
1151
+
1152
+ GGML_API struct ggml_tensor * ggml_sigmoid(
1153
+ struct ggml_context * ctx,
1154
+ struct ggml_tensor * a);
1155
+
1156
+ GGML_API struct ggml_tensor * ggml_sigmoid_inplace(
1157
+ struct ggml_context * ctx,
1158
+ struct ggml_tensor * a);
1159
+
1160
+ GGML_API struct ggml_tensor * ggml_gelu(
1161
+ struct ggml_context * ctx,
1162
+ struct ggml_tensor * a);
1163
+
1164
+ GGML_API struct ggml_tensor * ggml_gelu_inplace(
1165
+ struct ggml_context * ctx,
1166
+ struct ggml_tensor * a);
1167
+
1168
+ // GELU using erf (error function) when possible
1169
+ // some backends may fallback to approximation based on Abramowitz and Stegun formula
1170
+ GGML_API struct ggml_tensor * ggml_gelu_erf(
1171
+ struct ggml_context * ctx,
1172
+ struct ggml_tensor * a);
1173
+
1174
+ GGML_API struct ggml_tensor * ggml_gelu_erf_inplace(
1175
+ struct ggml_context * ctx,
1176
+ struct ggml_tensor * a);
1177
+
1178
+ GGML_API struct ggml_tensor * ggml_gelu_quick(
1179
+ struct ggml_context * ctx,
1180
+ struct ggml_tensor * a);
1181
+
1182
+ GGML_API struct ggml_tensor * ggml_gelu_quick_inplace(
1183
+ struct ggml_context * ctx,
1184
+ struct ggml_tensor * a);
1185
+
1186
+ GGML_API struct ggml_tensor * ggml_silu(
1187
+ struct ggml_context * ctx,
1188
+ struct ggml_tensor * a);
1189
+
1190
+ GGML_API struct ggml_tensor * ggml_silu_inplace(
1191
+ struct ggml_context * ctx,
1192
+ struct ggml_tensor * a);
1193
+
1194
+ // a - x
1195
+ // b - dy
1196
+ GGML_API struct ggml_tensor * ggml_silu_back(
1197
+ struct ggml_context * ctx,
1198
+ struct ggml_tensor * a,
1199
+ struct ggml_tensor * b);
1200
+
1201
+ // hardswish(x) = x * relu6(x + 3) / 6
1202
+ GGML_API struct ggml_tensor * ggml_hardswish(
1203
+ struct ggml_context * ctx,
1204
+ struct ggml_tensor * a);
1205
+
1206
+ // hardsigmoid(x) = relu6(x + 3) / 6
1207
+ GGML_API struct ggml_tensor * ggml_hardsigmoid(
1208
+ struct ggml_context * ctx,
1209
+ struct ggml_tensor * a);
1210
+
1211
+ GGML_API struct ggml_tensor * ggml_exp(
1212
+ struct ggml_context * ctx,
1213
+ struct ggml_tensor * a);
1214
+
1215
+ GGML_API struct ggml_tensor * ggml_exp_inplace(
1216
+ struct ggml_context * ctx,
1217
+ struct ggml_tensor * a);
1218
+
1219
+ GGML_API struct ggml_tensor * ggml_floor(
1220
+ struct ggml_context * ctx,
1221
+ struct ggml_tensor * a);
1222
+
1223
+ GGML_API struct ggml_tensor * ggml_floor_inplace(
1224
+ struct ggml_context * ctx,
1225
+ struct ggml_tensor * a);
1226
+
1227
+ GGML_API struct ggml_tensor * ggml_ceil(
1228
+ struct ggml_context * ctx,
1229
+ struct ggml_tensor * a);
1230
+
1231
+ GGML_API struct ggml_tensor * ggml_ceil_inplace(
1232
+ struct ggml_context * ctx,
1233
+ struct ggml_tensor * a);
1234
+
1235
+ GGML_API struct ggml_tensor * ggml_round(
1236
+ struct ggml_context * ctx,
1237
+ struct ggml_tensor * a);
1238
+
1239
+ GGML_API struct ggml_tensor * ggml_round_inplace(
1240
+ struct ggml_context * ctx,
1241
+ struct ggml_tensor * a);
1242
+
1243
+ /**
1244
+ * Truncates the fractional part of each element in the tensor (towards zero).
1245
+ * For example: trunc(3.7) = 3.0, trunc(-2.9) = -2.0
1246
+ * Similar to std::trunc in C/C++.
1247
+ */
1248
+
1249
+ GGML_API struct ggml_tensor * ggml_trunc(
1250
+ struct ggml_context * ctx,
1251
+ struct ggml_tensor * a);
1252
+
1253
+ GGML_API struct ggml_tensor * ggml_trunc_inplace(
1254
+ struct ggml_context * ctx,
1255
+ struct ggml_tensor * a);
1256
+
1257
+
1258
+
1259
+ // xIELU activation function
1260
+ // x = x * (c_a(alpha_n) + c_b(alpha_p, beta) * sigmoid(beta * x)) + eps * (x > 0)
1261
+ // where c_a = softplus and c_b(a, b) = softplus(a) + b are constraining functions
1262
+ // that constrain the positive and negative source alpha values respectively
1263
+ GGML_API struct ggml_tensor * ggml_xielu(
1264
+ struct ggml_context * ctx,
1265
+ struct ggml_tensor * a,
1266
+ float alpha_n,
1267
+ float alpha_p,
1268
+ float beta,
1269
+ float eps);
1270
+
1271
+ // gated linear unit ops
1272
+ // A: n columns, r rows,
1273
+ // result is n / 2 columns, r rows,
1274
+ // expects gate in second half of row, unless swapped is true
1275
+ GGML_API struct ggml_tensor * ggml_glu(
1276
+ struct ggml_context * ctx,
1277
+ struct ggml_tensor * a,
1278
+ enum ggml_glu_op op,
1279
+ bool swapped);
1280
+
1281
+ GGML_API struct ggml_tensor * ggml_reglu(
1282
+ struct ggml_context * ctx,
1283
+ struct ggml_tensor * a);
1284
+
1285
+ GGML_API struct ggml_tensor * ggml_reglu_swapped(
1286
+ struct ggml_context * ctx,
1287
+ struct ggml_tensor * a);
1288
+
1289
+ GGML_API struct ggml_tensor * ggml_geglu(
1290
+ struct ggml_context * ctx,
1291
+ struct ggml_tensor * a);
1292
+
1293
+ GGML_API struct ggml_tensor * ggml_geglu_swapped(
1294
+ struct ggml_context * ctx,
1295
+ struct ggml_tensor * a);
1296
+
1297
+ GGML_API struct ggml_tensor * ggml_swiglu(
1298
+ struct ggml_context * ctx,
1299
+ struct ggml_tensor * a);
1300
+
1301
+ GGML_API struct ggml_tensor * ggml_swiglu_swapped(
1302
+ struct ggml_context * ctx,
1303
+ struct ggml_tensor * a);
1304
+
1305
+ GGML_API struct ggml_tensor * ggml_geglu_erf(
1306
+ struct ggml_context * ctx,
1307
+ struct ggml_tensor * a);
1308
+
1309
+ GGML_API struct ggml_tensor * ggml_geglu_erf_swapped(
1310
+ struct ggml_context * ctx,
1311
+ struct ggml_tensor * a);
1312
+
1313
+ GGML_API struct ggml_tensor * ggml_geglu_quick(
1314
+ struct ggml_context * ctx,
1315
+ struct ggml_tensor * a);
1316
+
1317
+ GGML_API struct ggml_tensor * ggml_geglu_quick_swapped(
1318
+ struct ggml_context * ctx,
1319
+ struct ggml_tensor * a);
1320
+
1321
+ GGML_API struct ggml_tensor * ggml_siglu(
1322
+ struct ggml_context * ctx,
1323
+ struct ggml_tensor * a);
1324
+
1325
+ GGML_API struct ggml_tensor * ggml_siglu_swapped(
1326
+ struct ggml_context * ctx,
1327
+ struct ggml_tensor * a);
1328
+
1329
+ // A: n columns, r rows,
1330
+ // B: n columns, r rows,
1331
+ GGML_API struct ggml_tensor * ggml_glu_split(
1332
+ struct ggml_context * ctx,
1333
+ struct ggml_tensor * a,
1334
+ struct ggml_tensor * b,
1335
+ enum ggml_glu_op op);
1336
+
1337
+ GGML_API struct ggml_tensor * ggml_reglu_split(
1338
+ struct ggml_context * ctx,
1339
+ struct ggml_tensor * a,
1340
+ struct ggml_tensor * b);
1341
+
1342
+ GGML_API struct ggml_tensor * ggml_geglu_split(
1343
+ struct ggml_context * ctx,
1344
+ struct ggml_tensor * a,
1345
+ struct ggml_tensor * b);
1346
+
1347
+ GGML_API struct ggml_tensor * ggml_swiglu_split(
1348
+ struct ggml_context * ctx,
1349
+ struct ggml_tensor * a,
1350
+ struct ggml_tensor * b);
1351
+
1352
+ GGML_API struct ggml_tensor * ggml_geglu_erf_split(
1353
+ struct ggml_context * ctx,
1354
+ struct ggml_tensor * a,
1355
+ struct ggml_tensor * b);
1356
+
1357
+ GGML_API struct ggml_tensor * ggml_geglu_quick_split(
1358
+ struct ggml_context * ctx,
1359
+ struct ggml_tensor * a,
1360
+ struct ggml_tensor * b);
1361
+
1362
+ GGML_API struct ggml_tensor * ggml_siglu_split(
1363
+ struct ggml_context * ctx,
1364
+ struct ggml_tensor * a,
1365
+ struct ggml_tensor * b);
1366
+
1367
+ GGML_API struct ggml_tensor * ggml_swiglu_oai(
1368
+ struct ggml_context * ctx,
1369
+ struct ggml_tensor * a,
1370
+ struct ggml_tensor * b,
1371
+ float alpha,
1372
+ float limit);
1373
+
1374
+ // normalize along rows
1375
+ GGML_API struct ggml_tensor * ggml_norm(
1376
+ struct ggml_context * ctx,
1377
+ struct ggml_tensor * a,
1378
+ float eps);
1379
+
1380
+ GGML_API struct ggml_tensor * ggml_norm_inplace(
1381
+ struct ggml_context * ctx,
1382
+ struct ggml_tensor * a,
1383
+ float eps);
1384
+
1385
+ // fused: w * norm(a, eps) + b (LayerNorm affine in one kernel)
1386
+ GGML_API struct ggml_tensor * ggml_norm_affine(
1387
+ struct ggml_context * ctx,
1388
+ struct ggml_tensor * a,
1389
+ struct ggml_tensor * w,
1390
+ struct ggml_tensor * b,
1391
+ float eps);
1392
+
1393
+ GGML_API struct ggml_tensor * ggml_rms_norm(
1394
+ struct ggml_context * ctx,
1395
+ struct ggml_tensor * a,
1396
+ float eps);
1397
+
1398
+ GGML_API struct ggml_tensor * ggml_rms_norm_inplace(
1399
+ struct ggml_context * ctx,
1400
+ struct ggml_tensor * a,
1401
+ float eps);
1402
+
1403
+ // group normalize along ne0*ne1*n_groups
1404
+ // used in stable-diffusion
1405
+ GGML_API struct ggml_tensor * ggml_group_norm(
1406
+ struct ggml_context * ctx,
1407
+ struct ggml_tensor * a,
1408
+ int n_groups,
1409
+ float eps);
1410
+
1411
+ GGML_API struct ggml_tensor * ggml_group_norm_inplace(
1412
+ struct ggml_context * ctx,
1413
+ struct ggml_tensor * a,
1414
+ int n_groups,
1415
+ float eps);
1416
+
1417
+ // l2 normalize along rows
1418
+ // used in rwkv v7
1419
+ GGML_API struct ggml_tensor * ggml_l2_norm(
1420
+ struct ggml_context * ctx,
1421
+ struct ggml_tensor * a,
1422
+ float eps);
1423
+
1424
+ GGML_API struct ggml_tensor * ggml_l2_norm_inplace(
1425
+ struct ggml_context * ctx,
1426
+ struct ggml_tensor * a,
1427
+ float eps);
1428
+
1429
+ // a - x
1430
+ // b - dy
1431
+ GGML_API struct ggml_tensor * ggml_rms_norm_back(
1432
+ struct ggml_context * ctx,
1433
+ struct ggml_tensor * a,
1434
+ struct ggml_tensor * b,
1435
+ float eps);
1436
+
1437
+ // A: k columns, n rows => [ne03, ne02, n, k]
1438
+ // B: k columns, m rows (i.e. we transpose it internally) => [ne03 * x, ne02 * y, m, k]
1439
+ // result is n columns, m rows => [ne03 * x, ne02 * y, m, n]
1440
+ GGML_API struct ggml_tensor * ggml_mul_mat(
1441
+ struct ggml_context * ctx,
1442
+ struct ggml_tensor * a,
1443
+ struct ggml_tensor * b);
1444
+
1445
+ // change the precision of a matrix multiplication
1446
+ // set to GGML_PREC_F32 for higher precision (useful for phi-2)
1447
+ GGML_API void ggml_mul_mat_set_prec(
1448
+ struct ggml_tensor * a,
1449
+ enum ggml_prec prec);
1450
+
1451
+ // indirect matrix multiplication
1452
+ GGML_API struct ggml_tensor * ggml_mul_mat_id(
1453
+ struct ggml_context * ctx,
1454
+ struct ggml_tensor * as,
1455
+ struct ggml_tensor * b,
1456
+ struct ggml_tensor * ids);
1457
+
1458
+ // A: m columns, n rows,
1459
+ // B: p columns, n rows,
1460
+ // result is m columns, p rows
1461
+ GGML_API struct ggml_tensor * ggml_out_prod(
1462
+ struct ggml_context * ctx,
1463
+ struct ggml_tensor * a,
1464
+ struct ggml_tensor * b);
1465
+
1466
+ //
1467
+ // operations on tensors without backpropagation
1468
+ //
1469
+
1470
+ GGML_API struct ggml_tensor * ggml_scale(
1471
+ struct ggml_context * ctx,
1472
+ struct ggml_tensor * a,
1473
+ float s);
1474
+
1475
+ // in-place, returns view(a)
1476
+ GGML_API struct ggml_tensor * ggml_scale_inplace(
1477
+ struct ggml_context * ctx,
1478
+ struct ggml_tensor * a,
1479
+ float s);
1480
+
1481
+ // x = s * a + b
1482
+ GGML_API struct ggml_tensor * ggml_scale_bias(
1483
+ struct ggml_context * ctx,
1484
+ struct ggml_tensor * a,
1485
+ float s,
1486
+ float b);
1487
+
1488
+ GGML_API struct ggml_tensor * ggml_scale_bias_inplace(
1489
+ struct ggml_context * ctx,
1490
+ struct ggml_tensor * a,
1491
+ float s,
1492
+ float b);
1493
+
1494
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1495
+ GGML_API struct ggml_tensor * ggml_set(
1496
+ struct ggml_context * ctx,
1497
+ struct ggml_tensor * a,
1498
+ struct ggml_tensor * b,
1499
+ size_t nb1,
1500
+ size_t nb2,
1501
+ size_t nb3,
1502
+ size_t offset); // in bytes
1503
+
1504
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1505
+ GGML_API struct ggml_tensor * ggml_set_inplace(
1506
+ struct ggml_context * ctx,
1507
+ struct ggml_tensor * a,
1508
+ struct ggml_tensor * b,
1509
+ size_t nb1,
1510
+ size_t nb2,
1511
+ size_t nb3,
1512
+ size_t offset); // in bytes
1513
+
1514
+ GGML_API struct ggml_tensor * ggml_set_1d(
1515
+ struct ggml_context * ctx,
1516
+ struct ggml_tensor * a,
1517
+ struct ggml_tensor * b,
1518
+ size_t offset); // in bytes
1519
+
1520
+ GGML_API struct ggml_tensor * ggml_set_1d_inplace(
1521
+ struct ggml_context * ctx,
1522
+ struct ggml_tensor * a,
1523
+ struct ggml_tensor * b,
1524
+ size_t offset); // in bytes
1525
+
1526
+ // b -> view(a,offset,nb1,nb2,3), return modified a
1527
+ GGML_API struct ggml_tensor * ggml_set_2d(
1528
+ struct ggml_context * ctx,
1529
+ struct ggml_tensor * a,
1530
+ struct ggml_tensor * b,
1531
+ size_t nb1,
1532
+ size_t offset); // in bytes
1533
+
1534
+ // b -> view(a,offset,nb1,nb2,3), return view(a)
1535
+ GGML_API struct ggml_tensor * ggml_set_2d_inplace(
1536
+ struct ggml_context * ctx,
1537
+ struct ggml_tensor * a,
1538
+ struct ggml_tensor * b,
1539
+ size_t nb1,
1540
+ size_t offset); // in bytes
1541
+
1542
+ // a -> b, return view(b)
1543
+ GGML_API struct ggml_tensor * ggml_cpy(
1544
+ struct ggml_context * ctx,
1545
+ struct ggml_tensor * a,
1546
+ struct ggml_tensor * b);
1547
+
1548
+ // note: casting from f32 to i32 will discard the fractional part
1549
+ GGML_API struct ggml_tensor * ggml_cast(
1550
+ struct ggml_context * ctx,
1551
+ struct ggml_tensor * a,
1552
+ enum ggml_type type);
1553
+
1554
+ // make contiguous
1555
+ GGML_API struct ggml_tensor * ggml_cont(
1556
+ struct ggml_context * ctx,
1557
+ struct ggml_tensor * a);
1558
+
1559
+ // make contiguous, with new shape
1560
+ GGML_API struct ggml_tensor * ggml_cont_1d(
1561
+ struct ggml_context * ctx,
1562
+ struct ggml_tensor * a,
1563
+ int64_t ne0);
1564
+
1565
+ GGML_API struct ggml_tensor * ggml_cont_2d(
1566
+ struct ggml_context * ctx,
1567
+ struct ggml_tensor * a,
1568
+ int64_t ne0,
1569
+ int64_t ne1);
1570
+
1571
+ GGML_API struct ggml_tensor * ggml_cont_3d(
1572
+ struct ggml_context * ctx,
1573
+ struct ggml_tensor * a,
1574
+ int64_t ne0,
1575
+ int64_t ne1,
1576
+ int64_t ne2);
1577
+
1578
+ GGML_API struct ggml_tensor * ggml_cont_4d(
1579
+ struct ggml_context * ctx,
1580
+ struct ggml_tensor * a,
1581
+ int64_t ne0,
1582
+ int64_t ne1,
1583
+ int64_t ne2,
1584
+ int64_t ne3);
1585
+
1586
+ // return view(a), b specifies the new shape
1587
+ // TODO: when we start computing gradient, make a copy instead of view
1588
+ GGML_API struct ggml_tensor * ggml_reshape(
1589
+ struct ggml_context * ctx,
1590
+ struct ggml_tensor * a,
1591
+ struct ggml_tensor * b);
1592
+
1593
+ // return view(a)
1594
+ // TODO: when we start computing gradient, make a copy instead of view
1595
+ GGML_API struct ggml_tensor * ggml_reshape_1d(
1596
+ struct ggml_context * ctx,
1597
+ struct ggml_tensor * a,
1598
+ int64_t ne0);
1599
+
1600
+ GGML_API struct ggml_tensor * ggml_reshape_2d(
1601
+ struct ggml_context * ctx,
1602
+ struct ggml_tensor * a,
1603
+ int64_t ne0,
1604
+ int64_t ne1);
1605
+
1606
+ // return view(a)
1607
+ // TODO: when we start computing gradient, make a copy instead of view
1608
+ GGML_API struct ggml_tensor * ggml_reshape_3d(
1609
+ struct ggml_context * ctx,
1610
+ struct ggml_tensor * a,
1611
+ int64_t ne0,
1612
+ int64_t ne1,
1613
+ int64_t ne2);
1614
+
1615
+ GGML_API struct ggml_tensor * ggml_reshape_4d(
1616
+ struct ggml_context * ctx,
1617
+ struct ggml_tensor * a,
1618
+ int64_t ne0,
1619
+ int64_t ne1,
1620
+ int64_t ne2,
1621
+ int64_t ne3);
1622
+
1623
+ // offset in bytes
1624
+ GGML_API struct ggml_tensor * ggml_view_1d(
1625
+ struct ggml_context * ctx,
1626
+ struct ggml_tensor * a,
1627
+ int64_t ne0,
1628
+ size_t offset);
1629
+
1630
+ GGML_API struct ggml_tensor * ggml_view_2d(
1631
+ struct ggml_context * ctx,
1632
+ struct ggml_tensor * a,
1633
+ int64_t ne0,
1634
+ int64_t ne1,
1635
+ size_t nb1, // row stride in bytes
1636
+ size_t offset);
1637
+
1638
+ GGML_API struct ggml_tensor * ggml_view_3d(
1639
+ struct ggml_context * ctx,
1640
+ struct ggml_tensor * a,
1641
+ int64_t ne0,
1642
+ int64_t ne1,
1643
+ int64_t ne2,
1644
+ size_t nb1, // row stride in bytes
1645
+ size_t nb2, // slice stride in bytes
1646
+ size_t offset);
1647
+
1648
+ GGML_API struct ggml_tensor * ggml_view_4d(
1649
+ struct ggml_context * ctx,
1650
+ struct ggml_tensor * a,
1651
+ int64_t ne0,
1652
+ int64_t ne1,
1653
+ int64_t ne2,
1654
+ int64_t ne3,
1655
+ size_t nb1, // row stride in bytes
1656
+ size_t nb2, // slice stride in bytes
1657
+ size_t nb3,
1658
+ size_t offset);
1659
+
1660
+ GGML_API struct ggml_tensor * ggml_permute(
1661
+ struct ggml_context * ctx,
1662
+ struct ggml_tensor * a,
1663
+ int axis0,
1664
+ int axis1,
1665
+ int axis2,
1666
+ int axis3);
1667
+
1668
+ // alias for ggml_permute(ctx, a, 1, 0, 2, 3)
1669
+ GGML_API struct ggml_tensor * ggml_transpose(
1670
+ struct ggml_context * ctx,
1671
+ struct ggml_tensor * a);
1672
+
1673
+ // supports 4D a:
1674
+ // a [n_embd, ne1, ne2, ne3]
1675
+ // b I32 [n_rows, ne2, ne3, 1]
1676
+ //
1677
+ // return [n_embd, n_rows, ne2, ne3]
1678
+ GGML_API struct ggml_tensor * ggml_get_rows(
1679
+ struct ggml_context * ctx,
1680
+ struct ggml_tensor * a, // data
1681
+ struct ggml_tensor * b); // row indices
1682
+
1683
+ GGML_API struct ggml_tensor * ggml_get_rows_back(
1684
+ struct ggml_context * ctx,
1685
+ struct ggml_tensor * a, // gradients of ggml_get_rows result
1686
+ struct ggml_tensor * b, // row indices
1687
+ struct ggml_tensor * c); // data for ggml_get_rows, only used for its shape
1688
+
1689
+ // a TD [n_embd, ne1, ne2, ne3]
1690
+ // b TS [n_embd, n_rows, ne02, ne03] | ne02 == ne2, ne03 == ne3
1691
+ // c I64 [n_rows, ne11, ne12, 1] | c[i] in [0, ne1)
1692
+ //
1693
+ // undefined behavior if destination rows overlap
1694
+ //
1695
+ // broadcast:
1696
+ // ne2 % ne11 == 0
1697
+ // ne3 % ne12 == 0
1698
+ //
1699
+ // return view(a)
1700
+ GGML_API struct ggml_tensor * ggml_set_rows(
1701
+ struct ggml_context * ctx,
1702
+ struct ggml_tensor * a, // destination
1703
+ struct ggml_tensor * b, // source
1704
+ struct ggml_tensor * c); // row indices
1705
+
1706
+ GGML_API struct ggml_tensor * ggml_diag(
1707
+ struct ggml_context * ctx,
1708
+ struct ggml_tensor * a);
1709
+
1710
+ // set elements above the diagonal to -INF
1711
+ GGML_API struct ggml_tensor * ggml_diag_mask_inf(
1712
+ struct ggml_context * ctx,
1713
+ struct ggml_tensor * a,
1714
+ int n_past);
1715
+
1716
+ // in-place, returns view(a)
1717
+ GGML_API struct ggml_tensor * ggml_diag_mask_inf_inplace(
1718
+ struct ggml_context * ctx,
1719
+ struct ggml_tensor * a,
1720
+ int n_past);
1721
+
1722
+ // set elements above the diagonal to 0
1723
+ GGML_API struct ggml_tensor * ggml_diag_mask_zero(
1724
+ struct ggml_context * ctx,
1725
+ struct ggml_tensor * a,
1726
+ int n_past);
1727
+
1728
+ // in-place, returns view(a)
1729
+ GGML_API struct ggml_tensor * ggml_diag_mask_zero_inplace(
1730
+ struct ggml_context * ctx,
1731
+ struct ggml_tensor * a,
1732
+ int n_past);
1733
+
1734
+ GGML_API struct ggml_tensor * ggml_soft_max(
1735
+ struct ggml_context * ctx,
1736
+ struct ggml_tensor * a);
1737
+
1738
+ // in-place, returns view(a)
1739
+ GGML_API struct ggml_tensor * ggml_soft_max_inplace(
1740
+ struct ggml_context * ctx,
1741
+ struct ggml_tensor * a);
1742
+
1743
+ // a [ne0, ne01, ne02, ne03]
1744
+ // mask [ne0, ne11, ne12, ne13] | ne11 >= ne01, F16 or F32, optional
1745
+ //
1746
+ // broadcast:
1747
+ // ne02 % ne12 == 0
1748
+ // ne03 % ne13 == 0
1749
+ //
1750
+ // fused soft_max(a*scale + mask*(ALiBi slope))
1751
+ // max_bias = 0.0f for no ALiBi
1752
+ GGML_API struct ggml_tensor * ggml_soft_max_ext(
1753
+ struct ggml_context * ctx,
1754
+ struct ggml_tensor * a,
1755
+ struct ggml_tensor * mask,
1756
+ float scale,
1757
+ float max_bias);
1758
+
1759
+ GGML_API struct ggml_tensor * ggml_soft_max_ext_inplace(
1760
+ struct ggml_context * ctx,
1761
+ struct ggml_tensor * a,
1762
+ struct ggml_tensor * mask,
1763
+ float scale,
1764
+ float max_bias);
1765
+
1766
+ GGML_API void ggml_soft_max_add_sinks(
1767
+ struct ggml_tensor * a,
1768
+ struct ggml_tensor * sinks);
1769
+
1770
+ GGML_API struct ggml_tensor * ggml_soft_max_ext_back(
1771
+ struct ggml_context * ctx,
1772
+ struct ggml_tensor * a,
1773
+ struct ggml_tensor * b,
1774
+ float scale,
1775
+ float max_bias);
1776
+
1777
+ // in-place, returns view(a)
1778
+ GGML_API struct ggml_tensor * ggml_soft_max_ext_back_inplace(
1779
+ struct ggml_context * ctx,
1780
+ struct ggml_tensor * a,
1781
+ struct ggml_tensor * b,
1782
+ float scale,
1783
+ float max_bias);
1784
+
1785
+ // rotary position embedding
1786
+ // if (mode & 1) - skip n_past elements (NOT SUPPORTED)
1787
+ // if (mode & GGML_ROPE_TYPE_NEOX) - GPT-NeoX style
1788
+ //
1789
+ // b is an int32 vector with size a->ne[2], it contains the positions
1790
+ GGML_API struct ggml_tensor * ggml_rope(
1791
+ struct ggml_context * ctx,
1792
+ struct ggml_tensor * a,
1793
+ struct ggml_tensor * b,
1794
+ int n_dims,
1795
+ int mode);
1796
+
1797
+ // in-place, returns view(a)
1798
+ GGML_API struct ggml_tensor * ggml_rope_inplace(
1799
+ struct ggml_context * ctx,
1800
+ struct ggml_tensor * a,
1801
+ struct ggml_tensor * b,
1802
+ int n_dims,
1803
+ int mode);
1804
+
1805
+ // RoPE operations with extended options
1806
+ // a is the input tensor to apply RoPE to, shape [n_embd, n_head, n_token]
1807
+ // b is an int32 vector with size n_token
1808
+ // c is freq factors (e.g. phi3-128k), (optional)
1809
+ // mode can be GGML_ROPE_TYPE_NORMAL or NEOX; for MROPE and VISION mode, use ggml_rope_multi
1810
+ //
1811
+ // pseudo-code for computing theta:
1812
+ // for i in [0, n_dims/2):
1813
+ // theta[i] = b[i] * powf(freq_base, -2.0 * i / n_dims);
1814
+ // theta[i] = theta[i] / c[i]; # if c is provided, divide theta by c
1815
+ // theta[i] = rope_yarn(theta[i], ...); # note: theta = theta * freq_scale is applied here
1816
+ //
1817
+ // other params are used by YaRN RoPE scaling, these default values will disable YaRN:
1818
+ // freq_scale = 1.0f
1819
+ // ext_factor = 0.0f
1820
+ // attn_factor = 1.0f
1821
+ // beta_fast = 0.0f
1822
+ // beta_slow = 0.0f
1823
+ //
1824
+ // example:
1825
+ // (marking: c = cos, s = sin, 0 = unrotated)
1826
+ // given a single head with size = 8 --> [00000000]
1827
+ // GGML_ROPE_TYPE_NORMAL n_dims = 4 --> [cscs0000]
1828
+ // GGML_ROPE_TYPE_NORMAL n_dims = 8 --> [cscscscs]
1829
+ // GGML_ROPE_TYPE_NEOX n_dims = 4 --> [ccss0000]
1830
+ // GGML_ROPE_TYPE_NEOX n_dims = 8 --> [ccccssss]
1831
+ GGML_API struct ggml_tensor * ggml_rope_ext(
1832
+ struct ggml_context * ctx,
1833
+ struct ggml_tensor * a,
1834
+ struct ggml_tensor * b,
1835
+ struct ggml_tensor * c,
1836
+ int n_dims,
1837
+ int mode,
1838
+ int n_ctx_orig,
1839
+ float freq_base,
1840
+ float freq_scale,
1841
+ float ext_factor,
1842
+ float attn_factor,
1843
+ float beta_fast,
1844
+ float beta_slow);
1845
+
1846
+ // multi-dimensional RoPE, for Qwen-VL and similar vision models
1847
+ // mode can be either VISION, MROPE, IMROPE, cannot be combined with NORMAL or NEOX
1848
+ // sections specify how many dimensions to rotate in each section:
1849
+ // section length is equivalent to number of cos/sin pairs, NOT the number of dims
1850
+ // (i.e. sum of 4 sections are expected to be n_dims/2)
1851
+ // last sections can be 0, means ignored
1852
+ // all other options are identical to ggml_rope_ext
1853
+ //
1854
+ // important note:
1855
+ // - NEOX ordering is automatically applied and cannot be disabled for MROPE and VISION
1856
+ // if you need normal ordering, there are 2 methods:
1857
+ // (1) split the tensor manually using ggml_view
1858
+ // (2) permute the weight upon conversion
1859
+ // - for VISION, n_dims must be head_size/2
1860
+ //
1861
+ // example M-RoPE:
1862
+ // given sections = [t=4, y=2, x=2, 0]
1863
+ // given a single head with size = 18 --> [000000000000000000]
1864
+ // GGML_ROPE_TYPE_MROPE n_dims = 16 --> [ttttyyxxttttyyxx00] (cos/sin are applied in NEOX ordering)
1865
+ // GGML_ROPE_TYPE_IMROPE n_dims = 16 --> [ttyxttyxttyxttyx00] (interleaved M-RoPE, still NEOX ordering)
1866
+ // note: the theta for each dim is computed the same way as ggml_rope_ext, no matter the section
1867
+ // in other words, idx used for theta: [0123456789... until n_dims/2], not reset for each section
1868
+ //
1869
+ // example vision RoPE:
1870
+ // given sections = [y=4, x=4, 0, 0] (last 2 sections are ignored)
1871
+ // given a single head with size = 8 --> [00000000]
1872
+ // GGML_ROPE_TYPE_VISION n_dims = 4 --> [yyyyxxxx]
1873
+ // other values of n_dims are untested and is undefined behavior
1874
+ // note: unlike MROPE, the theta for each dim is computed differently for each section
1875
+ // in other words, idx used for theta: [0123] for y section, then [0123] for x section
1876
+ GGML_API struct ggml_tensor * ggml_rope_multi(
1877
+ struct ggml_context * ctx,
1878
+ struct ggml_tensor * a,
1879
+ struct ggml_tensor * b,
1880
+ struct ggml_tensor * c,
1881
+ int n_dims,
1882
+ int sections[GGML_MROPE_SECTIONS],
1883
+ int mode,
1884
+ int n_ctx_orig,
1885
+ float freq_base,
1886
+ float freq_scale,
1887
+ float ext_factor,
1888
+ float attn_factor,
1889
+ float beta_fast,
1890
+ float beta_slow);
1891
+
1892
+ // in-place, returns view(a)
1893
+ GGML_API struct ggml_tensor * ggml_rope_ext_inplace(
1894
+ struct ggml_context * ctx,
1895
+ struct ggml_tensor * a,
1896
+ struct ggml_tensor * b,
1897
+ struct ggml_tensor * c,
1898
+ int n_dims,
1899
+ int mode,
1900
+ int n_ctx_orig,
1901
+ float freq_base,
1902
+ float freq_scale,
1903
+ float ext_factor,
1904
+ float attn_factor,
1905
+ float beta_fast,
1906
+ float beta_slow);
1907
+
1908
+ GGML_API struct ggml_tensor * ggml_rope_multi_inplace(
1909
+ struct ggml_context * ctx,
1910
+ struct ggml_tensor * a,
1911
+ struct ggml_tensor * b,
1912
+ struct ggml_tensor * c,
1913
+ int n_dims,
1914
+ int sections[GGML_MROPE_SECTIONS],
1915
+ int mode,
1916
+ int n_ctx_orig,
1917
+ float freq_base,
1918
+ float freq_scale,
1919
+ float ext_factor,
1920
+ float attn_factor,
1921
+ float beta_fast,
1922
+ float beta_slow);
1923
+
1924
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_rope_custom(
1925
+ struct ggml_context * ctx,
1926
+ struct ggml_tensor * a,
1927
+ struct ggml_tensor * b,
1928
+ int n_dims,
1929
+ int mode,
1930
+ int n_ctx_orig,
1931
+ float freq_base,
1932
+ float freq_scale,
1933
+ float ext_factor,
1934
+ float attn_factor,
1935
+ float beta_fast,
1936
+ float beta_slow),
1937
+ "use ggml_rope_ext instead");
1938
+
1939
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_rope_custom_inplace(
1940
+ struct ggml_context * ctx,
1941
+ struct ggml_tensor * a,
1942
+ struct ggml_tensor * b,
1943
+ int n_dims,
1944
+ int mode,
1945
+ int n_ctx_orig,
1946
+ float freq_base,
1947
+ float freq_scale,
1948
+ float ext_factor,
1949
+ float attn_factor,
1950
+ float beta_fast,
1951
+ float beta_slow),
1952
+ "use ggml_rope_ext_inplace instead");
1953
+
1954
+ // compute correction dims for YaRN RoPE scaling
1955
+ GGML_API void ggml_rope_yarn_corr_dims(
1956
+ int n_dims, int n_ctx_orig, float freq_base, float beta_fast, float beta_slow, float dims[2]);
1957
+
1958
+ // rotary position embedding backward, i.e compute dx from dy
1959
+ // a - dy
1960
+ GGML_API struct ggml_tensor * ggml_rope_ext_back(
1961
+ struct ggml_context * ctx,
1962
+ struct ggml_tensor * a, // gradients of ggml_rope result
1963
+ struct ggml_tensor * b, // positions
1964
+ struct ggml_tensor * c, // freq factors
1965
+ int n_dims,
1966
+ int mode,
1967
+ int n_ctx_orig,
1968
+ float freq_base,
1969
+ float freq_scale,
1970
+ float ext_factor,
1971
+ float attn_factor,
1972
+ float beta_fast,
1973
+ float beta_slow);
1974
+
1975
+ GGML_API struct ggml_tensor * ggml_rope_multi_back(
1976
+ struct ggml_context * ctx,
1977
+ struct ggml_tensor * a,
1978
+ struct ggml_tensor * b,
1979
+ struct ggml_tensor * c,
1980
+ int n_dims,
1981
+ int sections[4],
1982
+ int mode,
1983
+ int n_ctx_orig,
1984
+ float freq_base,
1985
+ float freq_scale,
1986
+ float ext_factor,
1987
+ float attn_factor,
1988
+ float beta_fast,
1989
+ float beta_slow);
1990
+
1991
+
1992
+ // clamp
1993
+ // in-place, returns view(a)
1994
+ GGML_API struct ggml_tensor * ggml_clamp(
1995
+ struct ggml_context * ctx,
1996
+ struct ggml_tensor * a,
1997
+ float min,
1998
+ float max);
1999
+
2000
+ // im2col
2001
+ // converts data into a format that effectively results in a convolution when combined with matrix multiplication
2002
+ GGML_API struct ggml_tensor * ggml_im2col(
2003
+ struct ggml_context * ctx,
2004
+ struct ggml_tensor * a, // convolution kernel
2005
+ struct ggml_tensor * b, // data
2006
+ int s0, // stride dimension 0
2007
+ int s1, // stride dimension 1
2008
+ int p0, // padding dimension 0
2009
+ int p1, // padding dimension 1
2010
+ int d0, // dilation dimension 0
2011
+ int d1, // dilation dimension 1
2012
+ bool is_2D,
2013
+ enum ggml_type dst_type);
2014
+
2015
+ GGML_API struct ggml_tensor * ggml_im2col_back(
2016
+ struct ggml_context * ctx,
2017
+ struct ggml_tensor * a, // convolution kernel
2018
+ struct ggml_tensor * b, // gradient of im2col output
2019
+ int64_t * ne, // shape of im2col input
2020
+ int s0, // stride dimension 0
2021
+ int s1, // stride dimension 1
2022
+ int p0, // padding dimension 0
2023
+ int p1, // padding dimension 1
2024
+ int d0, // dilation dimension 0
2025
+ int d1, // dilation dimension 1
2026
+ bool is_2D);
2027
+
2028
+ GGML_API struct ggml_tensor * ggml_conv_1d(
2029
+ struct ggml_context * ctx,
2030
+ struct ggml_tensor * a, // convolution kernel
2031
+ struct ggml_tensor * b, // data
2032
+ int s0, // stride
2033
+ int p0, // padding
2034
+ int d0); // dilation
2035
+
2036
+ // conv_1d with padding = half
2037
+ // alias for ggml_conv_1d(a, b, s, a->ne[0]/2, d)
2038
+ GGML_API struct ggml_tensor* ggml_conv_1d_ph(
2039
+ struct ggml_context * ctx,
2040
+ struct ggml_tensor * a, // convolution kernel
2041
+ struct ggml_tensor * b, // data
2042
+ int s, // stride
2043
+ int d); // dilation
2044
+
2045
+ // depthwise
2046
+ // TODO: this is very likely wrong for some cases! - needs more testing
2047
+ GGML_API struct ggml_tensor * ggml_conv_1d_dw(
2048
+ struct ggml_context * ctx,
2049
+ struct ggml_tensor * a, // convolution kernel
2050
+ struct ggml_tensor * b, // data
2051
+ int s0, // stride
2052
+ int p0, // padding
2053
+ int d0); // dilation
2054
+
2055
+ GGML_API struct ggml_tensor * ggml_conv_1d_dw_ph(
2056
+ struct ggml_context * ctx,
2057
+ struct ggml_tensor * a, // convolution kernel
2058
+ struct ggml_tensor * b, // data
2059
+ int s0, // stride
2060
+ int d0); // dilation
2061
+
2062
+ GGML_API struct ggml_tensor * ggml_conv_transpose_1d(
2063
+ struct ggml_context * ctx,
2064
+ struct ggml_tensor * a, // convolution kernel
2065
+ struct ggml_tensor * b, // data
2066
+ int s0, // stride
2067
+ int p0, // padding
2068
+ int d0); // dilation
2069
+
2070
+ // col2im_1d: gather columns → 1D signal (ConvTranspose1d decomp).
2071
+ // col: [K*OC, T_in] F32/F16/BF16 — GEMM output (mul_mat of pre-permuted weight)
2072
+ // Output: [T_out, OC] F32 where T_out = (T_in-1)*s0 + K - p0
2073
+ // op_params: [s0=stride, OC, p0=left_crop]
2074
+ GGML_API struct ggml_tensor * ggml_col2im_1d(
2075
+ struct ggml_context * ctx,
2076
+ struct ggml_tensor * col, // [K*OC, T_in]
2077
+ int s0, // stride
2078
+ int oc, // output channels (= K*OC / K)
2079
+ int p0); // left offset / pre-crop
2080
+
2081
+ // CrispASR patch (PR #07-metal-aa-snake-beta): BigVGAN v2 anti-aliased
2082
+ // SnakeBeta — fused upsample 2× + sin²(α·x)/β + downsample 2×.
2083
+ // All inputs F32; output same shape as `x`.
2084
+ // x : [T, C] — time-fastest, channel-major
2085
+ // log_alpha: [C] — per-channel α frequency, log-scale
2086
+ // log_beta : [C] — per-channel β amplitude, log-scale
2087
+ // us_filter: [K, 1, 1] — Kaiser-windowed sinc, sum=1
2088
+ // ds_filter: [K, 1, 1] — Kaiser-windowed sinc, sum=1
2089
+ // K must be 12 (asserted in the CPU forward).
2090
+ // MUST RE-APPLY after every ggml bump.
2091
+ GGML_API struct ggml_tensor * ggml_aa_snake_beta(
2092
+ struct ggml_context * ctx,
2093
+ struct ggml_tensor * x,
2094
+ struct ggml_tensor * log_alpha,
2095
+ struct ggml_tensor * log_beta,
2096
+ struct ggml_tensor * us_filter,
2097
+ struct ggml_tensor * ds_filter);
2098
+
2099
+ GGML_API struct ggml_tensor * ggml_conv_2d(
2100
+ struct ggml_context * ctx,
2101
+ struct ggml_tensor * a, // convolution kernel
2102
+ struct ggml_tensor * b, // data
2103
+ int s0, // stride dimension 0
2104
+ int s1, // stride dimension 1
2105
+ int p0, // padding dimension 0
2106
+ int p1, // padding dimension 1
2107
+ int d0, // dilation dimension 0
2108
+ int d1); // dilation dimension 1
2109
+
2110
+ GGML_API struct ggml_tensor * ggml_im2col_3d(
2111
+ struct ggml_context * ctx,
2112
+ struct ggml_tensor * a,
2113
+ struct ggml_tensor * b,
2114
+ int64_t IC,
2115
+ int s0, // stride width
2116
+ int s1, // stride height
2117
+ int s2, // stride depth
2118
+ int p0, // padding width
2119
+ int p1, // padding height
2120
+ int p2, // padding depth
2121
+ int d0, // dilation width
2122
+ int d1, // dilation height
2123
+ int d2, // dilation depth
2124
+ enum ggml_type dst_type);
2125
+
2126
+ // a: [OC*IC, KD, KH, KW]
2127
+ // b: [N*IC, ID, IH, IW]
2128
+ // result: [N*OC, OD, OH, OW]
2129
+ GGML_API struct ggml_tensor * ggml_conv_3d(
2130
+ struct ggml_context * ctx,
2131
+ struct ggml_tensor * a,
2132
+ struct ggml_tensor * b,
2133
+ int64_t IC,
2134
+ int s0, // stride width
2135
+ int s1, // stride height
2136
+ int s2, // stride depth
2137
+ int p0, // padding width
2138
+ int p1, // padding height
2139
+ int p2, // padding depth
2140
+ int d0, // dilation width
2141
+ int d1, // dilation height
2142
+ int d2 // dilation depth
2143
+ );
2144
+
2145
+ // kernel size is a->ne[0] x a->ne[1]
2146
+ // stride is equal to kernel size
2147
+ // padding is zero
2148
+ // example:
2149
+ // a: 16 16 3 768
2150
+ // b: 1024 1024 3 1
2151
+ // res: 64 64 768 1
2152
+ // used in sam
2153
+ GGML_API struct ggml_tensor * ggml_conv_2d_sk_p0(
2154
+ struct ggml_context * ctx,
2155
+ struct ggml_tensor * a,
2156
+ struct ggml_tensor * b);
2157
+
2158
+ // kernel size is a->ne[0] x a->ne[1]
2159
+ // stride is 1
2160
+ // padding is half
2161
+ // example:
2162
+ // a: 3 3 256 256
2163
+ // b: 64 64 256 1
2164
+ // res: 64 64 256 1
2165
+ // used in sam
2166
+ GGML_API struct ggml_tensor * ggml_conv_2d_s1_ph(
2167
+ struct ggml_context * ctx,
2168
+ struct ggml_tensor * a,
2169
+ struct ggml_tensor * b);
2170
+
2171
+ // depthwise (via im2col and mul_mat)
2172
+ GGML_API struct ggml_tensor * ggml_conv_2d_dw(
2173
+ struct ggml_context * ctx,
2174
+ struct ggml_tensor * a, // convolution kernel
2175
+ struct ggml_tensor * b, // data
2176
+ int s0, // stride dimension 0
2177
+ int s1, // stride dimension 1
2178
+ int p0, // padding dimension 0
2179
+ int p1, // padding dimension 1
2180
+ int d0, // dilation dimension 0
2181
+ int d1); // dilation dimension 1
2182
+
2183
+ // Depthwise 2D convolution
2184
+ // may be faster than ggml_conv_2d_dw, but not available in all backends
2185
+ // a: KW KH 1 C convolution kernel
2186
+ // b: W H C N input data
2187
+ // res: W_out H_out C N
2188
+ GGML_API struct ggml_tensor * ggml_conv_2d_dw_direct(
2189
+ struct ggml_context * ctx,
2190
+ struct ggml_tensor * a,
2191
+ struct ggml_tensor * b,
2192
+ int stride0,
2193
+ int stride1,
2194
+ int pad0,
2195
+ int pad1,
2196
+ int dilation0,
2197
+ int dilation1);
2198
+
2199
+ GGML_API struct ggml_tensor * ggml_conv_transpose_2d_p0(
2200
+ struct ggml_context * ctx,
2201
+ struct ggml_tensor * a,
2202
+ struct ggml_tensor * b,
2203
+ int stride);
2204
+
2205
+ GGML_API struct ggml_tensor * ggml_conv_2d_direct(
2206
+ struct ggml_context * ctx,
2207
+ struct ggml_tensor * a, // convolution kernel [KW, KH, IC, OC]
2208
+ struct ggml_tensor * b, // input data [W, H, C, N]
2209
+ int s0, // stride dimension 0
2210
+ int s1, // stride dimension 1
2211
+ int p0, // padding dimension 0
2212
+ int p1, // padding dimension 1
2213
+ int d0, // dilation dimension 0
2214
+ int d1); // dilation dimension 1
2215
+
2216
+ GGML_API struct ggml_tensor * ggml_conv_3d_direct(
2217
+ struct ggml_context * ctx,
2218
+ struct ggml_tensor * a, // kernel [KW, KH, KD, IC * OC]
2219
+ struct ggml_tensor * b, // input [W, H, D, C * N]
2220
+ int s0, // stride
2221
+ int s1,
2222
+ int s2,
2223
+ int p0, // padding
2224
+ int p1,
2225
+ int p2,
2226
+ int d0, // dilation
2227
+ int d1,
2228
+ int d2,
2229
+ int n_channels,
2230
+ int n_batch,
2231
+ int n_channels_out);
2232
+
2233
+ enum ggml_op_pool {
2234
+ GGML_OP_POOL_MAX,
2235
+ GGML_OP_POOL_AVG,
2236
+ GGML_OP_POOL_COUNT,
2237
+ };
2238
+
2239
+ GGML_API struct ggml_tensor * ggml_pool_1d(
2240
+ struct ggml_context * ctx,
2241
+ struct ggml_tensor * a,
2242
+ enum ggml_op_pool op,
2243
+ int k0, // kernel size
2244
+ int s0, // stride
2245
+ int p0); // padding
2246
+
2247
+ // the result will have 2*p0 padding for the first dimension
2248
+ // and 2*p1 padding for the second dimension
2249
+ GGML_API struct ggml_tensor * ggml_pool_2d(
2250
+ struct ggml_context * ctx,
2251
+ struct ggml_tensor * a,
2252
+ enum ggml_op_pool op,
2253
+ int k0,
2254
+ int k1,
2255
+ int s0,
2256
+ int s1,
2257
+ float p0,
2258
+ float p1);
2259
+
2260
+ GGML_API struct ggml_tensor * ggml_pool_2d_back(
2261
+ struct ggml_context * ctx,
2262
+ struct ggml_tensor * a,
2263
+ struct ggml_tensor * af, // "a"/input used in forward pass
2264
+ enum ggml_op_pool op,
2265
+ int k0,
2266
+ int k1,
2267
+ int s0,
2268
+ int s1,
2269
+ float p0,
2270
+ float p1);
2271
+
2272
+ enum ggml_scale_mode {
2273
+ GGML_SCALE_MODE_NEAREST = 0,
2274
+ GGML_SCALE_MODE_BILINEAR = 1,
2275
+ GGML_SCALE_MODE_BICUBIC = 2,
2276
+
2277
+ GGML_SCALE_MODE_COUNT
2278
+ };
2279
+
2280
+ enum ggml_scale_flag {
2281
+ GGML_SCALE_FLAG_ALIGN_CORNERS = (1 << 8),
2282
+ GGML_SCALE_FLAG_ANTIALIAS = (1 << 9),
2283
+ };
2284
+
2285
+ // interpolate
2286
+ // multiplies ne0 and ne1 by scale factor
2287
+ GGML_API struct ggml_tensor * ggml_upscale(
2288
+ struct ggml_context * ctx,
2289
+ struct ggml_tensor * a,
2290
+ int scale_factor,
2291
+ enum ggml_scale_mode mode);
2292
+
2293
+ // interpolate
2294
+ // interpolate scale to specified dimensions
2295
+ GGML_DEPRECATED(GGML_API struct ggml_tensor * ggml_upscale_ext(
2296
+ struct ggml_context * ctx,
2297
+ struct ggml_tensor * a,
2298
+ int ne0,
2299
+ int ne1,
2300
+ int ne2,
2301
+ int ne3,
2302
+ enum ggml_scale_mode mode),
2303
+ "use ggml_interpolate instead");
2304
+
2305
+ // Up- or downsamples the input to the specified size.
2306
+ // 2D scale modes (eg. bilinear) are applied to the first two dimensions.
2307
+ GGML_API struct ggml_tensor * ggml_interpolate(
2308
+ struct ggml_context * ctx,
2309
+ struct ggml_tensor * a,
2310
+ int64_t ne0,
2311
+ int64_t ne1,
2312
+ int64_t ne2,
2313
+ int64_t ne3,
2314
+ uint32_t mode); // ggml_scale_mode [ | ggml_scale_flag...]
2315
+
2316
+ // pad each dimension with zeros: [x, ..., x] -> [x, ..., x, 0, ..., 0]
2317
+ GGML_API struct ggml_tensor * ggml_pad(
2318
+ struct ggml_context * ctx,
2319
+ struct ggml_tensor * a,
2320
+ int p0,
2321
+ int p1,
2322
+ int p2,
2323
+ int p3);
2324
+
2325
+ // pad each dimension with values on the other side of the torus (looping around)
2326
+ GGML_API struct ggml_tensor * ggml_pad_circular(
2327
+ struct ggml_context * ctx,
2328
+ struct ggml_tensor * a,
2329
+ int p0,
2330
+ int p1,
2331
+ int p2,
2332
+ int p3);
2333
+
2334
+ GGML_API struct ggml_tensor * ggml_pad_ext(
2335
+ struct ggml_context * ctx,
2336
+ struct ggml_tensor * a,
2337
+ int lp0,
2338
+ int rp0,
2339
+ int lp1,
2340
+ int rp1,
2341
+ int lp2,
2342
+ int rp2,
2343
+ int lp3,
2344
+ int rp3
2345
+ );
2346
+
2347
+ // pad each dimension with values on the other side of the torus (looping around)
2348
+ GGML_API struct ggml_tensor * ggml_pad_ext_circular(
2349
+ struct ggml_context * ctx,
2350
+ struct ggml_tensor * a,
2351
+ int lp0,
2352
+ int rp0,
2353
+ int lp1,
2354
+ int rp1,
2355
+ int lp2,
2356
+ int rp2,
2357
+ int lp3,
2358
+ int rp3);
2359
+
2360
+ // pad each dimension with reflection: [a, b, c, d] -> [b, a, b, c, d, c]
2361
+ GGML_API struct ggml_tensor * ggml_pad_reflect_1d(
2362
+ struct ggml_context * ctx,
2363
+ struct ggml_tensor * a,
2364
+ int p0,
2365
+ int p1);
2366
+
2367
+ // Move tensor elements by an offset given for each dimension. Elements that
2368
+ // are shifted beyond the last position are wrapped around to the beginning.
2369
+ GGML_API struct ggml_tensor * ggml_roll(
2370
+ struct ggml_context * ctx,
2371
+ struct ggml_tensor * a,
2372
+ int shift0,
2373
+ int shift1,
2374
+ int shift2,
2375
+ int shift3);
2376
+
2377
+ // Convert matrix into a triangular one (upper, strict upper, lower or strict lower) by writing
2378
+ // zeroes everywhere outside the masked area
2379
+ GGML_API struct ggml_tensor * ggml_tri(
2380
+ struct ggml_context * ctx,
2381
+ struct ggml_tensor * a,
2382
+ enum ggml_tri_type type);
2383
+
2384
+ // Fill tensor a with constant c
2385
+ GGML_API struct ggml_tensor * ggml_fill(
2386
+ struct ggml_context * ctx,
2387
+ struct ggml_tensor * a,
2388
+ float c);
2389
+
2390
+ GGML_API struct ggml_tensor * ggml_fill_inplace(
2391
+ struct ggml_context * ctx,
2392
+ struct ggml_tensor * a,
2393
+ float c);
2394
+
2395
+ // Ref: https://github.com/CompVis/stable-diffusion/blob/main/ldm/modules/diffusionmodules/util.py#L151
2396
+ // timesteps: [N,]
2397
+ // return: [N, dim]
2398
+ GGML_API struct ggml_tensor * ggml_timestep_embedding(
2399
+ struct ggml_context * ctx,
2400
+ struct ggml_tensor * timesteps,
2401
+ int dim,
2402
+ int max_period);
2403
+
2404
+ // sort rows
2405
+ enum ggml_sort_order {
2406
+ GGML_SORT_ORDER_ASC,
2407
+ GGML_SORT_ORDER_DESC,
2408
+ };
2409
+
2410
+ GGML_API struct ggml_tensor * ggml_argsort(
2411
+ struct ggml_context * ctx,
2412
+ struct ggml_tensor * a,
2413
+ enum ggml_sort_order order);
2414
+
2415
+ // similar to ggml_top_k but implemented as `argsort` + `view`
2416
+ GGML_API struct ggml_tensor * ggml_argsort_top_k(
2417
+ struct ggml_context * ctx,
2418
+ struct ggml_tensor * a,
2419
+ int k);
2420
+
2421
+ // top k elements per row
2422
+ // note: the resulting top k indices are in no particular order
2423
+ GGML_API struct ggml_tensor * ggml_top_k(
2424
+ struct ggml_context * ctx,
2425
+ struct ggml_tensor * a,
2426
+ int k);
2427
+
2428
+ GGML_API struct ggml_tensor * ggml_arange(
2429
+ struct ggml_context * ctx,
2430
+ float start,
2431
+ float stop,
2432
+ float step);
2433
+
2434
+ // q: [n_embd_k, n_batch, n_head, ne3 ]
2435
+ // k: [n_embd_k, n_kv, n_head_kv, ne3 ]
2436
+ // v: [n_embd_v, n_kv, n_head_kv, ne3 ] !! not transposed !!
2437
+ // mask: [n_kv, n_batch, ne32, ne33]
2438
+ // res: [n_embd_v, n_head, n_batch, ne3 ] !! permuted !!
2439
+ //
2440
+ // broadcast:
2441
+ // n_head % n_head_kv == 0
2442
+ // n_head % ne32 == 0
2443
+ // ne3 % ne33 == 0
2444
+ //
2445
+ GGML_API struct ggml_tensor * ggml_flash_attn_ext(
2446
+ struct ggml_context * ctx,
2447
+ struct ggml_tensor * q,
2448
+ struct ggml_tensor * k,
2449
+ struct ggml_tensor * v,
2450
+ struct ggml_tensor * mask,
2451
+ float scale,
2452
+ float max_bias,
2453
+ float logit_softcap);
2454
+
2455
+ GGML_API void ggml_flash_attn_ext_set_prec(
2456
+ struct ggml_tensor * a,
2457
+ enum ggml_prec prec);
2458
+
2459
+ GGML_API enum ggml_prec ggml_flash_attn_ext_get_prec(
2460
+ const struct ggml_tensor * a);
2461
+
2462
+ GGML_API void ggml_flash_attn_ext_add_sinks(
2463
+ struct ggml_tensor * a,
2464
+ struct ggml_tensor * sinks);
2465
+
2466
+ // TODO: needs to be adapted to ggml_flash_attn_ext
2467
+ GGML_API struct ggml_tensor * ggml_flash_attn_back(
2468
+ struct ggml_context * ctx,
2469
+ struct ggml_tensor * q,
2470
+ struct ggml_tensor * k,
2471
+ struct ggml_tensor * v,
2472
+ struct ggml_tensor * d,
2473
+ bool masked);
2474
+
2475
+ GGML_API struct ggml_tensor * ggml_ssm_conv(
2476
+ struct ggml_context * ctx,
2477
+ struct ggml_tensor * sx,
2478
+ struct ggml_tensor * c);
2479
+
2480
+ GGML_API struct ggml_tensor * ggml_ssm_scan(
2481
+ struct ggml_context * ctx,
2482
+ struct ggml_tensor * s,
2483
+ struct ggml_tensor * x,
2484
+ struct ggml_tensor * dt,
2485
+ struct ggml_tensor * A,
2486
+ struct ggml_tensor * B,
2487
+ struct ggml_tensor * C,
2488
+ struct ggml_tensor * ids);
2489
+
2490
+ // partition into non-overlapping windows with padding if needed
2491
+ // example:
2492
+ // a: 768 64 64 1
2493
+ // w: 14
2494
+ // res: 768 14 14 25
2495
+ // used in sam
2496
+ GGML_API struct ggml_tensor * ggml_win_part(
2497
+ struct ggml_context * ctx,
2498
+ struct ggml_tensor * a,
2499
+ int w);
2500
+
2501
+ // reverse of ggml_win_part
2502
+ // used in sam
2503
+ GGML_API struct ggml_tensor * ggml_win_unpart(
2504
+ struct ggml_context * ctx,
2505
+ struct ggml_tensor * a,
2506
+ int w0,
2507
+ int h0,
2508
+ int w);
2509
+
2510
+ GGML_API struct ggml_tensor * ggml_unary(
2511
+ struct ggml_context * ctx,
2512
+ struct ggml_tensor * a,
2513
+ enum ggml_unary_op op);
2514
+
2515
+ GGML_API struct ggml_tensor * ggml_unary_inplace(
2516
+ struct ggml_context * ctx,
2517
+ struct ggml_tensor * a,
2518
+ enum ggml_unary_op op);
2519
+
2520
+ // used in sam
2521
+ GGML_API struct ggml_tensor * ggml_get_rel_pos(
2522
+ struct ggml_context * ctx,
2523
+ struct ggml_tensor * a,
2524
+ int qh,
2525
+ int kh);
2526
+
2527
+ // used in sam
2528
+ GGML_API struct ggml_tensor * ggml_add_rel_pos(
2529
+ struct ggml_context * ctx,
2530
+ struct ggml_tensor * a,
2531
+ struct ggml_tensor * pw,
2532
+ struct ggml_tensor * ph);
2533
+
2534
+ GGML_API struct ggml_tensor * ggml_add_rel_pos_inplace(
2535
+ struct ggml_context * ctx,
2536
+ struct ggml_tensor * a,
2537
+ struct ggml_tensor * pw,
2538
+ struct ggml_tensor * ph);
2539
+
2540
+ GGML_API struct ggml_tensor * ggml_rwkv_wkv6(
2541
+ struct ggml_context * ctx,
2542
+ struct ggml_tensor * k,
2543
+ struct ggml_tensor * v,
2544
+ struct ggml_tensor * r,
2545
+ struct ggml_tensor * tf,
2546
+ struct ggml_tensor * td,
2547
+ struct ggml_tensor * state);
2548
+
2549
+ GGML_API struct ggml_tensor * ggml_gated_linear_attn(
2550
+ struct ggml_context * ctx,
2551
+ struct ggml_tensor * k,
2552
+ struct ggml_tensor * v,
2553
+ struct ggml_tensor * q,
2554
+ struct ggml_tensor * g,
2555
+ struct ggml_tensor * state,
2556
+ float scale);
2557
+
2558
+ GGML_API struct ggml_tensor * ggml_rwkv_wkv7(
2559
+ struct ggml_context * ctx,
2560
+ struct ggml_tensor * r,
2561
+ struct ggml_tensor * w,
2562
+ struct ggml_tensor * k,
2563
+ struct ggml_tensor * v,
2564
+ struct ggml_tensor * a,
2565
+ struct ggml_tensor * b,
2566
+ struct ggml_tensor * state);
2567
+
2568
+ /* Solves a specific equation of the form Ax=B, where A is a triangular matrix
2569
+ * without zeroes on the diagonal (i.e. invertible).
2570
+ * B can have any number of columns, but must have the same number of rows as A
2571
+ * If A is [n, n] and B is [n, m], then the result will be [n, m] as well
2572
+ * Has O(n^3) complexity (unlike most matrix ops out there), so use on cases
2573
+ * where n > 100 sparingly, pre-chunk if necessary.
2574
+ *
2575
+ * If left = false, solves xA=B instead
2576
+ * If lower = false, assumes upper triangular instead
2577
+ * If uni = true, assumes diagonal of A to be all ones (will override actual values)
2578
+ *
2579
+ * TODO: currently only lower, right, non-unitriangular variant is implemented
2580
+ */
2581
+ GGML_API struct ggml_tensor * ggml_solve_tri(
2582
+ struct ggml_context * ctx,
2583
+ struct ggml_tensor * a,
2584
+ struct ggml_tensor * b,
2585
+ bool left,
2586
+ bool lower,
2587
+ bool uni);
2588
+
2589
+ // TODO: add ggml_gated_delta_net_set_bcast() to be able to configure Q, K broadcast type: tiled vs interleaved [TAG_GGML_GDN_BCAST]
2590
+ // ref: https://github.com/ggml-org/llama.cpp/pull/19468#discussion_r2786394306
2591
+ GGML_API struct ggml_tensor * ggml_gated_delta_net(
2592
+ struct ggml_context * ctx,
2593
+ struct ggml_tensor * q,
2594
+ struct ggml_tensor * k,
2595
+ struct ggml_tensor * v,
2596
+ struct ggml_tensor * g,
2597
+ struct ggml_tensor * beta,
2598
+ struct ggml_tensor * state);
2599
+
2600
+ // custom operators
2601
+
2602
+ typedef void (*ggml_custom1_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, int ith, int nth, void * userdata);
2603
+ typedef void (*ggml_custom2_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, int ith, int nth, void * userdata);
2604
+ typedef void (*ggml_custom3_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, const struct ggml_tensor * b, const struct ggml_tensor * c, int ith, int nth, void * userdata);
2605
+
2606
+ #define GGML_N_TASKS_MAX (-1)
2607
+ // n_tasks == GGML_N_TASKS_MAX means to use max number of tasks
2608
+
2609
+ GGML_API struct ggml_tensor * ggml_map_custom1(
2610
+ struct ggml_context * ctx,
2611
+ struct ggml_tensor * a,
2612
+ ggml_custom1_op_t fun,
2613
+ int n_tasks,
2614
+ void * userdata);
2615
+
2616
+ GGML_API struct ggml_tensor * ggml_map_custom1_inplace(
2617
+ struct ggml_context * ctx,
2618
+ struct ggml_tensor * a,
2619
+ ggml_custom1_op_t fun,
2620
+ int n_tasks,
2621
+ void * userdata);
2622
+
2623
+ GGML_API struct ggml_tensor * ggml_map_custom2(
2624
+ struct ggml_context * ctx,
2625
+ struct ggml_tensor * a,
2626
+ struct ggml_tensor * b,
2627
+ ggml_custom2_op_t fun,
2628
+ int n_tasks,
2629
+ void * userdata);
2630
+
2631
+ GGML_API struct ggml_tensor * ggml_map_custom2_inplace(
2632
+ struct ggml_context * ctx,
2633
+ struct ggml_tensor * a,
2634
+ struct ggml_tensor * b,
2635
+ ggml_custom2_op_t fun,
2636
+ int n_tasks,
2637
+ void * userdata);
2638
+
2639
+ GGML_API struct ggml_tensor * ggml_map_custom3(
2640
+ struct ggml_context * ctx,
2641
+ struct ggml_tensor * a,
2642
+ struct ggml_tensor * b,
2643
+ struct ggml_tensor * c,
2644
+ ggml_custom3_op_t fun,
2645
+ int n_tasks,
2646
+ void * userdata);
2647
+
2648
+ GGML_API struct ggml_tensor * ggml_map_custom3_inplace(
2649
+ struct ggml_context * ctx,
2650
+ struct ggml_tensor * a,
2651
+ struct ggml_tensor * b,
2652
+ struct ggml_tensor * c,
2653
+ ggml_custom3_op_t fun,
2654
+ int n_tasks,
2655
+ void * userdata);
2656
+
2657
+ typedef void (*ggml_custom_op_t)(struct ggml_tensor * dst , int ith, int nth, void * userdata);
2658
+
2659
+ GGML_API struct ggml_tensor * ggml_custom_4d(
2660
+ struct ggml_context * ctx,
2661
+ enum ggml_type type,
2662
+ int64_t ne0,
2663
+ int64_t ne1,
2664
+ int64_t ne2,
2665
+ int64_t ne3,
2666
+ struct ggml_tensor ** args,
2667
+ int n_args,
2668
+ ggml_custom_op_t fun,
2669
+ int n_tasks,
2670
+ void * userdata);
2671
+
2672
+ GGML_API struct ggml_tensor * ggml_custom_inplace(
2673
+ struct ggml_context * ctx,
2674
+ struct ggml_tensor * a,
2675
+ struct ggml_tensor ** args,
2676
+ int n_args,
2677
+ ggml_custom_op_t fun,
2678
+ int n_tasks,
2679
+ void * userdata);
2680
+
2681
+ // loss function
2682
+
2683
+ GGML_API struct ggml_tensor * ggml_cross_entropy_loss(
2684
+ struct ggml_context * ctx,
2685
+ struct ggml_tensor * a, // logits
2686
+ struct ggml_tensor * b); // labels
2687
+
2688
+ GGML_API struct ggml_tensor * ggml_cross_entropy_loss_back(
2689
+ struct ggml_context * ctx,
2690
+ struct ggml_tensor * a, // logits
2691
+ struct ggml_tensor * b, // labels
2692
+ struct ggml_tensor * c); // gradients of cross_entropy_loss result
2693
+
2694
+ // AdamW optimizer step
2695
+ // Paper: https://arxiv.org/pdf/1711.05101v3.pdf
2696
+ // PyTorch: https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html
2697
+ GGML_API struct ggml_tensor * ggml_opt_step_adamw(
2698
+ struct ggml_context * ctx,
2699
+ struct ggml_tensor * a,
2700
+ struct ggml_tensor * grad,
2701
+ struct ggml_tensor * m,
2702
+ struct ggml_tensor * v,
2703
+ struct ggml_tensor * adamw_params); // parameters such as the learning rate
2704
+
2705
+ // stochastic gradient descent step (with weight decay)
2706
+ GGML_API struct ggml_tensor * ggml_opt_step_sgd(
2707
+ struct ggml_context * ctx,
2708
+ struct ggml_tensor * a,
2709
+ struct ggml_tensor * grad,
2710
+ struct ggml_tensor * sgd_params); // alpha, weight decay
2711
+
2712
+ // build forward multiple tensors and select one of them for computing
2713
+ // this is useful for creating graphs that have constant topology but compute different things based on the input
2714
+ // ref: https://github.com/ggml-org/llama.cpp/pull/18550
2715
+ //
2716
+ // nodes:
2717
+ // | - build forward into the graph but do not compute
2718
+ // c - build forward into the graph and compute
2719
+ //
2720
+ // | | ... c ... |
2721
+ // | | ... c ... |
2722
+ // | | ... c ... |
2723
+ // [0 1 ... idx ... n-1] <-- ggml_build_forward_select(..., n, idx)
2724
+ // c
2725
+ // c
2726
+ //
2727
+ // example:
2728
+ // struct ggml_tensor * curs[3];
2729
+ //
2730
+ // curs[0] = compute0(...);
2731
+ // curs[1] = compute1(...);
2732
+ // curs[2] = compute2(...);
2733
+ //
2734
+ // int idx = select_branch(some_input);
2735
+ //
2736
+ // struct ggml_tensor * out = ggml_build_forward_select(cgraph, curs, 3, idx);
2737
+ //
2738
+ GGML_API struct ggml_tensor * ggml_build_forward_select(
2739
+ struct ggml_cgraph * cgraph,
2740
+ struct ggml_tensor ** tensors,
2741
+ int n_tensors,
2742
+ int idx);
2743
+
2744
+ GGML_API void ggml_build_forward_expand(
2745
+ struct ggml_cgraph * cgraph,
2746
+ struct ggml_tensor * tensor);
2747
+
2748
+ GGML_API void ggml_build_backward_expand(
2749
+ struct ggml_context * ctx, // context for gradient computation
2750
+ struct ggml_cgraph * cgraph,
2751
+ struct ggml_tensor ** grad_accs);
2752
+
2753
+ // graph allocation in a context
2754
+ GGML_API struct ggml_cgraph * ggml_new_graph (struct ggml_context * ctx); // size = GGML_DEFAULT_GRAPH_SIZE, grads = false
2755
+ GGML_API struct ggml_cgraph * ggml_new_graph_custom(struct ggml_context * ctx, size_t size, bool grads);
2756
+ GGML_API struct ggml_cgraph * ggml_graph_dup (struct ggml_context * ctx, struct ggml_cgraph * cgraph, bool force_grads);
2757
+ GGML_API void ggml_graph_cpy (struct ggml_cgraph * src, struct ggml_cgraph * dst);
2758
+ GGML_API void ggml_graph_reset (struct ggml_cgraph * cgraph); // set regular grads + optimizer momenta to 0, set loss grad to 1
2759
+ GGML_API void ggml_graph_clear (struct ggml_cgraph * cgraph);
2760
+
2761
+ GGML_API int ggml_graph_size (struct ggml_cgraph * cgraph);
2762
+ GGML_API struct ggml_tensor * ggml_graph_node (struct ggml_cgraph * cgraph, int i); // if i < 0, returns nodes[n_nodes + i]
2763
+ GGML_API struct ggml_tensor ** ggml_graph_nodes (struct ggml_cgraph * cgraph);
2764
+ GGML_API int ggml_graph_n_nodes(struct ggml_cgraph * cgraph);
2765
+
2766
+ GGML_API void ggml_graph_add_node(struct ggml_cgraph * cgraph, struct ggml_tensor * tensor);
2767
+
2768
+ GGML_API size_t ggml_graph_overhead(void);
2769
+ GGML_API size_t ggml_graph_overhead_custom(size_t size, bool grads);
2770
+
2771
+ GGML_API struct ggml_tensor * ggml_graph_get_tensor (const struct ggml_cgraph * cgraph, const char * name);
2772
+ GGML_API struct ggml_tensor * ggml_graph_get_grad (const struct ggml_cgraph * cgraph, const struct ggml_tensor * node);
2773
+ GGML_API struct ggml_tensor * ggml_graph_get_grad_acc(const struct ggml_cgraph * cgraph, const struct ggml_tensor * node);
2774
+
2775
+ // print info and performance information for the graph
2776
+ GGML_API void ggml_graph_print(const struct ggml_cgraph * cgraph);
2777
+
2778
+ // dump the graph into a file using the dot format
2779
+ GGML_API void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * cgraph, const char * filename);
2780
+
2781
+ // TODO these functions were sandwiched in the old optimization interface, is there a better place for them?
2782
+ typedef void (*ggml_log_callback)(enum ggml_log_level level, const char * text, void * user_data);
2783
+
2784
+ // Set callback for all future logging events.
2785
+ // If this is not called, or NULL is supplied, everything is output on stderr.
2786
+ GGML_API void ggml_log_get(ggml_log_callback * log_callback, void ** user_data);
2787
+ GGML_API void ggml_log_set(ggml_log_callback log_callback, void * user_data);
2788
+
2789
+ GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);
2790
+
2791
+ //
2792
+ // quantization
2793
+ //
2794
+
2795
+ // - ggml_quantize_init can be called multiple times with the same type
2796
+ // it will only initialize the quantization tables for the first call or after ggml_quantize_free
2797
+ // automatically called by ggml_quantize_chunk for convenience
2798
+ //
2799
+ // - ggml_quantize_free will free any memory allocated by ggml_quantize_init
2800
+ // call this at the end of the program to avoid memory leaks
2801
+ //
2802
+ // note: these are thread-safe
2803
+ //
2804
+ GGML_API void ggml_quantize_init(enum ggml_type type);
2805
+ GGML_API void ggml_quantize_free(void);
2806
+
2807
+ // some quantization type cannot be used without an importance matrix
2808
+ GGML_API bool ggml_quantize_requires_imatrix(enum ggml_type type);
2809
+
2810
+ // calls ggml_quantize_init internally (i.e. can allocate memory)
2811
+ GGML_API size_t ggml_quantize_chunk(
2812
+ enum ggml_type type,
2813
+ const float * src,
2814
+ void * dst,
2815
+ int64_t start,
2816
+ int64_t nrows,
2817
+ int64_t n_per_row,
2818
+ const float * imatrix);
2819
+
2820
+ #ifdef __cplusplus
2821
+ // restrict not standard in C++
2822
+ # if defined(__GNUC__)
2823
+ # define GGML_RESTRICT __restrict__
2824
+ # elif defined(__clang__)
2825
+ # define GGML_RESTRICT __restrict
2826
+ # elif defined(_MSC_VER)
2827
+ # define GGML_RESTRICT __restrict
2828
+ # else
2829
+ # define GGML_RESTRICT
2830
+ # endif
2831
+ #else
2832
+ # if defined (_MSC_VER) && (__STDC_VERSION__ < 201112L)
2833
+ # define GGML_RESTRICT __restrict
2834
+ # else
2835
+ # define GGML_RESTRICT restrict
2836
+ # endif
2837
+ #endif
2838
+ typedef void (*ggml_to_float_t) (const void * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
2839
+ typedef void (*ggml_from_float_t)(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
2840
+
2841
+ struct ggml_type_traits {
2842
+ const char * type_name;
2843
+ int64_t blck_size;
2844
+ int64_t blck_size_interleave; // interleave elements in blocks
2845
+ size_t type_size;
2846
+ bool is_quantized;
2847
+ ggml_to_float_t to_float;
2848
+ ggml_from_float_t from_float_ref;
2849
+ };
2850
+
2851
+ GGML_API const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type);
2852
+
2853
+ // ggml threadpool
2854
+ // TODO: currently, only a few functions are in the base ggml API, while the rest are in the CPU backend
2855
+ // the goal should be to create an API that other backends can use move everything to the ggml base
2856
+
2857
+ // scheduling priorities
2858
+ enum ggml_sched_priority {
2859
+ GGML_SCHED_PRIO_LOW = -1,
2860
+ GGML_SCHED_PRIO_NORMAL,
2861
+ GGML_SCHED_PRIO_MEDIUM,
2862
+ GGML_SCHED_PRIO_HIGH,
2863
+ GGML_SCHED_PRIO_REALTIME
2864
+ };
2865
+
2866
+ // threadpool params
2867
+ // Use ggml_threadpool_params_default() or ggml_threadpool_params_init() to populate the defaults
2868
+ struct ggml_threadpool_params {
2869
+ bool cpumask[GGML_MAX_N_THREADS]; // mask of cpu cores (all-zeros means use default affinity settings)
2870
+ int n_threads; // number of threads
2871
+ enum ggml_sched_priority prio; // thread priority
2872
+ uint32_t poll; // polling level (0 - no polling, 100 - aggressive polling)
2873
+ bool strict_cpu; // strict cpu placement
2874
+ bool paused; // start in paused state
2875
+ };
2876
+
2877
+ struct ggml_threadpool; // forward declaration, see ggml.c
2878
+
2879
+ typedef struct ggml_threadpool * ggml_threadpool_t;
2880
+
2881
+ GGML_API struct ggml_threadpool_params ggml_threadpool_params_default(int n_threads);
2882
+ GGML_API void ggml_threadpool_params_init (struct ggml_threadpool_params * p, int n_threads);
2883
+ GGML_API bool ggml_threadpool_params_match (const struct ggml_threadpool_params * p0, const struct ggml_threadpool_params * p1);
2884
+
2885
+ #ifdef __cplusplus
2886
+ }
2887
+ #endif