Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Bug fixes (#3329)

Daniel Han70f790a8e408
diff --git a/unsloth/dataprep/synthetic.py b/unsloth/dataprep/synthetic.py
index 52c114fab6f..9651df23e86 100644
--- a/unsloth/dataprep/synthetic.py
+++ b/unsloth/dataprep/synthetic.py
@@ -28,6 +28,7 @@ from unsloth_zoo.vllm_utils import (
patch_vllm,
delete_vllm,
)
+from unsloth_zoo.log import logger
import numpy as np
from .synthetic_configs import (
@@ -76,6 +77,7 @@ class SyntheticDataKit:
return_args = True,
enable_lora = False,
use_bitsandbytes = False,
+ compilation_config = 3,
**kwargs,
)
if "dtype" in engine_args:
@@ -95,15 +97,17 @@ class SyntheticDataKit:
engine_args["dtype"] = "auto"
if "device" in engine_args: del engine_args["device"]
if "model" in engine_args: del engine_args["model"]
- if "compilation_config" in engine_args:
- # Cannot parse in vllm serve
- engine_args["compilation_config"] = 3
subprocess_commands = [
"vllm", "serve", str(model_name),
]
for key, value in engine_args.items():
- flag = key.replace("_", "-")
+ flag = key.replace("_", "-")
+ if key == "compilation_config":
+ # [TODO] Unsure why subprocess doesn't process json properly
+ # Also -O3 breaks on T4!
+ # subprocess_commands += ["-O3",]
+ continue
which = str(value).replace("torch.", "")
if which == "True":
# Ignore --enforce-eager True
@@ -117,6 +121,7 @@ class SyntheticDataKit:
else:
subprocess_commands += ["--" + flag, which,]
pass
+ logger.info(subprocess_commands)
vllm_process = subprocess.Popen(
subprocess_commands,
stdout = subprocess.PIPE,
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 11e5eb359cf..7414c073269 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -1200,7 +1200,8 @@ def CausalLM_fast_forward(fast_forward_inference):
if not RETURN_LOGITS and labels is not None:
- n_items = kwargs.get("num_items_in_batch", None) or kwargs.get("n_items", None)
+ n_items = kwargs.get("num_items_in_batch", None)
+ if n_items is None: n_items = kwargs.get("n_items", None)
if self.config.model_type == "falcon_h1":
hidden_states = hidden_states * self.config.lm_head_multiplier
@@ -1264,12 +1265,14 @@ def CausalLM_fast_forward(fast_forward_inference):
shift_labels[..., :-1] = labels[..., 1:]
shift_labels[..., -1] = -100
# shift_labels = torch.hstack((labels[..., 1:], self.extra_ignored_labels[:labels.shape[0]]))
+ n_items = kwargs.get("num_items_in_batch", None)
+ if n_items is None: n_items = kwargs.get("n_items", None)
loss = fast_cross_entropy_loss(
logits = shift_logits,
labels = shift_labels,
logit_softcapping = logit_softcapping,
logit_scaling = logit_scaling,
- n_items = kwargs.get("num_items_in_batch", None) or kwargs.get("n_items", None),
+ n_items = n_items,
)
else:
if logit_scaling != 0:
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 5a77e8fa1a7..6f1f000e68d 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -114,6 +114,7 @@ import numpy as np
from contextlib import nullcontext
from torch.nn import functional as F
from transformers import DataCollatorForSeq2Seq, DataCollatorForLanguageModeling as TransformersDataCollatorForLanguageModeling
+from transformers.training_args import ParallelMode
torch_compile_options = {{
"epilogue_fusion" : True,
@@ -168,6 +169,11 @@ class Unsloth{RLTrainer_name}(_Unsloth{RLTrainer_name}):
):
if args is None: args = Unsloth{RLConfig_name}()
{RLTrainer_extra_args}
+ # [TODO] Fix up DataParallel multiplying batch sizes
+ # [TODO] DDP works, but DP seems to not work? [TODO]
+ if getattr(args, "parallel_mode", None) == ParallelMode.NOT_DISTRIBUTED and args.n_gpu > 1:
+ if getattr(args, "_n_gpu", 1) != 1:
+ args._n_gpu = 1
super().__init__({RLTrainer_call_args}{RLTrainer_kwargs})
{RLTrainer_post}
pass
@@ -265,14 +271,17 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
"if not force_float32 and (float16 and use_bf16): raise TypeError('Unsloth: Model is in float16 precision but you want to use bfloat16 precision. Set fp16 to `True` and bf16 to `False`')\n"\
"if not force_float32 and (not float16 and use_fp16): raise TypeError('Unsloth: Model is in bfloat16 precision but you want to use float16 precision. Set fp16 to `False` and bf16 to `True`')\n"\
"if force_float32:\n"\
+ " # Forced float32 training\n"\
" args.fp16 = False\n"\
" args.bf16 = False\n"\
" os.environ['ACCELERATE_MIXED_PRECISION'] = 'no'\n"\
"elif (not use_bf16 and not use_fp16) and mixed_precision_dtype == 'float32':\n"\
+ " # Mixed precision training\n"\
" args.fp16 = float16\n"\
" args.bf16 = not float16\n"\
" os.environ['ACCELERATE_MIXED_PRECISION'] = 'fp16' if float16 else 'bf16'\n"
"elif mixed_precision_dtype == 'bfloat16':\n"\
+ " # Both False since bfloat16 full finetuning doesn't do any autocasting.\n"\
" args.fp16 = False\n"\
" args.bf16 = False\n"\
" os.environ['ACCELERATE_MIXED_PRECISION'] = 'no'\n"
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 545a2d4d1d9..84a2fc9f1cd 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -742,23 +742,15 @@ class FastBaseModel:
torch.xpu.empty_cache()
pass
max_seq_length = model.max_seq_length
- # if we pass loftq_config = None we will get an error
+ # If we pass loftq_config = None we will get an error
loftq_config = validate_loftq_config(loftq_config, lora_dropout, bias, init_lora_weights, model)
- lora_config_dict = {
- "r" : r,
- "lora_alpha" : lora_alpha,
- "target_modules" : target_modules,
- "target_parameters" : kwargs.get("target_parameters", None),
- "lora_dropout" : lora_dropout,
- "bias" : bias,
- "task_type" : task_type,
- "modules_to_save" : modules_to_save,
- "use_rslora" : use_rslora,
- "init_lora_weights" : init_lora_weights,
- "loftq_config" : loftq_config,
- }
+
+ # Get only allowed parameters for LoraConfig
+ local_variables = { **locals(), **kwargs, }
+ del local_variables["kwargs"]
+ allowed_parameters = inspect.signature(LoraConfig).parameters.keys()
lora_config = LoraConfig(
- **{k:v for k,v in lora_config_dict.items() if k in LoraConfig.__doc__},
+ **{ k : v for k, v in local_variables.items() if k in allowed_parameters },
)
model = prepare_model_for_kbit_training(
model,