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

  1. pip install the matching wheel from sgl-project/sgl-kernel-npu for your Python/CANN version
  2. Verify 'import attentions' succeeds in the exact interpreter used to launch the server
  3. 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

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


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/3562df91ccf6e4e9. Report an issue: GitHub.