Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggml_cont: fix issue with transposed tensors when one dimension is 1 #934

Merged
merged 4 commits into from
Aug 28, 2024

Conversation

smeso
Copy link
Contributor

@smeso smeso commented Aug 26, 2024

When using multiple threads, it is not enough to check for the tensors to be contiguous for
ggml_compute_forward_dup_same_cont to work correctly.
The tensors strides also need to match.

when using multiple threads, it is not enough
to check for the tensors to be contiguous for
ggml_compute_forward_dup_same_cont to work correctly.
The tensors strides also need to match.

Signed-off-by: Salvatore Mesoraca <[email protected]>
Signed-off-by: Salvatore Mesoraca <[email protected]>
it isn't possible to reach this code because
all these functions are invoked by ggml_compute_forward_dup
if and only if src0->type != dst->type

Signed-off-by: Salvatore Mesoraca <[email protected]>
Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following should be more precise I think:

diff --git a/src/ggml.c b/src/ggml.c
index 567084f..c27581c 100644
--- a/src/ggml.c
+++ b/src/ggml.c
@@ -8113,8 +8113,7 @@ static void ggml_compute_forward_dup_same_cont(
     GGML_ASSERT(ggml_is_contiguous(dst) && ggml_is_contiguous(src0));
     GGML_ASSERT(src0->type == dst->type);
 
-    const size_t nb00 = src0->nb[0];
-    const size_t nb0 = dst->nb[0];
+    const size_t nb0 = ggml_type_size(src0->type);
 
     const int ith = params->ith; // thread index
     const int nth = params->nth; // number of threads
@@ -8128,8 +8127,8 @@ static void ggml_compute_forward_dup_same_cont(
     if (ie0 < ie1) {
         memcpy(
             ((char *)  dst->data + ie0*nb0),
-            ((char *) src0->data + ie0*nb00),
-            (ie1 - ie0) * ggml_type_size(src0->type));
+            ((char *) src0->data + ie0*nb0),
+            (ie1 - ie0) * nb0);
     }
 }
 
@@ -9072,8 +9071,7 @@ static void ggml_compute_forward_dup_bytes(
 
     GGML_TENSOR_UNARY_OP_LOCALS;
 
-    if (ggml_is_contiguous(src0) && ggml_is_contiguous(dst) &&
-        nb00 == nb0 && nb01 == nb1 && nb02 == nb2 && nb03 == nb3) {
+    if (ggml_is_contiguous(src0) && ggml_is_contiguous(dst)) {
         ggml_compute_forward_dup_same_cont(params, dst);
         return;
     }

Co-authored-by: Georgi Gerganov <[email protected]>
Signed-off-by: Salvatore Mesoraca <[email protected]>
@ggerganov ggerganov merged commit c78a3d1 into ggerganov:master Aug 28, 2024
4 checks passed
@smeso smeso deleted the smeso/contbug_pr branch August 28, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants