Skip to content

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.

Update rl.py

Daniel Hanf24d897a298b
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index c55e4141d94..2d75452b20f 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -71,7 +71,14 @@ def PatchRL(FastLanguageModel):
pass
-# Handles NEFTune
+RLTrainer_replacement = '''
+import os
+from typing import *
+from dataclasses import dataclass, field
+from packaging.version import Version
+import torch
+
+# https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_utils.py#L126
def neftune_post_forward_hook(module, input, output):
if module.training:
dims = torch.tensor(output.size(1) * output.size(2))
@@ -80,13 +87,6 @@ def neftune_post_forward_hook(module, input, output):
return output
pass
-
-RLTrainer_replacement = '''
-import os
-from typing import *
-from dataclasses import dataclass, field
-from packaging.version import Version
-
@dataclass
class Unsloth{RLConfig_name}({RLConfig_name}):
"""