Skip to content

Exit with code 130 when unsloth train is stopped with Ctrl+C - #11151

Merged
Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:cli-train-ctrl-c-exit-code
Sep 17, 2026
Merged

Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:cli-train-ctrl-c-exit-code

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Pressing Ctrl+C during unsloth train saves a checkpoint and then exits with code 0, so a chained command like unsloth train -c cfg.yaml && unsloth export runs the export on a half-trained model.

The command now exits with 130 after the save. A normal finish still exits 0 and errors still exit 1. This covers both the CUDA trainer and the MLX adapter.

Tested with new unit tests and on a real GPU run: Ctrl+C at step 10 saved the checkpoint, exited 130 and the chained command did not run. A 3 step run still exits 0.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T20:57:02.991104Z f376e60 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f376e60d84

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the gap in unsloth_cli/commands/train.py where the KeyboardInterrupt path falls through to a 0 exit, and the 130 handling looks right. Could you drop the unrelated reformatting in studio/backend/main.py and the two test files so this stays just the exit-code change?

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks!

@Lyxot
Lyxot merged commit 5891aca into unslothai:main Sep 17, 2026
52 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ai#11151)

* CLI: exit 130 when unsloth train is stopped with Ctrl+C

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lyxot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants