Skip to content

Commit 8344ef5

Browse files
Xarbirusggerganov
andauthored
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 0226613 commit 8344ef5

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
@@ -16653,7 +16660,7 @@ static int llama_decode_internal(
1665316660
const uint32_t n_tokens_all = batch_all.n_tokens;
1665416661

1665516662
if (n_tokens_all == 0) {
16656-
LLAMA_LOG_ERROR("%s: n_tokens == 0", __func__);
16663+
LLAMA_LOG_ERROR("%s: n_tokens == 0\n", __func__);
1665716664
return -1;
1665816665
}
1665916666

@@ -16666,7 +16673,7 @@ static int llama_decode_internal(
1666616673
if (batch_all.token) {
1666716674
for (uint32_t i = 0; i < n_tokens_all; ++i) {
1666816675
if (batch_all.token[i] < 0 || (uint32_t)batch_all.token[i] >= model.vocab.n_vocab) {
16669-
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch_all.token[i]);
16676+
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d\n", __func__, i, batch_all.token[i]);
1667016677
return -1;
1667116678
}
1667216679
}
@@ -16954,7 +16961,7 @@ static int llama_encode_internal(
1695416961
const uint32_t n_tokens = batch.n_tokens;
1695516962

1695616963
if (n_tokens == 0) {
16957-
LLAMA_LOG_ERROR("%s: n_tokens == 0", __func__);
16964+
LLAMA_LOG_ERROR("%s: n_tokens == 0\n", __func__);
1695816965
return -1;
1695916966
}
1696016967

@@ -16967,7 +16974,7 @@ static int llama_encode_internal(
1696716974
if (batch.token) {
1696816975
for (uint32_t i = 0; i < n_tokens; ++i) {
1696916976
if (batch.token[i] < 0 || (uint32_t)batch.token[i] >= model.vocab.n_vocab) {
16970-
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d", __func__, i, batch.token[i]);
16977+
LLAMA_LOG_ERROR("%s: invalid token[%d] = %d\n", __func__, i, batch.token[i]);
1697116978
return -1;
1697216979
}
1697316980
}

0 commit comments

Comments
 (0)