Skip to content

Commit 6eb7a0f

Browse files
JohannesGaesslerggerganov
authored andcommitted
ggml: fix ggml_graph_cpy undefined behavior (ggml/943)
1 parent e8f0f9b commit 6eb7a0f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

ggml/include/ggml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ extern "C" {
651651

652652
struct ggml_hash_set {
653653
size_t size;
654-
ggml_bitset_t * used;
655-
struct ggml_tensor ** keys;
654+
ggml_bitset_t * used; // whether or not the keys are in use i.e. set
655+
struct ggml_tensor ** keys; // actual tensors in the set, keys[i] is only defined if ggml_bitset_get(used, i)
656656
};
657657

658658
// computation graph

ggml/src/ggml.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18764,7 +18764,8 @@ void ggml_graph_cpy(struct ggml_cgraph * src, struct ggml_cgraph * dst) {
1876418764
}
1876518765

1876618766
for (size_t i = 0; i < src->visited_hash_set.size; ++i) {
18767-
if (src->visited_hash_set.keys[i]) {
18767+
// copy all hashset keys (tensors) that are in use
18768+
if (ggml_bitset_get(src->visited_hash_set.used, i)) {
1876818769
ggml_hash_insert(&dst->visited_hash_set, src->visited_hash_set.keys[i]);
1876918770
}
1877018771
}

0 commit comments

Comments
 (0)