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,783 @@
1
+ #pragma once
2
+
3
+ // GGML internal header
4
+
5
+ #include "ggml.h"
6
+ #include "gguf.h"
7
+
8
+ #include <assert.h>
9
+ #include <math.h>
10
+ #include <stdlib.h> // load `stdlib.h` before other headers to work around MinGW bug: https://sourceforge.net/p/mingw-w64/bugs/192/
11
+ #include <stdbool.h>
12
+ #include <stdint.h>
13
+ #include <string.h>
14
+
15
+ #ifdef __ARM_FEATURE_SVE
16
+ #include <arm_sve.h>
17
+ #endif // __ARM_FEATURE_SVE
18
+
19
+ #if defined(__ARM_NEON) && !defined(__CUDACC__) && !defined(__MUSACC__)
20
+ // if YCM cannot find <arm_neon.h>, make a symbolic link to it, for example:
21
+ //
22
+ // $ ln -sfn /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/arm_neon.h ./src/
23
+ //
24
+ #include <arm_neon.h>
25
+ #endif
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ void ggml_print_backtrace(void);
32
+
33
+ uint64_t ggml_graph_next_uid(void);
34
+
35
+ #ifndef MIN
36
+ # define MIN(a, b) ((a) < (b) ? (a) : (b))
37
+ #endif
38
+
39
+ #ifndef MAX
40
+ # define MAX(a, b) ((a) > (b) ? (a) : (b))
41
+ #endif
42
+
43
+ // required for mmap as gguf only guarantees 32-byte alignment
44
+ #define TENSOR_ALIGNMENT 32
45
+
46
+ // static_assert should be a #define, but if it's not,
47
+ // fall back to the _Static_assert C11 keyword.
48
+ // if C99 - static_assert is noop
49
+ // ref: https://stackoverflow.com/a/53923785/4039976
50
+ #ifndef __cplusplus
51
+ #ifndef static_assert
52
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201100L)
53
+ #define static_assert(cond, msg) _Static_assert(cond, msg)
54
+ #else
55
+ #define static_assert(cond, msg) struct global_scope_noop_trick
56
+ #endif
57
+ #endif
58
+ #endif
59
+
60
+ static inline int ggml_up32(int n) {
61
+ return (n + 31) & ~31;
62
+ }
63
+
64
+ //static inline int ggml_up64(int n) {
65
+ // return (n + 63) & ~63;
66
+ //}
67
+
68
+ static inline int ggml_up(int n, int m) {
69
+ // assert m is a power of 2
70
+ GGML_ASSERT((m & (m - 1)) == 0);
71
+ return (n + m - 1) & ~(m - 1);
72
+ }
73
+
74
+ // TODO: move to ggml.h? (won't be able to inline)
75
+ static bool ggml_are_same_layout(const struct ggml_tensor * a, const struct ggml_tensor * b) {
76
+ if (a->type != b->type) {
77
+ return false;
78
+ }
79
+ for (int i = 0; i < GGML_MAX_DIMS; i++) {
80
+ if (a->ne[i] != b->ne[i]) {
81
+ return false;
82
+ }
83
+ if (a->nb[i] != b->nb[i]) {
84
+ return false;
85
+ }
86
+ }
87
+ return true;
88
+ }
89
+
90
+ static bool ggml_op_is_empty(enum ggml_op op) {
91
+ switch (op) {
92
+ case GGML_OP_NONE:
93
+ case GGML_OP_RESHAPE:
94
+ case GGML_OP_TRANSPOSE:
95
+ case GGML_OP_VIEW:
96
+ case GGML_OP_PERMUTE:
97
+ return true;
98
+ default:
99
+ return false;
100
+ }
101
+ }
102
+
103
+ static inline bool ggml_impl_is_view(const struct ggml_tensor * t) {
104
+ return t->view_src != NULL;
105
+ }
106
+
107
+ static inline float ggml_compute_softplus_f32(float input) {
108
+ return (input > 20.0f) ? input : logf(1 + expf(input));
109
+ }
110
+ //
111
+ // logging
112
+ //
113
+
114
+ GGML_ATTRIBUTE_FORMAT(2, 3)
115
+ GGML_API void ggml_log_internal (enum ggml_log_level level, const char * format, ...);
116
+ GGML_API void ggml_log_callback_default(enum ggml_log_level level, const char * text, void * user_data);
117
+
118
+ #define GGML_LOG(...) ggml_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__)
119
+ #define GGML_LOG_INFO(...) ggml_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
120
+ #define GGML_LOG_WARN(...) ggml_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
121
+ #define GGML_LOG_ERROR(...) ggml_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
122
+ #define GGML_LOG_DEBUG(...) ggml_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
123
+ #define GGML_LOG_CONT(...) ggml_log_internal(GGML_LOG_LEVEL_CONT , __VA_ARGS__)
124
+
125
+ #define GGML_DEBUG 0
126
+
127
+ #if (GGML_DEBUG >= 1)
128
+ #define GGML_PRINT_DEBUG(...) GGML_LOG_DEBUG(__VA_ARGS__)
129
+ #else
130
+ #define GGML_PRINT_DEBUG(...)
131
+ #endif
132
+
133
+ #if (GGML_DEBUG >= 5)
134
+ #define GGML_PRINT_DEBUG_5(...) GGML_LOG_DEBUG(__VA_ARGS__)
135
+ #else
136
+ #define GGML_PRINT_DEBUG_5(...)
137
+ #endif
138
+
139
+ #if (GGML_DEBUG >= 10)
140
+ #define GGML_PRINT_DEBUG_10(...) GGML_LOG_DEBUG(__VA_ARGS__)
141
+ #else
142
+ #define GGML_PRINT_DEBUG_10(...)
143
+ #endif
144
+
145
+ // tensor params
146
+
147
+ static void ggml_set_op_params(struct ggml_tensor * tensor, const void * params, size_t params_size) {
148
+ GGML_ASSERT(tensor != NULL); // silence -Warray-bounds warnings
149
+ assert(params_size <= GGML_MAX_OP_PARAMS);
150
+ memcpy(tensor->op_params, params, params_size);
151
+ }
152
+
153
+ static int32_t ggml_get_op_params_i32(const struct ggml_tensor * tensor, uint32_t i) {
154
+ assert(i < GGML_MAX_OP_PARAMS / sizeof(int32_t));
155
+ return ((const int32_t *)(tensor->op_params))[i];
156
+ }
157
+
158
+ static float ggml_get_op_params_f32(const struct ggml_tensor * tensor, uint32_t i) {
159
+ assert(i < GGML_MAX_OP_PARAMS / sizeof(float));
160
+ return ((const float *)(tensor->op_params))[i];
161
+ }
162
+
163
+ static void ggml_set_op_params_i32(struct ggml_tensor * tensor, uint32_t i, int32_t value) {
164
+ assert(i < GGML_MAX_OP_PARAMS / sizeof(int32_t));
165
+ ((int32_t *)(tensor->op_params))[i] = value;
166
+ }
167
+
168
+ static void ggml_set_op_params_f32(struct ggml_tensor * tensor, uint32_t i, float value) {
169
+ assert(i < GGML_MAX_OP_PARAMS / sizeof(float));
170
+ ((float *)(tensor->op_params))[i] = value;
171
+ }
172
+
173
+ struct ggml_map_custom1_op_params {
174
+ ggml_custom1_op_t fun;
175
+ int n_tasks;
176
+ void * userdata;
177
+ };
178
+
179
+ struct ggml_map_custom2_op_params {
180
+ ggml_custom2_op_t fun;
181
+ int n_tasks;
182
+ void * userdata;
183
+ };
184
+
185
+ struct ggml_map_custom3_op_params {
186
+ ggml_custom3_op_t fun;
187
+ int n_tasks;
188
+ void * userdata;
189
+ };
190
+
191
+ struct ggml_custom_op_params {
192
+ ggml_custom_op_t fun;
193
+ int n_tasks;
194
+ void * userdata;
195
+ };
196
+
197
+ // bitset
198
+
199
+ typedef uint32_t ggml_bitset_t;
200
+
201
+ static_assert(sizeof(ggml_bitset_t) == 4, "bitset_t constants must be updated");
202
+ #define BITSET_SHR 5 // log2(sizeof(ggml_bitset_t)*8)
203
+ #define BITSET_MASK (sizeof(ggml_bitset_t)*8 - 1)
204
+
205
+ static size_t ggml_bitset_size(size_t n) {
206
+ return (n + BITSET_MASK) >> BITSET_SHR;
207
+ }
208
+
209
+ static inline bool ggml_bitset_get(const ggml_bitset_t * bitset, size_t i) {
210
+ return !!(bitset[i >> BITSET_SHR] & (1u << (i & BITSET_MASK)));
211
+ }
212
+
213
+ static inline void ggml_bitset_set(ggml_bitset_t * bitset, size_t i) {
214
+ bitset[i >> BITSET_SHR] |= (1u << (i & BITSET_MASK));
215
+ }
216
+
217
+ static inline void ggml_bitset_clear(ggml_bitset_t * bitset, size_t i) {
218
+ bitset[i >> BITSET_SHR] &= ~(1u << (i & BITSET_MASK));
219
+ }
220
+
221
+ // hash set
222
+
223
+ #define GGML_HASHSET_FULL ((size_t)-1)
224
+ #define GGML_HASHSET_ALREADY_EXISTS ((size_t)-2)
225
+
226
+ struct ggml_hash_set {
227
+ size_t size;
228
+ ggml_bitset_t * used; // whether or not the keys are in use i.e. set
229
+ struct ggml_tensor ** keys; // actual tensors in the set, keys[i] is only defined if ggml_bitset_get(used, i)
230
+ };
231
+
232
+ struct ggml_hash_set ggml_hash_set_new(size_t size);
233
+ void ggml_hash_set_free(struct ggml_hash_set * hash_set);
234
+
235
+ // returns the minimum size for a hash set that can hold min_sz elements
236
+ size_t ggml_hash_size(size_t min_sz);
237
+
238
+ // remove all elements from the hash set
239
+ void ggml_hash_set_reset(struct ggml_hash_set * hash_set);
240
+
241
+ // returns true if key is in the hash set
242
+ static bool ggml_hash_contains(const struct ggml_hash_set * hash_set, struct ggml_tensor * key);
243
+
244
+ // returns GGML_HASHSET_FULL if table is full, otherwise the current index of the key or where it should be inserted
245
+ static size_t ggml_hash_find(const struct ggml_hash_set * hash_set, const struct ggml_tensor * key);
246
+
247
+ // returns GGML_HASHSET_ALREADY_EXISTS if key already exists, index otherwise, asserts if table is full
248
+ static size_t ggml_hash_insert(struct ggml_hash_set * hash_set, struct ggml_tensor * key);
249
+
250
+ // return index, asserts if table is full
251
+ static size_t ggml_hash_find_or_insert(struct ggml_hash_set * hash_set, struct ggml_tensor * key);
252
+
253
+ // hash function for ggml_tensor
254
+ static inline size_t ggml_hash(const struct ggml_tensor * p) {
255
+ // the last 4 bits are always zero due to alignment
256
+ return (size_t)(uintptr_t)p >> 4;
257
+ }
258
+
259
+ static size_t ggml_hash_find(const struct ggml_hash_set * hash_set, const struct ggml_tensor * key) {
260
+ size_t h = ggml_hash(key) % hash_set->size;
261
+
262
+ // linear probing
263
+ size_t i = h;
264
+ while (ggml_bitset_get(hash_set->used, i) && hash_set->keys[i] != key) {
265
+ i = (i + 1) % hash_set->size;
266
+ if (i == h) {
267
+ // visited all hash table entries -> not found
268
+ return GGML_HASHSET_FULL;
269
+ }
270
+ }
271
+ return i;
272
+ }
273
+
274
+ static bool ggml_hash_contains(const struct ggml_hash_set * hash_set, struct ggml_tensor * key) {
275
+ size_t i = ggml_hash_find(hash_set, key);
276
+ return i != GGML_HASHSET_FULL && ggml_bitset_get(hash_set->used, i);
277
+ }
278
+
279
+ static size_t ggml_hash_insert(struct ggml_hash_set * hash_set, struct ggml_tensor * key) {
280
+ size_t h = ggml_hash(key) % hash_set->size;
281
+
282
+ // linear probing
283
+ size_t i = h;
284
+ do {
285
+ if (!ggml_bitset_get(hash_set->used, i)) {
286
+ ggml_bitset_set(hash_set->used, i);
287
+ hash_set->keys[i] = key;
288
+ return i;
289
+ }
290
+ if (hash_set->keys[i] == key) {
291
+ return GGML_HASHSET_ALREADY_EXISTS;
292
+ }
293
+ i = (i + 1) % hash_set->size;
294
+ } while (i != h);
295
+
296
+ // visited all hash table entries -> not found
297
+ GGML_ABORT("fatal error");
298
+ }
299
+
300
+ static size_t ggml_hash_find_or_insert(struct ggml_hash_set * hash_set, struct ggml_tensor * key) {
301
+ size_t h = ggml_hash(key) % hash_set->size;
302
+
303
+ // linear probing
304
+ size_t i = h;
305
+ do {
306
+ if (!ggml_bitset_get(hash_set->used, i)) {
307
+ ggml_bitset_set(hash_set->used, i);
308
+ hash_set->keys[i] = key;
309
+ return i;
310
+ }
311
+ if (hash_set->keys[i] == key) {
312
+ return i;
313
+ }
314
+ i = (i + 1) % hash_set->size;
315
+ } while (i != h);
316
+
317
+ // visited all hash table entries -> not found
318
+ GGML_ABORT("fatal error");
319
+ }
320
+
321
+ // computation graph
322
+
323
+ enum ggml_cgraph_eval_order {
324
+ GGML_CGRAPH_EVAL_ORDER_LEFT_TO_RIGHT = 0,
325
+ GGML_CGRAPH_EVAL_ORDER_RIGHT_TO_LEFT,
326
+ GGML_CGRAPH_EVAL_ORDER_COUNT
327
+ };
328
+
329
+ struct ggml_cgraph {
330
+ int size; // maximum number of nodes/leafs/grads/grad_accs
331
+ int n_nodes; // number of nodes currently in use
332
+ int n_leafs; // number of leafs currently in use
333
+
334
+ struct ggml_tensor ** nodes; // tensors with data that can change if the graph is evaluated
335
+ struct ggml_tensor ** grads; // the outputs of these tensors are the gradients of the nodes
336
+ struct ggml_tensor ** grad_accs; // accumulators for node gradients
337
+ struct ggml_tensor ** leafs; // tensors with constant data
338
+ int32_t * use_counts;// number of uses of each tensor, indexed by hash table slot
339
+
340
+ struct ggml_hash_set visited_hash_set;
341
+
342
+ enum ggml_cgraph_eval_order order;
343
+
344
+ // an optional identifier that can be utilized to recognize same graphs if two non-zero values match
345
+ // a value of 0 means it is not set and should be ignored
346
+ uint64_t uid;
347
+ };
348
+
349
+ // returns a slice of cgraph with nodes [i0, i1)
350
+ // the slice does not have leafs or gradients
351
+ // if you need the gradients, get them from the original graph
352
+ struct ggml_cgraph ggml_graph_view(struct ggml_cgraph * cgraph, int i0, int i1);
353
+
354
+ // ggml-alloc.c: true if the operation can reuse memory from its sources
355
+ GGML_API bool ggml_op_can_inplace(enum ggml_op op);
356
+
357
+
358
+ // Memory allocation
359
+
360
+ GGML_API void * ggml_aligned_malloc(size_t size);
361
+ GGML_API void ggml_aligned_free(void * ptr, size_t size);
362
+
363
+ // FP16 <-> FP32
364
+ // ref: https://github.com/Maratyszcza/FP16
365
+
366
+ static inline float fp32_from_bits(uint32_t w) {
367
+ union {
368
+ uint32_t as_bits;
369
+ float as_value;
370
+ } fp32;
371
+ fp32.as_bits = w;
372
+ return fp32.as_value;
373
+ }
374
+
375
+ static inline uint32_t fp32_to_bits(float f) {
376
+ union {
377
+ float as_value;
378
+ uint32_t as_bits;
379
+ } fp32;
380
+ fp32.as_value = f;
381
+ return fp32.as_bits;
382
+ }
383
+
384
+ static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
385
+ const uint32_t w = (uint32_t) h << 16;
386
+ const uint32_t sign = w & UINT32_C(0x80000000);
387
+ const uint32_t two_w = w + w;
388
+
389
+ const uint32_t exp_offset = UINT32_C(0xE0) << 23;
390
+ #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
391
+ const float exp_scale = 0x1.0p-112f;
392
+ #else
393
+ const float exp_scale = fp32_from_bits(UINT32_C(0x7800000));
394
+ #endif
395
+ const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale;
396
+
397
+ const uint32_t magic_mask = UINT32_C(126) << 23;
398
+ const float magic_bias = 0.5f;
399
+ const float denormalized_value = fp32_from_bits((two_w >> 17) | magic_mask) - magic_bias;
400
+
401
+ const uint32_t denormalized_cutoff = UINT32_C(1) << 27;
402
+ const uint32_t result = sign |
403
+ (two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) : fp32_to_bits(normalized_value));
404
+ return fp32_from_bits(result);
405
+ }
406
+
407
+ static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
408
+ #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
409
+ const float scale_to_inf = 0x1.0p+112f;
410
+ const float scale_to_zero = 0x1.0p-110f;
411
+ #else
412
+ const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
413
+ const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
414
+ #endif
415
+ float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
416
+
417
+ const uint32_t w = fp32_to_bits(f);
418
+ const uint32_t shl1_w = w + w;
419
+ const uint32_t sign = w & UINT32_C(0x80000000);
420
+ uint32_t bias = shl1_w & UINT32_C(0xFF000000);
421
+ if (bias < UINT32_C(0x71000000)) {
422
+ bias = UINT32_C(0x71000000);
423
+ }
424
+
425
+ base = fp32_from_bits((bias >> 1) + UINT32_C(0x07800000)) + base;
426
+ const uint32_t bits = fp32_to_bits(base);
427
+ const uint32_t exp_bits = (bits >> 13) & UINT32_C(0x00007C00);
428
+ const uint32_t mantissa_bits = bits & UINT32_C(0x00000FFF);
429
+ const uint32_t nonsign = exp_bits + mantissa_bits;
430
+ return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
431
+ }
432
+
433
+ #define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
434
+ #define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
435
+
436
+ #define GGML_FP16_TO_FP32(x) GGML_COMPUTE_FP16_TO_FP32(x)
437
+ #define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x)
438
+
439
+ static inline float ggml_e8m0_to_fp32(uint8_t x) {
440
+ uint32_t bits; // Stores the raw bit representation of the float
441
+
442
+ // Handle special case for minimum exponent (denormalized float)
443
+ if (x == 0) {
444
+ // Bit pattern for 2^(-127):
445
+ // - Sign bit: 0 (positive)
446
+ // - Exponent: 0 (denormalized number)
447
+ // - Mantissa: 0x400000 (0.5 in fractional form)
448
+ // Value = 0.5 * 2^(-126) = 2^(-127)
449
+ bits = 0x00400000;
450
+ }
451
+ // note: disabled as we don't need to handle NaNs
452
+ //// Handle special case for NaN (all bits set)
453
+ //else if (x == 0xFF) {
454
+ // // Standard quiet NaN pattern:
455
+ // // - Sign bit: 0
456
+ // // - Exponent: all 1s (0xFF)
457
+ // // - Mantissa: 0x400000 (quiet NaN flag)
458
+ // bits = 0x7FC00000;
459
+ //}
460
+ // Normalized values (most common case)
461
+ else {
462
+ // Construct normalized float by shifting exponent into position:
463
+ // - Exponent field: 8 bits (positions 30-23)
464
+ // - Mantissa: 0 (implicit leading 1)
465
+ // Value = 2^(x - 127)
466
+ bits = (uint32_t) x << 23;
467
+ }
468
+
469
+ float result; // Final float value
470
+ // Safely reinterpret bit pattern as float without type-punning issues
471
+ memcpy(&result, &bits, sizeof(float));
472
+ return result;
473
+ }
474
+
475
+ // Equal to ggml_e8m0_to_fp32/2
476
+ // Useful with MXFP4 quantization since the E0M2 values are doubled
477
+ static inline float ggml_e8m0_to_fp32_half(uint8_t x) {
478
+ uint32_t bits;
479
+
480
+ // For x < 2: use precomputed denormal patterns
481
+ if (x < 2) {
482
+ // 0x00200000 = 2^(-128), 0x00400000 = 2^(-127)
483
+ bits = 0x00200000 << x;
484
+ }
485
+ // For x >= 2: normalized exponent adjustment
486
+ else {
487
+ // 0.5 * 2^(x-127) = 2^(x-128) = normalized with exponent (x-1)
488
+ bits = (uint32_t)(x - 1) << 23;
489
+ }
490
+ // Note: NaNs are not handled here
491
+
492
+ float result;
493
+ memcpy(&result, &bits, sizeof(float));
494
+ return result;
495
+ }
496
+
497
+ #define GGML_E8M0_TO_FP32(x) ggml_e8m0_to_fp32(x)
498
+ #define GGML_E8M0_TO_FP32_HALF(x) ggml_e8m0_to_fp32_half(x)
499
+
500
+ // UE4M3: unsigned, 4 exp bits (bias=7), 3 mantissa bits
501
+ // Returns value * 0.5 to match kvalues_mxfp4 convention (kvalues = 2 * E2M1_float)
502
+ static inline float ggml_ue4m3_to_fp32(uint8_t x) {
503
+ if (x == 0 || x == 0x7F) {
504
+ return 0.0f;
505
+ }
506
+ int exp = (x >> 3) & 0xF;
507
+ int man = x & 0x7;
508
+ float raw;
509
+ if (exp == 0) {
510
+ raw = ldexpf((float) man, -9);
511
+ } else {
512
+ raw = ldexpf(1.0f + (float) man / 8.0f, exp - 7);
513
+ }
514
+ return raw * 0.5f;
515
+ }
516
+
517
+ static inline uint8_t ggml_fp32_to_ue4m3(float x) {
518
+ if (!(x > 0.0f)) {
519
+ return 0;
520
+ }
521
+ if (x > 448.0f) {
522
+ x = 448.0f;
523
+ }
524
+ uint32_t bits;
525
+ memcpy(&bits, &x, 4);
526
+ int fp32_exp = ((bits >> 23) & 0xFF) - 127;
527
+ int fp32_man = (bits >> 20) & 0x7;
528
+ int ue4m3_exp = fp32_exp + 7;
529
+ if (ue4m3_exp <= 0) {
530
+ // subnormal: value = man * 2^-9, man = round(x * 2^9)
531
+ int man = (int) (x * 512.0f + 0.5f);
532
+ if (man > 7) {
533
+ man = 7;
534
+ }
535
+ if (man < 1) {
536
+ return 0;
537
+ }
538
+ return (uint8_t) man;
539
+ }
540
+ if (ue4m3_exp >= 15) {
541
+ return 0x7E;
542
+ }
543
+ int round_bit = (bits >> 19) & 1;
544
+ int ue4m3_man = fp32_man + round_bit;
545
+ if (ue4m3_man > 7) {
546
+ ue4m3_man = 0;
547
+ ue4m3_exp++;
548
+ if (ue4m3_exp >= 15) {
549
+ return 0x7E;
550
+ }
551
+ }
552
+ return (uint8_t) ((ue4m3_exp << 3) | ue4m3_man);
553
+ }
554
+
555
+ /**
556
+ * Converts brain16 to float32.
557
+ *
558
+ * The bfloat16 floating point format has the following structure:
559
+ *
560
+ * ┌sign
561
+ * │
562
+ * │ ┌exponent
563
+ * │ │
564
+ * │ │ ┌mantissa
565
+ * │ │ │
566
+ * │┌──┴───┐┌─┴───┐
567
+ * 0b0000000000000000 brain16
568
+ *
569
+ * Since bf16 has the same number of exponent bits as a 32bit float,
570
+ * encoding and decoding numbers becomes relatively straightforward.
571
+ *
572
+ * ┌sign
573
+ * │
574
+ * │ ┌exponent
575
+ * │ │
576
+ * │ │ ┌mantissa
577
+ * │ │ │
578
+ * │┌──┴───┐┌─┴───────────────────┐
579
+ * 0b00000000000000000000000000000000 IEEE binary32
580
+ *
581
+ * For comparison, the standard fp16 format has fewer exponent bits.
582
+ *
583
+ * ┌sign
584
+ * │
585
+ * │ ┌exponent
586
+ * │ │
587
+ * │ │ ┌mantissa
588
+ * │ │ │
589
+ * │┌─┴─┐┌─┴──────┐
590
+ * 0b0000000000000000 IEEE binary16
591
+ *
592
+ * @see IEEE 754-2008
593
+ */
594
+ static inline float ggml_compute_bf16_to_fp32(ggml_bf16_t h) {
595
+ union {
596
+ float f;
597
+ uint32_t i;
598
+ } u;
599
+ u.i = (uint32_t)h.bits << 16;
600
+ return u.f;
601
+ }
602
+
603
+ /**
604
+ * Converts float32 to brain16.
605
+ *
606
+ * This is binary identical with Google Brain float conversion.
607
+ * Floats shall round to nearest even, and NANs shall be quiet.
608
+ * Subnormals aren't flushed to zero, except perhaps when used.
609
+ * This code should vectorize nicely if using modern compilers.
610
+ */
611
+ static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
612
+ ggml_bf16_t h;
613
+ union {
614
+ float f;
615
+ uint32_t i;
616
+ } u;
617
+ u.f = s;
618
+ if ((u.i & 0x7fffffff) > 0x7f800000) { /* nan */
619
+ h.bits = (u.i >> 16) | 64; /* force to quiet */
620
+ return h;
621
+ }
622
+ h.bits = (u.i + (0x7fff + ((u.i >> 16) & 1))) >> 16;
623
+ return h;
624
+ }
625
+
626
+ #define GGML_FP32_TO_BF16(x) ggml_compute_fp32_to_bf16(x)
627
+ #define GGML_BF16_TO_FP32(x) ggml_compute_bf16_to_fp32(x)
628
+
629
+ static inline int32_t ggml_node_get_use_count(const struct ggml_cgraph * cgraph, int node_idx) {
630
+ const struct ggml_tensor * node = cgraph->nodes[node_idx];
631
+
632
+ size_t hash_pos = ggml_hash_find(&cgraph->visited_hash_set, node);
633
+ if (!ggml_bitset_get(cgraph->visited_hash_set.used, hash_pos)) {
634
+ return 0;
635
+ }
636
+ return cgraph->use_counts[hash_pos];
637
+ }
638
+
639
+ // return true if the node's results are only used by N other nodes
640
+ // and can be fused into their calculations.
641
+ static inline bool ggml_node_has_n_uses(const struct ggml_cgraph * cgraph, int node_idx, int32_t n_uses) {
642
+ const struct ggml_tensor * node = cgraph->nodes[node_idx];
643
+
644
+ // check the use count against how many we're replacing
645
+ if (ggml_node_get_use_count(cgraph, node_idx) != n_uses) {
646
+ return false;
647
+ }
648
+
649
+ // if node is a view, some other node might be using the intermediate result
650
+ // via the view source.
651
+ if (node->view_src) {
652
+ return false;
653
+ }
654
+
655
+ // If the user requested output for the node, can't fuse
656
+ if (node->flags & GGML_TENSOR_FLAG_OUTPUT) {
657
+ return false;
658
+ }
659
+
660
+ return true;
661
+ }
662
+
663
+ // Returns true if nodes with indices { node_idxs } are the sequence of ggml_ops in ops[]
664
+ // and are fusable. Nodes are considered fusable according to this function if:
665
+ // - all nodes except the last have only one use and are not views/outputs (see ggml_node_has_N_uses).
666
+ // - all nodes except the last are a src of the following node.
667
+ // - all nodes are the same shape.
668
+ // TODO: Consider allowing GGML_OP_NONE nodes in between
669
+ static inline bool ggml_can_fuse_ext(const struct ggml_cgraph * cgraph, const int * node_idxs, const enum ggml_op * ops, int num_ops) {
670
+ for (int i = 0; i < num_ops; ++i) {
671
+ if (node_idxs[i] >= cgraph->n_nodes) {
672
+ return false;
673
+ }
674
+
675
+ struct ggml_tensor * node = cgraph->nodes[node_idxs[i]];
676
+ if (node->op != ops[i]) {
677
+ return false;
678
+ }
679
+ if ((node->flags & GGML_TENSOR_FLAG_COMPUTE) == 0) {
680
+ return false;
681
+ }
682
+ if (i < num_ops - 1 && !ggml_node_has_n_uses(cgraph, node_idxs[i], 1)) {
683
+ return false;
684
+ }
685
+ if (i > 0) {
686
+ struct ggml_tensor * prev = cgraph->nodes[node_idxs[i - 1]];
687
+ if (node->src[0] != prev && node->src[1] != prev) {
688
+ return false;
689
+ }
690
+ if (!ggml_are_same_shape(node, prev)) {
691
+ return false;
692
+ }
693
+ }
694
+ }
695
+ return true;
696
+ }
697
+
698
+ // same as above, for sequential indices starting at node_idx
699
+ static inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, const enum ggml_op * ops, int num_ops) {
700
+ assert(num_ops < 32);
701
+
702
+ if (node_idx + num_ops > cgraph->n_nodes) {
703
+ return false;
704
+ }
705
+
706
+ int idxs[32];
707
+ for (int i = 0; i < num_ops; ++i) {
708
+ idxs[i] = node_idx + i;
709
+ }
710
+
711
+ return ggml_can_fuse_ext(cgraph, idxs, ops, num_ops);
712
+ }
713
+
714
+ GGML_API bool ggml_can_fuse_subgraph_ext(const struct ggml_cgraph * cgraph,
715
+ const int * node_idxs,
716
+ int count,
717
+ const enum ggml_op * ops,
718
+ const int * outputs,
719
+ int num_outputs);
720
+
721
+ // Returns true if the subgraph formed by {node_idxs} can be fused
722
+ // checks whethers all nodes which are not part of outputs can be elided
723
+ // by checking if their num_uses are confined to the subgraph
724
+ static inline bool ggml_can_fuse_subgraph(const struct ggml_cgraph * cgraph,
725
+ int node_idx,
726
+ int count,
727
+ const enum ggml_op * ops,
728
+ const int * outputs,
729
+ int num_outputs) {
730
+ GGML_ASSERT(count < 32);
731
+ if (node_idx + count > cgraph->n_nodes) {
732
+ return false;
733
+ }
734
+
735
+ int idxs[32];
736
+
737
+ for (int i = 0; i < count; ++i) {
738
+ idxs[i] = node_idx + i;
739
+ }
740
+
741
+ return ggml_can_fuse_subgraph_ext(cgraph, idxs, count, ops, outputs, num_outputs);
742
+ }
743
+
744
+ #ifdef __cplusplus
745
+ }
746
+ #endif
747
+
748
+ #ifdef __cplusplus
749
+ #include <array>
750
+ #include <initializer_list>
751
+ #include <vector>
752
+
753
+ // nicer C++ syntax for ggml_can_fuse
754
+ inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, std::initializer_list<enum ggml_op> ops) {
755
+ return ggml_can_fuse(cgraph, node_idx, ops.begin(), (int)ops.size());
756
+ }
757
+
758
+ inline bool ggml_can_fuse_subgraph(const struct ggml_cgraph * cgraph,
759
+ int start_idx,
760
+ std::initializer_list<enum ggml_op> ops,
761
+ std::initializer_list<int> outputs = {}) {
762
+ return ggml_can_fuse_subgraph(cgraph, start_idx, ops.size(), ops.begin(), outputs.begin(), outputs.size());
763
+ }
764
+
765
+ // Return true if the edges in the graph match expectations.
766
+ inline bool ggml_check_edges(const struct ggml_cgraph * cgraph,
767
+ int start_idx,
768
+ std::initializer_list<std::array<int, 3>> edges) {
769
+ for (const auto & edge : edges) {
770
+ int dst_node = edge[0];
771
+ int src_idx = edge[1];
772
+ int src_node = edge[2];
773
+ if (cgraph->nodes[start_idx + dst_node]->src[src_idx] != cgraph->nodes[start_idx + src_node]) {
774
+ return false;
775
+ }
776
+ }
777
+ return true;
778
+ }
779
+
780
+ // expose GGUF internals for test code
781
+ GGML_API size_t gguf_type_size(enum gguf_type type);
782
+ GGML_API void gguf_write_to_buf(const struct gguf_context * ctx, std::vector<int8_t> & buf, bool only_meta);
783
+ #endif // __cplusplus