]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Documented CUDA reproducibility, added warning (#1346)
authorJohannes Gäßler <redacted>
Mon, 8 May 2023 00:42:01 +0000 (02:42 +0200)
committerGitHub <redacted>
Mon, 8 May 2023 00:42:01 +0000 (02:42 +0200)
README.md
examples/common.cpp
ggml-cuda.cu

index 19cc94aa269c9c73f0863620773939c3a9299e1d..6cbdcbf834631c9c0d36943273ea1c56b0cac360 100644 (file)
--- a/README.md
+++ b/README.md
@@ -257,6 +257,8 @@ Building the program with BLAS support may lead to some performance improvements
     cmake --build . --config Release
     ```
 
+Note: Because llama.cpp uses multiple CUDA streams for matrix multiplication results [are not guaranteed to be reproducible](https://docs.nvidia.com/cuda/cublas/index.html#results-reproducibility). If you need reproducibility, set `GGML_CUDA_MAX_STREAMS` in the file `ggml-cuda.cu` to 1.
+
 ### Prepare Data & Run
 
 ```bash
index 97eded6eccd64811607e1719b0cc63a7824a4ee3..f1c3bae13b84cdde81b66cf1e25d9724e64b6e07 100644 (file)
@@ -100,6 +100,9 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
         arg = argv[i];
 
         if (arg == "-s" || arg == "--seed") {
+#if defined(GGML_USE_CUBLAS)
+            fprintf(stderr, "WARNING: when using cuBLAS generation results are NOT guaranteed to be reproducible.\n");
+#endif
             if (++i >= argc) {
                 invalid_param = true;
                 break;
index e8a1e77cb06fc0b947aec8de0de21c0988666f6f..127b352a0f2c98159e6bdff8baf24189a1b38ecc 100644 (file)
@@ -348,7 +348,7 @@ static void ggml_cuda_pool_free(void * ptr, size_t size) {
     CUDA_CHECK(cudaFree(ptr));
 }
 
-#define GGML_CUDA_MAX_STREAMS 8
+#define GGML_CUDA_MAX_STREAMS 8 // Set this to 1 for reproducible matrix multiplication.
 #define GGML_CUDA_MAX_EVENTS 64
 static cublasHandle_t g_cublasH = nullptr;
 static cudaStream_t g_cudaStreams[GGML_CUDA_MAX_STREAMS] = { nullptr };