[Bug] Literal EOS strings in SFT content are treated as termination tokens
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- huggingface, python
- Área
- machine-learning
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 5.2k
- Forks
- 466
- Merge medio
- 5 d 8 h
- PR fusionados (30 d)
- 44
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de InternLM/xtuner
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 4 días
-
enhancement good first issue
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
InternLM/xtuner#2246 · 3 comentarios ·
Los mantenedores suelen responder en 4 días
-
[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailablePosiblemente ocupada @li-lizhe la tomó hace 69 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 30/100
Los mantenedores suelen responder en 4 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
InternLM/xtuner#2118 · 6 comentarios ·
Los mantenedores suelen responder en 4 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
Los mantenedores suelen responder en 4 días
Todos los issues de InternLM/xtuner
Issues similares
-
accepted
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
future-agi/future-agi#5908 ·
Los mantenedores suelen responder en 1 día
-
Placeholder export disables HTML image input for picture descriptionPosiblemente ocupada @cloudiful la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
docling-project/docling-serve#817 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Techiebutler/freeframe#687 ·
Los mantenedores suelen responder en 1 día
-
Parse truncated verbose GC logs up to the first XML errorPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug verbose GC
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
IBM/javacore-analyser#677 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 2 días