{"record":{"id":"3562df91ccf6e4e9","repo":"sgl-project/sglang","slug":"the-required-attentions-package-is-not-installed","errorCode":null,"errorMessage":"The required 'attentions' package is not installed. Install it from sgl-project/sgl-kernel-npu.","messagePattern":"The required 'attentions' package is not installed\\. Install it from sgl-project/sgl-kernel-npu\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/laser_attn.py","lineNumber":23,"sourceCode":"    AttentionImpl,\n    AttentionMetadata,\n)\nfrom sglang.multimodal_gen.runtime.layers.attention.backends.sdpa import SDPABackend\nfrom sglang.multimodal_gen.runtime.platforms import AttentionBackendEnum\nfrom sglang.multimodal_gen.runtime.utils.logging_utils import init_logger\n\nlogger = init_logger(__name__)\n\n# Import to use torch.ops.attentions, install package with sgl_kernel_npu\ntry:\n    import attentions  # noqa: F401\nexcept ImportError as e:\n    logger.warning_once(\n        \"The 'attentions' library is not installed. Laser Attention is unavailable. \"\n        \"Installing this library may improve performance on NPU. \"\n        \"See: sgl-project/sgl-kernel-npu\"\n    )\n    raise ImportError(\n        (\n            \"The required 'attentions' package is not installed. \"\n            \"Install it from sgl-project/sgl-kernel-npu.\"\n        )\n    ) from e\n\n# The current NPU kernel stores QK scores and V in FP16 even for BF16 inputs.\n_BF16_LASER_SCALE = 256.0\n\n\nclass LaserAttentionBackend(AttentionBackend):\n\n    accept_output_buffer: bool = True\n\n    @staticmethod\n    def get_supported_head_sizes() -> list[int]:\n        return [32, 64, 96, 128]\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/laser_attn.py#L5-L41","documentation":"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.","triggerScenarios":"Importing laser_attn.py (or constructing the laser attention backend) in an environment where the 'attentions' wheel or its native NPU dependencies are missing.","commonSituations":"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.","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"],"exampleFix":"# before\npython -m sglang.launch_server ... --attention-backend laser   # ImportError\n# after\npip install sglang-kernel-npu  # provides 'attentions'\npython -m sglang.launch_server ... --attention-backend laser","handlingStrategy":"validation","validationCode":"try:\n    import attentions  # noqa\n    LASER_OK = True\nexcept ImportError:\n    LASER_OK = False\nif not LASER_OK:\n    select_backend('flash_attn')  # avoid laser backend","typeGuard":null,"tryCatchPattern":"try:\n    from sglang.multimodal_gen.runtime.layers.attention.backends.laser_attn import LaserAttnImpl\nexcept ImportError:\n    LaserAttnImpl = None","preventionTips":["Pre-install sglang-kernel-npu on NPU images","Gate backend selection on import probes at startup"],"tags":["import-error","npu","ascend","missing-dependency","laser-attention"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}