MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / weight_buft_supported

Function weight_buft_supported

subprojects/llama.cpp/src/llama-model.cpp:173–307  ·  view source on GitHub ↗

checks if the weight tensor can be used with the specified buffer type and device

Source from the content-addressed store, hash-verified

171
172// checks if the weight tensor can be used with the specified buffer type and device
173static bool weight_buft_supported(const llama_hparams & hparams, ggml_tensor * w, ggml_op op, ggml_backend_buffer_type_t buft, ggml_backend_dev_t dev) {
174 GGML_ASSERT(w != nullptr);
175
176 if (op == GGML_OP_NONE) {
177 return true;
178 }
179
180 ggml_init_params params = {
181 /*.mem_size =*/ ggml_tensor_overhead()*8,
182 /*.mem_buffer =*/ NULL,
183 /*.no_alloc =*/ true,
184 };
185 ggml_context_ptr ctx_ptr { ggml_init(params) };
186 if (!ctx_ptr) {
187 throw std::runtime_error(format("failed to create ggml context"));
188 }
189 ggml_context * ctx = ctx_ptr.get();
190
191 ggml_tensor * op_tensor = nullptr;
192
193 switch (op) {
194 case GGML_OP_GET_ROWS:
195 {
196 ggml_tensor * b = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, 512);
197 op_tensor = ggml_get_rows(ctx, w, b);
198 } break;
199 case GGML_OP_MUL_MAT:
200 {
201 ggml_tensor * b = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, w->ne[0], 512, w->ne[2], w->ne[3]);
202 op_tensor = ggml_mul_mat(ctx, w, b);
203 } break;
204 case GGML_OP_MUL_MAT_ID:
205 {
206 int n_expert_used = hparams.n_expert_used;
207 ggml_tensor * b = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, w->ne[0], n_expert_used, 512);
208 ggml_tensor * ids = ggml_new_tensor_2d(ctx, GGML_TYPE_I32, n_expert_used, 512);
209 op_tensor = ggml_mul_mat_id(ctx, w, b, ids);
210 } break;
211 case GGML_OP_ADD:
212 {
213 ggml_tensor * a = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, w->ne[0], w->ne[1], w->ne[2], w->ne[3]);
214 op_tensor = ggml_add(ctx, a, w);
215 } break;
216 case GGML_OP_ADD_ID:
217 {
218 int n_expert_used = hparams.n_expert_used;
219 ggml_tensor * a = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, w->ne[0], n_expert_used, 512);
220 ggml_tensor * c = ggml_new_tensor_2d(ctx, GGML_TYPE_I32, n_expert_used, 512);
221 op_tensor = ggml_add_id(ctx, a, w, c);
222 } break;
223 case GGML_OP_MUL:
224 {
225 ggml_tensor * a = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, w->ne[0], w->ne[1], w->ne[2], w->ne[3]);
226 op_tensor = ggml_mul(ctx, a, w);
227 } break;
228 case GGML_OP_DIV:
229 {
230 ggml_tensor * a = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, w->ne[0]);

Callers 1

select_weight_buftFunction · 0.85

Calls 15

ggml_tensor_overheadFunction · 0.85
ggml_initFunction · 0.85
formatFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_get_rowsFunction · 0.85
ggml_new_tensor_4dFunction · 0.85
ggml_mul_matFunction · 0.85
ggml_new_tensor_3dFunction · 0.85
ggml_new_tensor_2dFunction · 0.85
ggml_mul_mat_idFunction · 0.85
ggml_addFunction · 0.85
ggml_add_idFunction · 0.85

Tested by

no test coverage detected