Skip to content

Commit 051580c

Browse files
Xarbirusggerganov
authored andcommitted
llama : fix n_vocab init for 'no_vocab' case (ggml-org#9511)
* llama: fixed n_vocab for `no_vocab` models * llama: updated error output for `llama_decode_internal` and `llama_encode_internal` * llama: log warning if there's no vocab_size in metadata * llama: correct vocab size for logging Co-authored-by: Georgi Gerganov <[email protected]> --------- Co-authored-by: Georgi Gerganov <[email protected]>
1 parent eeca119 commit 051580c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/llama.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6107,8 +6107,15 @@ static void llm_load_vocab(
61076107
vocab.special_mask_id = -1;
61086108
vocab.linefeed_id = -1;
61096109

6110+
// read vocab size from metadata
6111+
if (!ml.get_key(LLM_KV_VOCAB_SIZE, vocab.n_vocab, false)) {
6112+
vocab.n_vocab = 0;
6113+
LLAMA_LOG_WARN("%s: there is no vocab_size in metadata, vocab.n_vocab will be set to %u\n", __func__, vocab.n_vocab);
6114+
}
61106115
return;
6111-
} else if (tokenizer_model == "llama") {
6116+
}
6117+
6118+
if (tokenizer_model == "llama") {
61126119
vocab.type = LLAMA_VOCAB_TYPE_SPM;
61136120

61146121
// default special tokens
@@ -16657,7 +16664,7 @@ static int llama_decode_internal(
1665716664
const uint32_t n_tokens_all = batch_all.n_tokens;
1665816665

1665916666
if (n_tokens_all == 0) {
16660-
LLAMA_LOG_ERROR("%s: n_tokens == 0", __func__);
16667+
LLAMA_LOG_ERROR("%s: n_tokens == 0\n", __func__);
1666116668
return -1;
1666216669
}
1666316670

@@ -16670,7 +16677,7 @@ static int llama_decode_internal(
1667016677
if (batch_all.token) {
1667116678
for (uint32_t i = 0; i < n_tokens_all; ++i) {
1667216679
if (batch_all.token[i] < 0 || (uint32_t)batch_all.token[i] >= model.vocab.n_vocab) {
16673-
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch_all.token[i]);
16680+
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d\n", __func__, i, batch_all.token[i]);
1667416681
return -1;
1667516682
}
1667616683
}
@@ -16958,7 +16965,7 @@ static int llama_encode_internal(
1695816965
const uint32_t n_tokens = batch.n_tokens;
1695916966

1696016967
if (n_tokens == 0) {
16961-
LLAMA_LOG_ERROR("%s: n_tokens == 0", __func__);
16968+
LLAMA_LOG_ERROR("%s: n_tokens == 0\n", __func__);
1696216969
return -1;
1696316970
}
1696416971

@@ -16971,7 +16978,7 @@ static int llama_encode_internal(
1697116978
if (batch.token) {
1697216979
for (uint32_t i = 0; i < n_tokens; ++i) {
1697316980
if (batch.token[i] < 0 || (uint32_t)batch.token[i] >= model.vocab.n_vocab) {
16974-
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch.token[i]);
16981+
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d\n", __func__, i, batch.token[i]);
1697516982
return -1;
1697616983
}
1697716984
}

0 commit comments

Comments
 (0)