Skip to content

Commit 1f48b0a

Browse files
Documented CUDA reproducibility, added warning (#1346)
1 parent e129551 commit 1f48b0a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ Building the program with BLAS support may lead to some performance improvements
257257
cmake --build . --config Release
258258
```
259259
260+
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.
261+
260262
### Prepare Data & Run
261263
262264
```bash

examples/common.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
100100
arg = argv[i];
101101

102102
if (arg == "-s" || arg == "--seed") {
103+
#if defined(GGML_USE_CUBLAS)
104+
fprintf(stderr, "WARNING: when using cuBLAS generation results are NOT guaranteed to be reproducible.\n");
105+
#endif
103106
if (++i >= argc) {
104107
invalid_param = true;
105108
break;

ggml-cuda.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static void ggml_cuda_pool_free(void * ptr, size_t size) {
348348
CUDA_CHECK(cudaFree(ptr));
349349
}
350350

351-
#define GGML_CUDA_MAX_STREAMS 8
351+
#define GGML_CUDA_MAX_STREAMS 8 // Set this to 1 for reproducible matrix multiplication.
352352
#define GGML_CUDA_MAX_EVENTS 64
353353
static cublasHandle_t g_cublasH = nullptr;
354354
static cudaStream_t g_cudaStreams[GGML_CUDA_MAX_STREAMS] = { nullptr };

0 commit comments

Comments
 (0)