diff --git a/sgl-kernel/python/sgl_kernel/__init__.py b/sgl-kernel/python/sgl_kernel/__init__.py index dc72ae30b..7960a03b9 100644 --- a/sgl-kernel/python/sgl_kernel/__init__.py +++ b/sgl-kernel/python/sgl_kernel/__init__.py @@ -1,9 +1,9 @@ import ctypes import logging import os -import platform import shutil from pathlib import Path +from typing import List import torch @@ -81,6 +81,8 @@ def _load_architecture_specific_ops(): logger.debug(f"[sgl_kernel] Found files: {raw_matching_files}") logger.debug(f"[sgl_kernel] Prioritized files: {matching_files}") + previous_import_errors: List[Exception] = [] + # Try to load from the architecture-specific directory if matching_files: ops_path = Path(matching_files[0]) # Use the first prioritized file @@ -102,6 +104,7 @@ def _load_architecture_specific_ops(): return common_ops except Exception as e: + previous_import_errors.append(e) logger.debug( f"[sgl_kernel] ✗ Failed to load from {ops_path}: {type(e).__name__}: {e}" ) @@ -138,6 +141,7 @@ def _load_architecture_specific_ops(): return common_ops except Exception as e: + previous_import_errors.append(e) logger.debug( f"[sgl_kernel] ✗ Failed to load fallback from {alt_path}: {type(e).__name__}: {e}" ) @@ -157,8 +161,13 @@ def _load_architecture_specific_ops(): logger.debug(f"[sgl_kernel] ✓ Module file: {common_ops.__file__}") return common_ops except ImportError as e: + previous_import_errors.append(e) logger.debug(f"[sgl_kernel] ✗ Standard Python import failed: {e}") + attempt_error_msg = "\n".join( + f"- {type(err).__name__}: {err}" for err in previous_import_errors + ) + # All attempts failed error_msg = f""" [sgl_kernel] CRITICAL: Could not load any common_ops library! @@ -174,6 +183,9 @@ GPU Info: Please ensure sgl_kernel is properly installed with: pip install --upgrade sgl_kernel + +Error details from previous import attempts: +{attempt_error_msg} """ logger.debug(error_msg) raise ImportError(error_msg)