Support mixed text and raw-token rollout content in Swift template - #10029
Open
kerbeans wants to merge 2 commits into
Open
Support mixed text and raw-token rollout content in Swift template#10029kerbeans wants to merge 2 commits into
kerbeans wants to merge 2 commits into
Conversation
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
Support mixed rollout response content in
Template._swift_encode().Rollout responses may contain multiple content components, including a text segment followed by a raw-token segment, for example:
[ "<think>...</think><tool_call>...</tool_call>", { "loss_scale": [...], "token_ids": [...] } ]The current Swift template encoding path assumes that a list whose final item is not a string can be treated directly as
List[int]. For mixed content such asList[str, dict], this passes the entire list totokenizer.decode(), causing a type error.This change recognizes a trailing raw-token component and uses its
token_idsonly for suffix inspection. The original response representation is preserved for template encoding, so raw-token rollout semantics are unchanged.Tests
tests/general/test_template_mixed_rollout.py: 5 passedtrainer_namefixture