Ct/03 ct test
What does this PR do?
This PR adds an end-to-end comparison harness for Continuous Token vs legacy AgentLoop tokenization. It runs real SingleTurnAgentLoop and ToolAgentLoop code with deterministic model outputs/tools, then compares CT and legacy prompt_ids, response_ids, response_mask, and logprobs.
[WIP] It also check continuous token output with conanical apply_chat_template to full historical messages.
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
Overview of test result
Family Models Runs Pass Mismatch Error Notes
Qwen 9 27 9 18 0 Single-turn passes; tool cases mismatch because legacy misses the newline after assistant EOS.
GLM 4 12 4 8 0 Single-turn CT-vs-legacy passes; tool cases mismatch on the observation boundary. GLM-5.1 matches full template; GLM-4.7/5 have acceptable think-boundary CT-vs-full raw mismatches.
Kimi 3 9 9 0 0 All default trajectories pass with tool_parser=kimi. CT-vs-full-template is WIP.
Seed-OSS 1 3 3 0 0 All default trajectories pass with tool_parser=seed. CT-vs-full-template is WIP.
MiniMax 3 9 3 0 6 Single-turn passes; tool cases are legacy-only TemplateError. CT-vs-full-template is WIP.
MiMo 2 6 6 0 0 All default trajectories pass with Hermes parser. CT-vs-full-template is WIP.
Nemotron 3 9 3 6 0 Single-turn passes; tool cases mismatch because legacy misses the tool-response user header. CT-vs-full-template is WIP.
Main Changes
- Adds structured mock trajectories for single-turn and multi-turn tool rollouts.
- Adds deterministic tools and deterministic server output generation based on each tokenizer's own chat template.
- Runs both paths:
- Legacy AgentLoop with CT disabled.
- Continuous Token AgentLoop with CT enabled.
- Compares token outputs, masks, logprobs, generation prompts, and full decoded CT text.
- Separately compares CT output against a full post-hoc
apply_chat_templaterender and classifies acceptable raw text differences. - Adds CLI options for selecting models, trajectories, parser format, cached/downloaded tokenizers, JSON ledger output, artifact dumps, and mismatch failures.
- Adds a README with the current default-model results.
Changed Files
-
tests/experimental/agent_loop/continuous_token/README.md- Documents the test setup, pass criteria, default trajectories, default model list, and family-level results.
- Records current results across Qwen, GLM, Kimi, Seed, MiniMax, MiMo, and Nemotron.
- Explains expected CT-vs-legacy mismatches where CT matches the canonical full-template boundary and legacy misses boundary tokens.
- Notes DeepSeek as WIP because the checked DeepSeek tokenizer family does not expose a compatible Jinja
chat_template.
-
tests/experimental/agent_loop/continuous_token/mock_trajectories.py- Adds trajectory dataclasses:
TrajectoryStep,SingleTurnTrajectory, andToolAgentTrajectory. - Adds deterministic function tools:
get_weather,estimate_travel,reserve_room, andlookup_incident. - Adds mock trajectories:
singleturnchatmultiturnsingletoolmultiturnmultitoolmultiturnretryusermultiturnretrysystem
- Adds helpers to select trajectories and tool-agent trajectories by name.
- Adds trajectory dataclasses:
-
tests/experimental/agent_loop/continuous_token/compare_agentloop_ct_vs_legacy.py- Adds the comparison CLI.
- Loads tokenizers, infers tool parser format, prepares assistant output suffixes from chat templates, and runs deterministic AgentLoop rollouts.
- Compares CT and legacy outputs at token and metadata level.
- Compares decoded CT text with full-template rendering and classifies acceptable differences such as final trailing newline, empty Qwen think block, and GLM think-boundary formatting.
- Can write a structured ledger and sequence artifacts for debugging mismatches.
Notes
The harness is intentionally tokenizer/template driven. It avoids hard-coding Hermes-style tool-call strings, so each model family is tested against its own chat-template rendering behavior.
This PR also contains the diff from PR02. After PR02 is merged, this branch will be rebased and will only show the diff brought about by this PR.
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.