Commit graph

3,211 commits

Author SHA1 Message Date
Daniel Han
6c6d0dfef1 Fix vLLM PDL bug on Blackwell GPUs (B200/B100)
vLLM's LoRA Triton kernels use tl.extra.cuda.gdc_wait() for PDL
optimization on SM90+ GPUs. This fails on SM100 (Blackwell) during
CUDA graph capture because Triton's pipeliner cannot handle gdc_wait
in complex kernels.

This fix:
- Detects SM100 GPUs and applies the workaround automatically
- Sets TRITON_DISABLE_PDL=1 environment variable
- Monkey-patches supports_pdl to return False in lora_expand_op and
  lora_shrink_op
- Checks GitHub issue #30872 status (with 3s timeout) to auto-disable
  the workaround once the upstream fix is merged
- Includes quick internet connectivity check (0.5s) to avoid delays
  when offline

Fixes the error:
'tt.elementwise_inline_asm' op pipeliner doesn't know how to predicate this op
LLVM ERROR: Fatal pipeliner error

See: https://github.com/vllm-project/vllm/issues/30872
2026-01-05 05:02:53 +00:00
Daniel Han
e63c2744ec Versioning 2026-01-04 06:12:44 -08:00
Daniel Han
741a24cd67 Merge pull request #3835 from unslothai/quant-config-respect
Respect user quantization_config
2026-01-04 05:43:20 -08:00
Daniel Han
5b2ebe13c9 Merge pull request #3834 from unslothai/rl-fixes
rl.py fixes: buffer reset, safer attribute access, typo fix
2026-01-04 05:25:45 -08:00
danielhanchen
e22ca346cf Keep 4bit flag for fast_inference 2026-01-04 13:18:15 +00:00
danielhanchen
bfa225b00c Handle dict quantization_config flags 2026-01-04 13:14:03 +00:00
danielhanchen
402e7d6285 Respect user quantization_config 2026-01-04 13:03:06 +00:00
danielhanchen
d31ec48a94 Fix psutil.cpu_count() potentially returning None in save.py 2026-01-04 12:58:45 +00:00
danielhanchen
08d619fca1 Handle older unsloth-zoo without reset_unsloth_gradient_checkpointing_buffers 2026-01-04 12:57:10 +00:00
danielhanchen
3d15865bbc rl.py fixes: buffer reset, safer attribute access, typo fix
1. Auto-reset gradient checkpointing buffers after trainer.train()
   - Import and call reset_unsloth_gradient_checkpointing_buffers() in
     prepare_for_training_mode wrapper to free memory after training
     while keeping buffers ready for subsequent runs

2. Replace eval/exec with safer getattr/setattr
   - eval(f"trl.trainer.{trainer}") -> getattr(trl.trainer, trainer)
   - exec(f"...{unwrap} = ...") -> setattr(current_trainer, unwrap, ...)
   - exec(f"Trainer.prediction_step=...") -> direct assignment

3. Fix psutil.cpu_count() potentially returning None
   - Change psutil.cpu_count()+4 to (psutil.cpu_count() or 1)+4
   - Prevents TypeError on systems where cpu_count() returns None

4. Fix typo: oriignal_is_vlm_text -> original_is_vlm_text
2026-01-04 12:21:39 +00:00
Daniel Han
34548a089c Merge pull request #3832 from ykaitao/ktyang_remove_redundant_code_has_block
remove redundant code of has_block
2026-01-03 23:18:27 -08:00
Kaitao Yang
1ea6585b0c remove redundant code of has_block 2026-01-03 22:38:37 -08:00
Daniel Han
021f0cbfb1 Merge pull request #3822 from Fizza-Mukhtar/fix/llama-build-curl
Make llama.cpp CURL dependency optional when building from source
2026-01-03 22:12:50 -08:00
pre-commit-ci[bot]
c50b7499ff [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-02 16:58:04 +00:00
Fizza-Mukhtar
8fa3228590 Make llama.cpp CURL support optional during CMake builds 2026-01-02 08:55:58 -08:00
Fizza-Mukhtar
9a3908c552 Make llama.cpp CURL support optional during CMake builds 2026-01-02 08:42:59 -08:00
Daniel Han
a2833aafd3 Merge pull request #3821 from unslothai/nightly
Bug fixes
2026-01-02 06:22:08 -08:00
Daniel Han
d688d3f564 Bug fixes 2026-01-02 06:07:16 -08:00
Daniel Han
8b402b45c7 Merge branch 'main' into nightly 2026-01-02 06:06:11 -08:00
Daniel Han
5b66898c56 Merge pull request #3820 from unslothai/fix/fast-generate-wrapper-helpful-errors
Add helpful error messages for fast_generate when fast_inference=False
2026-01-02 06:02:52 -08:00
pre-commit-ci[bot]
f23735af0a [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-02 13:58:50 +00:00
danielhanchen
c7d5f1569c Add helpful error messages for fast_generate when fast_inference=False
When users load a model with fast_inference=False but then try to use
vLLM-style arguments with fast_generate, they previously got confusing
errors. This adds a wrapper that detects common mistakes and provides
helpful guidance:

- Using sampling_params: explains to use HF generate args instead
- Using lora_request: explains LoRA weights are already merged
- Passing text strings: shows how to tokenize input first

Changes:
- Add make_fast_generate_wrapper to _utils.py
- Apply wrapper in llama.py when fast_inference=False
- Apply wrapper in vision.py when fast_inference=False
2026-01-02 13:58:08 +00:00
Daniel Han
3959006d19 Merge branch 'main' into nightly 2026-01-02 05:40:32 -08:00
Daniel Han
01e8f78f13 Update import_fixes.py 2026-01-02 05:05:47 -08:00
Daniel Han
a24695dcc2 Update import_fixes.py 2026-01-02 03:41:51 -08:00
Daniel Han
13e1255b6c Update loader.py 2026-01-02 02:48:28 -08:00
Daniel Han
ae219fe052 fix_huggingface_hub 2026-01-02 00:14:44 -08:00
Daniel Han
684a1d0ca1 Merge pull request #3818 from unslothai/fix-gemma3-qat-stability
Fix Gemma3 QAT training instability with int8-int4 scheme
2026-01-01 23:23:55 -08:00
danielhanchen
1080d0c4dc Fix Gemma3 QAT training instability with int8-int4 scheme
Gemma3 models have a large vocabulary (262144 tokens) which causes
training loss to explode when using int8 embedding quantization.

This fix auto-detects Gemma3 models and switches from int8-int4
(phone-deployment) to int4 weight-only QAT for stable training.
2026-01-02 07:19:08 +00:00
Daniel Han
9608174bc7 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
f7e0f4b152 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
fbf0745eb0 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
963bc35a96 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
982ae7bbeb 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
b21b4e6252 Refresh of Unsloth README.md with https://unsloth.ai/docs 2025-12-30 15:14:27 -08:00
pre-commit-ci[bot]
e43e67cb18 [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
f2e87251c7 Fix 3D tensor support for bitsandbytes 8-bit matmul in forward pass 2025-12-30 07:56:01 -08:00
Fizza-Mukhtar
c452eb13f5 Fix 3D tensor support for bitsandbytes 8-bit matmul in forward pass 2025-12-30 07:08:10 -08:00
lif
9fedb1c11d 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
ゆり
fe82f5f366 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
c8b0bada94 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
ab815692a9 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ü
c0c21a1e22 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
58235ee192 Update FUNDING.yml (#3792) 2025-12-28 19:57:43 -08:00
Michael Han
b314dca22d Update README for new unsloth.ai/docs.md 2025-12-27 00:49:19 -08:00
Fizza Mukhtar
181b76420e 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
08f1716a70 Add missing import of inspect (#3778)
* Add missing import of inspect

* Update device_type.py
2025-12-25 18:43:59 -08:00
Daniel Han
95c9854e64 Merge branch 'main' into nightly 2025-12-23 05:51:04 -08:00
Daniel Han
d7e3adf889 llama.cpp fixes 2025-12-23 05:50:26 -08:00
Daniel Han
7d9e691146 Update rl.py 2025-12-23 05:42:58 -08:00