Skip to content

Commit 56b41af

Browse files
committed
qwen2vl does not use RMS norm
1 parent 4947b81 commit 56b41af

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/mtmd/clip.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ struct clip_graph {
592592
const int n_pos = n_patches;
593593
const int num_position_ids = n_pos * 4; // m-rope requires 4 dim per position
594594

595+
norm_type norm_t = ctx->proj_type == PROJECTOR_TYPE_QWEN25VL
596+
? NORM_TYPE_RMS // qwen 2.5 vl
597+
: NORM_TYPE_NORMAL; // qwen 2 vl
598+
595599
int mrope_sections[4] = {d_head/4, d_head/4, d_head/4, d_head/4};
596600

597601
ggml_tensor * inp_raw = build_inp_raw();
@@ -633,7 +637,7 @@ struct clip_graph {
633637

634638
// pre-layernorm
635639
if (model.pre_ln_w) {
636-
inpL = build_norm(inpL, model.pre_ln_w, model.pre_ln_b, NORM_TYPE_RMS, eps, -1);
640+
inpL = build_norm(inpL, model.pre_ln_w, model.pre_ln_b, norm_t, eps, -1);
637641
}
638642

639643
if (use_window_attn) {
@@ -710,7 +714,7 @@ struct clip_graph {
710714
cb(cur, "ffn_inp", il);
711715

712716
// layernorm2
713-
cur = build_norm(cur, layer.ln_2_w, layer.ln_2_b, NORM_TYPE_RMS, eps, il);
717+
cur = build_norm(cur, layer.ln_2_w, layer.ln_2_b, norm_t, eps, il);
714718
cb(cur, "ffn_inp_normed", il);
715719

716720
// ffn
@@ -731,7 +735,7 @@ struct clip_graph {
731735

732736
// post-layernorm
733737
if (model.post_ln_w) {
734-
inpL = build_norm(inpL, model.post_ln_w, model.post_ln_b, NORM_TYPE_RMS, eps, n_layer);
738+
inpL = build_norm(inpL, model.post_ln_w, model.post_ln_b, norm_t, eps, n_layer);
735739
}
736740

737741
// multimodal projection

0 commit comments

Comments
 (0)