Skip to content

Add GLM5 SFT support - #1844

Open
samaritan1998 wants to merge 3 commits into
THUDM:mainfrom
samaritan1998:add-glm5-sft-support
Open

Add GLM5 SFT support#1844
samaritan1998 wants to merge 3 commits into
THUDM:mainfrom
samaritan1998:add-glm5-sft-support

Conversation

@samaritan1998

@samaritan1998 samaritan1998 commented Apr 20, 2026

Copy link
Copy Markdown

Summary

  • Add a GLM5-specific SFT loss mask type that follows GLM-style stop markers.
  • Append the correct GLM5 final stop marker for assistant turns: <|user|> for normal replies and <|observation|> for final tool calls.
  • Add a GLM5 SFT launch script using sft_loss and the existing GLM5 Megatron model config.
  • Add unit coverage for multi-turn GLM5 masking, tool calls, final tool-call stop markers, and step_loss_mask handling.
  • Apply the repository pre-commit formatting/lint fixes required by the all-files pre-commit CI job.

Details

The GLM5 mask generation renders the full chat template, supervises assistant spans, and treats <|user|>, <|observation|>, and <|endoftext|> as stop boundaries. This mirrors GLM5 chat-template behavior: regular assistant replies learn the <|user|> boundary, while assistant tool calls learn the <|observation|> boundary so the model stops before tool results are appended externally.

Validation

  • /tmp/slime-precommit-venv/bin/pre-commit run --all-files --show-diff-on-failure --color=always
  • Ran GLM5 mask tests via direct Python invocation with a lightweight transformers stub, because this local environment does not have pytest or transformers installed.
  • bash -n scripts/run-glm5-744B-A40B-sft.sh
  • git diff --check

Could not run python -m pytest directly because pytest is not installed in this local environment.

@samaritan1998 samaritan1998 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local validation passed for GLM5 loss mask behavior and script syntax.

@samaritan1998
samaritan1998 marked this pull request as ready for review April 20, 2026 04:52
@stevewx

stevewx commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Hi samaritan1998, this might be a duplicate of #1824

@samaritan1998

samaritan1998 commented Apr 21, 2026

Copy link
Copy Markdown
Author

Hi samaritan1998, this might be a duplicate of #1824
我看到了 #1824 但是#1824的实现是不是有bug 没有学eos token(<|user|>) 会导致模型不停止

@stevewx

stevewx commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

ahh yes you're right, closed #1824 in favor of this PR

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.

2 participants