Skip to content

Commit bf7b0c9

Browse files
authored
mtmd: pad mask for qwen2.5vl (#16954)
* mtmd: pad mask for qwen2.5vl * improve
1 parent fcfce04 commit bf7b0c9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tools/mtmd/clip.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,15 @@ struct clip_graph {
761761
ggml_set_name(window_mask, "window_mask");
762762
ggml_set_input(window_mask);
763763

764+
// if flash attn is used, we need to pad the mask and cast to f16
765+
if (ctx->flash_attn_type == CLIP_FLASH_ATTN_TYPE_ENABLED) {
766+
int n_pad = GGML_PAD(window_mask->ne[1], GGML_KQ_MASK_PAD) - window_mask->ne[1];
767+
if (n_pad > 0) {
768+
window_mask = ggml_pad(ctx0, window_mask, 0, n_pad, 0, 0);
769+
}
770+
window_mask = ggml_cast(ctx0, window_mask, GGML_TYPE_F16);
771+
}
772+
764773
// inpL shape: [n_embd, n_patches_x * n_patches_y, batch_size]
765774
GGML_ASSERT(batch_size == 1);
766775
inpL = ggml_reshape_2d(ctx0, inpL, n_embd * 4, n_patches_x * n_patches_y * batch_size / 4);

0 commit comments

Comments
 (0)