summaryrefslogtreecommitdiff
path: root/gguf-py/gguf/gguf_writer.py
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2024-04-16 08:13:13 +0200
committerGitHub <noreply@github.com>2024-04-16 09:13:13 +0300
commit4fbd8098e63670c6ae11a8adc350f5ba191cfda3 (patch)
tree2b788b46bac8408336d12594ffd39ee2cad1cf2d /gguf-py/gguf/gguf_writer.py
parent7593639ce335e8d7f89aa9a54d616951f273af60 (diff)
gguf : add special tokens metadata for FIM/Infill (#6689)
This commit adds special token metadata for Fill-In-the-Middle (FIM)/Infill to the GGUF model. The motivation for this is that currently there is support for CodeLlama but other models exist now like CodeGemma, but the different models use different token ids for the special tokens and this commit allows for supporting multiple models. Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'gguf-py/gguf/gguf_writer.py')
-rw-r--r--gguf-py/gguf/gguf_writer.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/gguf-py/gguf/gguf_writer.py b/gguf-py/gguf/gguf_writer.py
index f4c44076..ff9326d5 100644
--- a/gguf-py/gguf/gguf_writer.py
+++ b/gguf-py/gguf/gguf_writer.py
@@ -469,6 +469,18 @@ class GGUFWriter:
def add_chat_template(self, value: str) -> None:
self.add_string(Keys.Tokenizer.CHAT_TEMPLATE, value)
+ def add_prefix_token_id(self, id: int) -> None:
+ self.add_uint32(Keys.Tokenizer.PREFIX_ID, id)
+
+ def add_suffix_token_id(self, id: int) -> None:
+ self.add_uint32(Keys.Tokenizer.SUFFIX_ID, id)
+
+ def add_middle_token_id(self, id: int) -> None:
+ self.add_uint32(Keys.Tokenizer.MIDDLE_ID, id)
+
+ def add_eot_token_id(self, id: int) -> None:
+ self.add_uint32(Keys.Tokenizer.EOT_ID, id)
+
def _pack(self, fmt: str, value: Any, skip_pack_prefix: bool = False) -> bytes:
pack_prefix = ''
if not skip_pack_prefix: