{"record":{"id":"0e6b4ec812762bea","repo":"sgl-project/sglang","slug":"npu-detected-but-torchair-package-is-not-installe","errorCode":null,"errorMessage":"NPU detected, but torchair package is not installed. Please install torchair for torch.compile support on NPU.","messagePattern":"NPU detected, but torchair package is not installed\\. Please install torchair for torch\\.compile support on NPU\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/common.py","lineNumber":1003,"sourceCode":"\n    return major, minor\n\n\ndef get_compiler_backend(mode=None) -> str:\n    # OOT platforms provide their own compile backend.\n    if current_platform.is_out_of_tree():\n        return current_platform.get_compile_backend(mode)\n\n    if hasattr(torch, \"hpu\") and torch.hpu.is_available():\n        return \"hpu_backend\"\n\n    if hasattr(torch, \"npu\") and torch.npu.is_available():\n        try:\n            import torchair\n            import torchair.ge_concrete_graph.ge_converter.experimental.patch_for_hcom_allreduce  # noqa: F401\n            from torchair.configs.compiler_config import CompilerConfig\n        except ImportError:\n            raise ImportError(\n                \"NPU detected, but torchair package is not installed. \"\n                \"Please install torchair for torch.compile support on NPU.\"\n            )\n        compiler_config = CompilerConfig()\n        compiler_config.mode = \"max-autotune\"\n        if mode == \"npugraph_ex\":\n            compiler_config.mode = \"reduce-overhead\"\n            compiler_config.debug.run_eagerly = True\n        npu_backend = torchair.get_npu_backend(compiler_config=compiler_config)\n        return npu_backend\n\n    return \"inductor\"\n\n\ndef set_cuda_arch():\n    if is_flashinfer_available():\n        capability = torch.cuda.get_device_capability()\n        arch = f\"{capability[0]}.{capability[1]}\"","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/common.py#L985-L1021","documentation":"Raised when SGLang detects an available NPU (torch.npu.is_available()) and tries to build a torch.compile backend, but the torchair package (or its submodules) cannot be imported. torchair is Huawei's Ascend NPU compiler integration needed for torch.compile on NPU hardware. Without it, the npugraph/npugraph_ex compiler modes cannot function.","triggerScenarios":"Calling get_compiler_backend('npugraph' or 'npugraph_ex') on a machine where torch.npu.is_available() is True but torchair, its hcom_allreduce patch module, or torchair.configs.compiler_config.CompilerConfig is missing/mismatched. Reached via _maybe_enable_torch_compile, build_torch_compile_kwargs, patch_model_npu, or model classes like Llama4MoE that hardcode the NPU backend.","commonSituations":"Running SGLang on Ascend NPU with a torch/torchair version mismatch; torchair installed but too old to have ge_converter.experimental.patch_for_hcom_allreduce; enabling --enable-torch-compile on NPU without installing the CANN-matched torchair wheel.","solutions":["pip install a torchair version matching your CANN and torch builds (see Ascend pytorch and torchair release matrix)","Verify import works: python -c \"import torchair; import torchair.ge_concrete_graph.ge_converter.experimental.patch_for_hcom_allreduce; from torchair.configs.compiler_config import CompilerConfig\"","If you don't need torch.compile on NPU, disable it (drop --enable-torch-compile / npugraph modes)","Upgrade/downgrade torch to the version the installed torchair was compiled against"],"exampleFix":"# before\nserver_args.enable_torch_compile = True  # on NPU without torchair\n# after\npip install torchair==<version matching your CANN/torch>\n# or disable compile on NPU\nserver_args.enable_torch_compile = False","handlingStrategy":"validation","validationCode":"def has_torchair() -> bool:\n    try:\n        import torchair\n        import torchair.ge_concrete_graph.ge_converter.experimental.patch_for_hcom_allreduce  # noqa\n        from torchair.configs.compiler_config import CompilerConfig\n        return True\n    except ImportError:\n        return False\n\nif torch.npu.is_available() and args.enable_torch_compile and not has_torchair():\n    args.enable_torch_compile = False  # or abort with a clear message","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a matching torch/torchair/CANN version set in your environment manifest","Add a startup smoke test that imports torchair on NPU nodes before serving","Gate --enable-torch-compile on NPU behind a capability check"],"tags":["npu","ascend","torchair","torch-compile","import-error"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}