ultralytics/ultralytics · error · ImportError

Ascend inference requires the CANN runtime and `ais_bench` P

Error message

Ascend inference requires the CANN runtime and `ais_bench` Python package. See https://docs.ultralytics.com/integrations/ascend/#runtime-installation for instructions.

What it means

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.

Source

Thrown at ultralytics/nn/backends/ascend.py:35

    Loads a compiled .om offline model and runs inference on the Ascend AI Processor through the ais_bench runtime,
    which wraps CANN's pyACL bindings.
    """

    def load_model(self, weight: str | Path) -> None:
        """Load an Ascend model from a directory containing a .om file.

        Args:
            weight (str | Path): Path to the Ascend model directory containing the .om offline model.

        Raises:
            ImportError: If the ``ais_bench`` Python package is not installed.
            FileNotFoundError: If no .om file is found in the given directory.
        """
        try:
            from ais_bench.infer.interface import InferSession
        except ImportError as e:
            raise ImportError(
                "Ascend inference requires the CANN runtime and `ais_bench` Python package. "
                "See https://docs.ultralytics.com/integrations/ascend/#runtime-installation for instructions."
            ) from e

        LOGGER.info(f"Loading {weight} for Huawei Ascend inference...")

        w = Path(weight)
        found = next(w.rglob("*.om"), None)
        if found is None:
            raise FileNotFoundError(f"No .om file found in: {w}")

        self.model = InferSession(getattr(self.device, "index", None) or 0, str(found))

        # Load metadata
        metadata_file = found.parent / "metadata.yaml"
        if metadata_file.exists():
            self.apply_metadata(YAML.load(metadata_file))

View on GitHub (pinned to 0449ea011c)

Solutions

  1. 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.
  2. 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.
  3. 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).

Example fix

# before: on a machine without CANN
yolo predict model=runs/export/ascend/
# ImportError: Ascend inference requires the CANN runtime and `ais_bench`...

# after: on the Atlas host, in the env with CANN + ais_bench
source /usr/local/Ascend/ascend-toolkit/set_env.sh
yolo predict model=runs/export/ascend/
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

ASCEND_AVAILABLE = importlib.util.find_spec('ais_bench') is not None
if not ASCEND_AVAILABLE:
    raise SystemExit('ais_bench/CANN missing — install per https://docs.ultralytics.com/integrations/ascend/#runtime-installation')

model = YOLO('runs/export/ascend/')

Try / catch

try:
    model = YOLO(ascend_dir)
except ImportError as e:
    if 'ais_bench' in str(e):
        logger.error('CANN/ais_bench not installed on this host; falling back to onnx export')
        model = YOLO('yolo26n.onnx')
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of ultralytics/ultralytics@0449ea011c (2026-08-15). Data as JSON: /api/errors/48aefbd6287334d3. Report an issue: GitHub.