Skip to content

[recipe] fix: normalize LangGraph chat template token IDs - #140

Open
le-czs wants to merge 1 commit into
verl-project:mainfrom
le-czs:fix/langgraph-normalize-chat-template-token-ids
Open

[recipe] fix: normalize LangGraph chat template token IDs#140
le-czs wants to merge 1 commit into
verl-project:mainfrom
le-czs:fix/langgraph-normalize-chat-template-token-ids

Conversation

@le-czs

@le-czs le-czs commented Aug 20, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #139 by normalizing every tokenizer.apply_chat_template(..., tokenize=True) result used by the LangGraph recipe before it is sliced, appended to, sent to the rollout server, or stored in response metadata. This makes tokenizers returning a Transformers BatchEncoding follow the same path as tokenizers returning list[int].

This is not a duplicate: no open PR matched issue #139 or the langgraph BatchEncoding chat template keywords when checked on 2026-08-20. Open-PR search

AI assistance disclosure: OpenAI Codex was used to inspect the issue, implement the change, run checks, and draft this PR. The PR remains a draft pending human review of every changed line.

Checklist Before Starting

Test

  • pre-commit run --all-files --show-diff-on-failure --color=always: passed (ruff, ruff-format).
  • Model Factory CPU regression command including recipe/langgraph_agent/test_chat_model_on_cpu.py: 8 tests passed in the combined agent-loop regression suite.
  • Model Factory Qwen3-4B LangGraph GRPO val_only run on 2 H20 GPUs: platform phase 5, container exit code 0, MATH acc/mean@1=0.996, and no occurrence of BatchEncoding/list TypeError in the full job log.

API and Usage Example

No public API or configuration changes.

Design & Code Changes

  • Reuse the core verl.utils.normalize_token_ids helper already provided by the verl commit pinned in langgraph_agent/REQUIRED_VERL.txt.
  • Normalize initial prompt IDs, the bound system-prompt IDs, and Hermes tool-response IDs at their chat-template boundaries.
  • Add CPU regression tests using a tokenizer that returns BatchEncoding for all three paths.

Checklist Before Submitting

  • Read the contribution guide and repository agent instructions available in the parent verl repository.
  • Apply pre-commit checks.
  • Add / Update documentation. Not needed because this fixes internal token normalization without changing usage.
  • Add the test to a CI workflow. The repository currently runs pre-commit for this path but has no LangGraph CPU-test workflow; the focused test is included for local and parent-repository execution.
  • Request project CI in Slack or Feishu after human review.
  • Update the parent verl recipe submodule reference. This PR targets the recipe repository itself; the parent pin can be updated after merge.

Normalize chat-template outputs at LangGraph boundaries before they are sliced or mutated. Add CPU regression coverage for initial prompts, Hermes tool responses, and bound system prompts.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: CzsGit <czsde@outlook.com>
@le-czs
le-czs marked this pull request as ready for review August 20, 2026 07:53
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.

[BUG] langgraph_agent crashes when chat templates return BatchEncoding

2 participants