Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about structured generation without a prompt for Llama tokenizers #1321

Open
brandonwillard opened this issue Dec 4, 2024 · 0 comments
Labels
correctness Everything related to the generation correctness documentation Linked to documentation and examples structured generation Linked to structured generation tokenization

Comments

@brandonwillard
Copy link
Member

Llama(/SentencePiece?) tokenizers do something special with spaces and initial tokens. For example,

from transformers import AutoTokenizer

model = "NousResearch/Nous-Hermes-llama-2-7b"
tokenizer = AutoTokenizer.from_pretrained(
    model, clean_up_tokenization_spaces=True
)

https_tokens = tokenizer.encode("https://", add_special_tokens=False)
print(https_tokens)
# [2045, 597]

prompt_tokens = tokenizer.encode("prompt", add_special_tokens=False)
print(prompt_tokens)
# [9508]

print(tokenizer.batch_decode([https_tokens], skip_special_tokens=True))
# ['https://']

print(tokenizer.batch_decode([prompt_tokens + https_tokens], skip_special_tokens=True))
# ['prompt https://']

The decoding used by our structured generation doesn't have this no-space-for-the-first-token consideration, so we need to warn people that structured generation won't allow tokens like 2045 (because it strictly interprets them as " https") when/if generation starts without a prompt. I'm not sure why one would start generation without a prompt, but it's worth mentioning.

@brandonwillard brandonwillard added documentation Linked to documentation and examples structured generation Linked to structured generation tokenization correctness Everything related to the generation correctness labels Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
correctness Everything related to the generation correctness documentation Linked to documentation and examples structured generation Linked to structured generation tokenization
Projects
None yet
Development

No branches or pull requests

1 participant