Skip to content

fix(xtoken): ordinary chat mode mis-supervises a final assistant turn with prose and tool_calls #4831

Open

Description

@yuki-97

Problem

With collator.mode=chat and collator.native_thinking_alignment=false (the default), a final assistant message that has both non-empty content and tool_calls is silently mis-masked:

  • assistant_mask covers the prose and the <tool_call> token only.
  • The tool-call JSON payload, </tool_call> and the real <|im_end|> get no CE.
  • The cross-tokenizer EOT pair is built from <tool_call> on each side and is marked is_correct when the two surfaces match (e.g. a Qwen student with a Qwen teacher).

Nothing raises, so training runs normally with weaker supervision on tool-call turns.

Cause

_final_content_span returns only the prose span. In nemo_rl/data/xtoken/native_chat.py the EOT is then taken as the first non-whitespace token after that span:

suffix = text[end:]
terminator = suffix.lstrip()
eot_position = end + len(suffix) - len(terminator)
doc.eot_indices.append(
_eot_index(offsets, text, eot_position) if terminator else -1
)

For ChatML-style templates (Qwen3) the text after the prose is \n<tool_call>\n{...}\n</tool_call><|im_end|>, and <tool_call> is a single added token, so _eot_index returns it. Only the native branch reads tool_calls (native_chat.py:270). A tool-only final turn already raises (empty content span, native_chat.py:304), so the two cases behave inconsistently.

This was traced statically against the Qwen3 chat template and tokenizer config; it has not been reproduced on GPU.

Scope

  • Introduced together with the chat mode in feat(xtoken): replace DP token alignment with offset-based cluster alignment #3286; main has no chat mode before it.
  • Not hit by the shipped configs: examples/configs/xtoken_native_chat.yaml uses native_thinking_alignment: true, and the default exemplar uses mode: "text".
  • The guide does not say that tool conversations require native_thinking_alignment=true, and every existing tool_calls test in tests/unit/data/test_cross_tokenizer_native_chat.py uses native mode.

Suggested fix

Raise in _tokenize_chat_text when native_semantic_messages is None and messages[-1].get("tool_calls") is set, next to the existing reasoning_content guard and in the same style, pointing to collator.native_thinking_alignment=true. Add an ordinary-mode prose + tool_calls test.

Activity

  1. added
    bug
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions