diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 1427ca747f..80ddbf19a4 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -1587,6 +1587,7 @@ def _patch_prepare_multimodal_messages(): # Also patch in grpo_trainer module if imported try: import trl.trainer.grpo_trainer as _gt + if hasattr(_gt, "prepare_multimodal_messages"): _gt.prepare_multimodal_messages = _safe_prepare_multimodal_messages except ImportError: diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index 06969227b4..883a5392f5 100755 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -29,16 +29,20 @@ from unsloth_zoo.rl_replacements import RL_REPLACEMENTS, left_pack_padding from unsloth_zoo.utils import Version from importlib.metadata import version as importlib_version from unsloth_zoo.log import logger + # device_synchronize may not exist in older unsloth_zoo versions try: from unsloth_zoo.device_type import device_synchronize except ImportError: import torch + def device_synchronize(): if torch.cuda.is_available(): torch.cuda.synchronize() elif hasattr(torch, "xpu") and torch.xpu.is_available(): torch.xpu.synchronize() + + import importlib.util from ..device_type import ( is_hip,