Repository navigation
DeepSeek-V4.1 (transformers port): load, place and train it with LoRA / QLoRA - #17625
Merged
Merged
Conversation
…ram tables by transformers' no-placement rule, keep o_a_proj 16-bit under 4-bit, refuse padding-free, no region compile
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
meefs
pushed a commit
to meefs/unsloth
that referenced
this pull request
Nov 13, 2026
…point recompute match (unslothai#17660) ## Why Since unslothai#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
DeepSeek-V4.1-Flash is only in the community transformers port (
malaiwah/transformers@add-deepseek-v41). On a tiny copy of the real config, Unsloth could not load or train it:Unrecognized configuration class ... AutoModelForImageTextToText. The composite config has avision_config, but the port only maps a causal LM._no_placement_params = ["weight", "weight_scale_inv"]are bare names that transformers reads relative to a_no_split_modulesmodule, but Unsloth suffix-matched them, so they caught every weight.o_a_proj. It is a groupednn.Linearsubclass, and bitsandbytes swaps it for a plainLinear4bit.Min(index_topk, T)(torch 2.14). Unsloth's model compile also gave a compiled-vs-recompute mismatch (CheckpointError) under gradient checkpointing.Change
loader.py:AutoModelForCausalLM.deepseek_v41, load withUNSLOTH_COMPILE_DISABLE=partial, as csm already does.loader_utils.py: newno_placement_matcher, also used invision.py:vision.py: keepo_a_projin 16-bit under 4-bit loads.packing.py: refuse padding-free packing for this model._block_compile.py: do not region-compileDeepseekV41DecoderLayer.Everything except the matcher, which only fixes bare names, is keyed on the port's classes or model type, so other models are untouched.
Evidence
tests/test_deepseek_v41_lora_coverage.py: 6 passed; the new tests fail on main.tests/test_block_compile.pyplus the related suites: 89 passed.wkv.Not covered