From c9ca2096b779b80ca65f0e30ace1899d582029b2 Mon Sep 17 00:00:00 2001 From: feng lui <3090641@qq.com> Date: Mon, 12 May 2025 20:33:42 +0800 Subject: [PATCH] vLLM Windows CUDA support [tested] (#2158) * Update loader.py change vllm installed check by transformers utils function * Update llama.py change vllm installed check by transformers utils function * add sample notebook * fix Indentation * add global is_vLLM_available function * Pythonic style * Delete nb/Qwen2.5_(3B)-GRPO-windows.ipynb Would be great to move it to https://github.com/unslothai/notebooks - appreciate it! --------- Co-authored-by: Daniel Han --- unsloth/models/__init__.py | 4 ++-- unsloth/models/_utils.py | 4 ++++ unsloth/models/llama.py | 5 ++--- unsloth/models/loader.py | 6 +++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/unsloth/models/__init__.py b/unsloth/models/__init__.py index 99db55c086..fb3fc5c455 100644 --- a/unsloth/models/__init__.py +++ b/unsloth/models/__init__.py @@ -20,5 +20,5 @@ from .qwen3 import FastQwen3Model from .qwen3_moe import FastQwen3MoeModel from .granite import FastGraniteModel from .dpo import PatchDPOTrainer, PatchKTOTrainer -from ._utils import is_bfloat16_supported, __version__ -from .rl import PatchFastRL, vLLMSamplingParams +from ._utils import is_bfloat16_supported, is_vLLM_available, __version__ +from .rl import PatchFastRL, vLLMSamplingParams \ No newline at end of file diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 82a1d02fce..4b9e2cce06 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -17,6 +17,7 @@ __version__ = "2025.5.1" __all__ = [ "SUPPORTS_BFLOAT16", "is_bfloat16_supported", + "is_vLLM_available", "prepare_model_for_kbit_training", "xformers", @@ -800,6 +801,9 @@ def is_bfloat16_supported(): return SUPPORTS_BFLOAT16 pass +def is_vLLM_available(): + return _is_package_available("vllm") +pass # Patches models to add RoPE Scaling def patch_linear_scaling( diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index 2145571ae1..207540abf5 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -1661,9 +1661,8 @@ class FastLlamaModel: ) pass if fast_inference: - import platform - if platform.system().lower() == 'windows': - print("Unsloth: vLLM does not work in Windows! Will use Unsloth inference!") + if not is_vLLM_available(): + print("Unsloth: vLLM is not installed! Will use Unsloth inference!") fast_inference = False major_version, minor_version = torch.cuda.get_device_capability() if major_version < 7: diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 7e904471bc..c93c5d2742 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -14,6 +14,7 @@ from ._utils import ( is_bfloat16_supported, + is_vLLM_available, HAS_FLASH_ATTENTION, HAS_FLASH_ATTENTION_SOFTCAPPING, USE_MODELSCOPE, @@ -351,9 +352,8 @@ class FastLanguageModel(FastLlamaModel): pass if fast_inference: - import platform - if platform.system().lower() == 'windows': - print("Unsloth: vLLM does not work in Windows! Will use Unsloth inference!") + if not is_vLLM_available(): + print("Unsloth: vLLM is not installed! Will use Unsloth inference!") fast_inference = False pass from unsloth_zoo.vllm_utils import (