Skip to content

Commit d94c6e0

Browse files
llama : add support for SmolLm pre-tokenizer (#8609)
* Adding SmolLM Pre Tokenizer * Update convert_hf_to_gguf_update.py Co-authored-by: compilade <[email protected]> * Update src/llama.cpp Co-authored-by: compilade <[email protected]> * handle regex * removed .inp and out .out ggufs --------- Co-authored-by: compilade <[email protected]>
1 parent 566daa5 commit d94c6e0

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

convert_hf_to_gguf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ def get_vocab_base_pre(self, tokenizer) -> str:
597597
if chkhsh == "63b97e4253352e6f357cc59ea5b583e3a680eaeaf2632188c2b952de2588485e":
598598
# ref: https://huggingface.co/mistralai/Mistral-Nemo-Base-2407
599599
res = "tekken"
600+
if chkhsh == "855059429035d75a914d1eda9f10a876752e281a054a7a3d421ef0533e5b6249":
601+
# ref: https://huggingface.co/HuggingFaceTB/SmolLM-135M
602+
res = "smollm"
600603

601604
if res is None:
602605
logger.warning("\n")

convert_hf_to_gguf_update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class TOKENIZER_TYPE(IntEnum):
9292
{"name": "jais", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/core42/jais-13b", },
9393
{"name": "t5", "tokt": TOKENIZER_TYPE.UGM, "repo": "https://huggingface.co/google-t5/t5-small", },
9494
{"name": "tekken", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mistralai/Mistral-Nemo-Base-2407", },
95+
{"name": "smollm", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/HuggingFaceTB/SmolLM-135M", },
9596
]
9697

9798

include/llama.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern "C" {
9393
LLAMA_VOCAB_PRE_TYPE_VIKING = 18,
9494
LLAMA_VOCAB_PRE_TYPE_JAIS = 19,
9595
LLAMA_VOCAB_PRE_TYPE_TEKKEN = 20,
96+
LLAMA_VOCAB_PRE_TYPE_SMOLLM = 21,
9697
};
9798

9899
// note: these values should be synchronized with ggml_rope

src/llama.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5521,6 +5521,10 @@ static void llm_load_vocab(
55215521
vocab.tokenizer_clean_spaces = false;
55225522
vocab.tokenizer_ignore_merges = true;
55235523
vocab.tokenizer_add_bos = true;
5524+
} else if (
5525+
tokenizer_pre == "smollm") {
5526+
vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_SMOLLM;
5527+
vocab.tokenizer_clean_spaces = false;
55245528
} else {
55255529
throw std::runtime_error(format("unknown pre-tokenizer type: '%s'", tokenizer_pre.c_str()));
55265530
}
@@ -15543,6 +15547,7 @@ struct llm_tokenizer_bpe {
1554315547
case LLAMA_VOCAB_PRE_TYPE_STARCODER:
1554415548
case LLAMA_VOCAB_PRE_TYPE_REFACT:
1554515549
case LLAMA_VOCAB_PRE_TYPE_COMMAND_R:
15550+
case LLAMA_VOCAB_PRE_TYPE_SMOLLM:
1554615551
regex_exprs = {
1554715552
"\\p{N}",
1554815553
"'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)",

0 commit comments

Comments
 (0)