qbruntime.type.ModelConfig Class Reference

qbruntime.type.ModelConfig Class Reference#

SDK qb Runtime Library: qbruntime.type.ModelConfig Class Reference
SDK qb Runtime Library v1.2
MCS001-EN

Configures a core mode and core allocation of a model for NPU inference. More...

Public Member Functions

 __init__ (self, Optional[int] num_cores=None)
 Default constructor.
bool set_auto_core_mode (self)
 Sets the model to detect CoreMode automatically.
bool set_single_core_mode (self, Optional[int] num_cores=None, Optional[List[CoreId]] core_ids=None)
 Sets the model to use single-core mode for inference with a specified number of local cores.
bool set_global_core_mode (self, List[Cluster] clusters)
bool set_global4_core_mode (self, List[Cluster] clusters=[Cluster.Cluster0, Cluster.Cluster1])
 Sets the model to use global4-core mode for inference with a specified set of NPU clusters.
bool set_global8_core_mode (self)
 Sets the model to use global8-core mode for inference.
CoreMode get_core_mode (self)
 Gets the core mode to be applied to the model.
bool set_multi_core_mode (self, List[Cluster] clusters=[Cluster.Cluster0, Cluster.Cluster1])
 Sets the model to use multi-core mode for batch inference.
CoreAllocationPolicy get_core_allocation_policy (self)
 Gets the core allocation policy to be applied to the model.
int get_num_cores (self)
 Gets the number of cores to be allocated for the model.
bool force_single_npu_bundle (self, int npu_bundle_index)
 Forces the use of a specific NPU bundle.
bool get_forced_npu_bundle_index (self)
 Retrieves the index of the forced NPU bundle.
None set_async_pipeline_enabled (self, bool enable)
 Enables or disables the asynchronous pipeline required for asynchronous inference.
bool get_async_pipeline_enabled (self)
 Returns whether the asynchronous pipeline is enabled in this configuration.
None set_activation_slots (self, int num)
 Sets activation buffer slots for multi-activation supported model.
int get_activation_slots (self)
 Returns activation buffer slot count.
List[int] early_latencies (self)
List[int] finish_latencies (self)
 early_latencies (self, List[int] latencies)
 finish_latencies (self, List[int] latencies)
List[CoreIdget_core_ids (self)
 Returns the list of NPU CoreIds to be used for model inference.
 __repr__ (self)

Protected Attributes

tuple _model_config

Detailed Description

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.

Definition at line 452 of file type.py.

Constructor & Destructor Documentation

◆ __init__()

qbruntime.type.ModelConfig.__init__ ( self,
Optional[int] num_cores = None )

Default constructor.

This default-constructed object is initially set to auto-core mode.

Definition at line 465 of file type.py.

Member Function Documentation

◆ set_auto_core_mode()

bool qbruntime.type.ModelConfig.set_auto_core_mode ( self)

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.
activation buffer slots will be reset after set_auto_core_mode is called.
Returns
True if the mode was successfully set, False otherwise.

Definition at line 476 of file type.py.

◆ set_single_core_mode()

bool qbruntime.type.ModelConfig.set_single_core_mode ( self,
Optional[int] num_cores = None,
Optional[List[CoreId]] core_ids = None )

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
[in]num_coresThe number of local cores to use for inference.
[in]core_idsA list of CoreIds to be used for model inference.
Returns
True if the mode was successfully set, False otherwise.

Definition at line 491 of file type.py.

◆ set_global_core_mode()

bool qbruntime.type.ModelConfig.set_global_core_mode ( self,
List[Cluster] clusters )
Deprecated

Definition at line 522 of file type.py.

◆ set_global4_core_mode()

bool qbruntime.type.ModelConfig.set_global4_core_mode ( self,
List[Cluster] clusters = [Cluster.Cluster0, Cluster.Cluster1] )

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
[in]clustersA list of clusters to be used for model inference.
Returns
True if the mode was successfully set, False otherwise.

Definition at line 526 of file type.py.

◆ set_global8_core_mode()

bool qbruntime.type.ModelConfig.set_global8_core_mode ( self)

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.

Definition at line 543 of file type.py.

◆ get_core_mode()

CoreMode qbruntime.type.ModelConfig.get_core_mode ( self)

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.

Definition at line 555 of file type.py.

◆ set_multi_core_mode()

bool qbruntime.type.ModelConfig.set_multi_core_mode ( self,
List[Cluster] clusters = [Cluster.Cluster0, Cluster.Cluster1] )

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
[in]clustersA list of clusters to be used for multi-core batch inference.
Returns
True if the mode was successfully set, False otherwise.

Definition at line 565 of file type.py.

◆ get_core_allocation_policy()

CoreAllocationPolicy qbruntime.type.ModelConfig.get_core_allocation_policy ( self)

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.

Definition at line 581 of file type.py.

◆ get_num_cores()

int qbruntime.type.ModelConfig.get_num_cores ( self)

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.

Definition at line 592 of file type.py.

◆ force_single_npu_bundle()

bool qbruntime.type.ModelConfig.force_single_npu_bundle ( self,
int npu_bundle_index )

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
[in]npu_bundle_indexThe 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).

Definition at line 603 of file type.py.

◆ get_forced_npu_bundle_index()

bool qbruntime.type.ModelConfig.get_forced_npu_bundle_index ( self)

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.

Definition at line 622 of file type.py.

◆ set_async_pipeline_enabled()

None qbruntime.type.ModelConfig.set_async_pipeline_enabled ( self,
bool enable )

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
[in]enableSet to True to enable the asynchronous pipeline; set to False to disable it.

Definition at line 634 of file type.py.

◆ get_async_pipeline_enabled()

bool qbruntime.type.ModelConfig.get_async_pipeline_enabled ( self)

Returns whether the asynchronous pipeline is enabled in this configuration.

Returns
True if the asynchronous pipeline is enabled; False otherwise.

Definition at line 651 of file type.py.

◆ set_activation_slots()

None qbruntime.type.ModelConfig.set_activation_slots ( self,
int num )

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.
Currently, LLM model's activation slot is fixed to 1 and ignoring count.
Parameters
[in]countMulti activation counts. Must be >= 1.

Definition at line 659 of file type.py.

◆ get_activation_slots()

int qbruntime.type.ModelConfig.get_activation_slots ( self)

Returns activation buffer slot count.

Note
This function has no meaning on MXQ file in version earlier than MXQv7.
Returns
Activation buffer slot count.

Definition at line 681 of file type.py.

◆ early_latencies() [1/2]

List[int] qbruntime.type.ModelConfig.early_latencies ( self)

Definition at line 692 of file type.py.

◆ finish_latencies() [1/2]

List[int] qbruntime.type.ModelConfig.finish_latencies ( self)

Definition at line 696 of file type.py.

◆ early_latencies() [2/2]

qbruntime.type.ModelConfig.early_latencies ( self,
List[int] latencies )
Deprecated
This setting has no effect.

Definition at line 700 of file type.py.

◆ finish_latencies() [2/2]

qbruntime.type.ModelConfig.finish_latencies ( self,
List[int] latencies )
Deprecated
This setting has no effect.

Definition at line 705 of file type.py.

◆ get_core_ids()

List[CoreId] qbruntime.type.ModelConfig.get_core_ids ( self)

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.

Definition at line 709 of file type.py.

◆ __repr__()

qbruntime.type.ModelConfig.__repr__ ( self)

Definition at line 725 of file type.py.

Member Data Documentation

◆ _model_config

tuple qbruntime.type.ModelConfig._model_config
protected
Initial value:
= (
_cQbRuntime.ModelConfig()
if num_cores is None
else _cQbRuntime.ModelConfig(num_cores)
)

Definition at line 470 of file type.py.


The documentation for this class was generated from the following file: