Skip to content

speculators.utils.util

Functions:

get_current_device

get_current_device() -> str

Get the current accelerator device string (e.g. 'cuda:0', 'npu:0').

Source code in speculators/utils/util.py
def get_current_device() -> str:
    """Get the current accelerator device string (e.g. 'cuda:0', 'npu:0')."""
    acc = torch.accelerator.current_accelerator()
    if acc is None:
        return "cuda:0"
    device_idx = torch.accelerator.current_device_index()
    return f"{acc.type}:{device_idx}"

is_npu_available

is_npu_available() -> bool

Detect Ascend NPU availability

Source code in speculators/utils/util.py
def is_npu_available() -> bool:
    """Detect Ascend NPU availability"""
    try:
        return is_torch_npu_available()
    except (ImportError, RuntimeError, ModuleNotFoundError, AttributeError):
        return False