@novastera-oss/llamarn 0.0.1-alpha.4

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 (989) hide show
  1. package/INTERFACE.md +389 -0
  2. package/LICENSE +201 -0
  3. package/README.md +235 -0
  4. package/RNLlamaCpp.podspec +69 -0
  5. package/android/CMakeLists.txt +107 -0
  6. package/android/build.gradle +111 -0
  7. package/android/generated/java/com/novastera/llamarn/NativeRNLlamaCppSpec.java +47 -0
  8. package/android/generated/jni/CMakeLists.txt +36 -0
  9. package/android/generated/jni/RNLlamaCppSpec-generated.cpp +44 -0
  10. package/android/generated/jni/RNLlamaCppSpec.h +31 -0
  11. package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI-generated.cpp +42 -0
  12. package/android/generated/jni/react/renderer/components/RNLlamaCppSpec/RNLlamaCppSpecJSI.h +336 -0
  13. package/android/gradle.properties +5 -0
  14. package/android/src/main/AndroidManifest.xml +3 -0
  15. package/android/src/main/AndroidManifestNew.xml +2 -0
  16. package/android/src/main/cpp/include/llama-cpp.h +30 -0
  17. package/android/src/main/cpp/include/llama.h +1440 -0
  18. package/android/src/main/java/com/novastera/llamarn/RNLlamaCppPackage.kt +21 -0
  19. package/android/src/main/jniLibs/arm64-v8a/libOpenCL.so +0 -0
  20. package/android/src/main/jniLibs/arm64-v8a/libggml-base.so +0 -0
  21. package/android/src/main/jniLibs/arm64-v8a/libggml-cpu.so +0 -0
  22. package/android/src/main/jniLibs/arm64-v8a/libggml.so +0 -0
  23. package/android/src/main/jniLibs/arm64-v8a/libllama.so +0 -0
  24. package/android/src/main/jniLibs/x86_64/libOpenCL.so +0 -0
  25. package/android/src/main/jniLibs/x86_64/libggml-base.so +0 -0
  26. package/android/src/main/jniLibs/x86_64/libggml-cpu.so +0 -0
  27. package/android/src/main/jniLibs/x86_64/libggml.so +0 -0
  28. package/android/src/main/jniLibs/x86_64/libllama.so +0 -0
  29. package/cpp/LlamaCppModel.cpp +984 -0
  30. package/cpp/LlamaCppModel.h +162 -0
  31. package/cpp/PureCppImpl.cpp +308 -0
  32. package/cpp/PureCppImpl.h +59 -0
  33. package/cpp/SystemUtils.cpp +180 -0
  34. package/cpp/SystemUtils.h +74 -0
  35. package/cpp/build-info.cpp +4 -0
  36. package/cpp/llama.cpp/AUTHORS +1106 -0
  37. package/cpp/llama.cpp/CMakeLists.txt +254 -0
  38. package/cpp/llama.cpp/CMakePresets.json +84 -0
  39. package/cpp/llama.cpp/CODEOWNERS +11 -0
  40. package/cpp/llama.cpp/CONTRIBUTING.md +127 -0
  41. package/cpp/llama.cpp/LICENSE +21 -0
  42. package/cpp/llama.cpp/Makefile +1608 -0
  43. package/cpp/llama.cpp/README.md +575 -0
  44. package/cpp/llama.cpp/SECURITY.md +68 -0
  45. package/cpp/llama.cpp/build-xcframework.sh +540 -0
  46. package/cpp/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
  47. package/cpp/llama.cpp/cmake/arm64-windows-llvm.cmake +16 -0
  48. package/cpp/llama.cpp/cmake/build-info.cmake +64 -0
  49. package/cpp/llama.cpp/cmake/common.cmake +35 -0
  50. package/cpp/llama.cpp/cmake/git-vars.cmake +22 -0
  51. package/cpp/llama.cpp/cmake/llama-config.cmake.in +30 -0
  52. package/cpp/llama.cpp/cmake/llama.pc.in +10 -0
  53. package/cpp/llama.cpp/cmake/x64-windows-llvm.cmake +5 -0
  54. package/cpp/llama.cpp/common/CMakeLists.txt +170 -0
  55. package/cpp/llama.cpp/common/arg.cpp +3337 -0
  56. package/cpp/llama.cpp/common/arg.h +89 -0
  57. package/cpp/llama.cpp/common/base64.hpp +392 -0
  58. package/cpp/llama.cpp/common/build-info.cpp.in +4 -0
  59. package/cpp/llama.cpp/common/chat.cpp +1781 -0
  60. package/cpp/llama.cpp/common/chat.h +135 -0
  61. package/cpp/llama.cpp/common/cmake/build-info-gen-cpp.cmake +24 -0
  62. package/cpp/llama.cpp/common/common.cpp +1567 -0
  63. package/cpp/llama.cpp/common/common.h +668 -0
  64. package/cpp/llama.cpp/common/console.cpp +504 -0
  65. package/cpp/llama.cpp/common/console.h +19 -0
  66. package/cpp/llama.cpp/common/json-schema-to-grammar.cpp +1027 -0
  67. package/cpp/llama.cpp/common/json-schema-to-grammar.h +21 -0
  68. package/cpp/llama.cpp/common/json.hpp +24766 -0
  69. package/cpp/llama.cpp/common/llguidance.cpp +254 -0
  70. package/cpp/llama.cpp/common/log.cpp +393 -0
  71. package/cpp/llama.cpp/common/log.h +103 -0
  72. package/cpp/llama.cpp/common/minja/chat-template.hpp +537 -0
  73. package/cpp/llama.cpp/common/minja/minja.hpp +2941 -0
  74. package/cpp/llama.cpp/common/ngram-cache.cpp +286 -0
  75. package/cpp/llama.cpp/common/ngram-cache.h +101 -0
  76. package/cpp/llama.cpp/common/sampling.cpp +580 -0
  77. package/cpp/llama.cpp/common/sampling.h +107 -0
  78. package/cpp/llama.cpp/common/speculative.cpp +278 -0
  79. package/cpp/llama.cpp/common/speculative.h +28 -0
  80. package/cpp/llama.cpp/common/stb_image.h +7988 -0
  81. package/cpp/llama.cpp/convert_hf_to_gguf.py +6195 -0
  82. package/cpp/llama.cpp/convert_hf_to_gguf_update.py +393 -0
  83. package/cpp/llama.cpp/convert_llama_ggml_to_gguf.py +450 -0
  84. package/cpp/llama.cpp/convert_lora_to_gguf.py +461 -0
  85. package/cpp/llama.cpp/flake.lock +58 -0
  86. package/cpp/llama.cpp/flake.nix +185 -0
  87. package/cpp/llama.cpp/ggml/CMakeLists.txt +388 -0
  88. package/cpp/llama.cpp/ggml/cmake/GitVars.cmake +22 -0
  89. package/cpp/llama.cpp/ggml/cmake/common.cmake +26 -0
  90. package/cpp/llama.cpp/ggml/cmake/ggml-config.cmake.in +152 -0
  91. package/cpp/llama.cpp/ggml/include/ggml-alloc.h +76 -0
  92. package/cpp/llama.cpp/ggml/include/ggml-backend.h +354 -0
  93. package/cpp/llama.cpp/ggml/include/ggml-blas.h +25 -0
  94. package/cpp/llama.cpp/ggml/include/ggml-cann.h +123 -0
  95. package/cpp/llama.cpp/ggml/include/ggml-cpp.h +39 -0
  96. package/cpp/llama.cpp/ggml/include/ggml-cpu.h +143 -0
  97. package/cpp/llama.cpp/ggml/include/ggml-cuda.h +47 -0
  98. package/cpp/llama.cpp/ggml/include/ggml-kompute.h +50 -0
  99. package/cpp/llama.cpp/ggml/include/ggml-metal.h +66 -0
  100. package/cpp/llama.cpp/ggml/include/ggml-opencl.h +26 -0
  101. package/cpp/llama.cpp/ggml/include/ggml-opt.h +216 -0
  102. package/cpp/llama.cpp/ggml/include/ggml-rpc.h +33 -0
  103. package/cpp/llama.cpp/ggml/include/ggml-sycl.h +49 -0
  104. package/cpp/llama.cpp/ggml/include/ggml-vulkan.h +29 -0
  105. package/cpp/llama.cpp/ggml/include/ggml.h +2192 -0
  106. package/cpp/llama.cpp/ggml/include/gguf.h +202 -0
  107. package/cpp/llama.cpp/ggml/src/CMakeLists.txt +345 -0
  108. package/cpp/llama.cpp/ggml/src/ggml-alloc.c +1042 -0
  109. package/cpp/llama.cpp/ggml/src/ggml-backend-impl.h +255 -0
  110. package/cpp/llama.cpp/ggml/src/ggml-backend-reg.cpp +586 -0
  111. package/cpp/llama.cpp/ggml/src/ggml-backend.cpp +2008 -0
  112. package/cpp/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +87 -0
  113. package/cpp/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
  114. package/cpp/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +74 -0
  115. package/cpp/llama.cpp/ggml/src/ggml-cann/Doxyfile +2579 -0
  116. package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +179 -0
  117. package/cpp/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +258 -0
  118. package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +2589 -0
  119. package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +1083 -0
  120. package/cpp/llama.cpp/ggml/src/ggml-cann/common.h +420 -0
  121. package/cpp/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +2554 -0
  122. package/cpp/llama.cpp/ggml/src/ggml-common.h +1857 -0
  123. package/cpp/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +495 -0
  124. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +221 -0
  125. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/amx.h +8 -0
  126. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/common.h +91 -0
  127. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
  128. package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  129. package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.cpp +158 -0
  130. package/cpp/llama.cpp/ggml/src/ggml-cpu/binary-ops.h +16 -0
  131. package/cpp/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +100 -0
  132. package/cpp/llama.cpp/ggml/src/ggml-cpu/common.h +72 -0
  133. package/cpp/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +327 -0
  134. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +6431 -0
  135. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
  136. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
  137. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
  138. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +512 -0
  139. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +13131 -0
  140. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
  141. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
  142. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
  143. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +3492 -0
  144. package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +671 -0
  145. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.cpp +254 -0
  146. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kernels.h +60 -0
  147. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.cpp +287 -0
  148. package/cpp/llama.cpp/ggml/src/ggml-cpu/kleidiai/kleidiai.h +17 -0
  149. package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +3544 -0
  150. package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
  151. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp +8796 -0
  152. package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.h +110 -0
  153. package/cpp/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +892 -0
  154. package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.cpp +186 -0
  155. package/cpp/llama.cpp/ggml/src/ggml-cpu/unary-ops.h +28 -0
  156. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.cpp +252 -0
  157. package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.h +802 -0
  158. package/cpp/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +184 -0
  159. package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cu +47 -0
  160. package/cpp/llama.cpp/ggml/src/ggml-cuda/acc.cuh +5 -0
  161. package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cu +34 -0
  162. package/cpp/llama.cpp/ggml/src/ggml-cuda/arange.cuh +5 -0
  163. package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cu +91 -0
  164. package/cpp/llama.cpp/ggml/src/ggml-cuda/argmax.cuh +3 -0
  165. package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cu +104 -0
  166. package/cpp/llama.cpp/ggml/src/ggml-cuda/argsort.cuh +3 -0
  167. package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cu +363 -0
  168. package/cpp/llama.cpp/ggml/src/ggml-cuda/binbcast.cuh +9 -0
  169. package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cu +45 -0
  170. package/cpp/llama.cpp/ggml/src/ggml-cuda/clamp.cuh +5 -0
  171. package/cpp/llama.cpp/ggml/src/ggml-cuda/common.cuh +828 -0
  172. package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cu +221 -0
  173. package/cpp/llama.cpp/ggml/src/ggml-cuda/concat.cuh +5 -0
  174. package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cu +89 -0
  175. package/cpp/llama.cpp/ggml/src/ggml-cuda/conv-transpose-1d.cuh +5 -0
  176. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cu +730 -0
  177. package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cuh +26 -0
  178. package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cu +64 -0
  179. package/cpp/llama.cpp/ggml/src/ggml-cuda/count-equal.cuh +5 -0
  180. package/cpp/llama.cpp/ggml/src/ggml-cuda/cp-async.cuh +57 -0
  181. package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cu +695 -0
  182. package/cpp/llama.cpp/ggml/src/ggml-cuda/cpy.cuh +11 -0
  183. package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cu +189 -0
  184. package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cuh +7 -0
  185. package/cpp/llama.cpp/ggml/src/ggml-cuda/dequantize.cuh +103 -0
  186. package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cu +40 -0
  187. package/cpp/llama.cpp/ggml/src/ggml-cuda/diagmask.cuh +5 -0
  188. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-common.cuh +873 -0
  189. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh +1269 -0
  190. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cu +357 -0
  191. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cuh +3 -0
  192. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cu +365 -0
  193. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cuh +3 -0
  194. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f16.cuh +437 -0
  195. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f32.cuh +428 -0
  196. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cu +634 -0
  197. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cuh +3 -0
  198. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cu +345 -0
  199. package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn.cuh +3 -0
  200. package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cu +275 -0
  201. package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cuh +15 -0
  202. package/cpp/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu +3501 -0
  203. package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cu +93 -0
  204. package/cpp/llama.cpp/ggml/src/ggml-cuda/gla.cuh +3 -0
  205. package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cu +103 -0
  206. package/cpp/llama.cpp/ggml/src/ggml-cuda/im2col.cuh +5 -0
  207. package/cpp/llama.cpp/ggml/src/ggml-cuda/mma.cuh +396 -0
  208. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cu +322 -0
  209. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cuh +3217 -0
  210. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cu +336 -0
  211. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cuh +12 -0
  212. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cu +595 -0
  213. package/cpp/llama.cpp/ggml/src/ggml-cuda/mmvq.cuh +12 -0
  214. package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cu +458 -0
  215. package/cpp/llama.cpp/ggml/src/ggml-cuda/norm.cuh +11 -0
  216. package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cu +78 -0
  217. package/cpp/llama.cpp/ggml/src/ggml-cuda/opt-step-adamw.cuh +5 -0
  218. package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cu +68 -0
  219. package/cpp/llama.cpp/ggml/src/ggml-cuda/out-prod.cuh +3 -0
  220. package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cu +49 -0
  221. package/cpp/llama.cpp/ggml/src/ggml-cuda/pad.cuh +5 -0
  222. package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cu +94 -0
  223. package/cpp/llama.cpp/ggml/src/ggml-cuda/pool2d.cuh +5 -0
  224. package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cu +189 -0
  225. package/cpp/llama.cpp/ggml/src/ggml-cuda/quantize.cuh +27 -0
  226. package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cu +456 -0
  227. package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cuh +7 -0
  228. package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cu +31 -0
  229. package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cuh +5 -0
  230. package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cu +283 -0
  231. package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cuh +7 -0
  232. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cu +148 -0
  233. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cuh +3 -0
  234. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cu +153 -0
  235. package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cuh +3 -0
  236. package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cu +45 -0
  237. package/cpp/llama.cpp/ggml/src/ggml-cuda/sum.cuh +5 -0
  238. package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cu +39 -0
  239. package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cuh +5 -0
  240. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_16.cu +5 -0
  241. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_1-ncols2_8.cu +10 -0
  242. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_1.cu +10 -0
  243. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_2.cu +10 -0
  244. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_16-ncols2_4.cu +10 -0
  245. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_16.cu +5 -0
  246. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_4.cu +10 -0
  247. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_2-ncols2_8.cu +10 -0
  248. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_1.cu +10 -0
  249. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_32-ncols2_2.cu +10 -0
  250. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_16.cu +5 -0
  251. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_2.cu +10 -0
  252. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_4.cu +10 -0
  253. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_4-ncols2_8.cu +10 -0
  254. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_64-ncols2_1.cu +10 -0
  255. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_1.cu +10 -0
  256. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_2.cu +10 -0
  257. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_4.cu +10 -0
  258. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-mma-f16-instance-ncols1_8-ncols2_8.cu +10 -0
  259. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-f16.cu +5 -0
  260. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_0.cu +5 -0
  261. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q4_1.cu +5 -0
  262. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_0.cu +5 -0
  263. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q5_1.cu +5 -0
  264. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-f16-q8_0.cu +5 -0
  265. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-f16.cu +5 -0
  266. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_0.cu +5 -0
  267. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q4_1.cu +5 -0
  268. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_0.cu +5 -0
  269. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q5_1.cu +5 -0
  270. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_0-q8_0.cu +5 -0
  271. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-f16.cu +5 -0
  272. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_0.cu +5 -0
  273. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q4_1.cu +5 -0
  274. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_0.cu +5 -0
  275. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q5_1.cu +5 -0
  276. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q4_1-q8_0.cu +5 -0
  277. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-f16.cu +5 -0
  278. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_0.cu +5 -0
  279. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q4_1.cu +5 -0
  280. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_0.cu +5 -0
  281. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q5_1.cu +5 -0
  282. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_0-q8_0.cu +5 -0
  283. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-f16.cu +5 -0
  284. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_0.cu +5 -0
  285. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q4_1.cu +5 -0
  286. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_0.cu +5 -0
  287. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q5_1.cu +5 -0
  288. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q5_1-q8_0.cu +5 -0
  289. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-f16.cu +5 -0
  290. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_0.cu +5 -0
  291. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q4_1.cu +5 -0
  292. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_0.cu +5 -0
  293. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q5_1.cu +5 -0
  294. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs128-q8_0-q8_0.cu +5 -0
  295. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs256-f16-f16.cu +5 -0
  296. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-f16.cu +5 -0
  297. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_0.cu +5 -0
  298. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q4_1.cu +5 -0
  299. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_0.cu +5 -0
  300. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q5_1.cu +5 -0
  301. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f16-instance-hs64-f16-q8_0.cu +5 -0
  302. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-f16.cu +5 -0
  303. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_0.cu +5 -0
  304. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q4_1.cu +5 -0
  305. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_0.cu +5 -0
  306. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q5_1.cu +5 -0
  307. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-f16-q8_0.cu +5 -0
  308. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-f16.cu +5 -0
  309. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_0.cu +5 -0
  310. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q4_1.cu +5 -0
  311. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_0.cu +5 -0
  312. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q5_1.cu +5 -0
  313. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_0-q8_0.cu +5 -0
  314. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-f16.cu +5 -0
  315. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_0.cu +5 -0
  316. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q4_1.cu +5 -0
  317. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_0.cu +5 -0
  318. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q5_1.cu +5 -0
  319. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q4_1-q8_0.cu +5 -0
  320. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-f16.cu +5 -0
  321. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_0.cu +5 -0
  322. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q4_1.cu +5 -0
  323. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_0.cu +5 -0
  324. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q5_1.cu +5 -0
  325. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_0-q8_0.cu +5 -0
  326. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-f16.cu +5 -0
  327. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_0.cu +5 -0
  328. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q4_1.cu +5 -0
  329. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_0.cu +5 -0
  330. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q5_1.cu +5 -0
  331. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q5_1-q8_0.cu +5 -0
  332. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-f16.cu +5 -0
  333. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_0.cu +5 -0
  334. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q4_1.cu +5 -0
  335. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_0.cu +5 -0
  336. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q5_1.cu +5 -0
  337. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs128-q8_0-q8_0.cu +5 -0
  338. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs256-f16-f16.cu +5 -0
  339. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-f16.cu +5 -0
  340. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_0.cu +5 -0
  341. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q4_1.cu +5 -0
  342. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_0.cu +5 -0
  343. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q5_1.cu +5 -0
  344. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/fattn-vec-f32-instance-hs64-f16-q8_0.cu +5 -0
  345. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/generate_cu_files.py +78 -0
  346. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq1_s.cu +5 -0
  347. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_s.cu +5 -0
  348. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xs.cu +5 -0
  349. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq2_xxs.cu +5 -0
  350. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_s.cu +5 -0
  351. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq3_xxs.cu +5 -0
  352. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_nl.cu +5 -0
  353. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-iq4_xs.cu +5 -0
  354. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q2_k.cu +5 -0
  355. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q3_k.cu +5 -0
  356. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_0.cu +5 -0
  357. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_1.cu +5 -0
  358. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q4_k.cu +5 -0
  359. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_0.cu +5 -0
  360. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_1.cu +5 -0
  361. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q5_k.cu +5 -0
  362. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q6_k.cu +5 -0
  363. package/cpp/llama.cpp/ggml/src/ggml-cuda/template-instances/mmq-instance-q8_0.cu +5 -0
  364. package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cu +47 -0
  365. package/cpp/llama.cpp/ggml/src/ggml-cuda/tsembd.cuh +5 -0
  366. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cu +279 -0
  367. package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cuh +57 -0
  368. package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cu +51 -0
  369. package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cuh +5 -0
  370. package/cpp/llama.cpp/ggml/src/ggml-cuda/vecdotq.cuh +1135 -0
  371. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +15 -0
  372. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +243 -0
  373. package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +140 -0
  374. package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cu +199 -0
  375. package/cpp/llama.cpp/ggml/src/ggml-cuda/wkv.cuh +7 -0
  376. package/cpp/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +131 -0
  377. package/cpp/llama.cpp/ggml/src/ggml-impl.h +601 -0
  378. package/cpp/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +166 -0
  379. package/cpp/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
  380. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/common.comp +112 -0
  381. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +58 -0
  382. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +25 -0
  383. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +52 -0
  384. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +52 -0
  385. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +52 -0
  386. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +52 -0
  387. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +30 -0
  388. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +22 -0
  389. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +17 -0
  390. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +31 -0
  391. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +31 -0
  392. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +38 -0
  393. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +39 -0
  394. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +44 -0
  395. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +52 -0
  396. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +69 -0
  397. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +51 -0
  398. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +33 -0
  399. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +35 -0
  400. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +140 -0
  401. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +106 -0
  402. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +73 -0
  403. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +52 -0
  404. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +28 -0
  405. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +84 -0
  406. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +21 -0
  407. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +53 -0
  408. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +52 -0
  409. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +52 -0
  410. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +52 -0
  411. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +52 -0
  412. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +19 -0
  413. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +23 -0
  414. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +22 -0
  415. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +72 -0
  416. package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +71 -0
  417. package/cpp/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +120 -0
  418. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +618 -0
  419. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.m +5916 -0
  420. package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.metal +6891 -0
  421. package/cpp/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +107 -0
  422. package/cpp/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +96 -0
  423. package/cpp/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +4966 -0
  424. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/add.cl +83 -0
  425. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/clamp.cl +20 -0
  426. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cpy.cl +184 -0
  427. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/cvt.cl +118 -0
  428. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/diag_mask_inf.cl +58 -0
  429. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/embed_kernel.py +26 -0
  430. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gelu.cl +62 -0
  431. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle.cl +268 -0
  432. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gemv_noshuffle_general.cl +274 -0
  433. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/get_rows.cl +163 -0
  434. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f16.cl +57 -0
  435. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/im2col_f32.cl +57 -0
  436. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul.cl +79 -0
  437. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mat_Ab_Bi_8x4.cl +139 -0
  438. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f16.cl +118 -0
  439. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32.cl +118 -0
  440. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl +94 -0
  441. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f16_f32_l4.cl +84 -0
  442. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_f32_f32.cl +118 -0
  443. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32.cl +192 -0
  444. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_16x_flat.cl +307 -0
  445. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_1d_8x_flat.cl +265 -0
  446. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_8x_flat.cl +272 -0
  447. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q4_0_f32_v.cl +254 -0
  448. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mv_q6_k.cl +190 -0
  449. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/norm.cl +81 -0
  450. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/relu.cl +16 -0
  451. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rms_norm.cl +96 -0
  452. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/rope.cl +721 -0
  453. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/scale.cl +16 -0
  454. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/silu.cl +30 -0
  455. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +87 -0
  456. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +87 -0
  457. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f16.cl +86 -0
  458. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f32.cl +86 -0
  459. package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/transpose.cl +84 -0
  460. package/cpp/llama.cpp/ggml/src/ggml-opt.cpp +854 -0
  461. package/cpp/llama.cpp/ggml/src/ggml-quants.c +5232 -0
  462. package/cpp/llama.cpp/ggml/src/ggml-quants.h +100 -0
  463. package/cpp/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +9 -0
  464. package/cpp/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +1813 -0
  465. package/cpp/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +183 -0
  466. package/cpp/llama.cpp/ggml/src/ggml-sycl/backend.hpp +37 -0
  467. package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +350 -0
  468. package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +39 -0
  469. package/cpp/llama.cpp/ggml/src/ggml-sycl/common.cpp +83 -0
  470. package/cpp/llama.cpp/ggml/src/ggml-sycl/common.hpp +493 -0
  471. package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.cpp +197 -0
  472. package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.hpp +20 -0
  473. package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.cpp +100 -0
  474. package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.hpp +20 -0
  475. package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.cpp +596 -0
  476. package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.hpp +34 -0
  477. package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +701 -0
  478. package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +11 -0
  479. package/cpp/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +753 -0
  480. package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +1154 -0
  481. package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +27 -0
  482. package/cpp/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +2957 -0
  483. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1559 -0
  484. package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +75 -0
  485. package/cpp/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +70 -0
  486. package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +311 -0
  487. package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +20 -0
  488. package/cpp/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +4302 -0
  489. package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.cpp +105 -0
  490. package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.hpp +8 -0
  491. package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +136 -0
  492. package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +21 -0
  493. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +3030 -0
  494. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +33 -0
  495. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1081 -0
  496. package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +27 -0
  497. package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.cpp +474 -0
  498. package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.hpp +26 -0
  499. package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +46 -0
  500. package/cpp/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +10 -0
  501. package/cpp/llama.cpp/ggml/src/ggml-sycl/presets.hpp +74 -0
  502. package/cpp/llama.cpp/ggml/src/ggml-sycl/quants.hpp +61 -0
  503. package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.cpp +362 -0
  504. package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.hpp +20 -0
  505. package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +264 -0
  506. package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +20 -0
  507. package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +13 -0
  508. package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +23 -0
  509. package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +73 -0
  510. package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +20 -0
  511. package/cpp/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +1189 -0
  512. package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +305 -0
  513. package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +10 -0
  514. package/cpp/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
  515. package/cpp/llama.cpp/ggml/src/ggml-threading.h +14 -0
  516. package/cpp/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +202 -0
  517. package/cpp/llama.cpp/ggml/src/ggml-vulkan/cmake/host-toolchain.cmake.in +15 -0
  518. package/cpp/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +10502 -0
  519. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +22 -0
  520. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/acc.comp +29 -0
  521. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/add.comp +29 -0
  522. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp +51 -0
  523. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp +69 -0
  524. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp +17 -0
  525. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/concat.comp +41 -0
  526. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp +49 -0
  527. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp +105 -0
  528. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy.comp +23 -0
  529. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp +51 -0
  530. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +242 -0
  531. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/cos.comp +17 -0
  532. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp +31 -0
  533. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp +20 -0
  534. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs.comp +462 -0
  535. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_funcs_cm2.comp +699 -0
  536. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_head.comp +13 -0
  537. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp +42 -0
  538. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp +35 -0
  539. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp +44 -0
  540. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp +43 -0
  541. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp +48 -0
  542. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp +39 -0
  543. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp +49 -0
  544. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp +32 -0
  545. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp +34 -0
  546. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp +34 -0
  547. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp +42 -0
  548. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_0.comp +30 -0
  549. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_1.comp +32 -0
  550. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q4_k.comp +68 -0
  551. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_0.comp +34 -0
  552. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_1.comp +35 -0
  553. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q5_k.comp +70 -0
  554. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q6_k.comp +33 -0
  555. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/dequant_q8_0.comp +31 -0
  556. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/diag_mask_inf.comp +34 -0
  557. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/div.comp +27 -0
  558. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +483 -0
  559. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +383 -0
  560. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +59 -0
  561. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu.comp +25 -0
  562. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu_quick.comp +23 -0
  563. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_binary_head.comp +64 -0
  564. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_head.comp +9 -0
  565. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/generic_unary_head.comp +76 -0
  566. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows.comp +33 -0
  567. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/get_rows_quant.comp +41 -0
  568. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/group_norm.comp +66 -0
  569. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/im2col.comp +100 -0
  570. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/l2_norm.comp +41 -0
  571. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/leaky_relu.comp +22 -0
  572. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul.comp +27 -0
  573. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_split_k_reduce.comp +48 -0
  574. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec.comp +169 -0
  575. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_base.comp +118 -0
  576. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_m.comp +82 -0
  577. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq1_s.comp +79 -0
  578. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_s.comp +90 -0
  579. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xs.comp +87 -0
  580. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq2_xxs.comp +87 -0
  581. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_s.comp +90 -0
  582. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_iq3_xxs.comp +88 -0
  583. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp +118 -0
  584. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp +154 -0
  585. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q2_k.comp +130 -0
  586. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q3_k.comp +132 -0
  587. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q4_k.comp +136 -0
  588. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q5_k.comp +167 -0
  589. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp +130 -0
  590. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +868 -0
  591. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +441 -0
  592. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq.comp +442 -0
  593. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mmq_funcs.comp +99 -0
  594. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/norm.comp +44 -0
  595. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/opt_step_adamw.comp +42 -0
  596. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pad.comp +28 -0
  597. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/pool2d.comp +74 -0
  598. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/quantize_q8_1.comp +77 -0
  599. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/relu.comp +21 -0
  600. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat.comp +26 -0
  601. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/repeat_back.comp +37 -0
  602. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +52 -0
  603. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm_back.comp +55 -0
  604. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_head.comp +58 -0
  605. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +60 -0
  606. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +43 -0
  607. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +43 -0
  608. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_vision.comp +47 -0
  609. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +24 -0
  610. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sigmoid.comp +20 -0
  611. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu.comp +22 -0
  612. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/silu_back.comp +26 -0
  613. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sin.comp +17 -0
  614. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +173 -0
  615. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max_back.comp +50 -0
  616. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/square.comp +17 -0
  617. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sub.comp +29 -0
  618. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/sum_rows.comp +37 -0
  619. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/tanh.comp +20 -0
  620. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_bfloat16_support.comp +7 -0
  621. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat2_support.comp +7 -0
  622. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_coopmat_support.comp +7 -0
  623. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/test_integer_dot_support.comp +7 -0
  624. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp +41 -0
  625. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/types.comp +1373 -0
  626. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +36 -0
  627. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +740 -0
  628. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv6.comp +87 -0
  629. package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/wkv7.comp +91 -0
  630. package/cpp/llama.cpp/ggml/src/ggml.c +6499 -0
  631. package/cpp/llama.cpp/ggml/src/gguf.cpp +1330 -0
  632. package/cpp/llama.cpp/gguf-py/LICENSE +21 -0
  633. package/cpp/llama.cpp/gguf-py/README.md +99 -0
  634. package/cpp/llama.cpp/gguf-py/examples/reader.py +49 -0
  635. package/cpp/llama.cpp/gguf-py/examples/writer.py +39 -0
  636. package/cpp/llama.cpp/gguf-py/gguf/__init__.py +9 -0
  637. package/cpp/llama.cpp/gguf-py/gguf/constants.py +2296 -0
  638. package/cpp/llama.cpp/gguf-py/gguf/gguf.py +15 -0
  639. package/cpp/llama.cpp/gguf-py/gguf/gguf_reader.py +367 -0
  640. package/cpp/llama.cpp/gguf-py/gguf/gguf_writer.py +1041 -0
  641. package/cpp/llama.cpp/gguf-py/gguf/lazy.py +223 -0
  642. package/cpp/llama.cpp/gguf-py/gguf/metadata.py +642 -0
  643. package/cpp/llama.cpp/gguf-py/gguf/py.typed +0 -0
  644. package/cpp/llama.cpp/gguf-py/gguf/quants.py +1269 -0
  645. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_convert_endian.py +182 -0
  646. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_dump.py +454 -0
  647. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_editor_gui.py +1610 -0
  648. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_hash.py +102 -0
  649. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_new_metadata.py +207 -0
  650. package/cpp/llama.cpp/gguf-py/gguf/scripts/gguf_set_metadata.py +95 -0
  651. package/cpp/llama.cpp/gguf-py/gguf/tensor_mapping.py +1172 -0
  652. package/cpp/llama.cpp/gguf-py/gguf/utility.py +264 -0
  653. package/cpp/llama.cpp/gguf-py/gguf/vocab.py +492 -0
  654. package/cpp/llama.cpp/gguf-py/pyproject.toml +43 -0
  655. package/cpp/llama.cpp/gguf-py/tests/__init__.py +1 -0
  656. package/cpp/llama.cpp/gguf-py/tests/test_metadata.py +238 -0
  657. package/cpp/llama.cpp/gguf-py/tests/test_quants.py +238 -0
  658. package/cpp/llama.cpp/grammars/README.md +382 -0
  659. package/cpp/llama.cpp/grammars/arithmetic.gbnf +6 -0
  660. package/cpp/llama.cpp/grammars/c.gbnf +42 -0
  661. package/cpp/llama.cpp/grammars/chess.gbnf +13 -0
  662. package/cpp/llama.cpp/grammars/english.gbnf +6 -0
  663. package/cpp/llama.cpp/grammars/japanese.gbnf +7 -0
  664. package/cpp/llama.cpp/grammars/json.gbnf +25 -0
  665. package/cpp/llama.cpp/grammars/json_arr.gbnf +34 -0
  666. package/cpp/llama.cpp/grammars/list.gbnf +4 -0
  667. package/cpp/llama.cpp/include/llama-cpp.h +30 -0
  668. package/cpp/llama.cpp/include/llama.h +1440 -0
  669. package/cpp/llama.cpp/licenses/LICENSE-curl +9 -0
  670. package/cpp/llama.cpp/licenses/LICENSE-httplib +21 -0
  671. package/cpp/llama.cpp/licenses/LICENSE-jsonhpp +21 -0
  672. package/cpp/llama.cpp/licenses/LICENSE-linenoise +26 -0
  673. package/cpp/llama.cpp/media/llama0-banner.png +0 -0
  674. package/cpp/llama.cpp/media/llama0-logo.png +0 -0
  675. package/cpp/llama.cpp/media/llama1-banner.png +0 -0
  676. package/cpp/llama.cpp/media/llama1-logo.png +0 -0
  677. package/cpp/llama.cpp/media/llama1-logo.svg +34 -0
  678. package/cpp/llama.cpp/media/matmul.png +0 -0
  679. package/cpp/llama.cpp/media/matmul.svg +1238 -0
  680. package/cpp/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  681. package/cpp/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  682. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  683. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +112 -0
  684. package/cpp/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +46 -0
  685. package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +112 -0
  686. package/cpp/llama.cpp/models/ggml-vocab-chameleon.gguf.out +46 -0
  687. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  688. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.inp +112 -0
  689. package/cpp/llama.cpp/models/ggml-vocab-command-r.gguf.out +46 -0
  690. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  691. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
  692. package/cpp/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +46 -0
  693. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  694. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
  695. package/cpp/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +46 -0
  696. package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +112 -0
  697. package/cpp/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +46 -0
  698. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  699. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.inp +112 -0
  700. package/cpp/llama.cpp/models/ggml-vocab-falcon.gguf.out +46 -0
  701. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  702. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +112 -0
  703. package/cpp/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +46 -0
  704. package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +112 -0
  705. package/cpp/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +46 -0
  706. package/cpp/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  707. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  708. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +112 -0
  709. package/cpp/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +46 -0
  710. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  711. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +112 -0
  712. package/cpp/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +46 -0
  713. package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.inp +112 -0
  714. package/cpp/llama.cpp/models/ggml-vocab-llama4.gguf.out +46 -0
  715. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  716. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.inp +112 -0
  717. package/cpp/llama.cpp/models/ggml-vocab-mpt.gguf.out +46 -0
  718. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  719. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +112 -0
  720. package/cpp/llama.cpp/models/ggml-vocab-phi-3.gguf.out +46 -0
  721. package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +112 -0
  722. package/cpp/llama.cpp/models/ggml-vocab-pixtral.gguf.out +46 -0
  723. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  724. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +112 -0
  725. package/cpp/llama.cpp/models/ggml-vocab-qwen2.gguf.out +46 -0
  726. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  727. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.inp +112 -0
  728. package/cpp/llama.cpp/models/ggml-vocab-refact.gguf.out +46 -0
  729. package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +112 -0
  730. package/cpp/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +46 -0
  731. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  732. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +112 -0
  733. package/cpp/llama.cpp/models/ggml-vocab-starcoder.gguf.out +46 -0
  734. package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja +202 -0
  735. package/cpp/llama.cpp/models/templates/CohereForAI-c4ai-command-r7b-12-2024-tool_use.jinja +156 -0
  736. package/cpp/llama.cpp/models/templates/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use.jinja +152 -0
  737. package/cpp/llama.cpp/models/templates/NousResearch-Hermes-3-Llama-3.1-8B-tool_use.jinja +152 -0
  738. package/cpp/llama.cpp/models/templates/Qwen-Qwen2.5-7B-Instruct.jinja +54 -0
  739. package/cpp/llama.cpp/models/templates/README.md +22 -0
  740. package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Llama-8B.jinja +1 -0
  741. package/cpp/llama.cpp/models/templates/deepseek-ai-DeepSeek-R1-Distill-Qwen-32B.jinja +1 -0
  742. package/cpp/llama.cpp/models/templates/fireworks-ai-llama-3-firefunction-v2.jinja +57 -0
  743. package/cpp/llama.cpp/models/templates/google-gemma-2-2b-it.jinja +4 -0
  744. package/cpp/llama.cpp/models/templates/llama-cpp-deepseek-r1.jinja +76 -0
  745. package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.1.jinja +58 -0
  746. package/cpp/llama.cpp/models/templates/meetkai-functionary-medium-v3.2.jinja +287 -0
  747. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja +109 -0
  748. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.2-3B-Instruct.jinja +93 -0
  749. package/cpp/llama.cpp/models/templates/meta-llama-Llama-3.3-70B-Instruct.jinja +109 -0
  750. package/cpp/llama.cpp/models/templates/microsoft-Phi-3.5-mini-instruct.jinja +8 -0
  751. package/cpp/llama.cpp/models/templates/mistralai-Mistral-Nemo-Instruct-2407.jinja +87 -0
  752. package/cpp/llama.cpp/mypy.ini +7 -0
  753. package/cpp/llama.cpp/pocs/CMakeLists.txt +14 -0
  754. package/cpp/llama.cpp/pocs/vdot/CMakeLists.txt +9 -0
  755. package/cpp/llama.cpp/pocs/vdot/q8dot.cpp +173 -0
  756. package/cpp/llama.cpp/pocs/vdot/vdot.cpp +311 -0
  757. package/cpp/llama.cpp/poetry.lock +1197 -0
  758. package/cpp/llama.cpp/prompts/LLM-questions.txt +49 -0
  759. package/cpp/llama.cpp/prompts/alpaca.txt +1 -0
  760. package/cpp/llama.cpp/prompts/assistant.txt +31 -0
  761. package/cpp/llama.cpp/prompts/chat-with-baichuan.txt +4 -0
  762. package/cpp/llama.cpp/prompts/chat-with-bob.txt +7 -0
  763. package/cpp/llama.cpp/prompts/chat-with-qwen.txt +1 -0
  764. package/cpp/llama.cpp/prompts/chat-with-vicuna-v0.txt +7 -0
  765. package/cpp/llama.cpp/prompts/chat-with-vicuna-v1.txt +7 -0
  766. package/cpp/llama.cpp/prompts/chat.txt +28 -0
  767. package/cpp/llama.cpp/prompts/dan-modified.txt +1 -0
  768. package/cpp/llama.cpp/prompts/dan.txt +1 -0
  769. package/cpp/llama.cpp/prompts/mnemonics.txt +93 -0
  770. package/cpp/llama.cpp/prompts/parallel-questions.txt +43 -0
  771. package/cpp/llama.cpp/prompts/reason-act.txt +18 -0
  772. package/cpp/llama.cpp/pyproject.toml +45 -0
  773. package/cpp/llama.cpp/pyrightconfig.json +22 -0
  774. package/cpp/llama.cpp/requirements/requirements-all.txt +15 -0
  775. package/cpp/llama.cpp/requirements/requirements-compare-llama-bench.txt +2 -0
  776. package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +3 -0
  777. package/cpp/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +3 -0
  778. package/cpp/llama.cpp/requirements/requirements-convert_legacy_llama.txt +5 -0
  779. package/cpp/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +1 -0
  780. package/cpp/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +2 -0
  781. package/cpp/llama.cpp/requirements/requirements-gguf_editor_gui.txt +3 -0
  782. package/cpp/llama.cpp/requirements/requirements-pydantic.txt +3 -0
  783. package/cpp/llama.cpp/requirements/requirements-test-tokenizer-random.txt +1 -0
  784. package/cpp/llama.cpp/requirements/requirements-tool_bench.txt +12 -0
  785. package/cpp/llama.cpp/requirements.txt +13 -0
  786. package/cpp/llama.cpp/src/CMakeLists.txt +45 -0
  787. package/cpp/llama.cpp/src/llama-adapter.cpp +388 -0
  788. package/cpp/llama.cpp/src/llama-adapter.h +76 -0
  789. package/cpp/llama.cpp/src/llama-arch.cpp +1743 -0
  790. package/cpp/llama.cpp/src/llama-arch.h +437 -0
  791. package/cpp/llama.cpp/src/llama-batch.cpp +372 -0
  792. package/cpp/llama.cpp/src/llama-batch.h +89 -0
  793. package/cpp/llama.cpp/src/llama-chat.cpp +663 -0
  794. package/cpp/llama.cpp/src/llama-chat.h +58 -0
  795. package/cpp/llama.cpp/src/llama-context.cpp +2459 -0
  796. package/cpp/llama.cpp/src/llama-context.h +246 -0
  797. package/cpp/llama.cpp/src/llama-cparams.cpp +1 -0
  798. package/cpp/llama.cpp/src/llama-cparams.h +39 -0
  799. package/cpp/llama.cpp/src/llama-grammar.cpp +1219 -0
  800. package/cpp/llama.cpp/src/llama-grammar.h +173 -0
  801. package/cpp/llama.cpp/src/llama-graph.cpp +1713 -0
  802. package/cpp/llama.cpp/src/llama-graph.h +595 -0
  803. package/cpp/llama.cpp/src/llama-hparams.cpp +79 -0
  804. package/cpp/llama.cpp/src/llama-hparams.h +161 -0
  805. package/cpp/llama.cpp/src/llama-impl.cpp +167 -0
  806. package/cpp/llama.cpp/src/llama-impl.h +61 -0
  807. package/cpp/llama.cpp/src/llama-io.cpp +15 -0
  808. package/cpp/llama.cpp/src/llama-io.h +35 -0
  809. package/cpp/llama.cpp/src/llama-kv-cache.cpp +2486 -0
  810. package/cpp/llama.cpp/src/llama-kv-cache.h +405 -0
  811. package/cpp/llama.cpp/src/llama-memory.cpp +1 -0
  812. package/cpp/llama.cpp/src/llama-memory.h +31 -0
  813. package/cpp/llama.cpp/src/llama-mmap.cpp +600 -0
  814. package/cpp/llama.cpp/src/llama-mmap.h +68 -0
  815. package/cpp/llama.cpp/src/llama-model-loader.cpp +1133 -0
  816. package/cpp/llama.cpp/src/llama-model-loader.h +169 -0
  817. package/cpp/llama.cpp/src/llama-model.cpp +13453 -0
  818. package/cpp/llama.cpp/src/llama-model.h +420 -0
  819. package/cpp/llama.cpp/src/llama-quant.cpp +964 -0
  820. package/cpp/llama.cpp/src/llama-quant.h +1 -0
  821. package/cpp/llama.cpp/src/llama-sampling.cpp +2575 -0
  822. package/cpp/llama.cpp/src/llama-sampling.h +32 -0
  823. package/cpp/llama.cpp/src/llama-vocab.cpp +3313 -0
  824. package/cpp/llama.cpp/src/llama-vocab.h +125 -0
  825. package/cpp/llama.cpp/src/llama.cpp +340 -0
  826. package/cpp/llama.cpp/src/unicode-data.cpp +7034 -0
  827. package/cpp/llama.cpp/src/unicode-data.h +20 -0
  828. package/cpp/llama.cpp/src/unicode.cpp +849 -0
  829. package/cpp/llama.cpp/src/unicode.h +66 -0
  830. package/cpp/rn-completion.cpp +431 -0
  831. package/cpp/rn-llama.hpp +60 -0
  832. package/cpp/rn-utils.hpp +331 -0
  833. package/ios/OnLoad.mm +22 -0
  834. package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec-generated.mm +64 -0
  835. package/ios/generated/RNLlamaCppSpec/RNLlamaCppSpec.h +251 -0
  836. package/ios/generated/RNLlamaCppSpecJSI-generated.cpp +42 -0
  837. package/ios/generated/RNLlamaCppSpecJSI.h +336 -0
  838. package/ios/include/chat.h +135 -0
  839. package/ios/include/common/base64.hpp +392 -0
  840. package/ios/include/common/json.hpp +24766 -0
  841. package/ios/include/common/minja/chat-template.hpp +537 -0
  842. package/ios/include/common/minja/minja.hpp +2941 -0
  843. package/ios/include/common.h +668 -0
  844. package/ios/include/json-schema-to-grammar.h +21 -0
  845. package/ios/include/llama-cpp.h +30 -0
  846. package/ios/include/llama.h +1440 -0
  847. package/ios/include/log.h +103 -0
  848. package/ios/include/ngram-cache.h +101 -0
  849. package/ios/include/sampling.h +107 -0
  850. package/ios/include/speculative.h +28 -0
  851. package/ios/libs/llama.xcframework/Info.plist +135 -0
  852. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  853. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  854. package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
  855. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  856. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  857. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  858. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  859. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  860. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml.h +2192 -0
  861. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/gguf.h +202 -0
  862. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/llama.h +1440 -0
  863. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Info.plist +36 -0
  864. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Modules/module.modulemap +17 -0
  865. package/ios/libs/llama.xcframework/ios-arm64/llama.framework/llama +0 -0
  866. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  867. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  868. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  869. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
  870. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  871. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  872. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  873. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  874. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  875. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  876. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  877. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  878. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Info.plist +36 -0
  879. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  880. package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/llama +0 -0
  881. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  882. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  883. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  884. package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3442 -0
  885. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-alloc.h +76 -0
  886. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-backend.h +354 -0
  887. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-blas.h +25 -0
  888. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-cpu.h +143 -0
  889. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-metal.h +66 -0
  890. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml.h +2192 -0
  891. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/gguf.h +202 -0
  892. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/llama.h +1440 -0
  893. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Modules/module.modulemap +17 -0
  894. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Resources/Info.plist +32 -0
  895. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-alloc.h +76 -0
  896. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-backend.h +354 -0
  897. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-blas.h +25 -0
  898. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-cpu.h +143 -0
  899. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-metal.h +66 -0
  900. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml.h +2192 -0
  901. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/gguf.h +202 -0
  902. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/llama.h +1440 -0
  903. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Modules/module.modulemap +17 -0
  904. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Resources/Info.plist +32 -0
  905. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/llama +0 -0
  906. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-alloc.h +76 -0
  907. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-backend.h +354 -0
  908. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-blas.h +25 -0
  909. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-cpu.h +143 -0
  910. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-metal.h +66 -0
  911. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml.h +2192 -0
  912. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/gguf.h +202 -0
  913. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/llama.h +1440 -0
  914. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Modules/module.modulemap +17 -0
  915. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Resources/Info.plist +32 -0
  916. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/llama +0 -0
  917. package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/llama +0 -0
  918. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  919. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  920. package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4492 -0
  921. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  922. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  923. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  924. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  925. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  926. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml.h +2192 -0
  927. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/gguf.h +202 -0
  928. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/llama.h +1440 -0
  929. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Info.plist +35 -0
  930. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Modules/module.modulemap +17 -0
  931. package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/llama +0 -0
  932. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  933. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  934. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4513 -0
  935. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3440 -0
  936. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  937. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  938. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  939. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  940. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  941. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  942. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  943. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  944. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Info.plist +35 -0
  945. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  946. package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/llama +0 -0
  947. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  948. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  949. package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4528 -0
  950. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-alloc.h +76 -0
  951. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-backend.h +354 -0
  952. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-blas.h +25 -0
  953. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-cpu.h +143 -0
  954. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-metal.h +66 -0
  955. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml.h +2192 -0
  956. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/gguf.h +202 -0
  957. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/llama.h +1440 -0
  958. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Info.plist +32 -0
  959. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Modules/module.modulemap +17 -0
  960. package/ios/libs/llama.xcframework/xros-arm64/llama.framework/llama +0 -0
  961. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Info.plist +20 -0
  962. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
  963. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +4549 -0
  964. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3470 -0
  965. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-alloc.h +76 -0
  966. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +354 -0
  967. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-blas.h +25 -0
  968. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +143 -0
  969. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-metal.h +66 -0
  970. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +2192 -0
  971. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/gguf.h +202 -0
  972. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/llama.h +1440 -0
  973. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Info.plist +32 -0
  974. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Modules/module.modulemap +17 -0
  975. package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/llama +0 -0
  976. package/lib/module/NativeRNLlamaCpp.js +35 -0
  977. package/lib/module/NativeRNLlamaCpp.js.map +1 -0
  978. package/lib/module/index.js +20 -0
  979. package/lib/module/index.js.map +1 -0
  980. package/lib/module/package.json +1 -0
  981. package/lib/typescript/package.json +1 -0
  982. package/lib/typescript/src/NativeRNLlamaCpp.d.ts +222 -0
  983. package/lib/typescript/src/NativeRNLlamaCpp.d.ts.map +1 -0
  984. package/lib/typescript/src/index.d.ts +5 -0
  985. package/lib/typescript/src/index.d.ts.map +1 -0
  986. package/package.json +161 -0
  987. package/react-native.config.js +15 -0
  988. package/src/NativeRNLlamaCpp.ts +282 -0
  989. package/src/index.tsx +54 -0
@@ -0,0 +1,1610 @@
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import logging
5
+ import argparse
6
+ import os
7
+ import sys
8
+ import numpy
9
+ import enum
10
+ from pathlib import Path
11
+ from typing import Any, Optional, Tuple, Type
12
+ import warnings
13
+
14
+ import numpy as np
15
+ from PySide6.QtWidgets import (
16
+ QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
17
+ QPushButton, QLabel, QLineEdit, QFileDialog, QTableWidget,
18
+ QTableWidgetItem, QComboBox, QMessageBox, QTabWidget,
19
+ QTextEdit, QFormLayout,
20
+ QHeaderView, QDialog, QDialogButtonBox
21
+ )
22
+ from PySide6.QtCore import Qt
23
+
24
+ # Necessary to load the local gguf package
25
+ if "NO_LOCAL_GGUF" not in os.environ and (Path(__file__).parent.parent.parent.parent / 'gguf-py').exists():
26
+ sys.path.insert(0, str(Path(__file__).parent.parent.parent))
27
+
28
+ import gguf
29
+ from gguf import GGUFReader, GGUFWriter, GGUFValueType, ReaderField
30
+ from gguf.constants import TokenType, RopeScalingType, PoolingType, GGMLQuantizationType
31
+
32
+ logger = logging.getLogger("gguf-editor-gui")
33
+
34
+ # Map of key names to enum types for automatic enum interpretation
35
+ KEY_TO_ENUM_TYPE = {
36
+ gguf.Keys.Tokenizer.TOKEN_TYPE: TokenType,
37
+ gguf.Keys.Rope.SCALING_TYPE: RopeScalingType,
38
+ gguf.Keys.LLM.POOLING_TYPE: PoolingType,
39
+ gguf.Keys.General.FILE_TYPE: GGMLQuantizationType,
40
+ }
41
+
42
+ # Define the tokenizer keys that should be edited together
43
+ TOKENIZER_LINKED_KEYS = [
44
+ gguf.Keys.Tokenizer.LIST,
45
+ gguf.Keys.Tokenizer.TOKEN_TYPE,
46
+ gguf.Keys.Tokenizer.SCORES
47
+ ]
48
+
49
+
50
+ class TokenizerEditorDialog(QDialog):
51
+ def __init__(self, tokens, token_types, scores, parent=None):
52
+ super().__init__(parent)
53
+ self.setWindowTitle("Edit Tokenizer Data")
54
+ self.resize(900, 600)
55
+
56
+ self.tokens = tokens.copy() if tokens else []
57
+ self.token_types = token_types.copy() if token_types else []
58
+ self.scores = scores.copy() if scores else []
59
+
60
+ # Ensure all arrays have the same length
61
+ max_len = max(len(self.tokens), len(self.token_types), len(self.scores))
62
+ if len(self.tokens) < max_len:
63
+ self.tokens.extend([""] * (max_len - len(self.tokens)))
64
+ if len(self.token_types) < max_len:
65
+ self.token_types.extend([0] * (max_len - len(self.token_types)))
66
+ if len(self.scores) < max_len:
67
+ self.scores.extend([0.0] * (max_len - len(self.scores)))
68
+
69
+ layout = QVBoxLayout(self)
70
+
71
+ # Add filter controls
72
+ filter_layout = QHBoxLayout()
73
+ filter_layout.addWidget(QLabel("Filter:"))
74
+ self.filter_edit = QLineEdit()
75
+ self.filter_edit.setPlaceholderText("Type to filter tokens...")
76
+ self.filter_edit.textChanged.connect(self.apply_filter)
77
+ filter_layout.addWidget(self.filter_edit)
78
+
79
+ # Add page controls
80
+ self.page_size = 100 # Show 100 items per page
81
+ self.current_page = 0
82
+ self.total_pages = max(1, (len(self.tokens) + self.page_size - 1) // self.page_size)
83
+
84
+ self.page_label = QLabel(f"Page 1 of {self.total_pages}")
85
+ filter_layout.addWidget(self.page_label)
86
+
87
+ prev_page = QPushButton("Previous")
88
+ prev_page.clicked.connect(self.previous_page)
89
+ filter_layout.addWidget(prev_page)
90
+
91
+ next_page = QPushButton("Next")
92
+ next_page.clicked.connect(self.next_page)
93
+ filter_layout.addWidget(next_page)
94
+
95
+ layout.addLayout(filter_layout)
96
+
97
+ # Tokenizer data table
98
+ self.tokens_table = QTableWidget()
99
+ self.tokens_table.setColumnCount(4)
100
+ self.tokens_table.setHorizontalHeaderLabels(["Index", "Token", "Type", "Score"])
101
+ self.tokens_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
102
+ self.tokens_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
103
+ self.tokens_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
104
+ self.tokens_table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
105
+
106
+ layout.addWidget(self.tokens_table)
107
+
108
+ # Controls
109
+ controls_layout = QHBoxLayout()
110
+
111
+ add_button = QPushButton("Add Token")
112
+ add_button.clicked.connect(self.add_token)
113
+ controls_layout.addWidget(add_button)
114
+
115
+ remove_button = QPushButton("Remove Selected")
116
+ remove_button.clicked.connect(self.remove_selected)
117
+ controls_layout.addWidget(remove_button)
118
+
119
+ controls_layout.addStretch()
120
+
121
+ layout.addLayout(controls_layout)
122
+
123
+ # Buttons
124
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
125
+ buttons.accepted.connect(self.accept)
126
+ buttons.rejected.connect(self.reject)
127
+ layout.addWidget(buttons)
128
+
129
+ # Initialize the filtered values
130
+ self.filtered_indices = list(range(len(self.tokens)))
131
+
132
+ # Load data for the first page
133
+ self.load_page()
134
+
135
+ def apply_filter(self):
136
+ """Filter the tokens based on the search text."""
137
+ filter_text = self.filter_edit.text().lower()
138
+
139
+ if not filter_text:
140
+ # No filter, show all values
141
+ self.filtered_indices = list(range(len(self.tokens)))
142
+ else:
143
+ # Apply filter
144
+ self.filtered_indices = []
145
+ for i, token in enumerate(self.tokens):
146
+ if filter_text in str(token).lower():
147
+ self.filtered_indices.append(i)
148
+
149
+ # Reset to first page and reload
150
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
151
+ self.current_page = 0
152
+ self.page_label.setText(f"Page 1 of {self.total_pages}")
153
+ self.load_page()
154
+
155
+ def previous_page(self):
156
+ """Go to the previous page of results."""
157
+ if self.current_page > 0:
158
+ self.current_page -= 1
159
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
160
+ self.load_page()
161
+
162
+ def next_page(self):
163
+ """Go to the next page of results."""
164
+ if self.current_page < self.total_pages - 1:
165
+ self.current_page += 1
166
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
167
+ self.load_page()
168
+
169
+ def load_page(self):
170
+ """Load the current page of tokenizer data."""
171
+ self.tokens_table.setRowCount(0) # Clear the table
172
+
173
+ # Calculate start and end indices for the current page
174
+ start_idx = self.current_page * self.page_size
175
+ end_idx = min(start_idx + self.page_size, len(self.filtered_indices))
176
+
177
+ # Pre-allocate rows for better performance
178
+ self.tokens_table.setRowCount(end_idx - start_idx)
179
+
180
+ for row, i in enumerate(range(start_idx, end_idx)):
181
+ orig_idx = self.filtered_indices[i]
182
+
183
+ # Index
184
+ index_item = QTableWidgetItem(str(orig_idx))
185
+ index_item.setData(Qt.ItemDataRole.UserRole, orig_idx) # Store original index
186
+ index_item.setFlags(index_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
187
+ self.tokens_table.setItem(row, 0, index_item)
188
+
189
+ # Token
190
+ token_item = QTableWidgetItem(str(self.tokens[orig_idx]))
191
+ self.tokens_table.setItem(row, 1, token_item)
192
+
193
+ # Token Type
194
+ token_type = self.token_types[orig_idx] if orig_idx < len(self.token_types) else 0
195
+ try:
196
+ enum_val = TokenType(token_type)
197
+ display_text = f"{enum_val.name} ({token_type})"
198
+ except (ValueError, KeyError):
199
+ display_text = f"Unknown ({token_type})"
200
+
201
+ type_item = QTableWidgetItem(display_text)
202
+ type_item.setData(Qt.ItemDataRole.UserRole, token_type)
203
+
204
+ # Make type cell editable with a double-click handler
205
+ type_item.setFlags(type_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
206
+ self.tokens_table.setItem(row, 2, type_item)
207
+
208
+ # Score
209
+ score = self.scores[orig_idx] if orig_idx < len(self.scores) else 0.0
210
+ score_item = QTableWidgetItem(str(score))
211
+ self.tokens_table.setItem(row, 3, score_item)
212
+
213
+ # Connect double-click handler for token type cells
214
+ self.tokens_table.cellDoubleClicked.connect(self.handle_cell_double_click)
215
+
216
+ def handle_cell_double_click(self, row, column):
217
+ """Handle double-click on a cell, specifically for token type editing."""
218
+ if column == 2: # Token Type column
219
+ orig_item = self.tokens_table.item(row, 0)
220
+ if orig_item:
221
+ orig_idx = orig_item.data(Qt.ItemDataRole.UserRole)
222
+ self.edit_token_type(row, orig_idx)
223
+
224
+ def edit_token_type(self, row, orig_idx):
225
+ """Edit a token type using a dialog with a dropdown of all enum options."""
226
+ current_value = self.token_types[orig_idx] if orig_idx < len(self.token_types) else 0
227
+
228
+ # Create a dialog with enum options
229
+ dialog = QDialog(self)
230
+ dialog.setWindowTitle("Select Token Type")
231
+ layout = QVBoxLayout(dialog)
232
+
233
+ combo = QComboBox()
234
+ for enum_val in TokenType:
235
+ combo.addItem(f"{enum_val.name} ({enum_val.value})", enum_val.value)
236
+
237
+ # Set current value
238
+ try:
239
+ if isinstance(current_value, int):
240
+ enum_val = TokenType(current_value)
241
+ combo.setCurrentText(f"{enum_val.name} ({current_value})")
242
+ except (ValueError, KeyError):
243
+ pass
244
+
245
+ layout.addWidget(combo)
246
+
247
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
248
+ buttons.accepted.connect(dialog.accept)
249
+ buttons.rejected.connect(dialog.reject)
250
+ layout.addWidget(buttons)
251
+
252
+ if dialog.exec() == QDialog.DialogCode.Accepted:
253
+ # Get the selected value
254
+ new_value = combo.currentData()
255
+ enum_val = TokenType(new_value)
256
+ display_text = f"{enum_val.name} ({new_value})"
257
+
258
+ # Update the display
259
+ type_item = self.tokens_table.item(row, 2)
260
+ if type_item:
261
+ type_item.setText(display_text)
262
+ type_item.setData(Qt.ItemDataRole.UserRole, new_value)
263
+
264
+ # Update the actual value
265
+ self.token_types[orig_idx] = new_value
266
+
267
+ def add_token(self):
268
+ """Add a new token to the end of the list."""
269
+ # Add to the end of the arrays
270
+ self.tokens.append("")
271
+ self.token_types.append(0) # Default to normal token
272
+ self.scores.append(0.0)
273
+
274
+ orig_idx = len(self.tokens) - 1
275
+
276
+ # Add to filtered indices if it matches the current filter
277
+ filter_text = self.filter_edit.text().lower()
278
+ if not filter_text or filter_text in "":
279
+ self.filtered_indices.append(orig_idx)
280
+
281
+ # Update pagination
282
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
283
+
284
+ # Go to the last page to show the new item
285
+ self.current_page = self.total_pages - 1
286
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
287
+
288
+ # Reload the page
289
+ self.load_page()
290
+
291
+ def remove_selected(self):
292
+ """Remove selected tokens from all arrays."""
293
+ selected_rows = []
294
+ for item in self.tokens_table.selectedItems():
295
+ row = item.row()
296
+ if row not in selected_rows:
297
+ selected_rows.append(row)
298
+
299
+ if not selected_rows:
300
+ return
301
+
302
+ # Get original indices in descending order to avoid index shifting
303
+ orig_indices = []
304
+ for row in selected_rows:
305
+ orig_item = self.tokens_table.item(row, 0)
306
+ if orig_item:
307
+ orig_indices.append(orig_item.data(Qt.ItemDataRole.UserRole))
308
+ orig_indices.sort(reverse=True)
309
+
310
+ # Remove from all arrays
311
+ for idx in orig_indices:
312
+ if idx < len(self.tokens):
313
+ del self.tokens[idx]
314
+ if idx < len(self.token_types):
315
+ del self.token_types[idx]
316
+ if idx < len(self.scores):
317
+ del self.scores[idx]
318
+
319
+ # Rebuild filtered_indices
320
+ self.filtered_indices = []
321
+ filter_text = self.filter_edit.text().lower()
322
+
323
+ for i, token in enumerate(self.tokens):
324
+ if not filter_text or filter_text in str(token).lower():
325
+ self.filtered_indices.append(i)
326
+
327
+ # Update pagination
328
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
329
+ self.current_page = min(self.current_page, self.total_pages - 1)
330
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
331
+
332
+ # Reload the page
333
+ self.load_page()
334
+
335
+ def get_data(self):
336
+ """Return the edited tokenizer data."""
337
+ return self.tokens, self.token_types, self.scores
338
+
339
+
340
+ class ArrayEditorDialog(QDialog):
341
+ def __init__(self, array_values, element_type, key=None, parent=None):
342
+ super().__init__(parent)
343
+ self.setWindowTitle("Edit Array Values")
344
+ self.resize(700, 500)
345
+
346
+ self.array_values = array_values
347
+ self.element_type = element_type
348
+ self.key = key
349
+
350
+ # Get enum type for this array if applicable
351
+ self.enum_type = None
352
+ if key in KEY_TO_ENUM_TYPE and element_type == GGUFValueType.INT32:
353
+ self.enum_type = KEY_TO_ENUM_TYPE[key]
354
+
355
+ layout = QVBoxLayout(self)
356
+
357
+ # Add enum type information if applicable
358
+ if self.enum_type is not None:
359
+ enum_info_layout = QHBoxLayout()
360
+ enum_label = QLabel(f"Editing {self.enum_type.__name__} values:")
361
+ enum_info_layout.addWidget(enum_label)
362
+
363
+ # Add a legend for the enum values
364
+ enum_values = ", ".join([f"{e.name}={e.value}" for e in self.enum_type])
365
+ enum_values_label = QLabel(f"Available values: {enum_values}")
366
+ enum_values_label.setWordWrap(True)
367
+ enum_info_layout.addWidget(enum_values_label, 1)
368
+
369
+ layout.addLayout(enum_info_layout)
370
+
371
+ # Add search/filter controls
372
+ filter_layout = QHBoxLayout()
373
+ filter_layout.addWidget(QLabel("Filter:"))
374
+ self.filter_edit = QLineEdit()
375
+ self.filter_edit.setPlaceholderText("Type to filter values...")
376
+ self.filter_edit.textChanged.connect(self.apply_filter)
377
+ filter_layout.addWidget(self.filter_edit)
378
+
379
+ # Add page controls for large arrays
380
+ self.page_size = 100 # Show 100 items per page
381
+ self.current_page = 0
382
+ self.total_pages = max(1, (len(array_values) + self.page_size - 1) // self.page_size)
383
+
384
+ self.page_label = QLabel(f"Page 1 of {self.total_pages}")
385
+ filter_layout.addWidget(self.page_label)
386
+
387
+ prev_page = QPushButton("Previous")
388
+ prev_page.clicked.connect(self.previous_page)
389
+ filter_layout.addWidget(prev_page)
390
+
391
+ next_page = QPushButton("Next")
392
+ next_page.clicked.connect(self.next_page)
393
+ filter_layout.addWidget(next_page)
394
+
395
+ layout.addLayout(filter_layout)
396
+
397
+ # Array items table
398
+ self.items_table = QTableWidget()
399
+
400
+ # Set up columns based on whether we have an enum type
401
+ if self.enum_type is not None:
402
+ self.items_table.setColumnCount(3)
403
+ self.items_table.setHorizontalHeaderLabels(["Index", "Value", "Actions"])
404
+ self.items_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
405
+ self.items_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
406
+ self.items_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
407
+ else:
408
+ self.items_table.setColumnCount(2)
409
+ self.items_table.setHorizontalHeaderLabels(["Index", "Value"])
410
+ self.items_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
411
+ self.items_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
412
+
413
+ layout.addWidget(self.items_table)
414
+
415
+ # Controls
416
+ controls_layout = QHBoxLayout()
417
+
418
+ add_button = QPushButton("Add Item")
419
+ add_button.clicked.connect(self.add_item)
420
+ controls_layout.addWidget(add_button)
421
+
422
+ remove_button = QPushButton("Remove Selected")
423
+ remove_button.clicked.connect(self.remove_selected)
424
+ controls_layout.addWidget(remove_button)
425
+
426
+ # Add bulk edit button for enum arrays
427
+ if self.enum_type is not None:
428
+ bulk_edit_button = QPushButton("Bulk Edit Selected")
429
+ bulk_edit_button.clicked.connect(self.bulk_edit_selected)
430
+ controls_layout.addWidget(bulk_edit_button)
431
+
432
+ controls_layout.addStretch()
433
+
434
+ layout.addLayout(controls_layout)
435
+
436
+ # Buttons
437
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
438
+ buttons.accepted.connect(self.accept)
439
+ buttons.rejected.connect(self.reject)
440
+ layout.addWidget(buttons)
441
+
442
+ # Initialize the filtered values
443
+ self.filtered_indices = list(range(len(self.array_values)))
444
+
445
+ # Load array values for the first page
446
+ self.load_page()
447
+
448
+ def apply_filter(self):
449
+ """Filter the array values based on the search text."""
450
+ filter_text = self.filter_edit.text().lower()
451
+
452
+ if not filter_text:
453
+ # No filter, show all values
454
+ self.filtered_indices = list(range(len(self.array_values)))
455
+ else:
456
+ # Apply filter
457
+ self.filtered_indices = []
458
+ for i, value in enumerate(self.array_values):
459
+ # For enum values, search in both name and value
460
+ if self.enum_type is not None and isinstance(value, int):
461
+ try:
462
+ enum_val = self.enum_type(value)
463
+ display_text = f"{enum_val.name} ({value})".lower()
464
+ if filter_text in display_text:
465
+ self.filtered_indices.append(i)
466
+ except (ValueError, KeyError):
467
+ # If not a valid enum value, just check the raw value
468
+ if filter_text in str(value).lower():
469
+ self.filtered_indices.append(i)
470
+ else:
471
+ # For non-enum values, just check the string representation
472
+ if filter_text in str(value).lower():
473
+ self.filtered_indices.append(i)
474
+
475
+ # Reset to first page and reload
476
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
477
+ self.current_page = 0
478
+ self.page_label.setText(f"Page 1 of {self.total_pages}")
479
+ self.load_page()
480
+
481
+ def previous_page(self):
482
+ """Go to the previous page of results."""
483
+ if self.current_page > 0:
484
+ self.current_page -= 1
485
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
486
+ self.load_page()
487
+
488
+ def next_page(self):
489
+ """Go to the next page of results."""
490
+ if self.current_page < self.total_pages - 1:
491
+ self.current_page += 1
492
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
493
+ self.load_page()
494
+
495
+ def load_page(self):
496
+ """Load the current page of array values."""
497
+ self.items_table.setRowCount(0) # Clear the table
498
+
499
+ # Calculate start and end indices for the current page
500
+ start_idx = self.current_page * self.page_size
501
+ end_idx = min(start_idx + self.page_size, len(self.filtered_indices))
502
+
503
+ # Pre-allocate rows for better performance
504
+ self.items_table.setRowCount(end_idx - start_idx)
505
+
506
+ for row, i in enumerate(range(start_idx, end_idx)):
507
+ orig_idx = self.filtered_indices[i]
508
+ value = self.array_values[orig_idx]
509
+
510
+ # Index
511
+ index_item = QTableWidgetItem(str(orig_idx))
512
+ index_item.setData(Qt.ItemDataRole.UserRole, orig_idx) # Store original index
513
+ index_item.setFlags(index_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
514
+ self.items_table.setItem(row, 0, index_item)
515
+
516
+ # Value
517
+ if self.enum_type is not None:
518
+ # Display enum value and name
519
+ try:
520
+ if isinstance(value, (int, numpy.signedinteger)):
521
+ enum_val = self.enum_type(value)
522
+ display_text = f"{enum_val.name} ({value})"
523
+ else:
524
+ display_text = str(value)
525
+ except (ValueError, KeyError):
526
+ display_text = f"Unknown ({value})"
527
+
528
+ # Store the enum value in the item
529
+ value_item = QTableWidgetItem(display_text)
530
+ value_item.setData(Qt.ItemDataRole.UserRole, value)
531
+ value_item.setFlags(value_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
532
+ self.items_table.setItem(row, 1, value_item)
533
+
534
+ # Add an edit button in a separate column
535
+ edit_button = QPushButton("Edit")
536
+ edit_button.setProperty("row", row)
537
+ edit_button.clicked.connect(self.edit_array_enum_value)
538
+
539
+ # Create a widget to hold the button
540
+ button_widget = QWidget()
541
+ button_layout = QHBoxLayout(button_widget)
542
+ button_layout.setContentsMargins(2, 2, 2, 2)
543
+ button_layout.addWidget(edit_button)
544
+ button_layout.addStretch()
545
+
546
+ self.items_table.setCellWidget(row, 2, button_widget)
547
+ else:
548
+ value_item = QTableWidgetItem(str(value))
549
+ self.items_table.setItem(row, 1, value_item)
550
+
551
+ def edit_array_enum_value(self):
552
+ """Handle editing an enum value in the array editor."""
553
+ button = self.sender()
554
+ row = button.property("row")
555
+
556
+ # Get the original index from the table item
557
+ orig_item = self.items_table.item(row, 0)
558
+ new_item = self.items_table.item(row, 1)
559
+ if orig_item and new_item and self.enum_type and self.edit_enum_value(row, self.enum_type):
560
+ orig_idx = orig_item.data(Qt.ItemDataRole.UserRole)
561
+ new_value = new_item.data(Qt.ItemDataRole.UserRole)
562
+ # Update the stored value in the array
563
+ if isinstance(new_value, (int, float, str, bool)):
564
+ self.array_values[orig_idx] = new_value
565
+
566
+ def bulk_edit_selected(self):
567
+ """Edit multiple enum values at once."""
568
+ if not self.enum_type:
569
+ return
570
+
571
+ selected_rows = set()
572
+ for item in self.items_table.selectedItems():
573
+ selected_rows.add(item.row())
574
+
575
+ if not selected_rows:
576
+ QMessageBox.information(self, "No Selection", "Please select at least one row to edit.")
577
+ return
578
+
579
+ # Create a dialog with enum options
580
+ dialog = QDialog(self)
581
+ dialog.setWindowTitle(f"Bulk Edit {self.enum_type.__name__} Values")
582
+ layout = QVBoxLayout(dialog)
583
+
584
+ layout.addWidget(QLabel(f"Set {len(selected_rows)} selected items to:"))
585
+
586
+ combo = QComboBox()
587
+ for enum_val in self.enum_type:
588
+ combo.addItem(f"{enum_val.name} ({enum_val.value})", enum_val.value)
589
+
590
+ layout.addWidget(combo)
591
+
592
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
593
+ buttons.accepted.connect(dialog.accept)
594
+ buttons.rejected.connect(dialog.reject)
595
+ layout.addWidget(buttons)
596
+
597
+ if dialog.exec() == QDialog.DialogCode.Accepted:
598
+ # Get the selected value
599
+ new_value = combo.currentData()
600
+ enum_val = self.enum_type(new_value)
601
+ display_text = f"{enum_val.name} ({new_value})"
602
+
603
+ # Update all selected rows
604
+ for row in selected_rows:
605
+ orig_item = self.items_table.item(row, 0)
606
+ new_item = self.items_table.item(row, 1)
607
+ if orig_item and new_item:
608
+ orig_idx = orig_item.data(Qt.ItemDataRole.UserRole)
609
+ self.array_values[orig_idx] = new_value
610
+
611
+ # Update the display
612
+ new_item.setText(display_text)
613
+ new_item.setData(Qt.ItemDataRole.UserRole, new_value)
614
+
615
+ def add_item(self):
616
+ # Add to the end of the array
617
+ orig_idx = len(self.array_values)
618
+
619
+ # Add default value based on type
620
+ if self.enum_type is not None:
621
+ # Default to first enum value
622
+ default_value = list(self.enum_type)[0].value
623
+ self.array_values.append(default_value)
624
+ else:
625
+ if self.element_type == GGUFValueType.STRING:
626
+ self.array_values.append("")
627
+ else:
628
+ self.array_values.append(0)
629
+
630
+ # Add to filtered indices if it matches the current filter
631
+ self.filtered_indices.append(orig_idx)
632
+
633
+ # Update pagination
634
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
635
+
636
+ # Go to the last page to show the new item
637
+ self.current_page = self.total_pages - 1
638
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
639
+
640
+ # Reload the page
641
+ self.load_page()
642
+
643
+ def remove_selected(self):
644
+ selected_rows = []
645
+ for item in self.items_table.selectedItems():
646
+ row = item.row()
647
+ if row not in selected_rows:
648
+ selected_rows.append(row)
649
+
650
+ if not selected_rows:
651
+ return
652
+
653
+ # Get original indices in descending order to avoid index shifting
654
+ orig_indices = list()
655
+ for row in selected_rows:
656
+ orig_item = self.items_table.item(row, 0)
657
+ if orig_item:
658
+ orig_indices.append(orig_item.data(Qt.ItemDataRole.UserRole))
659
+ orig_indices.sort(reverse=True)
660
+
661
+ # Remove from array_values
662
+ for idx in orig_indices:
663
+ del self.array_values[idx]
664
+
665
+ # Rebuild filtered_indices
666
+ self.filtered_indices = []
667
+ filter_text = self.filter_edit.text().lower()
668
+
669
+ for i, value in enumerate(self.array_values):
670
+ if not filter_text:
671
+ self.filtered_indices.append(i)
672
+ else:
673
+ # Apply filter
674
+ if self.enum_type is not None and isinstance(value, int):
675
+ try:
676
+ enum_val = self.enum_type(value)
677
+ display_text = f"{enum_val.name} ({value})".lower()
678
+ if filter_text in display_text:
679
+ self.filtered_indices.append(i)
680
+ except (ValueError, KeyError):
681
+ if filter_text in str(value).lower():
682
+ self.filtered_indices.append(i)
683
+ else:
684
+ if filter_text in str(value).lower():
685
+ self.filtered_indices.append(i)
686
+
687
+ # Update pagination
688
+ self.total_pages = max(1, (len(self.filtered_indices) + self.page_size - 1) // self.page_size)
689
+ self.current_page = min(self.current_page, self.total_pages - 1)
690
+ self.page_label.setText(f"Page {self.current_page + 1} of {self.total_pages}")
691
+
692
+ # Reload the page
693
+ self.load_page()
694
+
695
+ def edit_enum_value(self, row: int, enum_type: Type[enum.Enum]):
696
+ """Edit an enum value using a dialog with a dropdown of all enum options."""
697
+ # Get the original index from the table item
698
+ orig_item = self.items_table.item(row, 0)
699
+ if orig_item:
700
+ orig_idx = orig_item.data(Qt.ItemDataRole.UserRole)
701
+ else:
702
+ return
703
+ current_value = self.array_values[orig_idx]
704
+
705
+ # Create a dialog with enum options
706
+ dialog = QDialog(self)
707
+ dialog.setWindowTitle(f"Select {enum_type.__name__} Value")
708
+ layout = QVBoxLayout(dialog)
709
+
710
+ # Add description
711
+ description = QLabel(f"Select a {enum_type.__name__} value:")
712
+ layout.addWidget(description)
713
+
714
+ # Use a combo box for quick selection
715
+ combo = QComboBox()
716
+ for enum_val in enum_type:
717
+ combo.addItem(f"{enum_val.name} ({enum_val.value})", enum_val.value)
718
+
719
+ # Set current value
720
+ try:
721
+ if isinstance(current_value, int):
722
+ enum_val = enum_type(current_value)
723
+ combo.setCurrentText(f"{enum_val.name} ({current_value})")
724
+ except (ValueError, KeyError):
725
+ pass
726
+
727
+ layout.addWidget(combo)
728
+
729
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
730
+ buttons.accepted.connect(dialog.accept)
731
+ buttons.rejected.connect(dialog.reject)
732
+ layout.addWidget(buttons)
733
+
734
+ if dialog.exec() == QDialog.DialogCode.Accepted:
735
+ # Update the value display and stored data
736
+ new_value = combo.currentData()
737
+ enum_val = enum_type(new_value)
738
+ display_text = f"{enum_val.name} ({new_value})"
739
+
740
+ new_item = self.items_table.item(row, 1)
741
+ if new_item:
742
+ new_item.setText(display_text)
743
+ new_item.setData(Qt.ItemDataRole.UserRole, new_value)
744
+
745
+ # Update the actual array value
746
+ self.array_values[orig_idx] = new_value
747
+ return True
748
+ return False
749
+
750
+ def get_array_values(self):
751
+ # The array_values list is kept up-to-date as edits are made
752
+ return self.array_values
753
+
754
+
755
+ class AddMetadataDialog(QDialog):
756
+ def __init__(self, parent=None):
757
+ super().__init__(parent)
758
+ self.setWindowTitle("Add Metadata")
759
+ self.resize(400, 200)
760
+
761
+ layout = QVBoxLayout(self)
762
+
763
+ form_layout = QFormLayout()
764
+
765
+ self.key_edit = QLineEdit()
766
+ form_layout.addRow("Key:", self.key_edit)
767
+
768
+ self.type_combo = QComboBox()
769
+ for value_type in GGUFValueType:
770
+ if value_type != GGUFValueType.ARRAY: # Skip array type for simplicity
771
+ self.type_combo.addItem(value_type.name, value_type)
772
+ form_layout.addRow("Type:", self.type_combo)
773
+
774
+ self.value_edit = QTextEdit()
775
+ form_layout.addRow("Value:", self.value_edit)
776
+
777
+ layout.addLayout(form_layout)
778
+
779
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
780
+ buttons.accepted.connect(self.accept)
781
+ buttons.rejected.connect(self.reject)
782
+ layout.addWidget(buttons)
783
+
784
+ def get_data(self) -> Tuple[str, GGUFValueType, Any]:
785
+ key = self.key_edit.text()
786
+ value_type = self.type_combo.currentData()
787
+ value_text = self.value_edit.toPlainText()
788
+
789
+ # Convert value based on type
790
+ if value_type == GGUFValueType.UINT8:
791
+ value = np.uint8(int(value_text))
792
+ elif value_type == GGUFValueType.INT8:
793
+ value = np.int8(int(value_text))
794
+ elif value_type == GGUFValueType.UINT16:
795
+ value = np.uint16(int(value_text))
796
+ elif value_type == GGUFValueType.INT16:
797
+ value = np.int16(int(value_text))
798
+ elif value_type == GGUFValueType.UINT32:
799
+ value = np.uint32(int(value_text))
800
+ elif value_type == GGUFValueType.INT32:
801
+ value = np.int32(int(value_text))
802
+ elif value_type == GGUFValueType.FLOAT32:
803
+ value = np.float32(float(value_text))
804
+ elif value_type == GGUFValueType.BOOL:
805
+ value = value_text.lower() in ('true', 'yes', '1')
806
+ elif value_type == GGUFValueType.STRING:
807
+ value = value_text
808
+ else:
809
+ value = value_text
810
+
811
+ return key, value_type, value
812
+
813
+
814
+ class GGUFEditorWindow(QMainWindow):
815
+ def __init__(self):
816
+ super().__init__()
817
+
818
+ self.setWindowTitle("GGUF Editor")
819
+ self.resize(1000, 800)
820
+
821
+ self.current_file = None
822
+ self.reader = None
823
+ self.modified = False
824
+ self.metadata_changes = {} # Store changes to apply when saving
825
+ self.metadata_to_remove = set() # Store keys to remove when saving
826
+
827
+ self.setup_ui()
828
+
829
+ def setup_ui(self):
830
+ central_widget = QWidget()
831
+ self.setCentralWidget(central_widget)
832
+
833
+ main_layout = QVBoxLayout(central_widget)
834
+
835
+ # File controls
836
+ file_layout = QHBoxLayout()
837
+
838
+ self.file_path_edit = QLineEdit()
839
+ self.file_path_edit.setReadOnly(True)
840
+ file_layout.addWidget(self.file_path_edit)
841
+
842
+ open_button = QPushButton("Open GGUF")
843
+ open_button.clicked.connect(self.open_file)
844
+ file_layout.addWidget(open_button)
845
+
846
+ save_button = QPushButton("Save As...")
847
+ save_button.clicked.connect(self.save_file)
848
+ file_layout.addWidget(save_button)
849
+
850
+ main_layout.addLayout(file_layout)
851
+
852
+ # Tabs for different views
853
+ self.tabs = QTabWidget()
854
+
855
+ # Metadata tab
856
+ self.metadata_tab = QWidget()
857
+ metadata_layout = QVBoxLayout(self.metadata_tab)
858
+
859
+ # Metadata table
860
+ self.metadata_table = QTableWidget()
861
+ self.metadata_table.setColumnCount(4)
862
+ self.metadata_table.setHorizontalHeaderLabels(["Key", "Type", "Value", "Actions"])
863
+ self.metadata_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
864
+ self.metadata_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
865
+ self.metadata_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
866
+ self.metadata_table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
867
+ metadata_layout.addWidget(self.metadata_table)
868
+
869
+ # Metadata controls
870
+ metadata_controls = QHBoxLayout()
871
+
872
+ add_metadata_button = QPushButton("Add Metadata")
873
+ add_metadata_button.clicked.connect(self.add_metadata)
874
+ metadata_controls.addWidget(add_metadata_button)
875
+
876
+ metadata_controls.addStretch()
877
+
878
+ metadata_layout.addLayout(metadata_controls)
879
+
880
+ # Tensors tab
881
+ self.tensors_tab = QWidget()
882
+ tensors_layout = QVBoxLayout(self.tensors_tab)
883
+
884
+ self.tensors_table = QTableWidget()
885
+ self.tensors_table.setColumnCount(5)
886
+ self.tensors_table.setHorizontalHeaderLabels(["Name", "Type", "Shape", "Elements", "Size (bytes)"])
887
+ self.tensors_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
888
+ self.tensors_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
889
+ self.tensors_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
890
+ self.tensors_table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
891
+ self.tensors_table.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents)
892
+ tensors_layout.addWidget(self.tensors_table)
893
+
894
+ # Add tabs to tab widget
895
+ self.tabs.addTab(self.metadata_tab, "Metadata")
896
+ self.tabs.addTab(self.tensors_tab, "Tensors")
897
+
898
+ main_layout.addWidget(self.tabs)
899
+
900
+ # Status bar
901
+ self.statusBar().showMessage("Ready")
902
+
903
+ def load_file(self, file_path):
904
+ """Load a GGUF file by path"""
905
+ try:
906
+ self.statusBar().showMessage(f"Loading {file_path}...")
907
+ QApplication.processEvents()
908
+
909
+ self.reader = GGUFReader(file_path, 'r')
910
+ self.current_file = file_path
911
+ self.file_path_edit.setText(file_path)
912
+
913
+ self.load_metadata()
914
+ self.load_tensors()
915
+
916
+ self.metadata_changes = {}
917
+ self.metadata_to_remove = set()
918
+ self.modified = False
919
+
920
+ self.statusBar().showMessage(f"Loaded {file_path}")
921
+ return True
922
+ except Exception as e:
923
+ QMessageBox.critical(self, "Error", f"Failed to open file: {str(e)}")
924
+ self.statusBar().showMessage("Error loading file")
925
+ return False
926
+
927
+ def open_file(self):
928
+ file_path, _ = QFileDialog.getOpenFileName(
929
+ self, "Open GGUF File", "", "GGUF Files (*.gguf);;All Files (*)"
930
+ )
931
+
932
+ if not file_path:
933
+ return
934
+
935
+ self.load_file(file_path)
936
+
937
+ def load_metadata(self):
938
+ self.metadata_table.setRowCount(0)
939
+
940
+ if not self.reader:
941
+ return
942
+
943
+ # Disconnect to prevent triggering during loading
944
+ with warnings.catch_warnings():
945
+ warnings.filterwarnings('ignore')
946
+ self.metadata_table.itemChanged.disconnect(self.on_metadata_changed)
947
+
948
+ for i, (key, field) in enumerate(self.reader.fields.items()):
949
+ self.metadata_table.insertRow(i)
950
+
951
+ # Key
952
+ key_item = QTableWidgetItem(key)
953
+ key_item.setFlags(key_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
954
+ self.metadata_table.setItem(i, 0, key_item)
955
+
956
+ # Type
957
+ if not field.types:
958
+ type_str = "N/A"
959
+ elif field.types[0] == GGUFValueType.ARRAY:
960
+ nest_count = len(field.types) - 1
961
+ element_type = field.types[-1].name
962
+ # Check if this is an enum array
963
+ enum_type = self.get_enum_for_key(key)
964
+ if enum_type is not None and field.types[-1] == GGUFValueType.INT32:
965
+ element_type = enum_type.__name__
966
+ type_str = '[' * nest_count + element_type + ']' * nest_count
967
+ else:
968
+ type_str = str(field.types[0].name)
969
+ # Check if this is an enum field
970
+ enum_type = self.get_enum_for_key(key)
971
+ if enum_type is not None and field.types[0] == GGUFValueType.INT32:
972
+ type_str = enum_type.__name__
973
+
974
+ type_item = QTableWidgetItem(type_str)
975
+ type_item.setFlags(type_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
976
+ self.metadata_table.setItem(i, 1, type_item)
977
+
978
+ # Value
979
+ value_str = self.format_field_value(field)
980
+ value_item = QTableWidgetItem(value_str)
981
+
982
+ # Make only simple values editable
983
+ if len(field.types) == 1 and field.types[0] != GGUFValueType.ARRAY:
984
+ value_item.setFlags(value_item.flags() | Qt.ItemFlag.ItemIsEditable)
985
+ else:
986
+ value_item.setFlags(value_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
987
+
988
+ self.metadata_table.setItem(i, 2, value_item)
989
+
990
+ # Actions
991
+ actions_widget = QWidget()
992
+ actions_layout = QHBoxLayout(actions_widget)
993
+ actions_layout.setContentsMargins(2, 2, 2, 2)
994
+
995
+ # Add Edit button for arrays and enum fields
996
+ if field.types and field.types[0] == GGUFValueType.ARRAY:
997
+ edit_button = QPushButton("Edit")
998
+ edit_button.setProperty("row", i)
999
+ edit_button.setProperty("key", key)
1000
+ edit_button.clicked.connect(self.edit_array_metadata)
1001
+ actions_layout.addWidget(edit_button)
1002
+
1003
+ # Add special label for tokenizer linked fields
1004
+ if key in TOKENIZER_LINKED_KEYS:
1005
+ edit_button.setText("Edit Tokenizer")
1006
+ edit_button.setToolTip("Edit all tokenizer data together")
1007
+ elif len(field.types) == 1 and self.get_enum_for_key(key) is not None:
1008
+ edit_button = QPushButton("Edit")
1009
+ edit_button.setProperty("row", i)
1010
+ edit_button.setProperty("key", key)
1011
+ edit_button.clicked.connect(self.edit_metadata_enum)
1012
+ actions_layout.addWidget(edit_button)
1013
+
1014
+ remove_button = QPushButton("Remove")
1015
+ remove_button.setProperty("row", i)
1016
+ remove_button.setProperty("key", key)
1017
+ remove_button.clicked.connect(self.remove_metadata)
1018
+ actions_layout.addWidget(remove_button)
1019
+
1020
+ self.metadata_table.setCellWidget(i, 3, actions_widget)
1021
+
1022
+ # Reconnect after loading
1023
+ self.metadata_table.itemChanged.connect(self.on_metadata_changed)
1024
+
1025
+ def extract_array_values(self, field: ReaderField) -> list:
1026
+ """Extract all values from an array field."""
1027
+ if not field.types or field.types[0] != GGUFValueType.ARRAY:
1028
+ return []
1029
+
1030
+ curr_type = field.types[1]
1031
+ array_values = []
1032
+ total_elements = len(field.data)
1033
+
1034
+ if curr_type == GGUFValueType.STRING:
1035
+ for element_pos in range(total_elements):
1036
+ value_string = str(bytes(field.parts[-1 - (total_elements - element_pos - 1) * 2]), encoding='utf-8')
1037
+ array_values.append(value_string)
1038
+ elif self.reader and curr_type in self.reader.gguf_scalar_to_np:
1039
+ for element_pos in range(total_elements):
1040
+ array_values.append(field.parts[-1 - (total_elements - element_pos - 1)][0])
1041
+
1042
+ return array_values
1043
+
1044
+ def get_enum_for_key(self, key: str) -> Optional[Type[enum.Enum]]:
1045
+ """Get the enum type for a given key if it exists."""
1046
+ return KEY_TO_ENUM_TYPE.get(key)
1047
+
1048
+ def format_enum_value(self, value: Any, enum_type: Type[enum.Enum]) -> str:
1049
+ """Format a value as an enum if possible."""
1050
+ try:
1051
+ if isinstance(value, (int, str)):
1052
+ enum_value = enum_type(value)
1053
+ return f"{enum_value.name} ({value})"
1054
+ except (ValueError, KeyError):
1055
+ pass
1056
+ return str(value)
1057
+
1058
+ def format_field_value(self, field: ReaderField) -> str:
1059
+ if not field.types:
1060
+ return "N/A"
1061
+
1062
+ if len(field.types) == 1:
1063
+ curr_type = field.types[0]
1064
+ if curr_type == GGUFValueType.STRING:
1065
+ return str(bytes(field.parts[-1]), encoding='utf-8')
1066
+ elif self.reader and curr_type in self.reader.gguf_scalar_to_np:
1067
+ value = field.parts[-1][0]
1068
+ # Check if this field has an enum type
1069
+ enum_type = self.get_enum_for_key(field.name)
1070
+ if enum_type is not None:
1071
+ return self.format_enum_value(value, enum_type)
1072
+ return str(value)
1073
+
1074
+ if field.types[0] == GGUFValueType.ARRAY:
1075
+ array_values = self.extract_array_values(field)
1076
+ render_element = min(5, len(array_values))
1077
+
1078
+ # Get enum type for this array if applicable
1079
+ enum_type = self.get_enum_for_key(field.name)
1080
+
1081
+ if enum_type is not None:
1082
+ array_elements = []
1083
+ for i in range(render_element):
1084
+ array_elements.append(self.format_enum_value(array_values[i], enum_type))
1085
+ else:
1086
+ array_elements = [str(array_values[i]) for i in range(render_element)]
1087
+
1088
+ return f"[ {', '.join(array_elements).strip()}{', ...' if len(array_values) > len(array_elements) else ''} ]"
1089
+
1090
+ return "Complex value"
1091
+
1092
+ def load_tensors(self):
1093
+ self.tensors_table.setRowCount(0)
1094
+
1095
+ if not self.reader:
1096
+ return
1097
+
1098
+ for i, tensor in enumerate(self.reader.tensors):
1099
+ self.tensors_table.insertRow(i)
1100
+
1101
+ # Name
1102
+ name_item = QTableWidgetItem(tensor.name)
1103
+ name_item.setFlags(name_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1104
+ self.tensors_table.setItem(i, 0, name_item)
1105
+
1106
+ # Type
1107
+ type_item = QTableWidgetItem(tensor.tensor_type.name)
1108
+ type_item.setFlags(type_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1109
+ self.tensors_table.setItem(i, 1, type_item)
1110
+
1111
+ # Shape
1112
+ shape_str = " × ".join(str(d) for d in tensor.shape)
1113
+ shape_item = QTableWidgetItem(shape_str)
1114
+ shape_item.setFlags(shape_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1115
+ self.tensors_table.setItem(i, 2, shape_item)
1116
+
1117
+ # Elements
1118
+ elements_item = QTableWidgetItem(str(tensor.n_elements))
1119
+ elements_item.setFlags(elements_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1120
+ self.tensors_table.setItem(i, 3, elements_item)
1121
+
1122
+ # Size
1123
+ size_item = QTableWidgetItem(f"{tensor.n_bytes:,}")
1124
+ size_item.setFlags(size_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1125
+ self.tensors_table.setItem(i, 4, size_item)
1126
+
1127
+ def on_metadata_changed(self, item):
1128
+ if item.column() != 2: # Only handle value column changes
1129
+ return
1130
+
1131
+ row = item.row()
1132
+ orig_item = self.metadata_table.item(row, 0)
1133
+ key = None
1134
+ if orig_item:
1135
+ key = orig_item.text()
1136
+ new_value = item.text()
1137
+
1138
+ field = None
1139
+ if self.reader and key:
1140
+ field = self.reader.get_field(key)
1141
+ if not field or not field.types or not key:
1142
+ return
1143
+
1144
+ value_type = field.types[0]
1145
+
1146
+ # Check if this is an enum field
1147
+ enum_type = self.get_enum_for_key(key)
1148
+ if enum_type is not None and value_type == GGUFValueType.INT32:
1149
+ # Try to parse the enum value from the text
1150
+ try:
1151
+ # Check if it's a name
1152
+ try:
1153
+ enum_val = enum_type[new_value]
1154
+ converted_value = enum_val.value
1155
+ except (KeyError, AttributeError):
1156
+ # Check if it's a number or "NAME (value)" format
1157
+ if '(' in new_value and ')' in new_value:
1158
+ # Extract the value from "NAME (value)" format
1159
+ value_part = new_value.split('(')[1].split(')')[0].strip()
1160
+ converted_value = int(value_part)
1161
+ else:
1162
+ # Try to convert directly to int
1163
+ converted_value = int(new_value)
1164
+
1165
+ # Validate that it's a valid enum value
1166
+ enum_type(converted_value)
1167
+
1168
+ # Store the change
1169
+ self.metadata_changes[key] = (value_type, converted_value)
1170
+ self.modified = True
1171
+
1172
+ # Update display with formatted enum value
1173
+ formatted_value = self.format_enum_value(converted_value, enum_type)
1174
+ item.setText(formatted_value)
1175
+
1176
+ self.statusBar().showMessage(f"Changed {key} to {formatted_value}")
1177
+ return
1178
+ except (ValueError, KeyError) as e:
1179
+ QMessageBox.warning(
1180
+ self,
1181
+ f"Invalid Enum Value ({e})",
1182
+ f"'{new_value}' is not a valid {enum_type.__name__} value.\n"
1183
+ f"Valid values are: {', '.join(v.name for v in enum_type)}")
1184
+
1185
+ # Revert to original value
1186
+ original_value = self.format_field_value(field)
1187
+ item.setText(original_value)
1188
+ return
1189
+
1190
+ try:
1191
+ # Convert the string value to the appropriate type
1192
+ if value_type == GGUFValueType.UINT8:
1193
+ converted_value = np.uint8(int(new_value))
1194
+ elif value_type == GGUFValueType.INT8:
1195
+ converted_value = np.int8(int(new_value))
1196
+ elif value_type == GGUFValueType.UINT16:
1197
+ converted_value = np.uint16(int(new_value))
1198
+ elif value_type == GGUFValueType.INT16:
1199
+ converted_value = np.int16(int(new_value))
1200
+ elif value_type == GGUFValueType.UINT32:
1201
+ converted_value = np.uint32(int(new_value))
1202
+ elif value_type == GGUFValueType.INT32:
1203
+ converted_value = np.int32(int(new_value))
1204
+ elif value_type == GGUFValueType.FLOAT32:
1205
+ converted_value = np.float32(float(new_value))
1206
+ elif value_type == GGUFValueType.BOOL:
1207
+ converted_value = new_value.lower() in ('true', 'yes', '1')
1208
+ elif value_type == GGUFValueType.STRING:
1209
+ converted_value = new_value
1210
+ else:
1211
+ # Unsupported type for editing
1212
+ return
1213
+
1214
+ # Store the change
1215
+ self.metadata_changes[key] = (value_type, converted_value)
1216
+ self.modified = True
1217
+
1218
+ self.statusBar().showMessage(f"Changed {key} to {new_value}")
1219
+ except ValueError:
1220
+ QMessageBox.warning(self, "Invalid Value", f"The value '{new_value}' is not valid for type {value_type.name}")
1221
+
1222
+ # Revert to original value
1223
+ original_value = self.format_field_value(field)
1224
+ item.setText(original_value)
1225
+
1226
+ def remove_metadata(self):
1227
+ button = self.sender()
1228
+ key = button.property("key")
1229
+ row = button.property("row")
1230
+
1231
+ reply = QMessageBox.question(
1232
+ self, "Confirm Removal",
1233
+ f"Are you sure you want to remove the metadata key '{key}'?",
1234
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No
1235
+ )
1236
+
1237
+ if reply == QMessageBox.StandardButton.Yes:
1238
+ self.metadata_table.removeRow(row)
1239
+ self.metadata_to_remove.add(key)
1240
+
1241
+ # If we previously had changes for this key, remove them
1242
+ if key in self.metadata_changes:
1243
+ del self.metadata_changes[key]
1244
+
1245
+ self.modified = True
1246
+ self.statusBar().showMessage(f"Marked {key} for removal")
1247
+
1248
+ def edit_metadata_enum(self):
1249
+ """Edit an enum metadata field."""
1250
+ button = self.sender()
1251
+ key = button.property("key")
1252
+ row = button.property("row")
1253
+
1254
+ field = None
1255
+ if self.reader:
1256
+ field = self.reader.get_field(key)
1257
+ if not field or not field.types:
1258
+ return
1259
+
1260
+ enum_type = self.get_enum_for_key(key)
1261
+ if enum_type is None:
1262
+ return
1263
+
1264
+ # Get current value
1265
+ current_value = field.contents()
1266
+
1267
+ # Create a dialog with enum options
1268
+ dialog = QDialog(self)
1269
+ dialog.setWindowTitle(f"Select {enum_type.__name__} Value")
1270
+ layout = QVBoxLayout(dialog)
1271
+
1272
+ combo = QComboBox()
1273
+ for enum_val in enum_type:
1274
+ combo.addItem(f"{enum_val.name} ({enum_val.value})", enum_val.value)
1275
+
1276
+ # Set current value
1277
+ try:
1278
+ if isinstance(current_value, (int, str)):
1279
+ enum_val = enum_type(current_value)
1280
+ combo.setCurrentText(f"{enum_val.name} ({current_value})")
1281
+ except (ValueError, KeyError):
1282
+ pass
1283
+
1284
+ layout.addWidget(combo)
1285
+
1286
+ buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
1287
+ buttons.accepted.connect(dialog.accept)
1288
+ buttons.rejected.connect(dialog.reject)
1289
+ layout.addWidget(buttons)
1290
+
1291
+ if dialog.exec() == QDialog.DialogCode.Accepted:
1292
+ # Get the selected value
1293
+ new_value = combo.currentData()
1294
+ enum_val = enum_type(new_value)
1295
+
1296
+ # Store the change
1297
+ self.metadata_changes[key] = (field.types[0], new_value)
1298
+ self.modified = True
1299
+
1300
+ # Update display
1301
+ display_text = f"{enum_val.name} ({new_value})"
1302
+ target_item = self.metadata_table.item(row, 2)
1303
+ if target_item:
1304
+ target_item.setText(display_text)
1305
+
1306
+ self.statusBar().showMessage(f"Changed {key} to {display_text}")
1307
+
1308
+ def edit_array_metadata(self):
1309
+ button = self.sender()
1310
+ key = button.property("key")
1311
+ row = button.property("row")
1312
+
1313
+ # Check if this is one of the linked tokenizer keys
1314
+ if key in TOKENIZER_LINKED_KEYS:
1315
+ self.edit_tokenizer_metadata(key)
1316
+ return
1317
+
1318
+ field = None
1319
+ if self.reader:
1320
+ field = self.reader.get_field(key)
1321
+ if not field or not field.types or field.types[0] != GGUFValueType.ARRAY:
1322
+ return
1323
+
1324
+ # Get array element type
1325
+ element_type = field.types[1]
1326
+
1327
+ # Extract array values
1328
+ array_values = self.extract_array_values(field)
1329
+
1330
+ # Open array editor dialog
1331
+ dialog = ArrayEditorDialog(array_values, element_type, key, self)
1332
+ if dialog.exec() == QDialog.DialogCode.Accepted:
1333
+ new_values = dialog.get_array_values()
1334
+
1335
+ # Store the change
1336
+ self.metadata_changes[key] = (GGUFValueType.ARRAY, (element_type, new_values))
1337
+ self.modified = True
1338
+
1339
+ # Update display
1340
+ enum_type = self.get_enum_for_key(key)
1341
+ if enum_type is not None and element_type == GGUFValueType.INT32:
1342
+ value_str = f"[ {', '.join(self.format_enum_value(v, enum_type) for v in new_values[:5])}{', ...' if len(new_values) > 5 else ''} ]"
1343
+ else:
1344
+ value_str = f"[ {', '.join(str(v) for v in new_values[:5])}{', ...' if len(new_values) > 5 else ''} ]"
1345
+ target_item = self.metadata_table.item(row, 2)
1346
+ if target_item:
1347
+ target_item.setText(value_str)
1348
+
1349
+ self.statusBar().showMessage(f"Updated array values for {key}")
1350
+
1351
+ def edit_tokenizer_metadata(self, trigger_key):
1352
+ """Edit the linked tokenizer metadata arrays together."""
1353
+ if not self.reader:
1354
+ return
1355
+
1356
+ # Get all three fields
1357
+ tokens_field = self.reader.get_field(gguf.Keys.Tokenizer.LIST)
1358
+ token_types_field = self.reader.get_field(gguf.Keys.Tokenizer.TOKEN_TYPE)
1359
+ scores_field = self.reader.get_field(gguf.Keys.Tokenizer.SCORES)
1360
+
1361
+ # Extract values from each field
1362
+ tokens = self.extract_array_values(tokens_field) if tokens_field else []
1363
+ token_types = self.extract_array_values(token_types_field) if token_types_field else []
1364
+ scores = self.extract_array_values(scores_field) if scores_field else []
1365
+
1366
+ # Apply any pending changes
1367
+ if gguf.Keys.Tokenizer.LIST in self.metadata_changes:
1368
+ _, (_, tokens) = self.metadata_changes[gguf.Keys.Tokenizer.LIST]
1369
+ if gguf.Keys.Tokenizer.TOKEN_TYPE in self.metadata_changes:
1370
+ _, (_, token_types) = self.metadata_changes[gguf.Keys.Tokenizer.TOKEN_TYPE]
1371
+ if gguf.Keys.Tokenizer.SCORES in self.metadata_changes:
1372
+ _, (_, scores) = self.metadata_changes[gguf.Keys.Tokenizer.SCORES]
1373
+
1374
+ # Open the tokenizer editor dialog
1375
+ dialog = TokenizerEditorDialog(tokens, token_types, scores, self)
1376
+ if dialog.exec() == QDialog.DialogCode.Accepted:
1377
+ new_tokens, new_token_types, new_scores = dialog.get_data()
1378
+
1379
+ # Store changes for all three arrays
1380
+ if tokens_field:
1381
+ self.metadata_changes[gguf.Keys.Tokenizer.LIST] = (
1382
+ GGUFValueType.ARRAY,
1383
+ (tokens_field.types[1], new_tokens)
1384
+ )
1385
+
1386
+ if token_types_field:
1387
+ self.metadata_changes[gguf.Keys.Tokenizer.TOKEN_TYPE] = (
1388
+ GGUFValueType.ARRAY,
1389
+ (token_types_field.types[1], new_token_types)
1390
+ )
1391
+
1392
+ if scores_field:
1393
+ self.metadata_changes[gguf.Keys.Tokenizer.SCORES] = (
1394
+ GGUFValueType.ARRAY,
1395
+ (scores_field.types[1], new_scores)
1396
+ )
1397
+
1398
+ self.modified = True
1399
+
1400
+ # Update display for all three fields
1401
+ self.update_tokenizer_display(gguf.Keys.Tokenizer.LIST, new_tokens)
1402
+ self.update_tokenizer_display(gguf.Keys.Tokenizer.TOKEN_TYPE, new_token_types)
1403
+ self.update_tokenizer_display(gguf.Keys.Tokenizer.SCORES, new_scores)
1404
+
1405
+ self.statusBar().showMessage("Updated tokenizer data")
1406
+
1407
+ def update_tokenizer_display(self, key, values):
1408
+ """Update the display of a tokenizer field in the metadata table."""
1409
+ for row in range(self.metadata_table.rowCount()):
1410
+ key_item = self.metadata_table.item(row, 0)
1411
+ if key_item and key_item.text() == key:
1412
+ value_str = f"[ {', '.join(str(v) for v in values[:5])}{', ...' if len(values) > 5 else ''} ]"
1413
+ value_item = self.metadata_table.item(row, 2)
1414
+ if value_item:
1415
+ value_item.setText(value_str)
1416
+ break
1417
+
1418
+ def add_metadata(self):
1419
+ dialog = AddMetadataDialog(self)
1420
+ if dialog.exec() == QDialog.DialogCode.Accepted:
1421
+ key, value_type, value = dialog.get_data()
1422
+
1423
+ if not key:
1424
+ QMessageBox.warning(self, "Invalid Key", "Key cannot be empty")
1425
+ return
1426
+
1427
+ # Check if key already exists
1428
+ for row in range(self.metadata_table.rowCount()):
1429
+ orig_item = self.metadata_table.item(row, 0)
1430
+ if orig_item and orig_item.text() == key:
1431
+ QMessageBox.warning(self, "Duplicate Key", f"Key '{key}' already exists")
1432
+ return
1433
+
1434
+ # Add to table
1435
+ row = self.metadata_table.rowCount()
1436
+ self.metadata_table.insertRow(row)
1437
+
1438
+ # Key
1439
+ key_item = QTableWidgetItem(key)
1440
+ key_item.setFlags(key_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1441
+ self.metadata_table.setItem(row, 0, key_item)
1442
+
1443
+ # Type
1444
+ type_item = QTableWidgetItem(value_type.name)
1445
+ type_item.setFlags(type_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
1446
+ self.metadata_table.setItem(row, 1, type_item)
1447
+
1448
+ # Value
1449
+ value_item = QTableWidgetItem(str(value))
1450
+ value_item.setFlags(value_item.flags() | Qt.ItemFlag.ItemIsEditable)
1451
+ self.metadata_table.setItem(row, 2, value_item)
1452
+
1453
+ # Actions
1454
+ actions_widget = QWidget()
1455
+ actions_layout = QHBoxLayout(actions_widget)
1456
+ actions_layout.setContentsMargins(2, 2, 2, 2)
1457
+
1458
+ remove_button = QPushButton("Remove")
1459
+ remove_button.setProperty("row", row)
1460
+ remove_button.setProperty("key", key)
1461
+ remove_button.clicked.connect(self.remove_metadata)
1462
+ actions_layout.addWidget(remove_button)
1463
+
1464
+ self.metadata_table.setCellWidget(row, 3, actions_widget)
1465
+
1466
+ # Store the change
1467
+ self.metadata_changes[key] = (value_type, value)
1468
+ self.modified = True
1469
+
1470
+ self.statusBar().showMessage(f"Added new metadata key {key}")
1471
+
1472
+ def save_file(self):
1473
+ if not self.reader:
1474
+ QMessageBox.warning(self, "No File Open", "Please open a GGUF file first")
1475
+ return
1476
+
1477
+ if not self.modified and not self.metadata_changes and not self.metadata_to_remove:
1478
+ QMessageBox.information(self, "No Changes", "No changes to save")
1479
+ return
1480
+
1481
+ file_path, _ = QFileDialog.getSaveFileName(
1482
+ self, "Save GGUF File As", "", "GGUF Files (*.gguf);;All Files (*)"
1483
+ )
1484
+
1485
+ if not file_path:
1486
+ return
1487
+
1488
+ try:
1489
+ self.statusBar().showMessage(f"Saving to {file_path}...")
1490
+ QApplication.processEvents()
1491
+
1492
+ # Get architecture and endianness from the original file
1493
+ arch = 'unknown'
1494
+ field = self.reader.get_field(gguf.Keys.General.ARCHITECTURE)
1495
+ if field:
1496
+ arch = field.contents()
1497
+
1498
+ # Create writer
1499
+ writer = GGUFWriter(file_path, arch=arch, endianess=self.reader.endianess)
1500
+
1501
+ # Get alignment if present
1502
+ alignment = None
1503
+ field = self.reader.get_field(gguf.Keys.General.ALIGNMENT)
1504
+ if field:
1505
+ alignment = field.contents()
1506
+ if alignment is not None:
1507
+ writer.data_alignment = alignment
1508
+
1509
+ # Copy metadata with changes
1510
+ for field in self.reader.fields.values():
1511
+ # Skip virtual fields and fields written by GGUFWriter
1512
+ if field.name == gguf.Keys.General.ARCHITECTURE or field.name.startswith('GGUF.'):
1513
+ continue
1514
+
1515
+ # Skip fields marked for removal
1516
+ if field.name in self.metadata_to_remove:
1517
+ continue
1518
+
1519
+ # Apply changes if any
1520
+ if field.name in self.metadata_changes:
1521
+ value_type, value = self.metadata_changes[field.name]
1522
+ if value_type == GGUFValueType.ARRAY:
1523
+ # Handle array values
1524
+ element_type, array_values = value
1525
+ writer.add_array(field.name, array_values)
1526
+ else:
1527
+ writer.add_key_value(field.name, value, value_type)
1528
+ else:
1529
+ # Copy original value
1530
+ value = field.contents()
1531
+ if value is not None and field.types:
1532
+ writer.add_key_value(field.name, value, field.types[0])
1533
+
1534
+ # Add new metadata
1535
+ for key, (value_type, value) in self.metadata_changes.items():
1536
+ # Skip if the key already existed (we handled it above)
1537
+ if self.reader.get_field(key) is not None:
1538
+ continue
1539
+
1540
+ writer.add_key_value(key, value, value_type)
1541
+
1542
+ # Add tensors (including data)
1543
+ for tensor in self.reader.tensors:
1544
+ writer.add_tensor(tensor.name, tensor.data, raw_shape=tensor.data.shape, raw_dtype=tensor.tensor_type)
1545
+
1546
+ # Write header and metadata
1547
+ writer.open_output_file(Path(file_path))
1548
+ writer.write_header_to_file()
1549
+ writer.write_kv_data_to_file()
1550
+
1551
+ # Write tensor data using the optimized method
1552
+ writer.write_tensors_to_file(progress=False)
1553
+
1554
+ writer.close()
1555
+
1556
+ self.statusBar().showMessage(f"Saved to {file_path}")
1557
+
1558
+ # Ask if user wants to open the new file
1559
+ reply = QMessageBox.question(
1560
+ self, "Open Saved File",
1561
+ "Would you like to open the newly saved file?",
1562
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.Yes
1563
+ )
1564
+
1565
+ if reply == QMessageBox.StandardButton.Yes:
1566
+ self.reader = GGUFReader(file_path, 'r')
1567
+ self.current_file = file_path
1568
+ self.file_path_edit.setText(file_path)
1569
+
1570
+ self.load_metadata()
1571
+ self.load_tensors()
1572
+
1573
+ self.metadata_changes = {}
1574
+ self.metadata_to_remove = set()
1575
+ self.modified = False
1576
+
1577
+ except Exception as e:
1578
+ QMessageBox.critical(self, "Error", f"Failed to save file: {str(e)}")
1579
+ self.statusBar().showMessage("Error saving file")
1580
+
1581
+
1582
+ def main() -> None:
1583
+ parser = argparse.ArgumentParser(description="GUI GGUF Editor")
1584
+ parser.add_argument("model_path", nargs="?", help="path to GGUF model file to load at startup")
1585
+ parser.add_argument("--verbose", action="store_true", help="increase output verbosity")
1586
+
1587
+ args = parser.parse_args()
1588
+
1589
+ logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
1590
+
1591
+ app = QApplication(sys.argv)
1592
+ window = GGUFEditorWindow()
1593
+ window.show()
1594
+
1595
+ # Load model if specified
1596
+ if args.model_path:
1597
+ if os.path.isfile(args.model_path) and args.model_path.endswith('.gguf'):
1598
+ window.load_file(args.model_path)
1599
+ else:
1600
+ logger.error(f"Invalid model path: {args.model_path}")
1601
+ QMessageBox.warning(
1602
+ window,
1603
+ "Invalid Model Path",
1604
+ f"The specified file does not exist or is not a GGUF file: {args.model_path}")
1605
+
1606
+ sys.exit(app.exec())
1607
+
1608
+
1609
+ if __name__ == '__main__':
1610
+ main()