]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Don't interefe with BLAS for large prompts by running only 1 thread
authorGeorgi Gerganov <redacted>
Sat, 25 Mar 2023 15:03:10 +0000 (17:03 +0200)
committerGeorgi Gerganov <redacted>
Sat, 25 Mar 2023 15:03:10 +0000 (17:03 +0200)
llama.cpp

index 9b4117cb70bcc90433570aabd2e5f137b55112b1..0015edec18df753c5fb2ef1d472c699f06cf7e60 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -852,8 +852,11 @@ static bool llama_eval_internal(
     };
 
     struct ggml_context * ctx0 = ggml_init(params);
+
+    // for big prompts, if BLAS is enabled, it is better to use only one thread
+    // otherwise, the threads are spin-lock waiting for the BLAS calls and are degrading the performance
     ggml_cgraph gf = {};
-    gf.n_threads = n_threads;
+    gf.n_threads = N > 255 && ggml_cpu_has_blas() ? 1 : n_threads;
 
     struct ggml_tensor * embd = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, N);
     memcpy(embd->data, tokens, N*ggml_element_size(embd));