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.

Fix VLM processor load degradation and vLLM CUDA version detection (#4091)

Daniel Hanfec06247c905
diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.py
index b3200baa052..172ba36f63c 100644
--- a/unsloth/import_fixes.py
+++ b/unsloth/import_fixes.py
@@ -1467,12 +1467,78 @@ def _is_broken_vllm_error(error) -> bool:
)
) or ("vllm" in message and "undefined symbol" in message):
return True
+ # Also catch CUDA shared library mismatches during vllm import
+ # e.g. "libcudart.so.12: cannot open shared object file"
+ if (
+ "libcudart" in message or "libcublas" in message or "libnvrtc" in message
+ ) and "cannot open shared object file" in message:
+ return True
current = getattr(current, "__cause__", None) or getattr(
current, "__context__", None
)
return False
+def _get_vllm_cuda_mismatch_message(error):
+ """If the error is a CUDA version mismatch, return a helpful install message."""
+ import re as _re
+
+ checked = set()
+ current = error
+ wanted_cuda = None
+ while current is not None and id(current) not in checked:
+ checked.add(id(current))
+ message = str(current)
+ # Extract the CUDA version vllm was built for, e.g. "libcudart.so.12"
+ match = _re.search(r"libcudart\.so\.(\d+)", message)
+ if match:
+ wanted_cuda = match.group(1)
+ break
+ current = getattr(current, "__cause__", None) or getattr(
+ current, "__context__", None
+ )
+ if wanted_cuda is None:
+ return None
+
+ # Detect what CUDA version is actually available on the system
+ system_cuda_display = None # Human-readable, e.g. "13.0"
+ system_cuda_tag = None # For wheel URL, e.g. "130"
+ try:
+ import torch
+
+ cuda_version = torch.version.cuda # e.g. "13.0" or "12.8"
+ if cuda_version:
+ system_cuda_display = cuda_version
+ system_cuda_tag = cuda_version.replace(".", "")[:3] # "130" or "128"
+ except Exception:
+ pass
+
+ if system_cuda_tag is None or system_cuda_tag.startswith(wanted_cuda):
+ return None # Not a mismatch or can't determine
+
+ try:
+ vllm_version = importlib_version("vllm").split("+")[0]
+ except Exception:
+ vllm_version = "VLLM_VERSION"
+
+ cpu_arch = "x86_64"
+ try:
+ import platform
+
+ cpu_arch = platform.machine()
+ except Exception:
+ pass
+
+ return (
+ f"Unsloth: vLLM was built for CUDA {wanted_cuda} but this system has "
+ f"CUDA {system_cuda_display}. Please reinstall vLLM with the correct CUDA version:\n"
+ f"\n"
+ f" uv pip install https://github.com/vllm-project/vllm/releases/download/"
+ f"v{vllm_version}/vllm-{vllm_version}+cu{system_cuda_tag}-cp38-abi3-"
+ f"manylinux_2_35_{cpu_arch}.whl"
+ )
+
+
class _CausalConv1dImportBlockerLoader(importlib.abc.Loader):
__slots__ = ("module_name",)
@@ -1621,12 +1687,16 @@ def disable_broken_vllm(error = None):
VLLM_BROKEN = True
_clear_vllm_modules()
_install_vllm_blocker()
- logger.warning(
- "Unsloth: Detected broken vLLM binary extension; "
- "disabling vLLM imports and continuing import.\n"
- "Please reinstall via `uv pip install unsloth vllm torchvision torchaudio "
- "--torch-backend=auto`."
- )
+ cuda_msg = _get_vllm_cuda_mismatch_message(failure)
+ if cuda_msg:
+ logger.warning(cuda_msg)
+ else:
+ logger.warning(
+ "Unsloth: Detected broken vLLM binary extension; "
+ "disabling vLLM imports and continuing import.\n"
+ "Please reinstall via `uv pip install unsloth vllm torchvision torchaudio "
+ "--torch-backend=auto`."
+ )
return True
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 00d8a3b7f2f..2d6c7ac93f0 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -916,6 +916,32 @@ class FastBaseModel:
# Counteract saved tokenizers
tokenizer_name = model_name if tokenizer_name is None else tokenizer_name
+
+ # Fix _Unsloth_Patched_ prefix in local config files from old saves (issue #4085)
+ if os.path.isdir(tokenizer_name):
+ import json as _json
+
+ for _cfg_name in (
+ "processor_config.json",
+ "preprocessor_config.json",
+ "tokenizer_config.json",
+ ):
+ _cfg_path = os.path.join(tokenizer_name, _cfg_name)
+ if os.path.exists(_cfg_path):
+ try:
+ with open(_cfg_path, "r", encoding = "utf-8") as _f:
+ _cfg = _json.load(_f)
+ if _cfg.get("processor_class", "").startswith(
+ "_Unsloth_Patched_"
+ ):
+ _cfg["processor_class"] = _cfg["processor_class"][
+ len("_Unsloth_Patched_") :
+ ]
+ with open(_cfg_path, "w", encoding = "utf-8") as _f:
+ _json.dump(_cfg, _f, indent = 2, ensure_ascii = False)
+ except Exception:
+ pass
+
if (whisper_language and whisper_task) or auto_model.__name__.endswith(
"ForConditionalGeneration"
):
@@ -947,14 +973,23 @@ class FastBaseModel:
)
# If processor loading failed (e.g., tokenizer class not found),
+ # or if AutoProcessor silently degraded to a text-only tokenizer
+ # instead of returning a full VLM processor (issue #4085),
# try constructing the processor manually from separate components.
- if tokenizer is None and is_vlm:
- tokenizer = _construct_vlm_processor_fallback(
+ _processor_is_degraded = (
+ is_vlm
+ and tokenizer is not None
+ and not hasattr(tokenizer, "image_processor")
+ )
+ if (tokenizer is None or _processor_is_degraded) and is_vlm:
+ _fallback = _construct_vlm_processor_fallback(
tokenizer_name,
model_type_arch,
token,
trust_remote_code,
)
+ if _fallback is not None:
+ tokenizer = _fallback
if tokenizer is None:
import sys