Skip to content

Commit 916a9ac

Browse files
smspillazslaren
andauthored
ggml-alloc: Don't try to re-use buffers of external tensors (#2562)
* ggml-alloc: Don't try to re-use buffers of external tensors They might be weights that came from another context, so we have no control over them (and they might be re-used elsewhere so writing to them would be a bad idea). * ggml-alloc: >= when checking for out-of-bounds Co-authored-by: slaren <[email protected]> --------- Co-authored-by: slaren <[email protected]>
1 parent ea04a4c commit 916a9ac

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ggml-alloc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ static void allocate_node(struct ggml_allocr * alloc, struct ggml_tensor * node)
394394
if (parent == NULL) {
395395
break;
396396
}
397+
398+
// if the node's data is external, then we cannot re-use it
399+
if ((char *) parent->data < (char *) alloc->data ||
400+
(char *) parent->data >= ((char *) alloc->data + alloc->size)) {
401+
AT_PRINTF("not reusing parent %s for %s as %p is external\n", parent->name, node->name, parent->data);
402+
continue;
403+
}
404+
397405
struct hash_node * p_hn = hash_get(ht, parent);
398406
if (parent->data != NULL && p_hn->n_children == 1 && p_hn->n_views == 0 && ggml_are_same_layout(node, parent)) {
399407
if (ggml_is_view(parent)) {

0 commit comments

Comments
 (0)