[ContinuousToken] chat template checker
What does this PR do?
This PR adds a standalone CLI for checking whether a model chat template is safe for append-only Continuous Token rollout. It reuses the mock trajectories from PR 03 and validates both raw template prefix behavior and production-shaped CT token merging.
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
scripts/chat_template_checker.py. - Loads a HuggingFace tokenizer by model ID or local path.
- Optionally overrides the tokenizer chat template with a local
.jinjafile. - Runs two layers of checks:
- Raw text prefix checks: verifies that rendering a shorter conversation is a prefix of rendering the longer conversation at assistant/tool boundaries.
- Continuous Token checks: creates the configured CT builder, incrementally appends assistant and non-assistant turns, and compares the result to full chat-template tokenization.
- Supports
model_family=auto, explicit CT builder families, custom builder modules, chat-template kwargs, and optional tokenizer download. - Prints per-case PASS/FAIL output and exits non-zero when the template is not CT-safe.
Changed Files
scripts/chat_template_checker.py- New CLI script.
- Uses
tests.experimental.agent_loop.continuous_token.mock_trajectories. - Uses
apply_chat_template,create_continuous_token_builder, andresolve_continuous_token_model_family. - Implements raw text checks, token-level CT checks, concise failure reporting, and exit codes:
0: all checks passed.1: checker ran and found failures.2: tokenizer/checker initialization failed.
Example Usage
python scripts/chat_template_checker.py --model Qwen/Qwen3-0.6B
python scripts/chat_template_checker.py --model zai-org/GLM-4.7-Flash --allow-download
python scripts/chat_template_checker.py --model Qwen/Qwen3-0.6B --template /path/to/chat_template.jinja
Notes
This tool is useful before adding support for a new model family. It gives a quick answer on whether the template is append-only by itself and whether the current CT builder can reproduce full-template tokenization across the mock trajectories.
This PR also contains the diff from PR03. After PR03 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.