]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
Fix SAM example mask output with latest ggml
authorYavorGIvanov <redacted>
Fri, 8 Sep 2023 13:17:44 +0000 (16:17 +0300)
committerYavorGIvanov <redacted>
Fri, 8 Sep 2023 13:17:47 +0000 (16:17 +0300)
- I am not sure why this inplace removal causes the output to turn
  correct again. I spend some time debugging and trying different
things, but my assumption is that some dependency is not properly
propagated and the allocator doesn't know about some tensor and
therefore decided to free it and overwrite its memory
- I also added commented out build_forward_expand, which also fixes
the output, but I am still not sure why
- Additionally I am still trying to figure out why the
  ggml_allocr_alloc(..) calls after the ggml_conv_transpose_2d_p0 are
needed
- I guess I have to spend some time debugging the ggml allocator and
  figure out what wrong is happening in this operations. Probably
something wrong in the operation implementation that I am unable to
notice.

Fixes #510.

examples/sam/main.cpp

index a3469021a23c3ba89c1017f0a0b257a872b5d2c4..e15cbefdec73f20a0cd68a55634e5a12e723fc7b 100644 (file)
@@ -1653,7 +1653,7 @@ bool sam_decode_mask(
                 struct ggml_tensor * q_0 = ggml_add(ctx0, queries, tokens);
 
                 struct ggml_tensor * self_attn = sam_decode_mask_transformer_attn(tfm_layer.self_attn, q_0, q_0, queries, ctx0, model);
-                queries = ggml_add_inplace(ctx0, queries, self_attn);
+                queries = ggml_add(ctx0, queries, self_attn);
             }
 
             queries = ggml_norm(ctx0, queries, hparams.eps_decoder_transformer);
@@ -1730,6 +1730,7 @@ bool sam_decode_mask(
     // ref: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/mask_decoder.py#L136
     keys = ggml_cont(ctx0, ggml_transpose(ctx0, keys));
     keys = ggml_view_4d(ctx0, keys, srcNE[0], srcNE[1], srcNE[2], srcNE[3], srcNE[0]*keys->nb[0], keys->nb[1], keys->nb[2], 0);
+    // ggml_build_forward_expand(gf, keys);
     struct ggml_tensor * upscaled_embedding = {};
     {
         // ConvTranspose2d