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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Suppress HIP amdgpu.ids stderr noise during causal_conv1d check (#4052)
Daniel Han6ec46f49a6b8
diff --git a/unsloth/__init__.py b/unsloth/__init__.pyindex a505e89ad47..990e4b915f5 100644--- a/unsloth/__init__.py+++ b/unsloth/__init__.py@@ -29,6 +29,7 @@ from .import_fixes import (fix_message_factory_issue,check_fbgemm_gpu_version,disable_broken_causal_conv1d,+ _suppress_hip_libdrm_ids_noise,torchvision_compatibility_check,fix_diffusers_warnings,fix_huggingface_hub,@@ -106,7 +107,8 @@ del PackageNotFoundError, importlib_version# Try importing PyTorch and check versiontry:- import torch+ with _suppress_hip_libdrm_ids_noise():+ import torchexcept ModuleNotFoundError:raise ImportError("Unsloth: Pytorch is not installed. Go to https://pytorch.org/.\n"@@ -115,14 +117,15 @@ except ModuleNotFoundError:except:raise-from unsloth_zoo.device_type import (- is_hip,- get_device_type,- DEVICE_TYPE,- DEVICE_TYPE_TORCH,- DEVICE_COUNT,- ALLOW_PREQUANTIZED_MODELS,-)+with _suppress_hip_libdrm_ids_noise():+ from unsloth_zoo.device_type import (+ is_hip,+ get_device_type,+ DEVICE_TYPE,+ DEVICE_TYPE_TORCH,+ DEVICE_COUNT,+ ALLOW_PREQUANTIZED_MODELS,+ )# Fix other issuesfrom .import_fixes import (diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.pyindex d037903bec8..0cac361888e 100644--- a/unsloth/import_fixes.py+++ b/unsloth/import_fixes.py@@ -16,6 +16,7 @@ import osimport importlib.abcimport importlib.machineryimport importlib.util+import contextlibfrom pathlib import Pathfrom importlib.metadata import version as importlib_versionfrom packaging.version import Version as TrueVersion@@ -1175,6 +1176,54 @@ _CAUSAL_CONV1D_PREFIX = "causal_conv1d"_CAUSAL_CONV1D_BLOCKER_SENTINEL = "_unsloth_causal_conv1d_blocker"+def _is_rocm_torch_build() -> bool:+ try:+ return "rocm" in str(importlib_version("torch")).lower()+ except Exception:+ return False+++def _suppress_stderr_fd():+ saved_stderr_fd = None+ devnull_fd = None+ redirected = False+ try:+ saved_stderr_fd = os.dup(2)+ devnull_fd = os.open(os.devnull, os.O_WRONLY)+ os.dup2(devnull_fd, 2)+ redirected = True+ except Exception:+ redirected = False++ try:+ yield+ finally:+ if redirected and saved_stderr_fd is not None:+ try:+ os.dup2(saved_stderr_fd, 2)+ except Exception:+ pass+ if devnull_fd is not None:+ try:+ os.close(devnull_fd)+ except Exception:+ pass+ if saved_stderr_fd is not None:+ try:+ os.close(saved_stderr_fd)+ except Exception:+ pass+++def _suppress_hip_libdrm_ids_noise():+ # ROCm/libdrm can emit amdgpu.ids missing errors via low-level fd=2 writes.+ # Python-level stderr filters cannot intercept those writes.+ if not _is_rocm_torch_build():+ return contextlib.nullcontext()+ return _suppress_stderr_fd()++def _is_causal_conv1d_name(module_name: str) -> bool:return module_name == _CAUSAL_CONV1D_PREFIX or module_name.startswith(_CAUSAL_CONV1D_PREFIX + "."@@ -1307,7 +1356,8 @@ def disable_broken_causal_conv1d():returntry:- import causal_conv1d # noqa: F401+ with _suppress_hip_libdrm_ids_noise():+ import causal_conv1d # noqa: F401returnexcept Exception as error: