Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions litgpt/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ def __init__(self, checkpoint_dir: Path | str) -> None:
raise NotImplementedError

# NOTE: A temporary fix until it's resolved on Tokenizers side.
# LlaMA tokenizer strips leading spaces if to decode a single token at a time.
# LLaMA and Mistral tokenizers strip leading spaces when decoding a single token at a time,
# because both are backed by SentencePiece which encodes word boundaries with a prefix space (▁).
# https://github.com/huggingface/transformers/issues/31643
self.apply_decoding_fix = None
if (config_path := checkpoint_dir / "tokenizer_config.json").is_file():
with open(config_path, encoding="utf-8") as fp:
self.apply_decoding_fix = "LlamaTokenizer" in json.load(fp)["tokenizer_class"]
tokenizer_class = json.load(fp).get("tokenizer_class", "")
self.apply_decoding_fix = "LlamaTokenizer" in tokenizer_class or "MistralTokenizer" in tokenizer_class

@property
def vocab_size(self) -> int:
Expand Down