Commit graph

3,315 commits

Author SHA1 Message Date
pre-commit-ci[bot]
d5df1f8463 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-08 12:02:39 +00:00
Daniel Han
e9a4ca0757 Add auto-compile for torch.compile based on training step breakeven analysis
Changes:
- Change default compile_mode from "reduce-overhead" to "default" since CUDA
  Graphs (used by reduce-overhead) is incompatible with PEFT/LoRA
- Add _estimate_compile_threshold() to calculate minimum steps needed for
  torch.compile to be beneficial based on model parameter count
- Add _apply_torch_compile() helper with accelerate unwrap_model bug workaround
- Defer torch.compile application to trainer initialization time so we can
  check max_steps against the breakeven threshold
- Patch SentenceTransformerTrainer to auto-apply compile when max_steps
  exceeds the calculated threshold

Breakeven thresholds (with 1.2x safety margin):
- 22M params (MiniLM): ~1388 steps
- 110M params (mpnet): ~242 steps
- 335M params (snowflake): ~203 steps

This ensures torch.compile warmup cost is only paid when training is long
enough to benefit from the speedup.
2026-01-08 12:02:13 +00:00
pre-commit-ci[bot]
18113b2248 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-08 03:17:48 +00:00
electroglyph
b2742f2543 add save_pretrained_torchao 2026-01-07 19:17:16 -08:00
electroglyph
f2a0b0259d Merge branch 'unslothai:main' into FST 2026-01-07 02:28:55 -08:00
Daniel Han
6b04af4f49 Merge pull request #3857 from Datta0/modelscope_stats
[ModelScope] Disable stats when modelscope is being used
2026-01-06 02:56:55 -08:00
pre-commit-ci[bot]
46d212c480 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-06 10:00:17 +00:00
Datta Nimmaturi
1d84ba5287 Check env var explicitly
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-01-06 15:30:06 +05:30
Datta Nimmaturi
9a5b824903 Disable stats when modelscope is being used 2026-01-06 09:53:20 +00:00
Daniel Han
e7fe25ee43 Versioning 2026-01-05 07:37:08 -08:00
Daniel Han
a50f0e1a75 Merge pull request #3843 from unslothai/fix-grpo-version-compat
Unify Version usage and fix TRL version handling
2026-01-05 06:07:41 -08:00
Daniel Han
5f1a62bc0b Merge pull request #3851 from unslothai/grpo-fix-on-pr3754
GRPO: restore model mode after generate (stacked on #3754)
2026-01-05 06:05:24 -08:00
danielhanchen
4a45983bf6 Merge main into grpo-fix-on-pr3754 2026-01-05 14:02:18 +00:00
danielhanchen
77e7f73641 Revert rl_replacements GRPO edits 2026-01-05 13:55:08 +00:00
danielhanchen
506bcc48e5 Fix GRPO training state restoration 2026-01-05 13:50:48 +00:00
pre-commit-ci[bot]
27e9a672a2 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 13:39:16 +00:00
danielhanchen
7fd3a6c177 Restore TRL version fallback in rl.py 2026-01-05 13:39:03 +00:00
Daniel Han
02ef2c25ca Merge branch 'main' into fix-grpo-version-compat 2026-01-05 05:31:42 -08:00
danielhanchen
dc986cd7e2 Drop rl.py GRPO changes from this branch 2026-01-05 13:29:58 +00:00
Daniel Han
0812d6c1e4 Merge pull request #3849 from unslothai/fix-pdl-use-vllm-version-check
Replace GitHub API check with vLLM version check for PDL fix
2026-01-05 05:22:16 -08:00
pre-commit-ci[bot]
c612bfe3a3 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 13:19:44 +00:00
Daniel Han
cb42ce8dae Address review feedback: add constant and debug logging 2026-01-05 13:19:37 +00:00
Daniel Han
9ced3523aa Replace GitHub API check with vLLM version check for PDL fix
The GitHub issue check had issues:
1. Network latency on import
2. Issue being closed does not mean the fix is in the installed vLLM version

Now skip the PDL workaround if vLLM version > 0.13.2, which is when
the upstream fix is expected to be included.
2026-01-05 13:15:17 +00:00
Daniel Han
2de0915e6f Merge pull request #3836 from ykaitao/remove_unused_variable_BlockDiagonalCausalMask
remove unused variable BlockDiagonalCausalMask
2026-01-05 04:42:25 -08:00
Daniel Han
a68cd336b6 Merge pull request #3842 from unslothai/fix-vllm-chat-template-sync
Sync chat_template from tokenizer to vLLM
2026-01-05 04:38:39 -08:00
Daniel Han
d9d26699b5 Merge pull request #3841 from unslothai/fix-vllm-pdl-blackwell
Fix vLLM PDL bug on Blackwell GPUs (B200/B100)
2026-01-05 04:37:58 -08:00
Daniel Han
9b6d536e0e Keep PDL module check but remove unnecessary env var setting
The check skips the GitHub API call for old vLLM versions.
No need to set TRITON_DISABLE_PDL for versions without PDL support.
2026-01-05 12:34:32 +00:00
Daniel Han
6bf555a34c Remove unnecessary PDL module existence check
Old vLLM versions without PDL modules don't need the fix.
The patching code already handles missing modules gracefully.
2026-01-05 12:32:16 +00:00
pre-commit-ci[bot]
0c2425cb8d [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 10:23:35 +00:00
Daniel Han
65fc139032 Use relative imports and add float16 machine support
- Changed absolute import to relative: from ._utils import prepare_model_for_kbit_training
- Added SUPPORTS_BFLOAT16 import for proper dtype detection
- Handle devices that don't support bfloat16 by falling back to float16
2026-01-05 10:23:11 +00:00
Daniel Han
aff2dc9061 Add None check for vLLM tokenizer
- Check _vllm_tok is not None before accessing attributes
- Use getattr for safer chat_template access
2026-01-05 10:02:11 +00:00
Daniel Han
f8d8915401 Use Unsloth's prepare_model_for_kbit_training for consistency
Changed from peft.prepare_model_for_kbit_training to
unsloth.models._utils.prepare_model_for_kbit_training.

Unsloth's version provides:
- Float32 mixed precision upcasting for LoRA layers
- Better numerical stability
- Consistency with rest of Unsloth codebase
2026-01-05 07:05:11 +00:00
pre-commit-ci[bot]
1a9543fadd [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 07:03:35 +00:00
danielhanchen
b9bbf47710 Improve TRL compatibility and GRPO state restore 2026-01-05 07:02:36 +00:00
pre-commit-ci[bot]
739aa923fb [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 06:56:57 +00:00
Daniel Han
3e595d1817 Fix FastSentenceTransformer performance: 6x speedup via torch.compile + SDPA
The original implementation was 31% slower than naive SentenceTransformer due to
conflicting decorators from Unsloth's auto-compiler (@torch.compile on attention
modules but @torch.compiler.disable on sub-modules).

Changes:
- Add fast encoder path that bypasses Unsloth patching for encoder models
- Use native torch.compile with mode="reduce-overhead" for 6x speedup
- Auto-detect and enable SDPA for models that support it (BERT, RoBERTa, etc.)
- Change defaults: load_in_16bit=True, load_in_4bit=False (16-bit is optimal)
- Change default: use_gradient_checkpointing=False (conflicts with torch.compile)
- Add UNSLOTH_COMPILE_DISABLE=1 env var to fall back to old path if needed

Supported encoder types: mpnet, bert, distilbert, roberta, xlm-roberta, albert, electra

Benchmark results (BS=32, seq_len=128):
- Naive 16-bit LoRA:     13-50ms per iter
- Unsloth 16-bit LoRA:   2-9ms per iter (5.4x-6.7x faster)
- Memory usage:          61MB-1.3GB (even largest model fits easily)

Note: 4-bit + torch.compile has a PyTorch bug (pytorch/pytorch#90665).
4-bit is also 1.7-1.9x slower than 16-bit due to dequantization overhead,
so 16-bit is recommended for these small encoder models anyway.
2026-01-05 06:55:09 +00:00
Daniel Han
35219633ab Fix PDL patch: target utils.py source module and clear lru_cache
- Patch vllm.lora.ops.triton_ops.utils directly where supports_pdl is defined
- Clear lru_cache before patching to prevent stale cached results
- Add fused_moe_lora_op to consumer modules list
- Use *args, **kwargs in fake function for compatibility
2026-01-05 06:53:42 +00:00
Daniel Han
9e181cb67e Merge branch 'main' into pr/3719 2026-01-04 22:53:17 -08:00
Daniel Han
ba548ff8c2 Combine nested if statements for clarity 2026-01-05 05:25:53 +00:00
pre-commit-ci[bot]
eac1f6b010 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 05:24:59 +00:00
Daniel Han
227c31f0ca Address review feedback: refactor and scan all GPUs
- Add _spec_exists helper function to reduce duplication
- Scan all GPUs for SM100 instead of just device 0
- Use loop for module patching to improve maintainability
2026-01-05 05:24:52 +00:00
Daniel Han
fbdb3b524e Add tokenizer fallback for chat_template sync 2026-01-05 05:10:24 +00:00
Daniel Han
36c9a841eb Sync chat_template from tokenizer to vLLM
When using base models with custom chat templates applied after loading,
vLLM's internal tokenizer may not have the chat_template set. This causes
issues during RL training with vLLM inference.

This fix syncs the chat_template from the processing_class (the tokenizer
you loaded and configured) to vLLM's internal tokenizer during trainer
initialization, but only if vLLM's tokenizer does not already have one set.
2026-01-05 05:03:56 +00:00
pre-commit-ci[bot]
efe949c941 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-01-05 05:03:29 +00:00
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
Kaitao Yang
b5addbc936 remove unused variable BlockDiagonalCausalMask 2026-01-04 09:21:44 -08:00
Daniel Han
e63c2744ec Versioning 2026-01-04 06:12:44 -08:00
Daniel Han
df569dab89 Merge branch 'main' into pr/3719 2026-01-04 05:50:05 -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