Commit graph

4,672 commits

Author SHA1 Message Date
Daniel Han
12004df0cb Merge pull request #3711 from oKatanaaa/ensure-weight-tying
FIX: weight tying for LoRA embeddings and lm_head
2026-01-01 04:55:01 -08:00
Daniel
41e6fe557a Add TODO comment for ensure_weight_tying in vision models
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 12:54:21 +00:00
Daniel Han
94c0329e38 Merge pull request #3806 from Fizza-Mukhtar/fix/3d-tensor-matmul
Fix 3D tensor support for bitsandbytes 8-bit matmul in forward pass
2026-01-01 04:07:43 -08:00
Daniel Han
f205be0ea7 Fix correctness bugs across multiple model files (#3813)
1. cohere.py:347-348 - Fixed wrong variable names in QK normalization.
   Used `Q`/`K` but variables were named `Qn`/`Kn`. This caused NameError
   when `use_qk_norm=True` (e.g., c4ai-command-r-plus models).

2. cohere.py:482 - Fixed wrong object reference in inference loop.
   Used `self.mlp` but should be `decoder_layer.mlp` since we're
   iterating through decoder layers. Caused AttributeError during inference.

3. falcon_h1.py:459,461 - Fixed wrong attribute names in inference path.
   Used `post_attention_layernorm` and `mlp` but Falcon H1 uses
   `pre_ff_layernorm` and `feed_forward`. Caused AttributeError during generation.

4. qwen3_moe.py:210 - Fixed wrong module path with incorrect capitalization.
   Used `transformers.models.Qwen3Moe` but should be `transformers.models.qwen3_moe`.
   Caused AttributeError when patching rotary embeddings.

5. qwen3_moe.py:239 - Fixed wrong model_patcher class.
   Used `FastQwen3Model` but should be `FastQwen3MoeModel` for MoE models.
   Caused incorrect patching for Qwen3 MoE models.

6. hf_hub.py:21-22 - Fixed floor division and missing return for billion values.
   Used `//` instead of `/` for millions, and had no return for values >= 1B.
   Caused incorrect formatting and None return for large numbers.

7. save.py:550 - Fixed self-assignment that did nothing.
   `sharded_ram_usage = sharded_ram_usage` should be `= max_shard_size`.
   Caused integer shard sizes to be ignored.

8. rl.py:562-567 - Fixed orphan string not included in length_check.
   The elif branch for max_seq_length validation was a standalone string
   expression, not concatenated to length_check. Caused silent skip of
   the max_seq_length > model_max_seq_length warning.

9. granite.py:49-52 - Fixed wrong model name and version in error message.
   Said "Gemma2" and "4.42.3" but should be "Granite" and "4.45.0".
2026-01-01 02:36:33 -08:00
Daniel Han
cbff64131f Fix correctness bugs in rl.py, rl_replacements.py, and vision.py (#3811)
* Fix correctness bugs in rl.py, rl_replacements.py, and vision.py

1. rl_replacements.py (lines 864, 870): Fixed undefined `nanmin`/`nanmax`
   functions by using `.nan_to_num(nan=inf/-inf).min()/.max()` pattern.
   PyTorch doesn't have torch.nanmin/nanmax, so we replace NaN values
   before computing min/max.

2. vision.py (line 150): Fixed bug where code checked for "input" key
   but then accessed kwargs["input_ids"] instead of kwargs["input"].

3. vision.py (line 159): Fixed bug where literal string "key" was used
   instead of the variable `key` when accessing kwargs.

4. rl.py (lines 903, 905): Fixed non-existent `MathError` exception
   by replacing with `ValueError`.

* [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>
2025-12-31 21:35:48 -08:00
Michael Han
9b5571fb69 Refresh of Unsloth README.md with https://unsloth.ai/docs 2025-12-30 15:14:27 -08:00
pre-commit-ci[bot]
c5a1eccb51 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-12-30 15:58:41 +00:00
Fizza-Mukhtar
9116aa8dfd Fix 3D tensor support for bitsandbytes 8-bit matmul in forward pass 2025-12-30 07:56:01 -08:00
Fizza-Mukhtar
4f59695810 Fix 3D tensor support for bitsandbytes 8-bit matmul in forward pass 2025-12-30 07:08:10 -08:00
lif
8ab0c0c913 fix: add support for init_lora_weights="corda" in get_peft_model (#3794)
Add "corda" as an allowed value for the init_lora_weights parameter
in FastLanguageModel.get_peft_model() and FastBaseModel.get_peft_model().

This enables users to use CorDA (Correlation-aware Decomposed Adaptation)
initialization from PEFT, which provides an alternative LoRA initialization
strategy for improved finetuning performance.

Fixes #3693

Signed-off-by: majiayu000 <1835304752@qq.com>
2025-12-28 23:17:58 -08:00
ゆり
5f1361aea3 Fix Boolean value of Tensor ambiguity error in mistral.py (#3790)
* Fix is_contiguous() method call and remove duplicate imports

- Fix bug in rope_embedding.py where is_contiguous was used without
  parentheses, causing the method object (always truthy) to be evaluated
  instead of calling the method. This fixes issue #3781 where fast rope
  backpropagation was broken for zero strided/non-contiguous tensors.

- Remove duplicate `import torch` in rl.py (lines 20 and 25)
- Remove duplicate `import functools` and `import types` in vision.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix Boolean value of Tensor ambiguity error in mistral.py

Replace `or` operator with explicit `is None` check when getting
n_items from kwargs. The `or` operator fails when the value is a
Tensor because Python cannot determine the boolean value of a
multi-element tensor.

Fixes #3766

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update rope_embedding.py

---------

Co-authored-by: yurekami <yurekami@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2025-12-28 21:30:55 -08:00
Fizza Mukhtar
091a801386 Fix crash when trl.experimental.openenv is unavailable (#3787)
* Guard optional trl.experimental.openenv usage in RL patches

* Simplify optional trl.openenv import handling

* [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>
2025-12-28 21:23:51 -08:00
Francesco Bertolotti
dabf2a901b fastrope fix for zero strided tensors (#3782)
Co-authored-by: Francesco Bertolotti <francesco.bertolotti@igenius.ai>
2025-12-28 21:21:48 -08:00
Alkın Ünlü
6180adda1b fix(trainer): import psutil to prevent NameError in _prepare_dataset (#3780)
* fix(trainer): import psutil to prevent NameError in _prepare_dataset

Fixes #3777

* Update rl.py

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2025-12-28 21:18:02 -08:00
Daniel Han
f40fa7a0e8 Update FUNDING.yml (#3792) 2025-12-28 19:57:43 -08:00
Michael Han
96de7a817d Update README for new unsloth.ai/docs.md 2025-12-27 00:49:19 -08:00
Fizza Mukhtar
f57cd25d46 Clarify NotImplementedError for fast_inference with full_finetuning (#3768)
* Improve error message for fast_inference and full_finetuning

* Refine error message string formatting

* Update unsloth/models/vision.py

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2025-12-25 18:46:13 -08:00
Strahinja Stamenkovic
a058885b8a Add missing import of inspect (#3778)
* Add missing import of inspect

* Update device_type.py
2025-12-25 18:43:59 -08:00
pre-commit-ci[bot]
7c1d528c00 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-12-23 20:06:37 +00:00
numb3r33
3aaca08a0e Refactor return statement replacement to use explicit newlines
Replace f-string triple-quoted approach with explicit newline characters
for clearer string construction in the grpo_trainer patch.
2025-12-24 01:34:21 +05:30
pre-commit-ci[bot]
d8c9e6aafb [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-12-24 01:34:21 +05:30
numb3r33
fe21809bda Fix indentation handling in grpo_trainer return statement replacement
Use regex to dynamically detect and preserve the original indentation
when replacing the 'return output' statement, instead of hardcoding
spaces. This ensures the patched code maintains consistent indentation
regardless of the original formatting.
2025-12-24 01:34:21 +05:30
pre-commit-ci[bot]
c8e7bd9f09 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-12-24 01:34:21 +05:30
numb3r33
a6405b36b4 Remove the comment. 2025-12-24 01:34:21 +05:30
abhishek.sharma
91671433b0 Fix model training state restoration in GRPO trainer
Store the model's training state before generation and restore inference
mode after completion if the model wasn't originally in training mode.
This ensures the model returns to the correct state after generate and
score operations.
2025-12-24 01:34:21 +05:30
Daniel Han
dea670a1b6 Merge branch 'main' into nightly 2025-12-23 05:51:04 -08:00
Daniel Han
1ff6fc85f0 llama.cpp fixes 2025-12-23 05:50:26 -08:00
Daniel Han
cbfa7a20f9 Update rl.py 2025-12-23 05:42:58 -08:00
Daniel Han
0ae7d2ba28 Update rl.py 2025-12-23 05:35:06 -08:00
Daniel Han
a4408f0e50 Merge branch 'main' into nightly 2025-12-23 04:52:58 -08:00
Daniel Han
fd42103a9b Nightly (#3767)
* Update _utils.py

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

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

* [FIX] [Transformers] VLM input embeds fix for gradients (#3715)

* Fix get_input_embeds call for VLMs

* patch input_require_grads instead

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

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

* cleanup old patch

* cleanup old patch

* cleanup

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

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

* Apply suggestion from @danielhanchen

* use logger instead of prints

* Move unsloth present set

* [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: Daniel Han <danielhanchen@gmail.com>

* Update rope_embedding.py

* Fixes

* Update _utils.py

* Update import_fixes.py

* Update rl_replacements.py

* fix_openenv_no_vllm

* Fix

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

* logger

* Update __init__.py

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

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

* Update __init__.py

* Update import_fixes.py

* Update __init__.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

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

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

* Update import_fixes.py

* Update unsloth/import_fixes.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update save.py

* [fbgemm] Silence tma fbgemm (#3735)

* Silence fbgemm TMA print

Also safer .push_to_hub

* [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>

* Update loader.py

* Update save.py

* Update save.py

* Update _utils.py

* Update _utils.py

* Diffusers warnings

* Update pyproject.toml

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

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

* [hf_hub] Token login (#3739)

* login on token

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

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

* cleanup old code

* safer imports

* cleanup

* Return token after login

* correct return types

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

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

* Apply suggestion from @danielhanchen

* add back imports

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

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

* finish return token

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>

* Do not overwrite slots (#3752)

* Do not overwrite slots

* [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>

* Update save.py

* [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: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-12-23 04:52:29 -08:00
pre-commit-ci[bot]
ad73b7e493 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-12-23 12:51:09 +00:00
Daniel Han
6866c4b3df Update save.py 2025-12-23 04:46:43 -08:00
Daniel Han
10ef983541 Merge branch 'main' into nightly 2025-12-23 04:46:15 -08:00
Daniel Han
691b5d129f Update save.py 2025-12-23 00:55:06 -08:00
pre-commit-ci[bot]
e134ceed79 [pre-commit.ci] pre-commit autoupdate (#3760)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.9 → v0.14.10](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.9...v0.14.10)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-12-22 23:12:00 -08:00
Daniel Han
ad5b2f66af Merge branch 'main' into nightly 2025-12-19 19:37:52 -08:00
Daniel Han
25a3141663 Update loader.py 2025-12-19 19:37:49 -08:00
Daniel Han
47ede31b8c Nightly (#3753)
* Update _utils.py

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

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

* [FIX] [Transformers] VLM input embeds fix for gradients (#3715)

* Fix get_input_embeds call for VLMs

* patch input_require_grads instead

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

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

* cleanup old patch

* cleanup old patch

* cleanup

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

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

* Apply suggestion from @danielhanchen

* use logger instead of prints

* Move unsloth present set

* [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: Daniel Han <danielhanchen@gmail.com>

* Update rope_embedding.py

* Fixes

* Update _utils.py

* Update import_fixes.py

* Update rl_replacements.py

* fix_openenv_no_vllm

* Fix

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

* logger

* Update __init__.py

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

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

* Update __init__.py

* Update import_fixes.py

* Update __init__.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

* Update import_fixes.py

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

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

* Update import_fixes.py

* Update unsloth/import_fixes.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update save.py

* [fbgemm] Silence tma fbgemm (#3735)

* Silence fbgemm TMA print

Also safer .push_to_hub

* [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>

* Update loader.py

* Update save.py

* Update save.py

* Update _utils.py

* Update _utils.py

* Diffusers warnings

* Update pyproject.toml

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

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

* [hf_hub] Token login (#3739)

* login on token

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

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

* cleanup old code

* safer imports

* cleanup

* Return token after login

* correct return types

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

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

* Apply suggestion from @danielhanchen

* add back imports

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

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

* finish return token

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>

* Do not overwrite slots (#3752)

* Do not overwrite slots

* [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: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-12-19 19:35:41 -08:00
Daniel Han
bfa7301768 Merge branch 'main' into nightly 2025-12-19 19:31:23 -08:00
Daniel Han
9a6d703d3c Update _utils.py 2025-12-19 19:24:49 -08:00
Strahinja Stamenkovic
490153500b Enable 4-bit quantization on AMD Radeon GPUs (#3748)
* Enable 4-bit quant on Radeon

* Fix table centering

* Update comments for clarity

* Handle failure to import Bitsandbytes

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

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

* Update device_type.py

* Apply suggestion from @danielhanchen

* Update device_type.py

* [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: Daniel Han <danielhanchen@gmail.com>
2025-12-19 19:22:56 -08:00
Dan Saunders
1a507b4a82 Fix VLM DDP checkpointing (#3751) 2025-12-19 19:09:16 -08:00
Datta Nimmaturi
3918e07df8 Do not overwrite slots (#3752)
* Do not overwrite slots

* [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>
2025-12-19 19:08:28 -08:00
Daniel Han
3f238efba5 Merge branch 'main' into nightly 2025-12-18 09:30:19 -08:00
Daniel Han
a36eb9b9a1 FunctionGemma 2025-12-18 09:27:46 -08:00
DoubleMathew
96bd2a7668 Fix Deepseek OCR Lora Model Load (#3738)
* fix deepseek ocr lora_model load: trust_remote_code option

check for import error in autoconfig/peftconfig from_pretrained error

handle import

* Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-12-18 04:09:17 -08:00
Datta Nimmaturi
6832ce8098 [hf_hub] Token login (#3739)
* login on token

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

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

* cleanup old code

* safer imports

* cleanup

* Return token after login

* correct return types

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

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

* Apply suggestion from @danielhanchen

* add back imports

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

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

* finish return token

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2025-12-18 04:07:12 -08:00
Dan Saunders
44104fa83d review comments 2025-12-17 15:28:03 -05:00
Dan Saunders
7833191626 review comments 2025-12-17 15:22:42 -05:00