Repository navigation
Conversation
chat_completion_streaming unconditionally decoded tokenizer.bos_token, which is None when bos_token_id is None (e.g. Qwen2/Qwen3 tokenizers), so chat_completion raised AttributeError before rendering the chat template. Pass an empty string to the template in that case instead.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Engine.chat_completionraisedAttributeErrorfor tokenizers that have no BOS token (e.g. Qwen2/Qwen3, wherebos_token_idisNone). It now renders the chat template with an emptybos_tokenin that case.Why
chat_completion_streamingbuilt the chat-template context by unconditionally decoding the BOS token:Tokenizer.bos_tokenisbytes | Noneand returnsNonewhenbos_token_idisNone(guidance/models/_engine/_tokenizer.py:59-63), so the.decode()call raisedAttributeError: 'NoneType' object has no attribute 'decode'before the chat template was ever rendered. mypy reports the same problem on that line (Item "None" of "bytes | None" has no attribute "decode").This is inconsistent with the rest of the engine:
Parser.process_promptalready guards onself.tokenizer.bos_token_id is not None(guidance/_parser.py:81-84), and the default ChatML template does not referencebos_token, so no BOS is needed to render a prompt.The existing
test_chat_completionruns against gpt2, whose tokenizer hasbos_token_id=50256, so theNonepath was untested.Changes
guidance/models/_engine/_engine.py: pass""asbos_tokento the chat template whenTokenizer.bos_tokenisNone.tests/model_integration/test_engine.py: addtest_chat_completion_tokenizer_without_bos_token, which loads the Qwen3-0.6B tokenizer (no BOS token) and runschat_completionend to end against a stub engine. Only the tokenizer is downloaded, mirroring the tokenizer-only download pattern already used intests/model_integration/test_tokenizers.py.Testing