From 52c92c0a8cc88f45bcde9556b4f6d4481a36bd9d Mon Sep 17 00:00:00 2001 From: xaedes Date: Mon, 14 Aug 2023 17:53:36 +0200 Subject: [PATCH] terminate recursive tensor cloning when reaching tensor without src tensors --- .../train-text-from-scratch.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/train-text-from-scratch/train-text-from-scratch.cpp b/examples/train-text-from-scratch/train-text-from-scratch.cpp index 266f378b9..9b73361ca 100644 --- a/examples/train-text-from-scratch/train-text-from-scratch.cpp +++ b/examples/train-text-from-scratch/train-text-from-scratch.cpp @@ -1423,6 +1423,17 @@ struct ggml_tensor * ggml_recompute_graph_node( return node; } + int count_children = 0; + for (int k = 0; k < GGML_MAX_SRC; ++k) { + if (node->src[k]) { + ++count_children; + } + } + + if (count_children == 0) { + return node; + } + size_t i = hash_find(replacements->keys, node); GGML_ASSERT(i < GGML_GRAPH_HASHTABLE_SIZE); // assert that not full if (replacements->keys[i] == node) {