Skip to content

[Fix] Append GLM-5.3-Flash training EOS only after the final assistant - #2190

Closed
ShilohYu wants to merge 1 commit into
InternLM:mainfrom
ShilohYu:fix/glm53-eos-boundary
Closed

ShilohYu wants to merge 1 commit into
InternLM:mainfrom
ShilohYu:fix/glm53-eos-boundary

Conversation

@ShilohYu

Copy link
Copy Markdown
Collaborator

What

GLM-5.3-Flash 的训练后缀 <|endoftext|> 只在最终 assistant 消息后追加;assistant→system、assistant→assistant 边界不再插入 EOS,与官方 chat_template.jinja 一致。

本 PR 是 #2181 按维度拆分系列的 1/7(失败报告条目 M02/M03)。原 #2181 混在一起 reviewer 难以拆分审查,现按飞书《glm5.3 flash 训推 chat template 一致性》失败报告的维度拆成独立小 PR。

Why

官方模板从不在对话中间输出 EOS(glm52_chat 共享逻辑把"下一条不是 user/tool 就补 EOS"带到了 glm53)。修复前 assistant_then_system / consecutive_assistants 样本在边界多插一个 EOS(原始报告各差 26/27、21/22 个 token),模型会在分布外位置学到停止信号。

Changes

  • glm53_chat.py render 主循环:next_role is None 才追加训练 EOS
  • glm53_tokenize_fn_slowspeed 对称处理:①前缀渲染末尾的训练 EOS 在前一条是 assistant 时删除(保持 token 级前缀对齐);②assistant→system/assistant 边界截掉监督区间末尾的 EOS(边界 token 本身不计入 loss)
  • docstring 补 EOS 语义说明
  • 测试:新增 TestGlm53OfficialTemplateContract,golden 用例 assistant_then_system / consecutive_assistants 逐字符对齐官方 jinja(fast/slow 一致)+ 中间边界无 EOS、边界 token 无 loss 断言

Test plan

  • GLM_5_3_FLASH_PATH=<四层 checkpoint> pytest tests/datasets/test_glm53_chat.py:11 passed
  • ruff check / ruff-format / mypy / docformatter 通过(pydantic-extra-check hook 因 hook 环境缺 transformers.models.glm5_next 无法导入,属环境问题,与改动无关)

系列 PR(#2181 拆分,全部 base=main,按依赖序)

  1. 本 PR EOS 边界(M02/M03)
  2. tool 结果块按 tool_calls 顺序重排(M04/M05)— 依赖本 PR
  3. 结构化 tool output 渲染 + 嵌套 tool_reference 展开(M06/M07)— 依赖 PR 2
  4. assistant 媒体渲染为三段式占位标记(M08–M10)— 依赖 PR 3
  5. 数据层拒绝非 user/pretrain 角色媒体(M11)— 独立
  6. collector 跳过纯字符串 content 块(E01)— 依赖 PR 5
  7. 混合图+视频样本丢弃不中断 + assert 改 RuntimeError 保护网(E02)— 依赖 PR 6

7 个 PR 全部合入后与 #2181 的 618d3c4 逐字节等价;#2181 将在系列建齐后关闭并指向本系列。层叠 PR 的 Files changed 会包含父 PR 提交直至父合并,审阅增量可用 compare 视图(链接在系列建齐后补充)。

@ShilohYu

Copy link
Copy Markdown
Collaborator Author

Superseded by #2198, which carries the rebased version of this change plus the matching GLM-5.2 fix. Closing.

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.

1 participant