Skip to content

Support mixed text and raw-token rollout content in Swift template - #10029

Open
kerbeans wants to merge 2 commits into
modelscope:mainfrom
kerbeans:support-mixed-rollout-content
Open

Support mixed text and raw-token rollout content in Swift template#10029
kerbeans wants to merge 2 commits into
modelscope:mainfrom
kerbeans:support-mixed-rollout-content

Conversation

@kerbeans

@kerbeans kerbeans commented Sep 2, 2026

Copy link
Copy Markdown

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 as List[str, dict], this passes the entire list to tokenizer.decode(), causing a type error.

This change recognizes a trailing raw-token component and uses its token_ids only 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 passed
  • Existing exact-token rollout tests: 33 passed; one unrelated existing test requires a missing trainer_name fixture

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.

1 participant