[Bug] Literal EOS strings in SFT content are treated as termination tokens
メンテナーはふだん 4 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- huggingface, python
調査の方向性
Start at OpenaiTokenizeFunctionConfig.build and reproduce the issue with the GLM-5.2 tokenizer and the provided messages. Trace how rendered content is tokenized and how labels are masked; done means literal EOS strings become ordinary text while template-added response terminators remain supervised EOS tokens, with regression coverage and affected caches handled.
索引モデルが issue の本文から書いたものです。
説明
XTuner can encode literal EOS strings in SFT content as actual termination tokens and include them in the training loss. For example, an assistant explaining <|endoftext|> should generate that spelling as ordinary text, while the template-added response terminator should remain a special token.
Reproduction
Verified with XTuner commit e7299bbc, Transformers 5.14.1, and the GLM-5.2 tokenizer:
from transformers import AutoTokenizer
from xtuner.v1.datasets import OpenaiTokenizeFunctionConfig
tokenizer = AutoTokenizer.from_pretrained(
"zai-org/GLM-5.2", trust_remote_code=True
)
tokenize_fn = OpenaiTokenizeFunctionConfig(
chat_template="glm5.2"
).build(tokenizer)
sample = tokenize_fn({
"messages": [
{"role": "user", "content": "解释 GPT-2 的结束标记。"},
{
"role": "assistant",
"content": "GPT-2 使用 <|endoftext|> 作为结束标记。",
},
]
})
print([
(i, sample["labels"][i])
for i, token_id in enumerate(sample["input_ids"])
if token_id == tokenizer.eos_token_id
])
Output:
[(28, 154820), (33, 154820)]
Both the literal inside the sentence and the actual response terminator become supervised EOS targets. Only the latter should be an EOS token.
Impact and scope
This produces incorrect EOS supervision and can cause unexpected early termination during inference. Tool calls can also be affected when their arguments contain EOS literals—for example, inside code or shell commands—potentially leaving the generated call incomplete.
The underlying behavior is not specific to GLM-5.2: Hugging Face tokenizers recognize registered special-token strings even with add_special_tokens=False. Other models can therefore be affected when their EOS spellings appear in training content; the exact markers depend on the tokenizer.
Proposed fix
Implement EOS-aware handling directly in the rendering/tokenization pipeline:
- Track template-inserted response terminators and preserve them as special tokens.
- Encode literal EOS occurrences in message content, reasoning, and tool arguments as ordinary subwords, while preserving other control tokens and model-specific turn boundaries.
- Preserve existing loss-mask semantics, invalidate affected caches, and add regression tests.
Globally enabling split_special_tokens=True on the rendered conversation would also split genuine template controls, so the handling should be selective.
Would this approach be suitable? If maintainers agree, I would be happy to prepare a PR with the implementation and regression tests.
- 主要言語
- Python
- スター
- 5.2k
- フォーク
- 466
- 平均マージ
- 5日 8時間
- マージ済み PR(30日)
- 44
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
InternLM/xtuner のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 4 日以内に返信
-
enhancement good first issue
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
InternLM/xtuner#2246 · コメント 3 件 ·
メンテナーはふだん 4 日以内に返信
-
[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailable対応中かも @li-lizhe が 69 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 30/100
メンテナーはふだん 4 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
InternLM/xtuner#2118 · コメント 6 件 ·
メンテナーはふだん 4 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
メンテナーはふだん 4 日以内に返信
InternLM/xtuner の issue をすべて見る
似ている issue
-
accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
future-agi/future-agi#5908 ·
メンテナーはふだん 1 日以内に返信
-
Placeholder export disables HTML image input for picture description対応中かも @cloudiful が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
docling-project/docling-serve#817 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
Techiebutler/freeframe#687 ·
メンテナーはふだん 1 日以内に返信
-
Parse truncated verbose GC logs up to the first XML error対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug verbose GC
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
IBM/javacore-analyser#677 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 2 日以内に返信