[Misc] Improve the error message of failed import (#12119)
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import torch
|
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] Found files: {raw_matching_files}")
|
||||||
logger.debug(f"[sgl_kernel] Prioritized files: {matching_files}")
|
logger.debug(f"[sgl_kernel] Prioritized files: {matching_files}")
|
||||||
|
|
||||||
|
previous_import_errors: List[Exception] = []
|
||||||
|
|
||||||
# Try to load from the architecture-specific directory
|
# Try to load from the architecture-specific directory
|
||||||
if matching_files:
|
if matching_files:
|
||||||
ops_path = Path(matching_files[0]) # Use the first prioritized file
|
ops_path = Path(matching_files[0]) # Use the first prioritized file
|
||||||
@@ -102,6 +104,7 @@ def _load_architecture_specific_ops():
|
|||||||
return common_ops
|
return common_ops
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
previous_import_errors.append(e)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"[sgl_kernel] ✗ Failed to load from {ops_path}: {type(e).__name__}: {e}"
|
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
|
return common_ops
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
previous_import_errors.append(e)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"[sgl_kernel] ✗ Failed to load fallback from {alt_path}: {type(e).__name__}: {e}"
|
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__}")
|
logger.debug(f"[sgl_kernel] ✓ Module file: {common_ops.__file__}")
|
||||||
return common_ops
|
return common_ops
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
previous_import_errors.append(e)
|
||||||
logger.debug(f"[sgl_kernel] ✗ Standard Python import failed: {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
|
# All attempts failed
|
||||||
error_msg = f"""
|
error_msg = f"""
|
||||||
[sgl_kernel] CRITICAL: Could not load any common_ops library!
|
[sgl_kernel] CRITICAL: Could not load any common_ops library!
|
||||||
@@ -174,6 +183,9 @@ GPU Info:
|
|||||||
|
|
||||||
Please ensure sgl_kernel is properly installed with:
|
Please ensure sgl_kernel is properly installed with:
|
||||||
pip install --upgrade sgl_kernel
|
pip install --upgrade sgl_kernel
|
||||||
|
|
||||||
|
Error details from previous import attempts:
|
||||||
|
{attempt_error_msg}
|
||||||
"""
|
"""
|
||||||
logger.debug(error_msg)
|
logger.debug(error_msg)
|
||||||
raise ImportError(error_msg)
|
raise ImportError(error_msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user