verl icon indicating copy to clipboard operation
verl copied to clipboard

[ContinuousToken] Continuous Token Builder Core

Open gxlvera opened this issue 5 months ago • 1 comments

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} include fsdp, 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 in feat, 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 MergeResult to report appended token count, assistant vs non-assistant merge kind, inserted boundary tokens, and removed prefix tokens.
  • Adds ContinuousTokenBuilder with 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.
  • Adds a registry and auto model-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=auto inference 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__.
  • verl/trainer/config/rollout/rollout.yaml

    • Adds the YAML config block:
      • multi_turn.continuous_token.enable
      • multi_turn.continuous_token.model_family
      • multi_turn.continuous_token.custom_builder_module

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.

gxlvera avatar Jun 13 '26 00:06 gxlvera

CLA assistant check
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.

CLAassistant avatar Jun 13 '26 00:06 CLAassistant