Skip to content

Commit 93aed75

Browse files
committed
common : don't crash if newline token is not found
1 parent 037259b commit 93aed75

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

llama.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,12 @@ static void llm_load_vocab(
33143314

33153315
// determine the newline token: LLaMA "<0x0A>" == 10 == '\n', Falcon 193 == '\n'
33163316
if (vocab.type == LLAMA_VOCAB_TYPE_SPM) {
3317-
vocab.linefeed_id = llama_byte_to_token(vocab, '\n');
3317+
try {
3318+
vocab.linefeed_id = llama_byte_to_token(vocab, '\n');
3319+
} catch (const std::exception & e) {
3320+
LLAMA_LOG_WARN("%s: SPM vocabulary, but newline token not found: %s! Using special_pad_id instead.", __func__, e.what());
3321+
vocab.linefeed_id = vocab.special_pad_id;
3322+
}
33183323
} else if (vocab.type == LLAMA_VOCAB_TYPE_WPM) {
33193324
vocab.linefeed_id = vocab.special_pad_id;
33203325
} else {

0 commit comments

Comments
 (0)