콘텐츠로 이동

ModelConfig

class ModelConfig

Configures a core mode and core allocation of a model for NPU inference. The ModelConfig class provides methods for setting a core mode and allocating cores for NPU inference. Supported core modes are single-core, multi-core, global4-core, and global8-core. Users can also specify which cores to allocate for the model. Additionally, the configuration offers an option to enforce the use of a specific NPU bundle.

Note

Deprecated functions are included for backward compatibility, but it is recommended to use the newer core mode configuration methods.

Attributes

Name Description
early_latencies
finish_latencies

early_latencies

property early_latencies: List[int]

Deprecated

This setting has no effect.

finish_latencies

property finish_latencies: List[int]

Deprecated

This setting has no effect.

Methods

Name Description
__init__ Default constructor. This default-constructed object is initially set to single-core mode with all NPU local cores included.
set_single_core_mode Sets the model to use single-core mode for inference with a specified number of local cores.
set_global_core_mode
set_global4_core_mode Sets the model to use global4-core mode for inference with a specified set of NPU clusters.
set_global8_core_mode Sets the model to use global8-core mode for inference.
get_core_mode Gets the core mode to be applied to the model.
set_multi_core_mode Sets the model to use multi-core mode for batch inference.
get_core_allocation_policy Gets the core allocation policy to be applied to the model.
get_num_cores Gets the number of cores to be allocated for the model.
force_single_npu_bundle Forces the use of a specific NPU bundle.
get_forced_npu_bundle_index Retrieves the index of the forced NPU bundle.
set_async_pipeline_enabled Enables or disables the asynchronous pipeline required for asynchronous inference.
get_async_pipeline_enabled Returns whether the asynchronous pipeline is enabled in this configuration.
set_activation_slots Sets activation buffer slots for multi-activation supported model.
get_activation_slots Returns activation buffer slot count.
get_core_ids Returns the list of NPU CoreIds to be used for model inference.
__repr__

__init__

def __init__(self, num_cores: Optional[int] = None)

Default constructor. This default-constructed object is initially set to single-core mode with all NPU local cores included.

set_single_core_mode

def set_single_core_mode(
    self, num_cores: Optional[int] = None, core_ids: Optional[List[CoreId]] = None
) -> bool

Sets the model to use single-core mode for inference with a specified number of local cores.

In single-core mode, each local core executes model inference independently. The number of cores used is specified by the num_cores parameter, and the core allocation policy is set to CoreAllocationPolicy.Auto, meaning the model will be automatically allocated to available local cores when the model is launched to the NPU, specifically when the Model.launch() function is called. Or The user can specify a list of CoreIds to determine which cores to use for inference.

Note

Use exactly one of num_cores or core_ids, not both.

Parameters

  • num_cores [in] — The number of local cores to use for inference.
  • core_ids [in] — A list of CoreIds to be used for model inference.

Returns

True if the mode was successfully set, False otherwise.

set_global_core_mode

def set_global_core_mode(self, clusters: List[Cluster]) -> bool

Deprecated

set_global4_core_mode

def set_global4_core_mode(
    self, clusters: List[Cluster] = [Cluster.Cluster0, Cluster.Cluster1]
) -> bool

Sets the model to use global4-core mode for inference with a specified set of NPU clusters.

For Aries NPU, there are two clusters, each consisting of four local cores. In global4-core mode, four local cores within the same cluster work together to execute the model inference.

Parameters

  • clusters [in] — A list of clusters to be used for model inference.

Returns

True if the mode was successfully set, False otherwise.

set_global8_core_mode

def set_global8_core_mode(self) -> bool

Sets the model to use global8-core mode for inference.

For Aries NPU, there are two clusters, each consisting of four local cores. In global8-core mode, all eight local cores across the two clusters work together to execute the model inference.

Returns

True if the mode was successfully set, False otherwise.

get_core_mode

def get_core_mode(self) -> CoreMode

Gets the core mode to be applied to the model.

This reflects the core mode that will be used when the model is created.

Returns

The CoreMode to be applied to the model.

set_multi_core_mode

def set_multi_core_mode(
    self, clusters: List[Cluster] = [Cluster.Cluster0, Cluster.Cluster1]
) -> bool

Sets the model to use multi-core mode for batch inference.

In multi-core mode, on Aries NPU, the four local cores within a cluster work together to process batch inference tasks efficiently. This mode is optimized for batch processing.

Parameters

  • clusters [in] — A list of clusters to be used for multi-core batch inference.

Returns

True if the mode was successfully set, False otherwise.

get_core_allocation_policy

def get_core_allocation_policy(self) -> CoreAllocationPolicy

Gets the core allocation policy to be applied to the model.

This reflects the core allocation policy that will be used when the model is created.

Returns

The CoreAllocationPolicy to be applied to the model.

get_num_cores

def get_num_cores(self) -> int

Gets the number of cores to be allocated for the model.

This represents the number of cores that will be allocated for inference when the model is launched to the NPU.

Returns

The number of cores to be allocated for the model.

force_single_npu_bundle

def force_single_npu_bundle(self, npu_bundle_index: int) -> bool

Forces the use of a specific NPU bundle.

This function forces the selection of a specific NPU bundle. If a non-negative index is provided, the corresponding NPU bundle is selected and runs without CPU offloading. If -1 is provided, all NPU bundles are used with CPU offloading enabled.

Parameters

  • npu_bundle_index [in] — The index of the NPU bundle to force. A non-negative integer selects a specific NPU bundle (runs without CPU offloading), or -1 to enable all NPU bundles with CPU offloading.

Returns

True if the index is valid and the NPU bundle is successfully set, False if the index is invalid (less than -1).

get_forced_npu_bundle_index

def get_forced_npu_bundle_index(self) -> bool

Retrieves the index of the forced NPU bundle.

This function returns the index of the NPU bundle that has been forced using the force_single_npu_bundle function. If no NPU bundle is forced, the returned value will be -1.

Returns

The index of the forced NPU bundle, or -1 if no bundle is forced.

set_async_pipeline_enabled

def set_async_pipeline_enabled(self, enable: bool) -> None

Enables or disables the asynchronous pipeline required for asynchronous inference.

Call this function with enable set to True if you intend to use Model.infer_async(), as the asynchronous pipeline is necessary for their operation.

If you are only using synchronous inference, such as Model.infer() or Model.infer_to_float(), it is recommended to keep the asynchronous pipeline disabled to avoid unnecessary overhead.

Parameters

  • enable [in] — Set to True to enable the asynchronous pipeline; set to False to disable it.

get_async_pipeline_enabled

def get_async_pipeline_enabled(self) -> bool

Returns whether the asynchronous pipeline is enabled in this configuration.

Returns

True if the asynchronous pipeline is enabled; False otherwise.

set_activation_slots

def set_activation_slots(self, num: int) -> None

Sets activation buffer slots for multi-activation supported model.

all this function if you want to set the number of activation buffer slots manually.

If you do not call this function, the default number of activation buffer slots is set differently depending on the CoreMode.

Note

This function has no effect on MXQ file in version earlier than MXQv7.

Note

Currently, LLM model's activation slot is fixed to 1 and ignoring count.

Parameters

  • count [in] — Multi activation counts. Must be >= 1.

get_activation_slots

def get_activation_slots(self) -> int

Returns activation buffer slot count.

Note

This function has no meaning on MXQ file in version earlier than MXQv7.

Returns

Activation buffer slot count.

get_core_ids

def get_core_ids(self) -> List[CoreId]

Returns the list of NPU CoreIds to be used for model inference.

This function returns a list of NPU CoreIds that the model will use for inference. When set_single_core_mode(num_cores) is called and the core allocation policy is set to CoreAllocationPolicy.Auto, it will return an empty list.

Returns

A list of NPU CoreIds.

__repr__

def __repr__(self)