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
Fix DAPO, TRL 0.19.0
Daniel Han3461b987fd36
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.pyindex 69785be206b..8ebb5c824b7 100644--- a/unsloth/models/rl.py+++ b/unsloth/models/rl.py@@ -471,6 +471,7 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):"num_generations" : 8,"top_k" : None,"vllm_mode" : "colocate",+ "generation_kwargs" : {},}for k, v in replacements.items():x = f"{k}( = [^,\n]{{1,}})?,\n"@@ -510,6 +511,8 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):# Check for loss_type = dr_grpo and scale_rewards for GRPOif "loss_type" in call_args and "scale_rewards" in call_args:+ # See https://github.com/huggingface/trl/issues/3130#issuecomment-2746947835+ # DAPO uses per token loss so BNPO loss usedcheck_dr_grpo = \"if loss_type.lower() == 'dr_grpo':\n"\" loss_type = 'dr_grpo'\n"\@@ -519,13 +522,16 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):" if scale_rewards == None:\n"\" scale_rewards = True\n"\" elif scale_rewards == True:\n"\- " print('The Dr GRPO paper recommends setting `scale_rewards` to False! Will override. Set it to `None` to force False.')\n"\+ " print('Unsloth: The Dr GRPO paper recommends setting `scale_rewards` to False! Will override. Set it to `None` to force False.')\n"\" scale_rewards = False\n"\"elif loss_type.lower() == 'dapo':\n"\- " print('The DAPO paper recommends `mask_truncated_completions = True`')\n"\- " print('The DAPO paper recommends `epsilon_high = 0.28`')\n"\+ " print('Unsloth: The DAPO paper recommends `mask_truncated_completions = True`')\n"\+ " print('Unsloth: The DAPO paper recommends `epsilon_high = 0.28`')\n"\+ " print('Unsloth: The DAPO paper recommends setting `beta = 0.0` to remove the KL term')\n"\" mask_truncated_completions = True\n"\" epsilon_high = 0.28\n"\+ " beta = 0.0\n"\+ " loss_type = 'bnpo'""\n"extra_args += check_dr_grpopass