Skip to content

Commit b76150c

Browse files
committed
llama : Added support for Viking pre-tokenizer (#8577)
1 parent a15ef8f commit b76150c

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

convert_hf_to_gguf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ def get_vocab_base_pre(self, tokenizer) -> str:
593593
if chkhsh == "b53802fb28e26d645c3a310b34bfe07da813026ec7c7716883404d5e0f8b1901":
594594
# ref: https://huggingface.co/core42/jais-13b
595595
res = "jais"
596+
if chkhsh == "aa78fe8b04bc622b077520b1fb3d3a5c6f7a53dd375e2361e62599be3cf58de1":
597+
# ref: https://huggingface.co/mistralai/Mistral-Nemo-Base-2407
598+
res = "tekken"
596599

597600
if res is None:
598601
logger.warning("\n")

convert_hf_to_gguf_update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class TOKENIZER_TYPE(IntEnum):
9191
{"name": "gemma-2", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/google/gemma-2-9b", },
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", },
94+
{"name": "tekken", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mistralai/Mistral-Nemo-Base-2407", },
9495
]
9596

9697

include/llama.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern "C" {
9292
LLAMA_VOCAB_PRE_TYPE_CHATGLM4 = 17,
9393
LLAMA_VOCAB_PRE_TYPE_VIKING = 18,
9494
LLAMA_VOCAB_PRE_TYPE_JAIS = 19,
95+
LLAMA_VOCAB_PRE_TYPE_TEKKEN = 20,
9596
};
9697

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

src/llama.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,6 +5517,12 @@ static void llm_load_vocab(
55175517
tokenizer_pre == "viking") {
55185518
vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_VIKING;
55195519
vocab.tokenizer_clean_spaces = false;
5520+
} else if (
5521+
tokenizer_pre == "tekken") {
5522+
vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_TEKKEN;
5523+
vocab.tokenizer_clean_spaces = true;
5524+
vocab.tokenizer_ignore_merges = true;
5525+
vocab.tokenizer_add_bos = true;
55205526
} else if (
55215527
tokenizer_pre == "jais") {
55225528
vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_JAIS;
@@ -15581,6 +15587,13 @@ struct llm_tokenizer_bpe {
1558115587
"\\p{N}",
1558215588
};
1558315589
break;
15590+
case LLAMA_VOCAB_PRE_TYPE_TEKKEN:
15591+
// original regex from tokenizer.json
15592+
// "[^\\r\\n\\p{L}\\p{N}]?[\\p{Lu}\\p{Lt}\\p{Lm}\\p{Lo}\\p{M}]*[\\p{Ll}\\p{Lm}\\p{Lo}\\p{M}]+|[^\\r\\n\\p{L}\\p{N}]?[\\p{Lu}\\p{Lt}\\p{Lm}\\p{Lo}\\p{M}]+[\\p{Ll}\\p{Lm}\\p{Lo}\\p{M}]*|\\p{N}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n/]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+"
15593+
regex_exprs = {
15594+
"[^\\r\\n\\p{L}\\p{N}]?((?=[\\p{L}])([^a-z]))*((?=[\\p{L}])([^A-Z]))+|[^\\r\\n\\p{L}\\p{N}]?((?=[\\p{L}])([^a-z]))+((?=[\\p{L}])([^A-Z]))*|\\p{N}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n/]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
15595+
};
15596+
break;
1558415597
default:
1558515598
// default regex for BPE tokenization pre-processing
1558615599
regex_exprs = {

0 commit comments

Comments
 (0)