{"record":{"id":"48aefbd6287334d3","repo":"ultralytics/ultralytics","slug":"ascend-inference-requires-the-cann-runtime-and-ai","errorCode":null,"errorMessage":"Ascend inference requires the CANN runtime and `ais_bench` Python package. See https://docs.ultralytics.com/integrations/ascend/#runtime-installation for instructions.","messagePattern":"Ascend inference requires the CANN runtime and `ais_bench` Python package\\. See https://docs\\.ultralytics\\.com/integrations/ascend/#runtime-installation for instructions\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"ultralytics/nn/backends/ascend.py","lineNumber":35,"sourceCode":"\n    Loads a compiled .om offline model and runs inference on the Ascend AI Processor through the ais_bench runtime,\n    which wraps CANN's pyACL bindings.\n    \"\"\"\n\n    def load_model(self, weight: str | Path) -> None:\n        \"\"\"Load an Ascend model from a directory containing a .om file.\n\n        Args:\n            weight (str | Path): Path to the Ascend model directory containing the .om offline model.\n\n        Raises:\n            ImportError: If the ``ais_bench`` Python package is not installed.\n            FileNotFoundError: If no .om file is found in the given directory.\n        \"\"\"\n        try:\n            from ais_bench.infer.interface import InferSession\n        except ImportError as e:\n            raise ImportError(\n                \"Ascend inference requires the CANN runtime and `ais_bench` Python package. \"\n                \"See https://docs.ultralytics.com/integrations/ascend/#runtime-installation for instructions.\"\n            ) from e\n\n        LOGGER.info(f\"Loading {weight} for Huawei Ascend inference...\")\n\n        w = Path(weight)\n        found = next(w.rglob(\"*.om\"), None)\n        if found is None:\n            raise FileNotFoundError(f\"No .om file found in: {w}\")\n\n        self.model = InferSession(getattr(self.device, \"index\", None) or 0, str(found))\n\n        # Load metadata\n        metadata_file = found.parent / \"metadata.yaml\"\n        if metadata_file.exists():\n            self.apply_metadata(YAML.load(metadata_file))\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/ultralytics/ultralytics/blob/0449ea011cfd6c9a0d50a0bf1043aca5190cd476/ultralytics/nn/backends/ascend.py#L17-L53","documentation":"Ultralytics' Ascend backend (ultralytics/nn/backends/ascend.py) raises this ImportError when AutoBackend dispatches to it for an Ascend export and the `ais_bench` package cannot be imported. `ais_bench` is Huawei's Python inference client and only works on top of the CANN toolkit installed on the host. Without both, no .om offline model can be loaded or executed.","triggerScenarios":"Calling YOLO('model.om_dir') or AutoBackend with an exported Ascend model on a machine where `from ais_bench.infer.interface import InferSession` fails — i.e. CANN toolkit or ais_bench is absent, or the active Python environment does not see the CANN site-packages path (set_vars.sh not sourced).","commonSituations":"Running Ascend inference on an x86 dev box instead of the Atlas/Ascend host; installing ais_bench into a different conda/venv than the one running Ultralytics; CANN installed but the environment activation script was never sourced so ais_bench is not on sys.path.","solutions":["Install the CANN toolkit and ais_bench on the Ascend host following https://docs.ultralytics.com/integrations/ascend/#runtime-installation, then source set_env.sh so ais_bench is importable.","Verify the import in the SAME environment that runs Ultralytics: python -c \"from ais_bench.infer.interface import InferSession\" — if it fails there, install it there.","If you have no Ascend hardware, do not select the Ascend backend: re-run prediction with the original .pt weights or a CPU/GPU-friendly export format (onnx, engine, tflite)."],"exampleFix":"# before: on a machine without CANN\nyolo predict model=runs/export/ascend/\n# ImportError: Ascend inference requires the CANN runtime and `ais_bench`...\n\n# after: on the Atlas host, in the env with CANN + ais_bench\nsource /usr/local/Ascend/ascend-toolkit/set_env.sh\nyolo predict model=runs/export/ascend/","handlingStrategy":"validation","validationCode":"import importlib.util\n\nASCEND_AVAILABLE = importlib.util.find_spec('ais_bench') is not None\nif not ASCEND_AVAILABLE:\n    raise SystemExit('ais_bench/CANN missing — install per https://docs.ultralytics.com/integrations/ascend/#runtime-installation')\n\nmodel = YOLO('runs/export/ascend/')","typeGuard":null,"tryCatchPattern":"try:\n    model = YOLO(ascend_dir)\nexcept ImportError as e:\n    if 'ais_bench' in str(e):\n        logger.error('CANN/ais_bench not installed on this host; falling back to onnx export')\n        model = YOLO('yolo26n.onnx')\n    else:\n        raise","preventionTips":["Gate Ascend deployment behind an importability check for ais_bench in the runtime environment.","Run Ascend inference on the Atlas host with set_env.sh sourced, not on the training workstation."],"tags":["ascend","cann","import-error","npu","inference-backend","environment"],"backgroundTag":null,"analyzedSha":"0449ea011cfd6c9a0d50a0bf1043aca5190cd476","analyzedAt":"2026-08-15T02:34:13.413Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}