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
logits / temperature
Daniel Hand9601bd14aee
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.pyindex dde09e08e2f..889bbd48075 100644--- a/unsloth/models/rl.py+++ b/unsloth/models/rl.py@@ -568,6 +568,17 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):extra_args += check_num_generationspass+ # Check temperature must not be <= 0. Also stop if >= 10+ if "temperature" in call_args:+ check_temperature = \+ "if temperature <= 0:\n"\+ " raise MathError('Unsloth: Please set a positive non-zero temperature since your results will be wrong.')\n"\+ "elif temperature >= 10:\n"\+ " raise MathError('Unsloth: Please set a positive non-zero temperature less than 10, since sampling will be quite erratic.')\n"\+ "\n"+ extra_args += check_temperature+ pass+# Edit config with anything extraif trainer_file in RL_CONFIG_CHANGES:process_extra_args = RL_CONFIG_CHANGES[trainer_file]diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.pyindex b6f02af946b..8efaf3fd1f3 100644--- a/unsloth/models/rl_replacements.py+++ b/unsloth/models/rl_replacements.py@@ -270,6 +270,8 @@ def grpo_trainer__get_per_token_logps(function_name, function):# See https://github.com/huggingface/trl/issues/2770# logits = logits[:, -logits_to_keep:]# return logits+ # See https://huggingface.co/blog/the_n_implementation_details_of_rlhf_with_ppo#policy-training-implementation-details+ # logits = logits / self.temperature# logps = selective_log_softmax(logits, input_ids)# row_indices, col_indices = torch.where(logps < -20)@@ -358,6 +360,7 @@ def grpo_trainer_compute_loss(function_name, function):epsilon_high = self.epsilon_high,max_completion_length = self.args.max_completion_length,delta = self.args.delta,+ temperature = self.args.temperature,)else:if hasattr(self.args, "loss_type"):@@ -374,6 +377,7 @@ def grpo_trainer_compute_loss(function_name, function):epsilon_high = self.epsilon_high,max_completion_length = self.args.max_completion_length,delta = self.args.delta,+ temperature = self.args.temperature,)else:# to ensure backwards compatibility with trl 0.15.2 and maybe even 0.17@@ -385,6 +389,7 @@ def grpo_trainer_compute_loss(function_name, function):advantages,old_hidden_states,n_chunks = self.args.unsloth_num_chunks,+ temperature = self.args.temperature,)# Log the metrics