From d892dc6884ba69ffce7db800a4a0e19db656c75d Mon Sep 17 00:00:00 2001 From: Daniel Hanchen Date: Mon, 9 Feb 2026 15:01:52 +0000 Subject: [PATCH] Fix OOM from prepare_model_for_kbit_training overwriting peft_config patching --- unsloth/models/rl.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 783efb56b6..6cb12f6a12 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -1627,12 +1627,15 @@ def patch_functions(RLTrainer, trainer_file, RLTrainer_name, all_imports, import for function in functions: if not hasattr(RLTrainer, function): continue - fx = getattr(RLTrainer, function) - try: - source = inspect.getsource(fx) - except: - continue - original_source = source + if function in changed: + original_source, source = changed[function] + else: + fx = getattr(RLTrainer, function) + try: + source = inspect.getsource(fx) + except: + continue + original_source = source # Check for function for edit_function in edit_functions: