metal : adjust .get_alloc_size to be alloc friendly

This commit is contained in:
Georgi Gerganov
2025-10-19 17:20:54 +03:00
parent cec5edbcae
commit f0076dc5a0
2 changed files with 10 additions and 1 deletions

View File

@@ -191,6 +191,15 @@ static size_t ggml_backend_metal_buffer_type_get_alloc_size(ggml_backend_buffer_
res += ggml_metal_op_mul_mat_id_extra_tpe(tensor);
res += ggml_metal_op_mul_mat_id_extra_ids(tensor);
} break;
case GGML_OP_MUL:
case GGML_OP_ADD_ID:
{
// TODO: ideally this should not be necessary
// ref: https://github.com/ggml-org/llama.cpp/issues/16646#issuecomment-3419232927
if (tensor->src[0]->op == GGML_OP_ADD_ID || tensor->src[0]->op == GGML_OP_MUL_MAT_ID) {
res = ggml_backend_metal_buffer_type_get_alloc_size(buft, tensor->src[0]);
}
} break;
case GGML_OP_FLASH_ATTN_EXT:
{
res += ggml_metal_op_flash_attn_ext_extra_pad(tensor);

View File

@@ -1071,7 +1071,7 @@ ggml_tensor * llm_graph_context::build_moe_ffn(
if (!weight_before_ffn) {
experts = ggml_mul(ctx0, experts, weights);
cb(cur, "ffn_moe_weighted", il);
cb(experts, "ffn_moe_weighted", il);
}
ggml_tensor * cur_experts[LLAMA_MAX_EXPERTS] = { nullptr };