unsloth/unsloth/models
Roland Tannous 6644a771b4
fix: patch PEFT for Gemma4ClippableLinear in loader checkpoint path (fixes export) (#4807)
* fix: patch PEFT for Gemma4ClippableLinear in loader checkpoint path

The same Gemma4ClippableLinear monkey-patch that exists in vision.py
for training is needed in loader.py for loading existing checkpoints
(used by export and inference).

Gemma4ClippableLinear wraps nn.Linear but does not subclass it, so
PEFT's LoRA injection fails with "Target module not supported".
The patch redirects PEFT to target the inner .linear child instead.

Applied only to the vision model PeftModel.from_pretrained path.
Temporary fix until PEFT adds native support (peft#3129).

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

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

* fix: wrap ClippableLinear patch in try/finally to always restore

Ensures _create_and_replace is restored even if PeftModel.from_pretrained
raises, preventing leaked global state across subsequent model loads.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-04-03 04:03:54 +04:00
..
__init__.py Revert "feat: Add Mixtral model support" 2026-03-13 22:38:49 -07:00
_utils.py Gemma-4 2026-04-02 11:59:37 -07:00
cohere.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
dpo.py Formatting & bug fixes (#3563) 2025-11-07 06:00:22 -08:00
falcon_h1.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
gemma.py Fix/pr 3699 leftpad prefill main (#4100) 2026-02-25 07:21:04 -08:00
gemma2.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
glm4_moe.py [MoE] Improve moe kernels for unsloth fine tuning (#3812) 2026-02-05 06:03:25 -08:00
granite.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
llama.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
llama4.py Qwen 3 2025-05-02 03:09:44 -07:00
loader.py fix: patch PEFT for Gemma4ClippableLinear in loader checkpoint path (fixes export) (#4807) 2026-04-03 04:03:54 +04:00
loader_utils.py Fixup mapper issues and resolve properly (#4124) 2026-03-03 06:57:25 -08:00
mapper.py Fixup mapper issues and resolve properly (#4124) 2026-03-03 06:57:25 -08:00
mistral.py Fix/pr 3699 leftpad prefill main (#4100) 2026-02-25 07:21:04 -08:00
qwen2.py Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
qwen3.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
qwen3_moe.py Fix correctness bugs across multiple model files (#3813) 2026-01-01 02:36:33 -08:00
rl.py Fix missing num_items_in_batch in unsloth_prediction_step (#4616) 2026-03-27 03:06:59 -07:00
rl_replacements.py Fix forward compatibility with transformers 5.x (#4752) 2026-04-01 06:04:03 -07:00
sentence_transformer.py Fix EmbeddingGemma float16 NaN via FORCE_FLOAT32 for gemma3_text (#4014) 2026-02-10 01:40:13 -08:00
vision.py UI Changes (#4782) 2026-04-02 08:05:55 -07:00