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_replacements.py
Daniel Han546be403399d
diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.pyindex ed802e48775..9b9a113f2d4 100644--- a/unsloth/models/rl_replacements.py+++ b/unsloth/models/rl_replacements.py@@ -212,14 +212,14 @@ def _grpo_compute_loss(old_logits, new_logits, input_ids, mask, beta):loss_i = -(loss_i - beta * kl_i)mask = mask.to(torch.float32)- n_mask = mask.sum(1)- loss_per_reward = (loss_i * mask).sum(1) / n_mask+ n_mask_per_reward = mask.sum(1)+ loss_per_reward = (loss_i * mask).sum(1) / n_mask_per_rewardloss = loss_per_reward.mean()# Get metrics as well which are foldedwith torch.inference_mode():- completion_length = n_mask.mean()- mean_kl_per_reward = (kl_i * mask).sum(1) / n_mask+ completion_length = n_mask_per_reward.mean()+ mean_kl_per_reward = (kl_i * mask).sum(1) / n_mask_per_rewardmean_kl = mean_kl_per_reward.mean()passreturn loss, completion_length, mean_kl