[ContinuousToken] Continuous Token Builder Core
What does this PR do?
This PR adds the core Continuous Token builder layer and rollout config surface. The new builder keeps a runtime token stream append-only across turns, so AgentLoop code can preserve generated assistant tokens and append tool/user/system messages without repeatedly reconstructing previous assistant text.
Continuous Token is disabled by default. Existing rollout behavior is unchanged unless multi_turn.continuous_token.enable is set to True.
Checklist Before Starting
- [x] Search for similar PRs. Paste at least one query link here: ...
- [x] Format the PR title as
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,fully_async,one_step_off- If this PR involves multiple modules, separate them with
,like[megatron, fsdp, doc] {type}is infeat,fix,refactor,chore,test- If this PR breaks any API (CLI arguments, config, function signature, etc.), add
[BREAKING]to the beginning of the title. - Example:
[BREAKING][fsdp, megatron] feat: dynamic batching
Test
For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.
API and Usage Example
Demonstrate how the API changes if any, and provide usage example(s) if possible.
# Add code snippet or script demonstrating how to use this
Design & Code Changes
Main Changes
- Adds
MergeResultto report appended token count, assistant vs non-assistant merge kind, inserted boundary tokens, and removed prefix tokens. - Adds
ContinuousTokenBuilderwith initial prompt rendering, append-only message validation, incremental non-assistant tokenization, assistant token appending, and token-level suffix diffing. - Adds model-family-specific builders for known chat-template boundary behavior:
- Qwen/Qwen2.5/Qwen3/Qwen3.5: inserts the missing newline after
<|im_end|>before appending the next non-assistant segment. - MiniMax: inserts the missing newline after
[e~[before appending the next segment. - GLM-4.7/GLM-5: removes ambiguous trailing
<|observation|>or<|user|>when that token is both an assistant stop token and the next message boundary.
- Qwen/Qwen2.5/Qwen3/Qwen3.5: inserts the missing newline after
- Adds a registry and
automodel-family resolver so built-in and custom builders can be selected from config/model metadata. - Adds rollout config fields for enabling CT, selecting the model family, and importing a custom builder module.
Changed Files
-
verl/utils/continuous_token.py- New core builder implementation.
- Defines
MergeResult,ContinuousTokenBuilder, Qwen, MiniMax, and GLM builders. - Handles tool-message grouping, synthetic context for tool responses, assistant token appends, and boundary token insert/remove metadata.
-
verl/utils/continuous_token_wiring.py- New builder registry and factory.
- Defines built-in families:
default,qwen,qwen25,qwen3,qwen35,minimax,glm47. - Adds
model_family=autoinference from model path/tokenizer name. - Supports custom builder registration through
custom_builder_module.
-
verl/workers/config/rollout.py- Adds
ContinuousTokenConfig. - Adds
MultiTurnConfig.continuous_token. - Exposes CT family option constants in
__all__.
- Adds
-
verl/trainer/config/rollout/rollout.yaml- Adds the YAML config block:
multi_turn.continuous_token.enablemulti_turn.continuous_token.model_familymulti_turn.continuous_token.custom_builder_module
- Adds the YAML config block:
Notes
This PR only introduces the reusable CT builder/config foundation. It does not yet route AgentLoop execution through CT; that integration is added in PR 02.
Checklist Before Submitting
[!IMPORTANT] Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
- [ ] Read the Contribute Guide.
- [ ] Apply pre-commit checks:
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always - [ ] Add / Update the documentation.
- [ ] Add unit or end-to-end test(s) to the CI workflow to cover all the code. If not feasible, explain why: ...
- [ ] Once your PR is ready for CI, send a message in the
ci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).) - [ ] If your PR is related to the
recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.