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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Update rl.py
Daniel Han9a64373b278b
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.pyindex c4122f7aaea..112ba5d70a1 100644--- a/unsloth/models/rl.py+++ b/unsloth/models/rl.py@@ -107,21 +107,18 @@ passdef _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):# Patch for vLLM and Unsloth PEFT- print(1)import trlimport trl.trainertry:trainer = eval(f"trl.trainer.{trainer_file}")except Exception as error:return- print(2)# Get SFTTrainer and SFTConfig namesname = [x for x in dir(trainer) if x.endswith("Trainer") and x != "Trainer" and trainer_file.split("_")[0] in x.lower()]config = [x for x in dir(trainer) if x.endswith("Config") and x != "Config" and trainer_file.split("_")[0] in x.lower()]if len(name) != 1: returnif len(config) != 1: return- print(3)# Get SFTTrainer, SFTConfigRLTrainer_name = name[0]@@ -130,7 +127,6 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):except: returntry: RLConfig = eval(f"trl.trainer.{trainer_file}.{RLConfig_name}" )except: return- print(4)# Check nameif RLTrainer.__name__.startswith("Unsloth"): return@@ -138,7 +134,6 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):all_imports = dir(trainer)imports = [x for x in all_imports if not x.startswith("_")]- print(5)# Get default argumentsEMPTY = inspect.Parameter.empty@@ -162,7 +157,6 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):call_args = f"\n{' '*12}" + f",\n{' '*12}".join(call_args)processed.append((arguments, call_args,))pass- print(6)# Process RLTrainer firstarguments, call_args = processed[0]@@ -277,16 +271,14 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):RLConfig_call_args = call_args# Patch vLLM- RLTrainer_extras = patch_vllm(trainer_file, RLTrainer_name, all_imports, imports)+ RLTrainer_extras = patch_vllm(RLTrainer, trainer_file, RLTrainer_name, all_imports, imports)if RLTrainer_extras is None:RLTrainer_extras = f"_Unsloth{RLTrainer_name} = {RLTrainer_name}"- print(7)# Create full moduleexec(f"from trl.trainer import ({RLTrainer_name}, {RLConfig_name},)")__RLTrainer_doc__ = eval(f"trl.trainer.{RLTrainer_name}").__doc____RLConfig_doc__ = eval(f"trl.trainer.{RLConfig_name}") .__doc__- print(8)RLTrainer_source = RLTrainer_replacement.format(RLTrainer_name = RLTrainer_name,@@ -311,7 +303,6 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):f"trl.trainer.{trainer_file}",imports,)- print(9)# Patch Trainerexec(f"trl.{RLTrainer_name} = created_module.Unsloth{RLTrainer_name}", locals(), globals())@@ -326,6 +317,7 @@ passdef patch_vllm(trainer_file, RLTrainer_name, all_imports, imports):+ import trl.trainerRLTrainer = eval(f"trl.trainer.{trainer_file}.{RLTrainer_name}")init = inspect.getsource(RLTrainer.__init__)old_init = init