Skip to content

Commit 2160aef

Browse files
authored
handle cls_out shape based on output labels
1 parent 3f84682 commit 2160aef

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/llama-arch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ static const std::map<llm_kv, const char *> LLM_KV_NAMES = {
174174
{ LLM_KV_CONVNEXT_EMBEDDING_LENGTH, "%s.convnext.embedding_length" },
175175
{ LLM_KV_CONVNEXT_BLOCK_COUNT, "%s.convnext.block_count" },
176176

177+
{ LLM_KV_CLASSIFIER_OUTPUT_LABELS, "%s.classifier.output_labels" },
178+
177179
{ LLM_KV_TOKENIZER_MODEL, "tokenizer.ggml.model" },
178180
{ LLM_KV_TOKENIZER_PRE, "tokenizer.ggml.pre" },
179181
{ LLM_KV_TOKENIZER_LIST, "tokenizer.ggml.tokens" },

src/llama-arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ enum llm_kv {
213213
LLM_KV_CONVNEXT_EMBEDDING_LENGTH,
214214
LLM_KV_CONVNEXT_BLOCK_COUNT,
215215

216+
LLM_KV_CLASSIFIER_OUTPUT_LABELS,
217+
216218
// deprecated:
217219
LLM_KV_TOKENIZER_PREFIX_ID,
218220
LLM_KV_TOKENIZER_SUFFIX_ID,

src/llama-hparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct llama_hparams {
131131
bool attn_soft_cap = false;
132132
bool use_kq_norm = true;
133133

134+
// for Classifiers
135+
uint32_t n_cls_out_labels = 1;
136+
134137
// llama4
135138
uint32_t n_moe_layer_step = 0;
136139
uint32_t n_no_rope_layer_step = 4;

src/llama-model.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ void llama_model::load_hparams(llama_model_loader & ml) {
683683
ml.get_key(LLM_KV_ATTENTION_LAYERNORM_EPS, hparams.f_norm_eps);
684684
ml.get_key(LLM_KV_ATTENTION_CAUSAL, hparams.causal_attn);
685685
ml.get_key(LLM_KV_POOLING_TYPE, hparams.pooling_type, false);
686+
ml.get_arr_n(LLM_KV_CLASSIFIER_OUTPUT_LABELS, hparams.n_cls_out_labels, false);
686687

687688
switch (hparams.n_layer) {
688689
case 3:
@@ -2121,8 +2122,8 @@ bool llama_model::load_tensors(llama_model_loader & ml) {
21212122
cls = create_tensor(tn(LLM_TENSOR_CLS, "weight"), {n_embd, n_embd}, TENSOR_NOT_REQUIRED);
21222123
cls_b = create_tensor(tn(LLM_TENSOR_CLS, "bias"), {n_embd}, TENSOR_NOT_REQUIRED);
21232124

2124-
cls_out = create_tensor(tn(LLM_TENSOR_CLS_OUT, "weight"), {n_embd, 1}, TENSOR_NOT_REQUIRED);
2125-
cls_out_b = create_tensor(tn(LLM_TENSOR_CLS_OUT, "bias"), {1}, TENSOR_NOT_REQUIRED);
2125+
cls_out = create_tensor(tn(LLM_TENSOR_CLS_OUT, "weight"), {n_embd, hparams.n_cls_out_labels}, TENSOR_NOT_REQUIRED);
2126+
cls_out_b = create_tensor(tn(LLM_TENSOR_CLS_OUT, "bias"), {hparams.n_cls_out_labels}, TENSOR_NOT_REQUIRED);
21262127
}
21272128

21282129
tok_norm = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD_NORM, "weight"), {n_embd}, 0);

0 commit comments

Comments
 (0)