Skip to content

DeepSeek-V4.1: keep torch.compile on when unsloth_zoo makes the checkpoint recompute match - #17660

Merged
danielhanchen merged 2 commits into
mainfrom
dsv41-compile-gc
Nov 13, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
dsv41-compile-gc

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Why

Since #17625, loading DeepSeek-V4.1 (community port) sets UNSLOTH_COMPILE_DISABLE=partial, because a compiled helper inside a checkpointed layer did not match its recompute. The model has trained with only the loss compiled since then.

unslothai/unsloth-zoo#2488 fixes the mismatch and adds prepare_compiled_checkpoint(). With it, the non-reentrant checkpointed layers run compiled helpers in both passes.

What this changes

unsloth/models/loader.py, the deepseek_v41 branch:

  • It calls unsloth_zoo.temporary_patches.deepseek_v41.prepare_compiled_checkpoint().
  • It still sets UNSLOTH_COMPILE_DISABLE=partial when the import fails (an unsloth_zoo without the fix) or the call returns False. Either side can update first without breaking training.

tests/test_deepseek_v41_lora_coverage.py: the source-level branch test now checks the call and the fallback.

Evidence

Colab L4, torch 2.14.1, the port (malaiwah/transformers@62d7ebd), this branch on main 624ddb3 plus unsloth-zoo#2488. Tiny DeepSeek-V4.1, Unsloth LoRA / QLoRA on every linear, unsloth gradient checkpointing, engram tables on disk, 12 steps:

run step ms (median after 3) graphs / breaks max rel loss diff vs eager
16-bit compiled 379, repeat 293 35 / 0 1.7e-4
16-bit eager 611, repeat 486 0 / 0
4-bit compiled 380 39 / 9 3.1e-4
4-bit eager 527 0 / 0
16-bit compiled + offload_layers=2 297 35 / 0 0 vs 16-bit compiled
4-bit compiled + offload_layers=2 380 39 / 9 2.2e-4 vs 4-bit compiled
  • Per 16-bit step, the profiler counts 38,321 ops compiled vs 86,824 eager, and 34.8 ms GPU time vs 66.7 ms.
  • The 4-bit breaks are all _forward_generic_experts_eagerly, the bnb 4-bit expert path, which is disabled on purpose.
  • Before this change, forcing compile on failed in the first backward with CheckpointError.

The zoo PR has the failed alternatives (LRU cache off, automatic dynamic off, raised recompile limit) and the root cause.

Not covered

  • Real-size speed. The tiny model is overhead bound.
  • Multi-GPU. Not run.

…point recompute match

unsloth_zoo's prepare_compiled_checkpoint() lets the non-reentrant checkpointed layers run compiled helpers in both
passes. Call it for deepseek_v41 and keep the old partial compile disable only when it is missing (older
unsloth_zoo) or cannot apply.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T10:35:32.856489Z 7bc7ae9 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 7bc7ae918a

ℹ️ 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
danielhanchen merged commit 8d2d5db into main Nov 13, 2026
@danielhanchen
danielhanchen deleted the dsv41-compile-gc branch November 13, 2026 21:50
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 16, 2026
Final comment pass for recently merged PRs.

Trims comments added by unslothai#17660, unslothai#17806, unslothai#17807, unslothai#17808, unslothai#17812, unslothai#17830,
unslothai#17854, unslothai#17857 and unslothai#17870 that are still on main.
Multi-line explanations are collapsed to one line, and comments that
restate the code are removed.
Comments that explain a version quirk or a correctness trap are kept,
along with license headers and pragmas.
Changed comment lines: unslothai#17660 5 -> 2, unslothai#17806 4 -> 2, unslothai#17808 1 -> 0,
unslothai#17830 3 -> 1, unslothai#17857 1 -> 0. unslothai#17807, unslothai#17812, unslothai#17854 and unslothai#17870 are
unchanged.
Overall: 6 files, 14 lines removed, 5 added. Only comments change: the
AST check (comment_tools.py check) and the pre-push gate both pass.
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