@fugood/llama.node 0.3.6 → 0.3.8

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 (186) hide show
  1. package/README.md +17 -2
  2. package/bin/darwin/arm64/llama-node.node +0 -0
  3. package/bin/darwin/x64/llama-node.node +0 -0
  4. package/bin/linux/arm64/llama-node.node +0 -0
  5. package/bin/linux/x64/llama-node.node +0 -0
  6. package/bin/linux-cuda/arm64/llama-node.node +0 -0
  7. package/bin/linux-cuda/x64/llama-node.node +0 -0
  8. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  9. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  10. package/bin/win32/arm64/llama-node.node +0 -0
  11. package/bin/win32/arm64/node.lib +0 -0
  12. package/bin/win32/x64/llama-node.node +0 -0
  13. package/bin/win32/x64/node.lib +0 -0
  14. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  15. package/bin/win32-vulkan/arm64/node.lib +0 -0
  16. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  17. package/bin/win32-vulkan/x64/node.lib +0 -0
  18. package/lib/binding.ts +3 -1
  19. package/lib/index.js +16 -1
  20. package/lib/index.ts +16 -0
  21. package/package.json +1 -1
  22. package/src/EmbeddingWorker.cpp +4 -3
  23. package/src/LlamaCompletionWorker.cpp +4 -2
  24. package/src/LlamaContext.cpp +61 -6
  25. package/src/LlamaContext.h +1 -0
  26. package/src/common.hpp +6 -11
  27. package/src/llama.cpp/.github/workflows/build.yml +19 -17
  28. package/src/llama.cpp/.github/workflows/docker.yml +77 -30
  29. package/src/llama.cpp/.github/workflows/editorconfig.yml +3 -1
  30. package/src/llama.cpp/.github/workflows/server.yml +22 -3
  31. package/src/llama.cpp/CMakeLists.txt +49 -24
  32. package/src/llama.cpp/common/arg.cpp +82 -26
  33. package/src/llama.cpp/common/arg.h +3 -0
  34. package/src/llama.cpp/common/common.cpp +192 -72
  35. package/src/llama.cpp/common/common.h +51 -18
  36. package/src/llama.cpp/common/ngram-cache.cpp +12 -12
  37. package/src/llama.cpp/common/ngram-cache.h +2 -2
  38. package/src/llama.cpp/common/sampling.cpp +11 -6
  39. package/src/llama.cpp/common/speculative.cpp +18 -15
  40. package/src/llama.cpp/docs/build.md +2 -0
  41. package/src/llama.cpp/examples/batched/batched.cpp +9 -7
  42. package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +3 -3
  43. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +10 -8
  44. package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +11 -8
  45. package/src/llama.cpp/examples/cvector-generator/mean.hpp +1 -1
  46. package/src/llama.cpp/examples/cvector-generator/pca.hpp +1 -1
  47. package/src/llama.cpp/examples/embedding/embedding.cpp +8 -7
  48. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +7 -6
  49. package/src/llama.cpp/examples/export-lora/export-lora.cpp +8 -7
  50. package/src/llama.cpp/examples/gguf/gguf.cpp +10 -6
  51. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +1 -0
  52. package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +8 -7
  53. package/src/llama.cpp/examples/gritlm/gritlm.cpp +13 -10
  54. package/src/llama.cpp/examples/imatrix/imatrix.cpp +13 -12
  55. package/src/llama.cpp/examples/infill/infill.cpp +23 -24
  56. package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +44 -13
  57. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +11 -6
  58. package/src/llama.cpp/examples/llava/clip.cpp +4 -2
  59. package/src/llama.cpp/examples/llava/llava-cli.cpp +9 -6
  60. package/src/llama.cpp/examples/llava/llava.cpp +2 -2
  61. package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +8 -4
  62. package/src/llama.cpp/examples/llava/qwen2vl-cli.cpp +11 -8
  63. package/src/llama.cpp/examples/lookahead/lookahead.cpp +6 -7
  64. package/src/llama.cpp/examples/lookup/lookup-create.cpp +4 -9
  65. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +3 -7
  66. package/src/llama.cpp/examples/lookup/lookup.cpp +5 -6
  67. package/src/llama.cpp/examples/main/main.cpp +51 -29
  68. package/src/llama.cpp/examples/parallel/parallel.cpp +5 -6
  69. package/src/llama.cpp/examples/passkey/passkey.cpp +7 -5
  70. package/src/llama.cpp/examples/perplexity/perplexity.cpp +37 -23
  71. package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +12 -14
  72. package/src/llama.cpp/examples/retrieval/retrieval.cpp +8 -8
  73. package/src/llama.cpp/examples/rpc/rpc-server.cpp +12 -0
  74. package/src/llama.cpp/examples/run/CMakeLists.txt +1 -1
  75. package/src/llama.cpp/examples/run/linenoise.cpp/linenoise.cpp +1351 -0
  76. package/src/llama.cpp/examples/run/linenoise.cpp/linenoise.h +114 -0
  77. package/src/llama.cpp/examples/run/run.cpp +175 -61
  78. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +4 -25
  79. package/src/llama.cpp/examples/server/CMakeLists.txt +1 -0
  80. package/src/llama.cpp/examples/server/httplib.h +1295 -409
  81. package/src/llama.cpp/examples/server/server.cpp +387 -181
  82. package/src/llama.cpp/examples/server/tests/requirements.txt +1 -0
  83. package/src/llama.cpp/examples/server/utils.hpp +170 -58
  84. package/src/llama.cpp/examples/simple/simple.cpp +9 -8
  85. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +16 -12
  86. package/src/llama.cpp/examples/speculative/speculative.cpp +22 -23
  87. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +8 -12
  88. package/src/llama.cpp/examples/tokenize/tokenize.cpp +17 -5
  89. package/src/llama.cpp/examples/tts/tts.cpp +64 -23
  90. package/src/llama.cpp/ggml/CMakeLists.txt +5 -21
  91. package/src/llama.cpp/ggml/include/ggml-backend.h +2 -0
  92. package/src/llama.cpp/ggml/include/ggml-cpp.h +1 -0
  93. package/src/llama.cpp/ggml/include/ggml.h +36 -145
  94. package/src/llama.cpp/ggml/include/gguf.h +202 -0
  95. package/src/llama.cpp/ggml/src/CMakeLists.txt +6 -3
  96. package/src/llama.cpp/ggml/src/ggml-alloc.c +5 -0
  97. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -1
  98. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +79 -49
  99. package/src/llama.cpp/ggml/src/ggml-backend.cpp +5 -2
  100. package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +33 -23
  101. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +57 -72
  102. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +87 -2
  103. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +335 -66
  104. package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +10 -2
  105. package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1090 -378
  106. package/src/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.h +2 -2
  107. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +1 -0
  108. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +3 -0
  109. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +3 -0
  110. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +3 -1
  111. package/src/llama.cpp/ggml/src/ggml-impl.h +11 -16
  112. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +16 -0
  113. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +6 -6
  114. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +154 -35
  115. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +1 -0
  116. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +9 -3
  117. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +18 -0
  118. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +3 -2
  119. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +1 -2
  120. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +3 -2
  121. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +1 -2
  122. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +40 -95
  123. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +48 -48
  124. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +24 -24
  125. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +238 -164
  126. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +105 -0
  127. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +8 -0
  128. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +3 -3
  129. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +1 -2
  130. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +3 -2
  131. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +1 -2
  132. package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.cpp +7 -5
  133. package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.hpp +1 -2
  134. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +74 -4
  135. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +314 -116
  136. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +4 -2
  137. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +9 -3
  138. package/src/llama.cpp/ggml/src/ggml.c +117 -1327
  139. package/src/llama.cpp/ggml/src/gguf.cpp +1329 -0
  140. package/src/llama.cpp/include/llama-cpp.h +6 -1
  141. package/src/llama.cpp/include/llama.h +138 -75
  142. package/src/llama.cpp/src/CMakeLists.txt +13 -1
  143. package/src/llama.cpp/src/llama-adapter.cpp +347 -0
  144. package/src/llama.cpp/src/llama-adapter.h +74 -0
  145. package/src/llama.cpp/src/llama-arch.cpp +1487 -0
  146. package/src/llama.cpp/src/llama-arch.h +400 -0
  147. package/src/llama.cpp/src/llama-batch.cpp +368 -0
  148. package/src/llama.cpp/src/llama-batch.h +88 -0
  149. package/src/llama.cpp/src/llama-chat.cpp +578 -0
  150. package/src/llama.cpp/src/llama-chat.h +52 -0
  151. package/src/llama.cpp/src/llama-context.cpp +1775 -0
  152. package/src/llama.cpp/src/llama-context.h +128 -0
  153. package/src/llama.cpp/src/llama-cparams.cpp +1 -0
  154. package/src/llama.cpp/src/llama-cparams.h +37 -0
  155. package/src/llama.cpp/src/llama-grammar.cpp +5 -4
  156. package/src/llama.cpp/src/llama-grammar.h +3 -1
  157. package/src/llama.cpp/src/llama-hparams.cpp +71 -0
  158. package/src/llama.cpp/src/llama-hparams.h +139 -0
  159. package/src/llama.cpp/src/llama-impl.cpp +167 -0
  160. package/src/llama.cpp/src/llama-impl.h +16 -136
  161. package/src/llama.cpp/src/llama-kv-cache.cpp +718 -0
  162. package/src/llama.cpp/src/llama-kv-cache.h +218 -0
  163. package/src/llama.cpp/src/llama-mmap.cpp +589 -0
  164. package/src/llama.cpp/src/llama-mmap.h +67 -0
  165. package/src/llama.cpp/src/llama-model-loader.cpp +1124 -0
  166. package/src/llama.cpp/src/llama-model-loader.h +167 -0
  167. package/src/llama.cpp/src/llama-model.cpp +3953 -0
  168. package/src/llama.cpp/src/llama-model.h +370 -0
  169. package/src/llama.cpp/src/llama-quant.cpp +934 -0
  170. package/src/llama.cpp/src/llama-quant.h +1 -0
  171. package/src/llama.cpp/src/llama-sampling.cpp +147 -32
  172. package/src/llama.cpp/src/llama-sampling.h +3 -19
  173. package/src/llama.cpp/src/llama-vocab.cpp +1832 -575
  174. package/src/llama.cpp/src/llama-vocab.h +97 -142
  175. package/src/llama.cpp/src/llama.cpp +7160 -20314
  176. package/src/llama.cpp/src/unicode.cpp +8 -3
  177. package/src/llama.cpp/tests/CMakeLists.txt +2 -0
  178. package/src/llama.cpp/tests/test-autorelease.cpp +3 -3
  179. package/src/llama.cpp/tests/test-backend-ops.cpp +370 -59
  180. package/src/llama.cpp/tests/test-chat-template.cpp +162 -125
  181. package/src/llama.cpp/tests/test-gguf.cpp +222 -187
  182. package/src/llama.cpp/tests/test-model-load-cancel.cpp +1 -1
  183. package/src/llama.cpp/tests/test-sampling.cpp +0 -1
  184. package/src/llama.cpp/tests/test-tokenizer-0.cpp +4 -4
  185. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +9 -7
  186. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +8 -6
@@ -0,0 +1,370 @@
1
+ #pragma once
2
+
3
+ #include "llama.h"
4
+ #include "llama-arch.h"
5
+ #include "llama-hparams.h"
6
+ #include "llama-vocab.h"
7
+
8
+ #include <memory>
9
+ #include <string>
10
+ #include <unordered_map>
11
+ #include <vector>
12
+
13
+ struct llama_model_loader;
14
+
15
+ // available models
16
+ enum llm_type {
17
+ LLM_TYPE_UNKNOWN,
18
+ LLM_TYPE_14M,
19
+ LLM_TYPE_17M,
20
+ LLM_TYPE_22M,
21
+ LLM_TYPE_33M,
22
+ LLM_TYPE_60M,
23
+ LLM_TYPE_70M,
24
+ LLM_TYPE_80M,
25
+ LLM_TYPE_109M,
26
+ LLM_TYPE_137M,
27
+ LLM_TYPE_160M,
28
+ LLM_TYPE_220M,
29
+ LLM_TYPE_250M,
30
+ LLM_TYPE_270M,
31
+ LLM_TYPE_335M,
32
+ LLM_TYPE_410M,
33
+ LLM_TYPE_450M,
34
+ LLM_TYPE_770M,
35
+ LLM_TYPE_780M,
36
+ LLM_TYPE_0_5B,
37
+ LLM_TYPE_1B,
38
+ LLM_TYPE_1_3B,
39
+ LLM_TYPE_1_4B,
40
+ LLM_TYPE_1_5B,
41
+ LLM_TYPE_1_6B,
42
+ LLM_TYPE_2B,
43
+ LLM_TYPE_2_8B,
44
+ LLM_TYPE_3B,
45
+ LLM_TYPE_4B,
46
+ LLM_TYPE_6B,
47
+ LLM_TYPE_6_9B,
48
+ LLM_TYPE_7B,
49
+ LLM_TYPE_8B,
50
+ LLM_TYPE_9B,
51
+ LLM_TYPE_11B,
52
+ LLM_TYPE_12B,
53
+ LLM_TYPE_13B,
54
+ LLM_TYPE_14B,
55
+ LLM_TYPE_15B,
56
+ LLM_TYPE_16B,
57
+ LLM_TYPE_20B,
58
+ LLM_TYPE_30B,
59
+ LLM_TYPE_32B,
60
+ LLM_TYPE_34B,
61
+ LLM_TYPE_35B,
62
+ LLM_TYPE_40B,
63
+ LLM_TYPE_65B,
64
+ LLM_TYPE_70B,
65
+ LLM_TYPE_236B,
66
+ LLM_TYPE_314B,
67
+ LLM_TYPE_671B,
68
+ LLM_TYPE_SMALL,
69
+ LLM_TYPE_MEDIUM,
70
+ LLM_TYPE_LARGE,
71
+ LLM_TYPE_XL,
72
+ LLM_TYPE_A1_7B,
73
+ LLM_TYPE_A2_7B,
74
+ LLM_TYPE_8x7B,
75
+ LLM_TYPE_8x22B,
76
+ LLM_TYPE_16x12B,
77
+ LLM_TYPE_16x3_8B,
78
+ LLM_TYPE_10B_128x3_66B,
79
+ LLM_TYPE_57B_A14B,
80
+ LLM_TYPE_27B,
81
+ };
82
+
83
+ struct llama_layer_posnet {
84
+ // resnet
85
+ struct ggml_tensor * norm1 = nullptr;
86
+ struct ggml_tensor * norm1_b = nullptr;
87
+
88
+ struct ggml_tensor * conv1 = nullptr;
89
+ struct ggml_tensor * conv1_b = nullptr;
90
+
91
+ struct ggml_tensor * norm2 = nullptr;
92
+ struct ggml_tensor * norm2_b = nullptr;
93
+
94
+ struct ggml_tensor * conv2 = nullptr;
95
+ struct ggml_tensor * conv2_b = nullptr;
96
+
97
+ // attention
98
+ struct ggml_tensor * attn_norm = nullptr;
99
+ struct ggml_tensor * attn_norm_b = nullptr;
100
+
101
+ struct ggml_tensor * attn_q = nullptr;
102
+ struct ggml_tensor * attn_q_b = nullptr;
103
+
104
+ struct ggml_tensor * attn_k = nullptr;
105
+ struct ggml_tensor * attn_k_b = nullptr;
106
+
107
+ struct ggml_tensor * attn_v = nullptr;
108
+ struct ggml_tensor * attn_v_b = nullptr;
109
+
110
+ struct ggml_tensor * attn_o = nullptr;
111
+ struct ggml_tensor * attn_o_b = nullptr;
112
+
113
+ // normalize
114
+ struct ggml_tensor * norm = nullptr;
115
+ struct ggml_tensor * norm_b = nullptr;
116
+ };
117
+
118
+ struct llama_layer_convnext {
119
+ struct ggml_tensor * dw = nullptr;
120
+ struct ggml_tensor * dw_b = nullptr;
121
+
122
+ struct ggml_tensor * norm = nullptr;
123
+ struct ggml_tensor * norm_b = nullptr;
124
+
125
+ struct ggml_tensor * pw1 = nullptr;
126
+ struct ggml_tensor * pw1_b = nullptr;
127
+
128
+ struct ggml_tensor * pw2 = nullptr;
129
+ struct ggml_tensor * pw2_b = nullptr;
130
+
131
+ struct ggml_tensor * gamma = nullptr;
132
+ };
133
+
134
+ struct llama_layer {
135
+ // normalization
136
+ struct ggml_tensor * attn_norm = nullptr;
137
+ struct ggml_tensor * attn_norm_b = nullptr;
138
+ struct ggml_tensor * attn_norm_2 = nullptr;
139
+ struct ggml_tensor * attn_norm_2_b = nullptr;
140
+ struct ggml_tensor * attn_q_norm = nullptr;
141
+ struct ggml_tensor * attn_q_norm_b = nullptr;
142
+ struct ggml_tensor * attn_k_norm = nullptr;
143
+ struct ggml_tensor * attn_k_norm_b = nullptr;
144
+ struct ggml_tensor * attn_out_norm = nullptr;
145
+ struct ggml_tensor * attn_out_norm_b = nullptr;
146
+ struct ggml_tensor * attn_q_a_norm = nullptr;
147
+ struct ggml_tensor * attn_kv_a_norm = nullptr;
148
+ struct ggml_tensor * attn_sub_norm = nullptr;
149
+ struct ggml_tensor * attn_post_norm = nullptr;
150
+ struct ggml_tensor * ffn_sub_norm = nullptr;
151
+ struct ggml_tensor * attn_norm_cross = nullptr;
152
+ struct ggml_tensor * attn_norm_enc = nullptr;
153
+
154
+ // attention
155
+ struct ggml_tensor * wq = nullptr;
156
+ struct ggml_tensor * wk = nullptr;
157
+ struct ggml_tensor * wv = nullptr;
158
+ struct ggml_tensor * wo = nullptr;
159
+ struct ggml_tensor * wqkv = nullptr;
160
+ struct ggml_tensor * wq_a = nullptr;
161
+ struct ggml_tensor * wq_b = nullptr;
162
+ struct ggml_tensor * wkv_a_mqa = nullptr;
163
+ struct ggml_tensor * wkv_b = nullptr;
164
+ struct ggml_tensor * wq_cross = nullptr;
165
+ struct ggml_tensor * wk_cross = nullptr;
166
+ struct ggml_tensor * wv_cross = nullptr;
167
+ struct ggml_tensor * wo_cross = nullptr;
168
+ struct ggml_tensor * wq_enc = nullptr;
169
+ struct ggml_tensor * wk_enc = nullptr;
170
+ struct ggml_tensor * wv_enc = nullptr;
171
+ struct ggml_tensor * wo_enc = nullptr;
172
+
173
+ // attention bias
174
+ struct ggml_tensor * bq = nullptr;
175
+ struct ggml_tensor * bk = nullptr;
176
+ struct ggml_tensor * bv = nullptr;
177
+ struct ggml_tensor * bo = nullptr;
178
+ struct ggml_tensor * bqkv = nullptr;
179
+
180
+ // relative position bias
181
+ struct ggml_tensor * attn_rel_b = nullptr;
182
+ struct ggml_tensor * attn_rel_b_enc = nullptr;
183
+ struct ggml_tensor * attn_rel_b_cross = nullptr;
184
+
185
+ // normalization
186
+ struct ggml_tensor * ffn_norm = nullptr;
187
+ struct ggml_tensor * ffn_norm_b = nullptr;
188
+ struct ggml_tensor * ffn_post_norm = nullptr;
189
+ struct ggml_tensor * layer_out_norm = nullptr;
190
+ struct ggml_tensor * layer_out_norm_b = nullptr;
191
+ struct ggml_tensor * ffn_norm_exps = nullptr;
192
+ struct ggml_tensor * ffn_norm_enc = nullptr;
193
+
194
+ // ff
195
+ struct ggml_tensor * ffn_gate = nullptr; // w1
196
+ struct ggml_tensor * ffn_down = nullptr; // w2
197
+ struct ggml_tensor * ffn_up = nullptr; // w3
198
+ struct ggml_tensor * ffn_gate_enc = nullptr;
199
+ struct ggml_tensor * ffn_down_enc = nullptr;
200
+ struct ggml_tensor * ffn_up_enc = nullptr;
201
+
202
+ // ff MoE
203
+ struct ggml_tensor * ffn_gate_inp = nullptr;
204
+ struct ggml_tensor * ffn_gate_exps = nullptr;
205
+ struct ggml_tensor * ffn_down_exps = nullptr;
206
+ struct ggml_tensor * ffn_up_exps = nullptr;
207
+
208
+ // ff shared expert (shexp)
209
+ struct ggml_tensor * ffn_gate_inp_shexp = nullptr;
210
+ struct ggml_tensor * ffn_gate_shexp = nullptr;
211
+ struct ggml_tensor * ffn_down_shexp = nullptr;
212
+ struct ggml_tensor * ffn_up_shexp = nullptr;
213
+
214
+ // ff bias
215
+ struct ggml_tensor * ffn_gate_b = nullptr;
216
+ struct ggml_tensor * ffn_down_b = nullptr; // b2
217
+ struct ggml_tensor * ffn_up_b = nullptr; // b3
218
+ struct ggml_tensor * ffn_act = nullptr;
219
+ struct ggml_tensor * ffn_exp_probs_b = nullptr;
220
+
221
+ // mamba proj
222
+ struct ggml_tensor * ssm_in = nullptr;
223
+ struct ggml_tensor * ssm_x = nullptr;
224
+ struct ggml_tensor * ssm_dt = nullptr;
225
+ struct ggml_tensor * ssm_out = nullptr;
226
+
227
+ // mamba
228
+ struct ggml_tensor * ssm_conv1d = nullptr;
229
+ struct ggml_tensor * ssm_a = nullptr;
230
+ struct ggml_tensor * ssm_d = nullptr;
231
+
232
+ // mamba bias
233
+ struct ggml_tensor * ssm_conv1d_b = nullptr;
234
+ struct ggml_tensor * ssm_dt_b = nullptr;
235
+
236
+ // rwkv
237
+ struct ggml_tensor * time_mix_w1 = nullptr;
238
+ struct ggml_tensor * time_mix_w2 = nullptr;
239
+ struct ggml_tensor * time_mix_lerp_x = nullptr;
240
+ struct ggml_tensor * time_mix_lerp_w = nullptr;
241
+ struct ggml_tensor * time_mix_lerp_k = nullptr;
242
+ struct ggml_tensor * time_mix_lerp_v = nullptr;
243
+ struct ggml_tensor * time_mix_lerp_r = nullptr;
244
+ struct ggml_tensor * time_mix_lerp_g = nullptr;
245
+ struct ggml_tensor * time_mix_lerp_fused = nullptr;
246
+
247
+ struct ggml_tensor * time_mix_first = nullptr;
248
+ struct ggml_tensor * time_mix_decay = nullptr;
249
+ struct ggml_tensor * time_mix_decay_w1 = nullptr;
250
+ struct ggml_tensor * time_mix_decay_w2 = nullptr;
251
+ struct ggml_tensor * time_mix_key = nullptr;
252
+ struct ggml_tensor * time_mix_key_b = nullptr;
253
+ struct ggml_tensor * time_mix_value = nullptr;
254
+ struct ggml_tensor * time_mix_value_b = nullptr;
255
+ struct ggml_tensor * time_mix_receptance = nullptr;
256
+ struct ggml_tensor * time_mix_receptance_b = nullptr;
257
+ struct ggml_tensor * time_mix_gate = nullptr;
258
+
259
+ struct ggml_tensor * time_mix_ln = nullptr;
260
+ struct ggml_tensor * time_mix_ln_b = nullptr;
261
+ struct ggml_tensor * time_mix_output = nullptr;
262
+
263
+ struct ggml_tensor * channel_mix_lerp_k = nullptr;
264
+ struct ggml_tensor * channel_mix_lerp_r = nullptr;
265
+
266
+ struct ggml_tensor * channel_mix_key = nullptr;
267
+ struct ggml_tensor * channel_mix_receptance = nullptr;
268
+ struct ggml_tensor * channel_mix_value = nullptr;
269
+
270
+ // long rope factors
271
+ struct ggml_tensor * rope_long = nullptr;
272
+ struct ggml_tensor * rope_short = nullptr;
273
+ struct ggml_tensor * rope_freqs = nullptr;
274
+
275
+ // bitnet scale
276
+ struct ggml_tensor * wq_scale = nullptr;
277
+ struct ggml_tensor * wk_scale = nullptr;
278
+ struct ggml_tensor * wv_scale = nullptr;
279
+ struct ggml_tensor * wo_scale = nullptr;
280
+ struct ggml_tensor * ffn_gate_scale = nullptr;
281
+ struct ggml_tensor * ffn_up_scale = nullptr;
282
+ struct ggml_tensor * ffn_down_scale = nullptr;
283
+
284
+ struct llama_layer_posnet posnet;
285
+
286
+ struct llama_layer_convnext convnext;
287
+ };
288
+
289
+ struct llama_model {
290
+ llm_type type = LLM_TYPE_UNKNOWN;
291
+ llm_arch arch = LLM_ARCH_UNKNOWN;
292
+
293
+ std::string name = "n/a";
294
+
295
+ llama_hparams hparams = {};
296
+ llama_vocab vocab;
297
+
298
+ struct ggml_tensor * tok_embd = nullptr;
299
+ struct ggml_tensor * type_embd = nullptr;
300
+ struct ggml_tensor * pos_embd = nullptr;
301
+ struct ggml_tensor * tok_norm = nullptr;
302
+ struct ggml_tensor * tok_norm_b = nullptr;
303
+
304
+ struct ggml_tensor * output_norm = nullptr;
305
+ struct ggml_tensor * output_norm_b = nullptr;
306
+ struct ggml_tensor * output = nullptr;
307
+ struct ggml_tensor * output_b = nullptr;
308
+ struct ggml_tensor * output_norm_enc = nullptr;
309
+
310
+ // classifier
311
+ struct ggml_tensor * cls = nullptr;
312
+ struct ggml_tensor * cls_b = nullptr;
313
+ struct ggml_tensor * cls_out = nullptr;
314
+ struct ggml_tensor * cls_out_b = nullptr;
315
+
316
+ struct ggml_tensor * conv1d = nullptr;
317
+ struct ggml_tensor * conv1d_b = nullptr;
318
+
319
+ std::vector<llama_layer> layers;
320
+
321
+ llama_model_params params;
322
+
323
+ // gguf metadata
324
+ std::unordered_map<std::string, std::string> gguf_kv;
325
+
326
+ // list of devices used in this model
327
+ std::vector<ggml_backend_dev_t> devices;
328
+
329
+ // for quantize-stats only
330
+ std::vector<std::pair<std::string, struct ggml_tensor *>> tensors_by_name;
331
+
332
+ int64_t t_load_us = 0;
333
+ int64_t t_start_us = 0;
334
+
335
+ explicit llama_model(const struct llama_model_params & params);
336
+ ~llama_model();
337
+
338
+ void load_stats (llama_model_loader & ml);
339
+ void load_arch (llama_model_loader & ml);
340
+ void load_hparams(llama_model_loader & ml);
341
+ void load_vocab (llama_model_loader & ml);
342
+ bool load_tensors(llama_model_loader & ml); // returns false if cancelled by progress_callback
343
+
344
+ std::string arch_name() const;
345
+ std::string type_name() const;
346
+
347
+ std::string desc() const;
348
+
349
+ size_t size() const;
350
+ size_t max_nodes() const;
351
+ size_t n_devices() const;
352
+
353
+ // total number of parameters in the model
354
+ uint64_t n_elements() const;
355
+
356
+ void print_info() const;
357
+
358
+ ggml_backend_dev_t dev_layer(int il) const;
359
+ ggml_backend_dev_t dev_output() const;
360
+
361
+ ggml_backend_buffer_type_t select_buft(int il) const;
362
+
363
+ const struct ggml_tensor * get_tensor(const char * name) const;
364
+
365
+ private:
366
+ struct impl;
367
+ std::unique_ptr<impl> pimpl;
368
+ };
369
+
370
+ const char * llm_type_name(llm_type type);