sgl-project/sglang · error · ImportError
The required 'attentions' package is not installed. Install
Error message
The required 'attentions' package is not installed. Install it from sgl-project/sgl-kernel-npu.
What it means
laser_attn.py imports the 'attentions' NPU acceleration package inside try/except; on ImportError it logs a warning and re-raises ImportError directing you to install it from sgl-project/sgl-kernel-npu. Laser Attention cannot run without this package.
Source
Thrown at python/sglang/multimodal_gen/runtime/layers/attention/backends/laser_attn.py:23
AttentionImpl,
AttentionMetadata,
)
from sglang.multimodal_gen.runtime.layers.attention.backends.sdpa import SDPABackend
from sglang.multimodal_gen.runtime.platforms import AttentionBackendEnum
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
logger = init_logger(__name__)
# Import to use torch.ops.attentions, install package with sgl_kernel_npu
try:
import attentions # noqa: F401
except ImportError as e:
logger.warning_once(
"The 'attentions' library is not installed. Laser Attention is unavailable. "
"Installing this library may improve performance on NPU. "
"See: sgl-project/sgl-kernel-npu"
)
raise ImportError(
(
"The required 'attentions' package is not installed. "
"Install it from sgl-project/sgl-kernel-npu."
)
) from e
# The current NPU kernel stores QK scores and V in FP16 even for BF16 inputs.
_BF16_LASER_SCALE = 256.0
class LaserAttentionBackend(AttentionBackend):
accept_output_buffer: bool = True
@staticmethod
def get_supported_head_sizes() -> list[int]:
return [32, 64, 96, 128]
View on GitHub (pinned to 0132848349)
Solutions
- pip install the matching wheel from sgl-project/sgl-kernel-npu for your Python/CANN version
- Verify 'import attentions' succeeds in the exact interpreter used to launch the server
- If NPU is not the target, switch the attention backend away from laser
Example fix
# before python -m sglang.launch_server ... --attention-backend laser # ImportError # after pip install sglang-kernel-npu # provides 'attentions' python -m sglang.launch_server ... --attention-backend laser
Defensive patterns
Strategy: validation
Validate before calling
try:
import attentions # noqa
LASER_OK = True
except ImportError:
LASER_OK = False
if not LASER_OK:
select_backend('flash_attn') # avoid laser backend Try / catch
try:
from sglang.multimodal_gen.runtime.layers.attention.backends.laser_attn import LaserAttnImpl
except ImportError:
LaserAttnImpl = None Prevention
- Pre-install sglang-kernel-npu on NPU images
- Gate backend selection on import probes at startup
When it happens
Trigger: Importing laser_attn.py (or constructing the laser attention backend) in an environment where the 'attentions' wheel or its native NPU dependencies are missing.
Common situations: Selecting the laser attention backend on Ascend NPU without installing sgl-kernel-npu; broken CANN/NPU toolchain making the extension import fail; CI images missing the NPU wheels.
Related errors
- NPU detected, but torchair package is not installed. Please
- FlashAttention-4 CUTE is not available. Install flash-attn-4
- FlashAttention-4 CUTE is not available. Install flash-attn-4
- {name} is required for NPU packed attention
- {name} must be a 1D int32 or int64 tensor
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/3562df91ccf6e4e9.
Report an issue: GitHub.