]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ggml: Don't assert fail when tensor data changes (#13222)
authorJesse Gross <redacted>
Thu, 1 May 2025 20:46:10 +0000 (13:46 -0700)
committerGitHub <redacted>
Thu, 1 May 2025 20:46:10 +0000 (22:46 +0200)
The following scenario will cause an assertion failure in the graph
allocator:
 - Build and allocate a graph containing a tensor with a non-NULL data
   pointer
 - Build and allocate a new graph where that data is NULL

Result:
ggml-alloc.c:819: GGML_ASSERT(talloc->buffer_id >= 0) failed

This happens during revalidation because we think that memory should
have been previously allocated based on the current graph but in
reality the previous graph was different. In this situation, we
should do a full reallocation pass.

ggml/src/ggml-alloc.c

index a3d3f690133b0fa0300323a5efa8b8b602179c1c..5fd379f6a9461ec0b1a6913d1fef5f52b683efc9 100644 (file)
@@ -816,7 +816,10 @@ static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor *
 static bool ggml_gallocr_node_needs_realloc(ggml_gallocr_t galloc, struct ggml_tensor * node, struct tensor_alloc * talloc) {
     size_t node_size = 0;
     if (!node->data && !node->view_src) {
-        GGML_ASSERT(talloc->buffer_id >= 0); // prevent segfault when misusing the API
+        // If we previously had data but don't now then reallocate
+        if (talloc->buffer_id < 0) {
+            return false;
+        }
         node_size = ggml_backend_buft_get_alloc_size(galloc->bufts[talloc->buffer_id], node);
     }
     return talloc->size_max >= node_size;