Commit graph

3,005 commits

Author SHA1 Message Date
Daniel Han
7cdad0c7df Merge branch 'main' into nightly November-2025 2025-11-25 07:59:24 -08:00
Daniel Han
efa783df3c Update mapper.py 2025-11-25 07:59:21 -08:00
Daniel Han
84e303dc63 Merge branch 'main' into nightly 2025-11-25 07:45:27 -08:00
Daniel Han
3bc471b1af Update loader.py 2025-11-25 07:45:14 -08:00
Daniel Han
6231d25fca Merge branch 'main' into nightly 2025-11-25 07:39:00 -08:00
Daniel Han
a66b828a98 Update loader.py 2025-11-25 07:38:51 -08:00
Daniel Han
a90452e04c Merge branch 'main' into nightly 2025-11-25 07:23:55 -08:00
Daniel Han
38aa148aba Float8 GRPO, RL (#3640)
* Enable FP8 + RL training for bf16 models (#3440)

* Enable FP8 + RL training for bf16 models

**Summary:** Enable FP8 + RL training using TorchAO for 1.33x faster training and 42% less model memory usage:
- We quantize the frozen LoRA weights into fp8 and keep the LoRA adapters in bf16
- We leverage TorchAO's `Float8Tensor`, which calls into fbgemm's fp8 x fp8 rowwise matmul kernel
- For now, we need to do an offline quantization first, because vllm doesn't support on-the-fly quantization for torchao yet  (this is in progress: https://github.com/vllm-project/vllm/pull/26327)

**Example usage:**
```
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-8B-Base",
    max_seq_length = 2048,
    load_in_4bit = False,
    fast_inference = True,
    max_lora_rank = 32,
    load_in_fp8 = True,  # set this to True
)

\# the rest is the same as before
model = FastLanguageModel.get_peft_model(...)
```

**Initial results:**
```
\# fp8
{'train_runtime': 1725.4337, 'train_samples_per_second': 0.232, 'train_steps_per_second': 0.058, 'train_loss': 0.00015715716748673002, 'epoch': 0.01}

\# bf16
{'train_runtime': 2297.8145, 'train_samples_per_second': 0.174, 'train_steps_per_second': 0.044, 'train_loss': 0.00016081033063528594, 'epoch': 0.01}
```

<img width="1199" height="448" alt="Screenshot 2025-11-11 at 4 10 50 PM" src="https://github.com/user-attachments/assets/b6304afd-89e9-42b1-8064-775807e17b23" />

Test script: https://gist.github.com/andrewor14/5b85119fae46845d07b608d420907423

**Requires:**
- https://github.com/pytorch/ao/pull/3158 (torchao nightly or 0.15.0+)
- https://github.com/unslothai/unsloth-zoo/pull/351

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

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

* Update utils.py

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

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

* _get_inference_mode_context_manager

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

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

* Update utils.py

* Update utils.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>

* Update __init__.py

* Fix/save torchao model loading logic (#3621)

* make loading gpt-oss-BF16 faster. Linked to unsloth-zoo PR #314

* fix model loading and clean merged model directory

* revert default quant

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

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

* revert mapper.py

---------

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

* Update loader_utils.py

* Update loader_utils.py

* Add 128x128 PerBlock FP8 + RL (#3629)

* Add 128x128 PerBlock FP8 + RL

**Summary:** Following https://github.com/unslothai/unsloth/pull/3440,
this PR extends torchao FP8 + RL support to also handle 128x128
PerBlock granularity (in addition to PerRow).

**Example usage:**

```
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-8B-Base",
    max_seq_length = 2048,
    load_in_4bit = False,
    fast_inference = True,
    max_lora_rank = 32,
    load_in_fp8 = "block",  # or "row" or True
)
```

**Initial results:** TBD

**Note:**
- Requires https://github.com/pytorch/ao/pull/3370

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

* Version

* Update vision.py

* Update rl.py

* Add torch 2.9.1

* Fix auto installer

* Update fp8.py

* Float8

* Update fp8.py

* Update mapper.py

* Update mapper.py

* Update loader_utils.py

* Update loader.py

* Update fp8.py

* Versioning

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

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

---------

Co-authored-by: andrewor14 <andrewor14@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Roland Tannous <115670425+rolandtannous@users.noreply.github.com>
2025-11-25 07:23:26 -08:00
pre-commit-ci[bot]
e7acd095eb [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-11-25 15:20:19 +00:00
Daniel Han
69c7a23bc4 Versioning 2025-11-25 07:12:45 -08:00
Daniel Han
2368a0ce51 Update fp8.py 2025-11-25 07:11:30 -08:00
Daniel Han
422ab9bba6 Update loader.py 2025-11-25 07:06:41 -08:00
Daniel Han
5f51fc644c Update loader_utils.py 2025-11-25 07:05:43 -08:00
Daniel Han
3ba79978e4 Update mapper.py 2025-11-25 07:02:20 -08:00
Daniel Han
9bce1d4116 Update mapper.py 2025-11-25 06:53:06 -08:00
Daniel Han
db292872c8 Update fp8.py 2025-11-25 06:50:58 -08:00
Daniel Han
cb00618e49 Float8 2025-11-25 06:48:10 -08:00
Daniel Han
fee3841c24 Update fp8.py 2025-11-25 05:35:34 -08:00
Daniel Han
c69a5ffe8e Fix auto installer 2025-11-25 01:47:58 -08:00
Daniel Han
b3612aa636 Add torch 2.9.1 2025-11-25 01:36:11 -08:00
Daniel Han
bfb57e564c Update rl.py 2025-11-24 22:13:17 -08:00
pre-commit-ci[bot]
7ac912194d [pre-commit.ci] pre-commit autoupdate (#3634)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.5 → v0.14.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.5...v0.14.6)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-24 17:16:56 -08:00
Daniel Han
6f8fe138a5 Update vision.py 2025-11-24 05:50:22 -08:00
Daniel Han
a04af0d884 Merge branch 'main' into nightly 2025-11-24 02:16:53 -08:00
Lei Zhenyuan
9c07b203aa [intel] change windows to remove windows-triton for intel xpu (#3168)
* change windows to remove windows-triton for intel xpu

* add changes for different platform

* Update pyproject.toml

* update mode windows

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

* Update pyproject.toml

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

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-11-23 22:03:54 -08:00
Etherll
3cbfa1573a Add trust_remote_code parameter to tokenizer (#3631) 2025-11-23 21:12:40 -08:00
Daniel Han
8d7964f108 Version 2025-11-22 06:20:00 -08:00
andrewor14
7dfb239f22 Add 128x128 PerBlock FP8 + RL (#3629)
* Add 128x128 PerBlock FP8 + RL

**Summary:** Following https://github.com/unslothai/unsloth/pull/3440,
this PR extends torchao FP8 + RL support to also handle 128x128
PerBlock granularity (in addition to PerRow).

**Example usage:**

```
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-8B-Base",
    max_seq_length = 2048,
    load_in_4bit = False,
    fast_inference = True,
    max_lora_rank = 32,
    load_in_fp8 = "block",  # or "row" or True
)
```

**Initial results:** TBD

**Note:**
- Requires https://github.com/pytorch/ao/pull/3370

* [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-11-21 20:09:27 -08:00
Mercury
874b5f0448 Fix missing code and support inputs_embeds only input. (#3623) 2025-11-20 07:56:52 -08:00
Daniel Han
9f19876a09 Update loader_utils.py 2025-11-20 04:04:19 -08:00
Daniel Han
25f25f9d30 Update loader_utils.py 2025-11-20 00:06:11 -08:00
Roland Tannous
b701d743ee Fix/save torchao model loading logic (#3621)
* make loading gpt-oss-BF16 faster. Linked to unsloth-zoo PR #314

* fix model loading and clean merged model directory

* revert default quant

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

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

* revert mapper.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-20 00:02:31 -08:00
Daniel Han
a458d59e91 Update __init__.py 2025-11-19 23:56:38 -08:00
andrewor14
89d8677c0c Enable FP8 + RL training for bf16 models (#3440)
* Enable FP8 + RL training for bf16 models

**Summary:** Enable FP8 + RL training using TorchAO for 1.33x faster training and 42% less model memory usage:
- We quantize the frozen LoRA weights into fp8 and keep the LoRA adapters in bf16
- We leverage TorchAO's `Float8Tensor`, which calls into fbgemm's fp8 x fp8 rowwise matmul kernel
- For now, we need to do an offline quantization first, because vllm doesn't support on-the-fly quantization for torchao yet  (this is in progress: https://github.com/vllm-project/vllm/pull/26327)

**Example usage:**
```
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-8B-Base",
    max_seq_length = 2048,
    load_in_4bit = False,
    fast_inference = True,
    max_lora_rank = 32,
    load_in_fp8 = True,  # set this to True
)

\# the rest is the same as before
model = FastLanguageModel.get_peft_model(...)
```

**Initial results:**
```
\# fp8
{'train_runtime': 1725.4337, 'train_samples_per_second': 0.232, 'train_steps_per_second': 0.058, 'train_loss': 0.00015715716748673002, 'epoch': 0.01}

\# bf16
{'train_runtime': 2297.8145, 'train_samples_per_second': 0.174, 'train_steps_per_second': 0.044, 'train_loss': 0.00016081033063528594, 'epoch': 0.01}
```

<img width="1199" height="448" alt="Screenshot 2025-11-11 at 4 10 50 PM" src="https://github.com/user-attachments/assets/b6304afd-89e9-42b1-8064-775807e17b23" />

Test script: https://gist.github.com/andrewor14/5b85119fae46845d07b608d420907423

**Requires:**
- https://github.com/pytorch/ao/pull/3158 (torchao nightly or 0.15.0+)
- https://github.com/unslothai/unsloth-zoo/pull/351

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

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

* Update utils.py

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

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

* _get_inference_mode_context_manager

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

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

* Update utils.py

* Update utils.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-11-19 23:51:43 -08:00
DoubleMathew
ecacc17f7e Remove grpo requirement bs=num_generations (#3609)
* Remove grpo requirement bs=num_generations

* Update rl.py

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

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

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-19 19:57:01 -08:00
DoubleMathew
0362092b1b Add an int64 path for mlp kernels (#3614)
* Add an int64 path for mlp kernels

* move constant expressions to globals

* fix name
2025-11-19 19:45:10 -08:00
Dan Saunders
6e16ef3d4c remove pre-commit workflow (covered by pre-commit app) (#3618) 2025-11-19 15:34:32 -08:00
mk0walsk
0cf5762060 Fix broken links and typo in README (#3611)
* README Link Fixes

* Update README.md

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

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-11-18 20:04:14 -08:00
pre-commit-ci[bot]
98d04047dd [pre-commit.ci] pre-commit autoupdate (#3606)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.4 → v0.14.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.4...v0.14.5)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-17 17:02:44 -08:00
Datta Nimmaturi
0f0b1fba15 Do not force set beta to 0 for DAPO (#3604) 2025-11-16 22:39:36 -08:00
DoubleMathew
3c963f811a fix qwen3 vl gradient accumulation (#3598)
* fix qwen3 vl gradient accumulation

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

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

* Update unsloth/models/_utils.py

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[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-11-15 02:26:34 -08:00
Daniel Han
22e7288271 Update pyproject.toml 2025-11-14 20:01:02 -08:00
Scott Roy
402c004e46 Extend TorchAOConfig to support mobile usecases (#3587)
* up

* up

* [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-11-14 03:08:21 -08:00
Yuxiao Cheng
64f40dbf12 Fix: prevent rope_embedding AssertionError by checking kv_seq_len before reuse (#3578)
* fix: add kv_seq_len boundary check before reusing RoPE embeddings

Prevented AssertionError in rope_embedding.forward when kv_seq_len exceeds
the cached rope size. Added condition to verify kv_seq_len <=
position_embeddings[0].shape[0] before reuse, ensuring dynamic extension
triggers correctly.

Fixes #3036 #3216

* fix falcon h1

---------

Co-authored-by: jarrycyx <dzdzzd@126.com>
2025-11-14 03:06:33 -08:00
Giuseppe Franco
fa5b05b70b Support for out-of-source quantizers (#3534)
* Support for out-of-source quantizers

* Fix decorators and functions to be staticmethod

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

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

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

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-14 02:52:24 -08:00
DoubleMathew
9e932030ff Patch in tiled mlp (#3584)
* Patch in tiled mlp

* Update unsloth/models/llama.py

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

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

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

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-13 21:26:49 -08:00
DoubleMathew
0dbff7bade Resize rope embeddings for long sequence training (#3586) 2025-11-11 18:11:31 -08:00
pre-commit-ci[bot]
ff16d280f9 [pre-commit.ci] pre-commit autoupdate (#3576)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.0 → v0.14.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.0...v0.14.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-11-11 18:10:49 -08:00
Daniel Han
3ef5b4d3c3 Update _utils.py 2025-11-10 04:49:27 -08:00
Dan Saunders
63821d4f7b pre-commit CI config (#3565) 2025-11-07 14:44:18 -08:00