From e64f237e04a3fc5fbf14dab802325871769f7cdc Mon Sep 17 00:00:00 2001 From: Lizonghang <870644199@qq.com> Date: Sat, 15 Feb 2025 17:43:03 +0400 Subject: [PATCH] fix bugs in available_mem calculation --- common/common.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/common.cpp b/common/common.cpp index bcd3c49a..f13a2e12 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1432,7 +1432,11 @@ static bool assign_layers_to_device( if (dev.gpu_support.cuda || dev.gpu_support.metal) { int64_t required_mem = w[m] * b_prime; - int64_t available_mem = dev.gpu_props.memory_free * GIGABYTE - c_gpu[m]; + int64_t available_mem = dev.gpu_props.memory_free * GIGABYTE - c_gpu[m]; + if (dev.gpu_support.metal && m == 0 && cparams.keep_out_in_metal) { + available_mem -= bo; + } + if (required_mem <= available_mem) { n_gpu_layers[m] = w[m]; } else {