]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
#1869 Fix null reference errors when training from scratch with CUDA (#1907)
authorRobyn <redacted>
Sat, 24 Jun 2023 18:10:29 +0000 (04:10 +1000)
committerGitHub <redacted>
Sat, 24 Jun 2023 18:10:29 +0000 (20:10 +0200)
* #1869 Fix null reference errors when training from scratch with CUDA build

Calling ggml_compute_forward when node->src0 was null was causing train-text-from-scratch.exe to terminate unexpectedly.

* ggml : do not dereference src0 if NULL

---------

Co-authored-by: Georgi Gerganov <redacted>
ggml-cuda.cu
ggml.c

index 36a251ecce973bddee7df398cd61931fbed22cf9..010682edb703cbbf1282b0ab76e5298132662f49 100644 (file)
@@ -2635,7 +2635,7 @@ void ggml_cuda_free_scratch() {
 bool ggml_cuda_compute_forward(struct ggml_compute_params * params, struct ggml_tensor * tensor){
     ggml_cuda_func_t func;
     const bool any_on_device = tensor->backend == GGML_BACKEND_GPU
-        || tensor->src0->backend == GGML_BACKEND_GPU || tensor->src0->backend == GGML_BACKEND_GPU_SPLIT
+        || (tensor->src0 != nullptr && (tensor->src0->backend == GGML_BACKEND_GPU || tensor->src0->backend == GGML_BACKEND_GPU_SPLIT))
         || (tensor->src1 != nullptr && tensor->src1->backend == GGML_BACKEND_GPU);
 
     switch (tensor->op) {
diff --git a/ggml.c b/ggml.c
index ef9e8585d9deb2f4cdee0bd7c36724d7860750bf..7104be01b87c7f193a85b3560be47a5df0abf715 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -14911,7 +14911,7 @@ static void ggml_compute_forward(struct ggml_compute_params * params, struct ggm
     if (skip_cpu) {
         return;
     }
-    GGML_ASSERT(tensor->src0->backend == GGML_BACKEND_CPU);
+    GGML_ASSERT(tensor->src0 == NULL || tensor->src0->backend == GGML_BACKEND_CPU);
     GGML_ASSERT(tensor->src1 == NULL || tensor->src1->backend == GGML_BACKEND_CPU);
 #endif // GGML_USE_CUBLAS