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

Check if the given token is a string #745

Merged
merged 3 commits into from
Mar 14, 2024
Merged

Conversation

silverriver
Copy link
Contributor

@rlouf
Copy link
Member

rlouf commented Mar 14, 2024

Thank you! Is this solving an issue you encountered? Also would you mind running pre-commit to fix code style?

@rlouf rlouf merged commit aa0a35e into outlines-dev:main Mar 14, 2024
4 checks passed
@silverriver
Copy link
Contributor Author

Thank you! Is this solving an issue you encountered? Also would you mind running pre-commit to fix code style?

Yeap, this solves my issue when I am using the Qwen model family, such as https://huggingface.co/Qwen/Qwen-1_8B.

Here is a code snip:

import vllm
from outlines.serve.vllm import RegexLogitsProcessor
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen-1_8B', trust_remote_code=True)
prompt = "Answer with A, B, C, or D."

llm = vllm.LLM(model="Qwen/Qwen-1_8B", trust_remote_code=True)
logits_processor = RegexLogitsProcessor(regex_string=r'[ABCD]', llm=llm)
outputs = llm.generate([prompt],
            sampling_params=vllm.SamplingParams(
                max_tokens=5, logits_processors=[logits_processor]
            ),
        )

I have also found out that the Qwen model family use a non-standard tokenizer implementation, i.e., they return byte sequences as their tokens, not strings. However, I think it is always benifical to consider more corner cases.

@silverriver silverriver deleted the patch-1 branch March 14, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants