Skip to content

Commit ea83dd8

Browse files
mtmd: replace n_layer hack with explicit has_standard_layers flag
1 parent 7e7a065 commit ea83dd8

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

tools/mtmd/clip.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,15 +1641,14 @@ struct clip_model_loader {
16411641

16421642
model.position_embeddings = get_tensor(string_format(TN_POS_EMBD, prefix), false);
16431643

1644-
const int n_layer_orig = hparams.n_layer;
1645-
if (model.proj_type == PROJECTOR_TYPE_GEMMA3NV
1646-
|| model.proj_type == PROJECTOR_TYPE_GRANITE_SPEECH) {
1647-
hparams.n_layer = 0; // these models do not use the generic layer structure
1648-
}
1644+
const bool has_standard_layers = (
1645+
model.proj_type != PROJECTOR_TYPE_GEMMA3NV &&
1646+
model.proj_type != PROJECTOR_TYPE_GRANITE_SPEECH);
16491647

16501648
// layers
1651-
model.layers.resize(hparams.n_layer);
1652-
for (int il = 0; il < hparams.n_layer; ++il) {
1649+
const int n_layers_to_load = has_standard_layers ? hparams.n_layer : 0;
1650+
model.layers.resize(n_layers_to_load);
1651+
for (int il = 0; il < n_layers_to_load; ++il) {
16531652
auto & layer = model.layers[il];
16541653
layer.k_w = get_tensor(string_format(TN_ATTN_K, prefix, il, "weight"), false);
16551654
layer.q_w = get_tensor(string_format(TN_ATTN_Q, prefix, il, "weight"), false);
@@ -2356,7 +2355,6 @@ struct clip_model_loader {
23562355
} break;
23572356
case PROJECTOR_TYPE_GRANITE_SPEECH:
23582357
{
2359-
hparams.n_layer = n_layer_orig;
23602358
model.layers.resize(hparams.n_layer);
23612359

23622360
model.inp_proj_w = get_tensor(string_format(TN_INP_PROJ, "weight"));

0 commit comments

Comments
 (0)