Skip to content

Commit 4640eff

Browse files
committed
Don't interefe with BLAS for large prompts by running only 1 thread
1 parent ab77d76 commit 4640eff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llama.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,11 @@ static bool llama_eval_internal(
852852
};
853853

854854
struct ggml_context * ctx0 = ggml_init(params);
855+
856+
// for big prompts, if BLAS is enabled, it is better to use only one thread
857+
// otherwise, the threads are spin-lock waiting for the BLAS calls and are degrading the performance
855858
ggml_cgraph gf = {};
856-
gf.n_threads = n_threads;
859+
gf.n_threads = N > 255 && ggml_cpu_has_blas() ? 1 : n_threads;
857860

858861
struct ggml_tensor * embd = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, N);
859862
memcpy(embd->data, tokens, N*ggml_element_size(embd));

0 commit comments

Comments
 (0)