[Bug] Literal EOS strings in SFT content are treated as termination tokens
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- huggingface, python
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 5.2k
- Fork
- 466
- Merge trung bình
- 5 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 44
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của InternLM/xtuner
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 4 ngày
-
enhancement good first issue
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
InternLM/xtuner#2246 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailableCó thể đã có người làm @li-lizhe đã nhận 69 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
InternLM/xtuner#2118 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của InternLM/xtuner
Issue tương tự
-
accepted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
future-agi/future-agi#5908 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Placeholder export disables HTML image input for picture descriptionCó thể đã có người làm @cloudiful đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
docling-project/docling-serve#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
Techiebutler/freeframe#687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Parse truncated verbose GC logs up to the first XML errorCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug verbose GC
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
IBM/javacore-analyser#677 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 2 ngày