-
-
Notifications
You must be signed in to change notification settings - Fork 20k
fix: add missing bos_token to example templates #11432
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1a7f9e3
fix: add missing bos_token to example templates
toslunar 263ab89
test: BOS occurrence in formatted conversation
toslunar 774a24f
chore: rename dir
toslunar 506de06
ci: add non-e2e examples test
toslunar 781237d
ci: merge examples tests
toslunar cea1d41
test: bugfix `jinja_paths` collection
toslunar 0d9fb7c
test: use VLLM_PATH
toslunar b40c526
test: update expected output
toslunar f49990c
Merge branch 'main' into example-jinja-bos
toslunar f58717f
chore: format
toslunar dd2883a
fix!: make LLM.chat tokenize
toslunar 30ae8ae
Merge branch 'main' into example-jinja-bos
toslunar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| {{ bos_token -}} | ||
| {% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content']}}{% if (loop.last and add_generation_prompt) or not loop.last %}{{ '<|im_end|>' + '\n'}}{% endif %}{% endfor %} | ||
| {% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{ '<|im_start|>assistant\n' }}{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| {{- bos_token }} | ||
| {%- if tools %} | ||
| {{- '<|start_of_role|>available_tools<|end_of_role|> | ||
| ' }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| {{- bos_token }} | ||
| {%- macro json_to_python_type(json_spec) %} | ||
| {%- set basic_type_map = { | ||
| "string": "str", | ||
|
|
||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import transformers | ||
|
|
||
| jinja_paths = [ | ||
| pytest.param(path, id=path.stem) | ||
| for path in sorted((Path(__name__).parent.parent / | ||
| "examples").glob("*.jinja")) | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("path", jinja_paths) | ||
| @pytest.mark.parametrize("num_messages", [1, 3]) | ||
| def test_bos(path: Path, num_messages: int) -> None: | ||
| with path.open("r", encoding="utf-8") as f: | ||
| chat_template = f.read() | ||
| # We might guess an appropriate tokenizer model from the file name but we | ||
| # don't maintain such list. | ||
| # Use arbitrary BOS for testing. It doesn't have to match the str in the | ||
| # correct tokenizer. | ||
| bos_token = "=BOS=" | ||
| tokenizer = transformers.PreTrainedTokenizerBase( | ||
| chat_template=chat_template, bos_token=bos_token, eos_token="=EOS=") | ||
| conversation = [ | ||
| { | ||
| "role": "user", | ||
| "content": "1" | ||
| }, | ||
| { | ||
| "role": "assistant", | ||
| "content": "2" | ||
| }, | ||
| { | ||
| "role": "user", | ||
| "content": "3" | ||
| }, | ||
| ][:num_messages] | ||
| try: | ||
| prompt: str = tokenizer.apply_chat_template(conversation=conversation, | ||
| tokenize=False) | ||
| except Exception as e: | ||
| if str(e | ||
| ) == "Embedding models should only embed one message at a time": | ||
| pytest.skip(reason=str(e)) | ||
| raise | ||
| assert prompt.startswith(bos_token) | ||
| assert prompt.count(bos_token) == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.