@novastera-oss/llamarn 0.2.9 → 0.3.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 (247) hide show
  1. package/android/src/main/jniLibs/arm64-v8a/libggml-base.so +0 -0
  2. package/android/src/main/jniLibs/arm64-v8a/libggml-cpu.so +0 -0
  3. package/android/src/main/jniLibs/arm64-v8a/libggml.so +0 -0
  4. package/android/src/main/jniLibs/arm64-v8a/libllama.so +0 -0
  5. package/android/src/main/jniLibs/armeabi-v7a/libggml-base.so +0 -0
  6. package/android/src/main/jniLibs/armeabi-v7a/libggml-cpu.so +0 -0
  7. package/android/src/main/jniLibs/armeabi-v7a/libggml.so +0 -0
  8. package/android/src/main/jniLibs/armeabi-v7a/libllama.so +0 -0
  9. package/android/src/main/jniLibs/x86/libggml-base.so +0 -0
  10. package/android/src/main/jniLibs/x86/libggml-cpu.so +0 -0
  11. package/android/src/main/jniLibs/x86/libggml.so +0 -0
  12. package/android/src/main/jniLibs/x86/libllama.so +0 -0
  13. package/android/src/main/jniLibs/x86_64/libggml-base.so +0 -0
  14. package/android/src/main/jniLibs/x86_64/libggml-cpu.so +0 -0
  15. package/android/src/main/jniLibs/x86_64/libggml.so +0 -0
  16. package/android/src/main/jniLibs/x86_64/libllama.so +0 -0
  17. package/cpp/build-info.cpp +2 -2
  18. package/cpp/llama.cpp/CMakeLists.txt +0 -1
  19. package/cpp/llama.cpp/README.md +4 -5
  20. package/cpp/llama.cpp/build-xcframework.sh +1 -1
  21. package/cpp/llama.cpp/common/CMakeLists.txt +4 -5
  22. package/cpp/llama.cpp/common/arg.cpp +17 -0
  23. package/cpp/llama.cpp/common/chat.cpp +37 -20
  24. package/cpp/llama.cpp/common/chat.h +2 -0
  25. package/cpp/llama.cpp/common/common.h +4 -0
  26. package/cpp/llama.cpp/convert_hf_to_gguf.py +745 -6
  27. package/cpp/llama.cpp/convert_hf_to_gguf_update.py +9 -0
  28. package/cpp/llama.cpp/ggml/CMakeLists.txt +7 -2
  29. package/cpp/llama.cpp/ggml/include/ggml-backend.h +1 -1
  30. package/cpp/llama.cpp/ggml/include/ggml.h +173 -10
  31. package/cpp/llama.cpp/ggml/src/CMakeLists.txt +0 -1
  32. package/cpp/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -8
  33. package/cpp/llama.cpp/ggml/src/ggml-backend.cpp +36 -18
  34. package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +68 -5
  35. package/cpp/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +16 -2
  36. package/cpp/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +6 -1
  37. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +28 -1
  38. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp +1203 -163
  39. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.h +6 -0
  40. package/cpp/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +1 -1
  41. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.cpp +33 -9
  42. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.h +142 -9
  43. package/cpp/llama.cpp/ggml/src/ggml-cuda/common.cuh +17 -0
  44. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cu +22 -0
  45. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cuh +5 -0
  46. package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cu +2 -14
  47. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-common.cuh +4 -1
  48. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh +8 -4
  49. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cu +6 -4
  50. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cu +14 -12
  51. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f16.cuh +5 -3
  52. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f32.cuh +15 -10
  53. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cu +8 -6
  54. package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cu +8 -0
  55. package/cpp/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu +185 -79
  56. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cuh +2 -8
  57. package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cu +21 -27
  58. package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cu +8 -6
  59. package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cu +119 -58
  60. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cu +10 -2
  61. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cu +192 -52
  62. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cu +97 -0
  63. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cuh +11 -0
  64. package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cu +92 -6
  65. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +14 -5
  66. package/cpp/llama.cpp/ggml/src/ggml-impl.h +64 -0
  67. package/cpp/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +4 -2
  68. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +35 -9
  69. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.m +167 -39
  70. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.metal +254 -57
  71. package/cpp/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +3 -0
  72. package/cpp/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +505 -40
  73. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gelu.cl +27 -0
  74. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/glu.cl +337 -0
  75. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mat_f16_f32.cl +130 -0
  76. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/scale.cl +3 -2
  77. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/set_rows.cl +95 -0
  78. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +24 -11
  79. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +24 -11
  80. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f16.cl +24 -11
  81. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f32.cl +24 -11
  82. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/upscale.cl +2 -3
  83. package/cpp/llama.cpp/ggml/src/ggml-quants.c +6 -6
  84. package/cpp/llama.cpp/ggml/src/ggml-sycl/backend.hpp +1 -0
  85. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +693 -1034
  86. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +18 -9
  87. package/cpp/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +60 -9
  88. package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.cpp +15 -18
  89. package/cpp/llama.cpp/ggml/src/ggml-sycl/set_rows.cpp +131 -0
  90. package/cpp/llama.cpp/ggml/src/ggml-sycl/set_rows.hpp +8 -0
  91. package/cpp/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +711 -292
  92. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +58 -7
  93. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +28 -23
  94. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.comp +14 -9
  95. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +38 -32
  96. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +32 -27
  97. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +44 -12
  98. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu.comp +13 -0
  99. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu_erf.comp +27 -0
  100. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +11 -0
  101. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +39 -0
  102. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.comp +15 -0
  103. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.comp +29 -0
  104. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +128 -72
  105. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +38 -9
  106. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/reglu.comp +9 -0
  107. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +12 -3
  108. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +46 -0
  109. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +7 -9
  110. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +7 -9
  111. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +7 -9
  112. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +1 -1
  113. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +20 -4
  114. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/swiglu.comp +9 -0
  115. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +69 -5
  116. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +23 -3
  117. package/cpp/llama.cpp/ggml/src/ggml.c +382 -61
  118. package/cpp/llama.cpp/ggml/src/gguf.cpp +8 -1
  119. package/cpp/llama.cpp/gguf-py/gguf/constants.py +209 -0
  120. package/cpp/llama.cpp/gguf-py/gguf/gguf_writer.py +8 -2
  121. package/cpp/llama.cpp/gguf-py/gguf/tensor_mapping.py +73 -21
  122. package/cpp/llama.cpp/gguf-py/gguf/vocab.py +12 -3
  123. package/cpp/llama.cpp/include/llama.h +0 -40
  124. package/cpp/llama.cpp/src/llama-arch.cpp +210 -3
  125. package/cpp/llama.cpp/src/llama-arch.h +18 -1
  126. package/cpp/llama.cpp/src/llama-batch.cpp +27 -1
  127. package/cpp/llama.cpp/src/llama-batch.h +8 -1
  128. package/cpp/llama.cpp/src/llama-chat.cpp +15 -0
  129. package/cpp/llama.cpp/src/llama-chat.h +1 -0
  130. package/cpp/llama.cpp/src/llama-graph.cpp +119 -184
  131. package/cpp/llama.cpp/src/llama-graph.h +47 -60
  132. package/cpp/llama.cpp/src/llama-hparams.cpp +7 -1
  133. package/cpp/llama.cpp/src/llama-hparams.h +3 -0
  134. package/cpp/llama.cpp/src/llama-kv-cache-unified-iswa.cpp +28 -18
  135. package/cpp/llama.cpp/src/llama-kv-cache-unified-iswa.h +4 -2
  136. package/cpp/llama.cpp/src/llama-kv-cache-unified.cpp +214 -65
  137. package/cpp/llama.cpp/src/llama-kv-cache-unified.h +62 -24
  138. package/cpp/llama.cpp/src/llama-kv-cells.h +62 -10
  139. package/cpp/llama.cpp/src/llama-memory-hybrid.cpp +9 -4
  140. package/cpp/llama.cpp/src/llama-memory-hybrid.h +3 -1
  141. package/cpp/llama.cpp/src/llama-memory-recurrent.cpp +20 -10
  142. package/cpp/llama.cpp/src/llama-memory.cpp +17 -0
  143. package/cpp/llama.cpp/src/llama-memory.h +3 -0
  144. package/cpp/llama.cpp/src/llama-model.cpp +2530 -685
  145. package/cpp/llama.cpp/src/llama-model.h +18 -0
  146. package/cpp/llama.cpp/src/llama-quant.cpp +1 -0
  147. package/cpp/llama.cpp/src/llama-vocab.cpp +13 -2
  148. package/cpp/llama.cpp/src/llama-vocab.h +41 -0
  149. package/ios/include/chat.h +2 -0
  150. package/ios/include/common.h +4 -0
  151. package/ios/include/llama.h +0 -40
  152. package/ios/libs/llama.xcframework/Info.plist +19 -19
  153. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  154. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5055 -4886
  155. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-backend.h +1 -1
  156. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml.h +173 -10
  157. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/llama.h +0 -40
  158. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/llama +0 -0
  159. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  160. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4861
  161. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3889 -3764
  162. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
  163. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +173 -10
  164. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/llama.h +0 -40
  165. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/llama +0 -0
  166. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  167. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4861
  168. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3891 -3766
  169. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-backend.h +1 -1
  170. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml.h +173 -10
  171. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/llama.h +0 -40
  172. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-backend.h +1 -1
  173. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml.h +173 -10
  174. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/llama.h +0 -40
  175. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/llama +0 -0
  176. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-backend.h +1 -1
  177. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml.h +173 -10
  178. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/llama.h +0 -40
  179. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/llama +0 -0
  180. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/llama +0 -0
  181. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  182. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5059 -4890
  183. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-backend.h +1 -1
  184. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml.h +173 -10
  185. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/llama.h +0 -40
  186. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/llama +0 -0
  187. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  188. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4861
  189. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3889 -3764
  190. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
  191. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +173 -10
  192. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/llama.h +0 -40
  193. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/llama +0 -0
  194. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  195. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5091 -4922
  196. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-backend.h +1 -1
  197. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml.h +173 -10
  198. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/llama.h +0 -40
  199. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/llama +0 -0
  200. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  201. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5066 -4897
  202. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3919 -3794
  203. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
  204. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +173 -10
  205. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/llama.h +0 -40
  206. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/llama +0 -0
  207. package/package.json +1 -1
  208. package/cpp/llama.cpp/ggml/include/ggml-kompute.h +0 -50
  209. package/cpp/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  210. package/cpp/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  211. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/common.comp +0 -112
  212. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +0 -58
  213. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +0 -25
  214. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +0 -52
  215. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +0 -52
  216. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +0 -52
  217. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +0 -52
  218. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +0 -30
  219. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +0 -22
  220. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +0 -17
  221. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +0 -31
  222. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +0 -31
  223. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +0 -38
  224. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +0 -39
  225. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +0 -44
  226. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +0 -52
  227. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +0 -69
  228. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +0 -51
  229. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +0 -33
  230. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +0 -35
  231. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +0 -140
  232. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +0 -106
  233. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +0 -73
  234. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +0 -52
  235. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +0 -28
  236. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +0 -84
  237. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +0 -21
  238. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +0 -53
  239. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +0 -52
  240. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +0 -52
  241. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +0 -52
  242. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +0 -52
  243. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +0 -19
  244. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +0 -23
  245. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +0 -22
  246. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +0 -72
  247. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +0 -71
@@ -196,6 +196,103 @@ void ggml_cuda_op_log(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
196
196
  ggml_cuda_op_unary<op_log>(ctx, dst);
197
197
  }
198
198
 
199
+ /* gated ops */
200
+
201
+ template <float (*op)(float), typename T>
202
+ static __global__ void unary_gated_op_kernel(const T * x, const T * g, T * dst, const int64_t k, const int64_t n, const int64_t o0, const int64_t o1) {
203
+ const int64_t i = int64_t(blockDim.x)*blockIdx.x + threadIdx.x;
204
+
205
+ if (i >= k) {
206
+ return;
207
+ }
208
+
209
+ // perform base op and multiply with gate (either offset in same tensor or a separate one)
210
+ const int64_t j0 = (i / n) * o0 + (i % n);
211
+ const int64_t j1 = o0 == o1 ? j0 : (i / n) * o1 + (i % n);
212
+
213
+ dst[i] = (T)(op((float)x[j0]) * (float)g[j1]);
214
+ }
215
+
216
+ template <float (*op)(float), typename T>
217
+ static void unary_gated_cuda(const T * x, const T * g, T * dst, const int64_t k, const int64_t n, const int64_t o0, const int64_t o1, cudaStream_t stream) {
218
+ const int64_t num_blocks = (k + CUDA_GLU_BLOCK_SIZE - 1) / CUDA_GLU_BLOCK_SIZE;
219
+ unary_gated_op_kernel<op><<<num_blocks, CUDA_GLU_BLOCK_SIZE, 0, stream>>>(x, g, dst, k, n, o0, o1);
220
+ }
221
+
222
+ template <float (*op)(float)>
223
+ void ggml_cuda_op_unary_gated(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
224
+ const ggml_tensor * src0 = dst->src[0];
225
+ const ggml_tensor * src1 = dst->src[1];
226
+ void * src0_d = src0->data;
227
+ void * src1_d = src1 ? src1->data : src0->data;
228
+ const int64_t src0_o = src0->nb[1];
229
+ const int64_t src1_o = src1 ? src1->nb[1] : src0->nb[1];
230
+ void * dst_d = dst->data;
231
+ const int64_t nc = src1 ? src0->ne[0] : src0->ne[0] / 2;
232
+ cudaStream_t stream = ctx.stream();
233
+
234
+ GGML_ASSERT(ggml_is_contiguous_1(src0));
235
+ GGML_ASSERT(src0->nb[0] == ggml_element_size(src0));
236
+ GGML_ASSERT(ggml_is_contiguous(dst));
237
+
238
+ GGML_ASSERT(src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16);
239
+ GGML_ASSERT( dst->type == GGML_TYPE_F32 || dst->type == GGML_TYPE_F16);
240
+ GGML_ASSERT(src0->type == dst->type);
241
+ GGML_ASSERT(dst->ne[0] == nc);
242
+ GGML_ASSERT(ggml_nrows(dst) == ggml_nrows(src0));
243
+
244
+ if (src1) {
245
+ GGML_ASSERT(ggml_is_contiguous_1(src1));
246
+ GGML_ASSERT(src1->nb[0] == ggml_element_size(src1));
247
+ GGML_ASSERT(src1->ne[0] == nc);
248
+ GGML_ASSERT(src0->type == src1->type);
249
+ }
250
+
251
+ const int32_t swapped = ((const int32_t *) dst->op_params)[1];
252
+
253
+ if (src0->type == GGML_TYPE_F16) {
254
+ half * src0_p = (half *) src0_d;
255
+ half * src1_p = (half *) src1_d;
256
+
257
+ if (!src1) {
258
+ src0_p += swapped ? nc : 0;
259
+ src1_p += swapped ? 0 : nc;
260
+ }
261
+
262
+ unary_gated_cuda<op>(src0_p, src1_p, (half *)dst_d, ggml_nelements(dst), nc, src0_o / sizeof(half), src1_o / sizeof(half), stream);
263
+ } else {
264
+ float * src0_p = (float *) src0_d;
265
+ float * src1_p = (float *) src1_d;
266
+
267
+ if (!src1) {
268
+ src0_p += swapped ? nc : 0;
269
+ src1_p += swapped ? 0 : nc;
270
+ }
271
+
272
+ unary_gated_cuda<op>(src0_p, src1_p, (float *)dst_d, ggml_nelements(dst), nc, src0_o / sizeof(float), src1_o / sizeof(float), stream);
273
+ }
274
+ }
275
+
276
+ void ggml_cuda_op_reglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
277
+ ggml_cuda_op_unary_gated<op_relu>(ctx, dst);
278
+ }
279
+
280
+ void ggml_cuda_op_geglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
281
+ ggml_cuda_op_unary_gated<op_gelu>(ctx, dst);
282
+ }
283
+
284
+ void ggml_cuda_op_swiglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
285
+ ggml_cuda_op_unary_gated<op_silu>(ctx, dst);
286
+ }
287
+
288
+ void ggml_cuda_op_geglu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
289
+ ggml_cuda_op_unary_gated<op_gelu_erf>(ctx, dst);
290
+ }
291
+
292
+ void ggml_cuda_op_geglu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
293
+ ggml_cuda_op_unary_gated<op_gelu_quick>(ctx, dst);
294
+ }
295
+
199
296
  /* silu_back */
200
297
 
201
298
  static __device__ __forceinline__ float op_silu_back(float grad, float x) {
@@ -15,6 +15,7 @@
15
15
  #define CUDA_SQRT_BLOCK_SIZE 256
16
16
  #define CUDA_SIN_BLOCK_SIZE 256
17
17
  #define CUDA_COS_BLOCK_SIZE 256
18
+ #define CUDA_GLU_BLOCK_SIZE 256
18
19
 
19
20
  void ggml_cuda_op_abs(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
20
21
 
@@ -57,3 +58,13 @@ void ggml_cuda_op_sin(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
57
58
  void ggml_cuda_op_cos(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
58
59
 
59
60
  void ggml_cuda_op_log(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
61
+
62
+ void ggml_cuda_op_reglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
63
+
64
+ void ggml_cuda_op_geglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
65
+
66
+ void ggml_cuda_op_swiglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
67
+
68
+ void ggml_cuda_op_geglu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
69
+
70
+ void ggml_cuda_op_geglu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
@@ -22,17 +22,88 @@ static __global__ void upscale_f32(const float * x, float * dst,
22
22
  dst[index] = *( (const float *)((const char *)x + i03 * nb03 + i02 * nb02 + i01 * nb01 + i00 * nb00) );
23
23
  }
24
24
 
25
+ static __global__ void upscale_f32_bilinear(const float * x, float * dst,
26
+ const int nb00, const int nb01, const int nb02, const int nb03,
27
+ const int ne00_src, const int ne01_src,
28
+ const int ne10_dst, const int ne11_dst, const int ne12_dst, const int ne13_dst,
29
+ const float sf0, const float sf1, const float sf2, const float sf3,
30
+ const float pixel_offset) {
31
+ const int64_t index = threadIdx.x + blockIdx.x * blockDim.x;
32
+ const int64_t dst_total_elements = ne10_dst * ne11_dst * ne12_dst * ne13_dst;
33
+
34
+ if (index >= dst_total_elements) {
35
+ return;
36
+ }
37
+
38
+ const int i10_dst = index % ne10_dst;
39
+ const int i11_dst = (index / ne10_dst) % ne11_dst;
40
+ const int i12_dst = (index / (ne10_dst * ne11_dst)) % ne12_dst;
41
+ const int i13_dst = index / (ne10_dst * ne11_dst * ne12_dst);
42
+
43
+ const int i02_src = (int)(i12_dst / sf2);
44
+ const int i03_src = (int)(i13_dst / sf3);
45
+
46
+ const float y_src_f = ((float)i11_dst + pixel_offset) / sf1 - pixel_offset;
47
+ int y0_src = (int)floorf(y_src_f);
48
+ int y1_src = y0_src + 1;
49
+
50
+ y0_src = max(0, min(y0_src, ne01_src - 1));
51
+ y1_src = max(0, min(y1_src, ne01_src - 1));
52
+
53
+ float dy = y_src_f - (float)y0_src;
54
+ dy = max(0.0f, min(dy, 1.0f));
55
+
56
+ float x_src_f = ((float)i10_dst + pixel_offset) / sf0 - pixel_offset;
57
+ int x0_src = (int)floorf(x_src_f);
58
+ int x1_src = x0_src + 1;
59
+
60
+ x0_src = max(0, min(x0_src, ne00_src - 1));
61
+ x1_src = max(0, min(x1_src, ne00_src - 1));
62
+
63
+ float dx = x_src_f - (float)x0_src;
64
+ dx = max(0.0f, min(dx, 1.0f));
65
+
66
+ const float * p_a = (const float *)((const char *)x + (int64_t)x0_src * nb00 + (int64_t)y0_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
67
+ const float * p_b = (const float *)((const char *)x + (int64_t)x1_src * nb00 + (int64_t)y0_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
68
+ const float * p_c = (const float *)((const char *)x + (int64_t)x0_src * nb00 + (int64_t)y1_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
69
+ const float * p_d = (const float *)((const char *)x + (int64_t)x1_src * nb00 + (int64_t)y1_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
70
+
71
+ const float val_a = *p_a;
72
+ const float val_b = *p_b;
73
+ const float val_c = *p_c;
74
+ const float val_d = *p_d;
75
+
76
+ float result = val_a * (1.0f - dx) * (1.0f - dy) +
77
+ val_b * dx * (1.0f - dy) +
78
+ val_c * (1.0f - dx) * dy +
79
+ val_d * dx * dy;
80
+
81
+ dst[index] = result;
82
+ }
83
+
25
84
  static void upscale_f32_cuda(const float * x, float * dst,
26
85
  const int nb00, const int nb01, const int nb02, const int nb03,
27
86
  const int ne10, const int ne11, const int ne12, const int ne13,
28
87
  const float sf0, const float sf1, const float sf2, const float sf3,
29
88
  cudaStream_t stream) {
30
- int dst_size = ne10 * ne11 * ne12 * ne13;
31
- int num_blocks = (dst_size + CUDA_UPSCALE_BLOCK_SIZE - 1) / CUDA_UPSCALE_BLOCK_SIZE;
89
+ const int64_t dst_size = ne10 * ne11 * ne12 * ne13;
90
+ const int64_t num_blocks = (dst_size + CUDA_UPSCALE_BLOCK_SIZE - 1) / CUDA_UPSCALE_BLOCK_SIZE;
32
91
 
33
92
  upscale_f32<<<num_blocks, CUDA_UPSCALE_BLOCK_SIZE,0,stream>>>(x, dst, nb00, nb01, nb02, nb03, ne10, ne11, ne12, ne13, sf0, sf1, sf2, sf3);
34
93
  }
35
94
 
95
+ static void upscale_f32_bilinear_cuda(const float * x, float * dst,
96
+ const int nb00, const int nb01, const int nb02, const int nb03,
97
+ const int ne00_src, const int ne01_src,
98
+ const int ne10_dst, const int ne11_dst, const int ne12_dst, const int ne13_dst,
99
+ const float sf0, const float sf1, const float sf2, const float sf3,
100
+ const float pixel_offset, cudaStream_t stream) {
101
+ const int64_t dst_size = ne10_dst * ne11_dst * ne12_dst * ne13_dst;
102
+ const int64_t num_blocks = (dst_size + CUDA_UPSCALE_BLOCK_SIZE - 1) / CUDA_UPSCALE_BLOCK_SIZE;
103
+
104
+ upscale_f32_bilinear<<<num_blocks, CUDA_UPSCALE_BLOCK_SIZE,0,stream>>>(x, dst, nb00, nb01, nb02, nb03, ne00_src, ne01_src, ne10_dst, ne11_dst, ne12_dst, ne13_dst, sf0, sf1, sf2, sf3, pixel_offset);
105
+ }
106
+
36
107
  void ggml_cuda_op_upscale(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
37
108
  const ggml_tensor * src0 = dst->src[0];
38
109
  const float * src0_d = (const float *)src0->data;
@@ -42,10 +113,25 @@ void ggml_cuda_op_upscale(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
42
113
  GGML_ASSERT(src0->type == GGML_TYPE_F32);
43
114
  GGML_ASSERT( dst->type == GGML_TYPE_F32);
44
115
 
45
- const float sf0 = (float)dst->ne[0]/src0->ne[0];
46
- const float sf1 = (float)dst->ne[1]/src0->ne[1];
47
- const float sf2 = (float)dst->ne[2]/src0->ne[2];
116
+ const int mode_flags = dst->op_params[0];
117
+ const ggml_scale_mode mode = (ggml_scale_mode)(mode_flags & 0xFF);
118
+
119
+ float sf0 = (float)dst->ne[0]/src0->ne[0];
120
+ float sf1 = (float)dst->ne[1]/src0->ne[1];
121
+ float sf2 = (float)dst->ne[2]/src0->ne[2];
48
122
  const float sf3 = (float)dst->ne[3]/src0->ne[3];
49
123
 
50
- upscale_f32_cuda(src0_d, dst_d, src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], dst->ne[0], dst->ne[1], dst->ne[2], dst->ne[3], sf0, sf1, sf2, sf3, stream);
124
+ if (mode == GGML_SCALE_MODE_NEAREST) {
125
+ upscale_f32_cuda(src0_d, dst_d, src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], dst->ne[0], dst->ne[1], dst->ne[2], dst->ne[3], sf0, sf1, sf2, sf3, stream);
126
+ } else if (mode == GGML_SCALE_MODE_BILINEAR) {
127
+ float pixel_offset = 0.5f;
128
+ if (mode_flags & GGML_SCALE_FLAG_ALIGN_CORNERS) {
129
+ sf0 = (float)(dst->ne[0] - 1) / (src0->ne[0] - 1);
130
+ sf1 = (float)(dst->ne[1] - 1) / (src0->ne[1] - 1);
131
+ pixel_offset = 0.0f;
132
+ }
133
+ upscale_f32_bilinear_cuda(src0_d, dst_d, src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
134
+ src0->ne[0], src0->ne[1], dst->ne[0], dst->ne[1], dst->ne[2], dst->ne[3],
135
+ sf0, sf1, sf2, sf3, pixel_offset, stream);
136
+ }
51
137
  }
@@ -10,9 +10,6 @@
10
10
  #include "rocblas/rocblas.h"
11
11
  #endif // __HIP_PLATFORM_AMD__
12
12
 
13
- #define CUBLAS_COMPUTE_16F HIPBLAS_R_16F
14
- #define CUBLAS_COMPUTE_32F HIPBLAS_R_32F
15
- #define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_R_32F
16
13
  #define CUBLAS_GEMM_DEFAULT HIPBLAS_GEMM_DEFAULT
17
14
  #define CUBLAS_GEMM_DEFAULT_TENSOR_OP HIPBLAS_GEMM_DEFAULT
18
15
  #define CUBLAS_OP_N HIPBLAS_OP_N
@@ -30,7 +27,6 @@
30
27
  #define CU_CHECK(fn) {hipError_t err = fn; if(err != hipSuccess) { GGML_ABORT("HipVMM Failure: %s\n", hipGetErrorString(err)); }}
31
28
  #define __shfl_sync(mask, var, laneMask, width) __shfl(var, laneMask, width)
32
29
  #define __shfl_xor_sync(mask, var, laneMask, width) __shfl_xor(var, laneMask, width)
33
- #define cublasComputeType_t hipblasDatatype_t //deprecated, new hipblasComputeType_t not in 5.6
34
30
  #define cublasCreate hipblasCreate
35
31
  #define cublasDestroy hipblasDestroy
36
32
  #define cublasGemmEx hipblasGemmEx
@@ -42,7 +38,6 @@
42
38
  #define cublasSgemm hipblasSgemm
43
39
  #define cublasStatus_t hipblasStatus_t
44
40
  #define cublasOperation_t hipblasOperation_t
45
- #define cudaDataType_t hipblasDatatype_t //deprecated, new hipblasDatatype not in 5.6
46
41
  #define cudaDeviceCanAccessPeer hipDeviceCanAccessPeer
47
42
  #define cudaDeviceDisablePeerAccess hipDeviceDisablePeerAccess
48
43
  #define cudaDeviceEnablePeerAccess hipDeviceEnablePeerAccess
@@ -144,6 +139,20 @@
144
139
  #define CUBLAS_STATUS_INTERNAL_ERROR HIPBLAS_STATUS_INTERNAL_ERROR
145
140
  #define CUBLAS_STATUS_NOT_SUPPORTED HIPBLAS_STATUS_NOT_SUPPORTED
146
141
 
142
+ #if defined(__HIP_PLATFORM_AMD__) && HIP_VERSION >= 70000000
143
+ #define CUBLAS_COMPUTE_16F HIPBLAS_COMPUTE_16F
144
+ #define CUBLAS_COMPUTE_32F HIPBLAS_COMPUTE_32F
145
+ #define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_COMPUTE_32F_FAST_16F
146
+ #define cublasComputeType_t hipblasComputeType_t
147
+ #define cudaDataType_t hipDataType
148
+ #else
149
+ #define CUBLAS_COMPUTE_16F HIPBLAS_R_16F
150
+ #define CUBLAS_COMPUTE_32F HIPBLAS_R_32F
151
+ #define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_R_32F
152
+ #define cublasComputeType_t hipblasDatatype_t
153
+ #define cudaDataType_t hipblasDatatype_t
154
+ #endif
155
+
147
156
  #define __CUDA_ARCH__ 1300
148
157
 
149
158
  #if defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__)
@@ -301,6 +301,7 @@ struct ggml_cgraph {
301
301
  struct ggml_tensor ** grads; // the outputs of these tensors are the gradients of the nodes
302
302
  struct ggml_tensor ** grad_accs; // accumulators for node gradients
303
303
  struct ggml_tensor ** leafs; // tensors with constant data
304
+ int32_t * use_counts;// number of uses of each tensor, indexed by hash table slot
304
305
 
305
306
  struct ggml_hash_set visited_hash_set;
306
307
 
@@ -467,13 +468,76 @@ static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
467
468
  #define GGML_FP32_TO_BF16(x) ggml_compute_fp32_to_bf16(x)
468
469
  #define GGML_BF16_TO_FP32(x) ggml_compute_bf16_to_fp32(x)
469
470
 
471
+ // return true if the node's results are only used by N other nodes
472
+ // and can be fused into their calculations.
473
+ static inline bool ggml_node_has_n_uses(const struct ggml_cgraph * cgraph, int node_idx, int32_t n_uses) {
474
+ const struct ggml_tensor * node = cgraph->nodes[node_idx];
475
+
476
+ // check the use count against how many we're replacing
477
+ size_t hash_pos = ggml_hash_find(&cgraph->visited_hash_set, node);
478
+ if (!ggml_bitset_get(cgraph->visited_hash_set.used, hash_pos) || cgraph->use_counts[hash_pos] != n_uses) {
479
+ return false;
480
+ }
481
+
482
+ // if node is a view, some other node might be using the intermediate result
483
+ // via the view source.
484
+ if (node->view_src) {
485
+ return false;
486
+ }
487
+
488
+ // If the user requested output for the node, can't fuse
489
+ if (node->flags & GGML_TENSOR_FLAG_OUTPUT) {
490
+ return false;
491
+ }
492
+
493
+ return true;
494
+ }
495
+
496
+ // Returns true if nodes [i, i+ops.size()) are the sequence of ggml_ops in ops[]
497
+ // and are fusable. Nodes are considered fusable according to this function if:
498
+ // - all nodes except the last have only one use and are not views/outputs (see ggml_node_has_N_uses).
499
+ // - all nodes except the last are a src of the following node.
500
+ // - all nodes are the same shape.
501
+ // TODO: Consider allowing GGML_OP_NONE nodes in between
502
+ static inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, const enum ggml_op * ops, int num_ops) {
503
+ if (node_idx + num_ops > cgraph->n_nodes) {
504
+ return false;
505
+ }
506
+
507
+ for (int i = 0; i < num_ops; ++i) {
508
+ struct ggml_tensor * node = cgraph->nodes[node_idx + i];
509
+ if (node->op != ops[i]) {
510
+ return false;
511
+ }
512
+ if (i < num_ops - 1 && !ggml_node_has_n_uses(cgraph, node_idx + i, 1)) {
513
+ return false;
514
+ }
515
+ if (i > 0) {
516
+ struct ggml_tensor * prev = cgraph->nodes[node_idx + i - 1];
517
+ if (node->src[0] != prev && node->src[1] != prev) {
518
+ return false;
519
+ }
520
+ if (!ggml_are_same_shape(node, prev)) {
521
+ return false;
522
+ }
523
+ }
524
+ }
525
+ return true;
526
+ }
527
+
470
528
  #ifdef __cplusplus
471
529
  }
472
530
  #endif
473
531
 
474
532
  #ifdef __cplusplus
533
+ #include <initializer_list>
475
534
  #include <vector>
476
535
 
536
+ // nicer C++ syntax for ggml_can_fuse
537
+ inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, std::initializer_list<enum ggml_op> ops) {
538
+ return ggml_can_fuse(cgraph, node_idx, ops.begin(), (int)ops.size());
539
+ }
540
+
477
541
  // expose GGUF internals for test code
478
542
  GGML_API size_t gguf_type_size(enum gguf_type type);
479
543
  GGML_API struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_params params);
@@ -71,7 +71,9 @@ else()
71
71
  # note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
72
72
  # note: unfortunately, we have to call it default.metallib instead of ggml.metallib
73
73
  # ref: https://github.com/ggerganov/whisper.cpp/issues/1720
74
- set(XC_FLAGS -fno-fast-math -fno-inline -g)
74
+ # note: adding -g causes segmentation fault during compile
75
+ #set(XC_FLAGS -fno-fast-math -fno-inline -g)
76
+ set(XC_FLAGS -fno-fast-math -fno-inline)
75
77
  else()
76
78
  set(XC_FLAGS -O3)
77
79
  endif()
@@ -90,7 +92,7 @@ else()
90
92
  add_custom_command(
91
93
  OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
92
94
  COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o - |
93
- xcrun -sdk macosx metallib - -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
95
+ xcrun -sdk macosx metallib - -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
94
96
  COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
95
97
  COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
96
98
  DEPENDS ggml-metal.metal ${METALLIB_COMMON}
@@ -229,7 +229,11 @@ typedef struct {
229
229
  uint64_t nb21;
230
230
  uint64_t nb22;
231
231
  uint64_t nb23;
232
+ int32_t ne32;
233
+ int32_t ne33;
232
234
  uint64_t nb31;
235
+ uint64_t nb32;
236
+ uint64_t nb33;
233
237
  int32_t ne1;
234
238
  int32_t ne2;
235
239
  float scale;
@@ -422,6 +426,17 @@ typedef struct {
422
426
  int32_t KHW; // KH * KW, pre-computed on CPU to save GPU resources
423
427
  } ggml_metal_kargs_im2col;
424
428
 
429
+ typedef struct{
430
+ int32_t ne00;
431
+ uint64_t nb01;
432
+ int32_t ne10;
433
+ uint64_t nb11;
434
+ int32_t ne0;
435
+ uint64_t nb1;
436
+ int32_t i00;
437
+ int32_t i10;
438
+ } ggml_metal_kargs_glu;
439
+
425
440
  typedef struct {
426
441
  int64_t ne00;
427
442
  int64_t ne01;
@@ -450,9 +465,21 @@ typedef struct {
450
465
  } ggml_metal_kargs_sum_rows;
451
466
 
452
467
  typedef struct {
453
- int64_t ne00;
454
- int64_t ne01;
455
- int64_t ne02;
468
+ int32_t ne00;
469
+ int32_t ne01;
470
+ int32_t ne02;
471
+ uint64_t nb01;
472
+ uint64_t nb02;
473
+ uint64_t nb03;
474
+ int32_t ne11;
475
+ int32_t ne12;
476
+ int32_t ne13;
477
+ uint64_t nb11;
478
+ uint64_t nb12;
479
+ uint64_t nb13;
480
+ uint64_t nb1;
481
+ uint64_t nb2;
482
+ uint64_t nb3;
456
483
  float scale;
457
484
  float max_bias;
458
485
  float m0;
@@ -488,26 +515,25 @@ typedef struct {
488
515
  typedef struct {
489
516
  int64_t d_state;
490
517
  int64_t d_inner;
518
+ int64_t n_head;
519
+ int64_t n_group;
491
520
  int64_t n_seq_tokens;
492
521
  int64_t n_seqs;
493
- uint64_t nb00;
494
522
  uint64_t nb01;
495
523
  uint64_t nb02;
496
- uint64_t nb10;
524
+ uint64_t nb03;
497
525
  uint64_t nb11;
498
526
  uint64_t nb12;
499
527
  uint64_t nb13;
500
- uint64_t nb20;
501
528
  uint64_t nb21;
502
529
  uint64_t nb22;
503
- uint64_t nb30;
504
530
  uint64_t nb31;
505
- uint64_t nb40;
506
531
  uint64_t nb41;
507
532
  uint64_t nb42;
508
- uint64_t nb50;
533
+ uint64_t nb43;
509
534
  uint64_t nb51;
510
535
  uint64_t nb52;
536
+ uint64_t nb53;
511
537
  } ggml_metal_kargs_ssm_scan;
512
538
 
513
539
  typedef struct {