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.
Methods¶
| Name | Description |
|---|---|
__init__ |
Default constructor. This default-constructed object is initially set to auto-core mode. |
set_auto_core_mode |
Sets the model to detect CoreMode automatically. |
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. |
get_clusters |
Returns the list of clusters to be used for model inference. |
__repr__ |
__init__¶
Default constructor. This default-constructed object is initially set to auto-core mode.
set_auto_core_mode¶
Sets the model to detect CoreMode automatically.
In auto-core mode, the model automatically detects a supported CoreMode while using all available NPU cores.
Note
If the model has more than one CoreMode, CoreMode.Auto is not supported.
Note
activation buffer slots will be reset after set_auto_core_mode is called.
Returns
True if the mode was successfully set, False otherwise.
set_single_core_mode¶
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.
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.
Note
Supported call forms (provide exactly one of num_cores / core_ids):
set_single_core_mode(num_cores): auto-allocatenum_coreslocal cores. (deprecated in latest models)set_single_core_mode(core_ids): use exactly the cores listed incore_ids.
set_global_core_mode¶
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¶
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¶
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¶
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¶
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¶
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¶
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¶
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 toTrueto enable the asynchronous pipeline; set toFalseto disable it.
get_async_pipeline_enabled¶
Returns whether the asynchronous pipeline is enabled in this configuration.
Returns
True if the asynchronous pipeline is enabled; False otherwise.
set_activation_slots¶
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.
CoreMode.Single: 2 * (the number of target core ids)CoreMode.Multi: 2 * (the number of target clusters)CoreMode.Global4: 2 * (the number of target clusters)CoreMode.Global8: 2
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¶
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¶
Returns the list of NPU CoreIds to be used for model inference.
The returned list reflects only what was set on this ModelConfig. What it contains depends on the configured CoreMode:
- Single mode via
set_single_core_mode(core_ids): the specified core_ids. - Single mode via
set_single_core_mode(num_cores): empty. The actual cores are resolved from the target NPU when the model is created. - Multi, Global4, Global8, and Auto modes: empty. Use
get_clusters()for the cluster-based modes.
Returns
A list of NPU CoreIds.
get_clusters¶
Returns the list of clusters to be used for model inference.
The returned list reflects only what was set on this ModelConfig. What it contains depends on the configured CoreMode:
- Multi mode via
set_multi_core_mode()and Global4 mode viaset_global4_core_mode(): the specified clusters (defaults to all clusters). - Single, Global8, and Auto modes: empty.
Returns
A list of NPU Clusters.