diff --git a/pyproject.toml b/pyproject.toml index 8e2648865a..146c5a85f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,11 +55,11 @@ huggingfacenotorch = [ "hf_transfer", "diffusers", "transformers>=4.51.3,!=4.52.0,!=4.52.1,!=4.52.2,!=4.52.3,!=4.53.0,!=4.54.0,!=4.55.0,!=4.55.1,!=4.57.0,<=4.57.2", - "trl>=0.18.2,!=0.19.0,<=0.23.0", + "trl>=0.18.2,!=0.19.0,<=0.24.0", ] huggingface = [ "unsloth[huggingfacenotorch]", - "unsloth_zoo>=2025.10.13", + "unsloth_zoo>=2025.11.1", "torchvision", "unsloth[triton]", ] @@ -489,7 +489,7 @@ colab-ampere-torch220 = [ "flash-attn>=2.6.3 ; ('linux' in sys_platform)", ] colab-new = [ - "unsloth_zoo>=2025.10.13", + "unsloth_zoo>=2025.11.1", "packaging", "tyro", "transformers>=4.51.3,!=4.52.0,!=4.52.1,!=4.52.2,!=4.52.3,!=4.53.0,!=4.54.0,!=4.55.0,!=4.55.1,!=4.57.0,<=4.57.2", @@ -507,7 +507,7 @@ colab-new = [ ] colab-no-deps = [ "accelerate>=0.34.1", - "trl>=0.18.2,!=0.19.0,<=0.23.0", + "trl>=0.18.2,!=0.19.0,<=0.24.0", "peft>=0.7.1", "xformers ; ('linux' in sys_platform or sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')", "bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0", diff --git a/unsloth/__init__.py b/unsloth/__init__.py index 9fb2e0dc40..a7ee579241 100644 --- a/unsloth/__init__.py +++ b/unsloth/__init__.py @@ -29,7 +29,6 @@ # their code at import time. If they're imported first, the original (slower, # more memory-intensive) implementations will be used instead of Unsloth's # optimized versions, potentially causing OOM errors or slower training. - if already_imported: # stacklevel=2 makes warning point to user's import line rather than this library code, # showing them exactly where to fix the import order in their script @@ -40,7 +39,7 @@ f"Please restructure your imports with 'import unsloth' at the top of your file.", stacklevel = 2, ) -pass +del already_imported, critical_modules # Unsloth currently does not work on multi GPU setups - sadly we are a 2 brother team so # enabling it will require much more work, so we have to prioritize. Please understand! @@ -57,14 +56,12 @@ # Log Unsloth is being used os.environ["UNSLOTH_IS_PRESENT"] = "1" -import importlib.util -from pathlib import Path from importlib.metadata import version as importlib_version from importlib.metadata import PackageNotFoundError # Check for unsloth_zoo try: unsloth_zoo_version = importlib_version("unsloth_zoo") - if Version(unsloth_zoo_version) < Version("2025.10.13"): + if Version(unsloth_zoo_version) < Version("2025.11.1"): print( "Unsloth: Please update Unsloth and Unsloth-Zoo to the latest version!\n"\ "Do this via `pip install --upgrade --force-reinstall --no-cache-dir --no-deps unsloth unsloth_zoo`" @@ -82,7 +79,7 @@ raise ImportError(f"Unsloth: Please install unsloth_zoo via `pip install unsloth_zoo` then retry!") except: raise -pass +del PackageNotFoundError, importlib_version # Try importing PyTorch and check version try: @@ -92,8 +89,8 @@ "Unsloth: Pytorch is not installed. Go to https://pytorch.org/.\n"\ "We have some installation instructions on our Github page." ) -except Exception as exception: - raise exception +except: + raise pass from unsloth_zoo.device_type import ( @@ -130,7 +127,7 @@ def is_bf16_supported(including_emulation = False): else: def is_bf16_supported(): return SUPPORTS_BFLOAT16 torch.cuda.is_bf16_supported = is_bf16_supported - pass + del major_version, minor_version elif DEVICE_TYPE == "hip": SUPPORTS_BFLOAT16 = torch.cuda.is_bf16_supported() elif DEVICE_TYPE == "xpu": @@ -179,6 +176,8 @@ def is_bf16_supported(): return SUPPORTS_BFLOAT16 latest_cuda = np.argsort([float(find_number.search(x).group(1)) for x in possible_cudas])[::-1][0] latest_cuda = possible_cudas[latest_cuda] os.system(f"ldconfig /usr/local/{latest_cuda}") + del find_number, latest_cuda + del possible_cudas, find_cuda pass importlib.reload(bnb) @@ -200,7 +199,7 @@ def is_bf16_supported(): return SUPPORTS_BFLOAT16 "Also try `sudo ldconfig /usr/local/cuda-xx.x` - find the latest cuda version.\n"\ "Unsloth will still run for now, but maybe it might crash - let's hope it works!" ) - pass + del libcuda_dirs elif DEVICE_TYPE == "hip": # NO-OP for rocm device pass diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index b9ae4282cd..0e79b7ce88 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "2025.10.12" +__version__ = "2025.11.1" __all__ = [ "SUPPORTS_BFLOAT16", @@ -235,6 +235,9 @@ def filter(self, x): return not (self.text in x.getMessage()) # No label_names provided for model class from transformers.trainer import logger as transformers_trainer_logger transformers_trainer_logger.addFilter(HideLoggingMessage("No label_names")) + +# The tokenizer has new PAD/BOS/EOS tokens that differ from the model config and generation config. +transformers_trainer_logger.addFilter(HideLoggingMessage("The tokenizer has new")) del transformers_trainer_logger # Using the default loss: `ForCausalLMLoss`. diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 9ced8f1992..67b407075c 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -752,11 +752,11 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): " scale_rewards = False\n"\ "elif loss_type.lower() == 'dapo':\n"\ " if mask_truncated_completions != True:\n"\ - " print('Unsloth: The DAPO paper recommends `mask_truncated_completions = True`')\n"\ + " print('Unsloth: The DAPO paper recommends `mask_truncated_completions = True` - we will set it.')\n"\ " if epsilon_high != 0.28:\n"\ - " print('Unsloth: The DAPO paper recommends `epsilon_high = 0.28`')\n"\ + " print('Unsloth: The DAPO paper recommends `epsilon_high = 0.28` - we will set it.')\n"\ " if beta != 0.0:\n"\ - " print('Unsloth: The DAPO paper recommends setting `beta = 0.0` to remove the KL term')\n"\ + " print('Unsloth: The DAPO paper recommends setting `beta = 0.0` to remove the KL term - we will set it.')\n"\ " mask_truncated_completions = True\n"\ " epsilon_high = 0.28\n"\ " beta = 0.0\n"\ @@ -1085,10 +1085,13 @@ def patch_functions(RLTrainer, trainer_file, RLTrainer_name, all_imports, import ) # Replace self.llm.generate and self.llm.chat - lora_name = trainer_file + "_lora_model" + if "CUDA_VISIBLE_DEVICES" in os.environ: + lora_name = trainer_file + "_lora_model_' + " + "(os.environ.get('CUDA_VISIBLE_DEVICES', '0').replace(',',''))" + else: + lora_name = trainer_file + "_lora_model'" source = re.sub( r"(self\.llm\.(?:generate|chat)\([^\)]{1,})\)", - r"\1, lora_request = self.model.load_lora('" + lora_name + r"', load_tensors = True))", + r"\1, lora_request = self.model.load_lora('" + lora_name + r", load_tensors = True))", source ) # Prefer using unsloth's sampling params and fallback to trl's if not found diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index ea7183fc5a..281e3a71df 100644 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -216,17 +216,17 @@ def grpo_trainer__generate_and_score_completions(function_name, function): replacement_lines = """ batch_size = self.args.per_device_train_batch_size if mode == "train" else self.args.per_device_eval_batch_size try: - #TRL 0.23.1 and below path + # TRL 0.23.1 and below path if not has_images: # Left pad prompt before calculation old and ref hidden states prompt_completion_ids = left_pack_padding(prompt_completion_ids, self.processing_class.pad_token_id) self.model.for_training() - except: - #TRL 0.24.0 and below path + except: + # TRL 0.24.0 and below path if images is None: # Left pad prompt before calculation old and ref hidden states prompt_completion_ids = left_pack_padding(prompt_completion_ids, self.processing_class.pad_token_id) - self.model.for_training()""" + self.model.for_training()""" function = function.replace(line_to_replace, replacement_lines) diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 65ba9ccf9b..3ec4c46f7f 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -91,6 +91,7 @@ "qwen2_5_vl", "gemma3", "mistral3", + "qwen3_vl", ] VLLM_NON_LORA_VLM = [ "mllama",