* Fix mamba

* Update loader.py

* Update vision.py

* Update loader.py

* Filter vLLM standby logs (#3131)

* filter vLLM standby logs

* safeguard standby logger patch

* Update unsloth/models/_utils.py

* Update unsloth/models/_utils.py

* Update unsloth/models/_utils.py

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>

* Update loader.py

* Add scaler

* Update llama.py

* Update _utils.py

* Versioning

* GPT OSS fix

* GPT OSS fix

* Update loader.py

* Update vision.py

* Update vision.py

* Update loader.py

* Update vision.py

* Update vision.py

* Update llama.py

* Update llama.py

* Update llama.py

* Versioning

* Update mapper.py

* Update vision.py

* Update vision.py

* Update vision.py

* Upcast norms

* Update loader.py

* Update vision.py

* Upcast layernorms

* Update llama.py

* Update llama.py

* Update llama.py

* Update llama.py

* Update llama.py

* Update llama.py

* Update save.py

* Update rl.py

* Update pyproject.toml

* Update rl.py

* Update rl_replacements.py

* Update rl.py

* Update rl.py

* Update rl.py

* Update _utils.py

* Update __init__.py

* Torch 2.8

* Update rl_replacements.py

* Update loader.py

* UNSLOTH_ENABLE_CCE

* Fix

* Update loader.py

* Update loader.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Import fixes

* Update loader.py

* Fix aimv2 issue

* Update loader.py

* Update import_fixes.py

* Update import_fixes.py

* Update loader.py

* Update loader.py

* Update loader.py

* Upgrade

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update vision.py

* Update vision.py

* custom_datatype

* recheck

* Float16

* Update vision.py

* Update vision.py

* Update vision.py

* Update vision.py

* Update vision.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Bug fix

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* torch_dtype

* Update rl.py

* Fix CE Loss

* Versioning

* Update loader.py

* Update loader.py

* extract_model_type_from_config

* Model types

* Update loader.py

* get_transformers_model_type

* Update loader.py

* Update loader.py

* Update loader.py

* Update rl.py

* Update pyproject.toml

* Update loader.py

* Update loader.py

* Update loader.py

* Update loader.py

* Versioning

* Update _utils.py

* Update _utils.py

* Update _utils.py

* Update _utils.py

* Update vision.py

* Update vision.py

* Fix DataParallel

* Update _utils.py

* Update rl.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

* Update synthetic.py

---------

Co-authored-by: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>
This commit is contained in:
Daniel Han 2025-09-17 05:06:23 -07:00 committed by GitHub
commit 70f790a8e4
4 changed files with 30 additions and 21 deletions

View file

@ -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,

View file

@ -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:

View file

@ -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"

View file

@ -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,