From: Johannes Gäßler Date: Sat, 31 Aug 2024 12:35:42 +0000 (+0200) Subject: ggml: fix ggml_graph_cpy undefined behavior (ggml/943) X-Git-Tag: upstream/0.0.4488~794 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=dbbebcab339c7d63d3806e8f32574bb9aad9a694;p=pkg%2Fggml%2Fsources%2Fllama.cpp ggml: fix ggml_graph_cpy undefined behavior (ggml/943) --- diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 09c72b09..6354fcf5 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -681,8 +681,8 @@ extern "C" { struct ggml_hash_set { size_t size; - ggml_bitset_t * used; - struct ggml_tensor ** keys; + ggml_bitset_t * used; // whether or not the keys are in use i.e. set + struct ggml_tensor ** keys; // actual tensors in the set, keys[i] is only defined if ggml_bitset_get(used, i) }; // computation graph diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 3504e9ad..5f106d52 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -19130,7 +19130,8 @@ void ggml_graph_cpy(struct ggml_cgraph * src, struct ggml_cgraph * dst) { } for (size_t i = 0; i < src->visited_hash_set.size; ++i) { - if (src->visited_hash_set.keys[i]) { + // copy all hashset keys (tensors) that are in use + if (ggml_bitset_get(src->visited_hash_set.used, i)) { ggml_hash_insert(&dst->visited_hash_set, src->visited_hash_set.keys[i]); } }