Skip to main content

Python class

NPU

NPU

class max.driver.NPU(self, id: int = -1)

source

Bases: Accelerator

Creates an NPU accelerator device.

NPU is a subclass of Accelerator: an NPU is an accelerator, and isinstance(device, Accelerator) returns True for any NPU instance. The reason to construct an NPU instead of a bare Accelerator is to select the NPU dispatch path: the graph compiler stamps an "npu" device label, emits target="npu" Mojo kernels, and routes through the NPU plugin hook rather than the default GPU dispatch path.

On platforms without an NPU backend the device will still be created, but downstream graph compilation will fail with an unsupported target error.

from max import driver
device = driver.NPU()
device = driver.NPU(id=0)

Parameters:

id (int, optional) – The device ID to use. Defaults to -1, which selects the first available NPU.

Returns:

A new NPU device object.

Return type:

NPU