Python API Reference

Python API Reference#

SDK qb Runtime Library: Python API Reference
SDK qb Runtime Library v1.0
MCS001-
Python API Reference

Python API provides wrapper functions for C++ implemented library. More...

Classes

class  qbruntime.accelerator.Accelerator
 Represents an accelerator, i.e., an NPU, used for executing models. More...
class  qbruntime.future.Future
 Represents a future for retrieving the result of asynchronous inference. More...
class  qbruntime.model.Model
 Represents an AI model loaded from an MXQ file. More...
class  qbruntime.model_variant_handle.ModelVariantHandle
 Handle to a specific variant of a loaded model. More...
class  qbruntime.type.Cluster
 Enumerates clusters in the ARIES NPU. More...
class  qbruntime.type.Core
 Enumerates cores within a cluster in the ARIES NPU. More...
class  qbruntime.type.CoreAllocationPolicy
 Core allocation policy. More...
class  qbruntime.type.Scale
 Struct for scale values. More...
class  qbruntime.type.CoreId
 Represents a unique identifier for an NPU core. More...
class  qbruntime.type.Buffer
 A simple byte-sized buffer. More...
class  qbruntime.type.CoreMode
 Defines the core mode for NPU execution. More...
class  qbruntime.type.BufferInfo
 Struct representing input/output buffer information. More...
class  qbruntime.type.ModelConfig
 Configures a core mode and core allocation of a model for NPU inference. More...
class  qbruntime.type.LogLevel
 LogLevel. More...
class  qbruntime.type.CacheType
 CacheType. More...
class  qbruntime.type.CacheInfo
 Struct representing KV-cache information. More...

Functions

bool qbruntime.model._is_valid_shape (_Shape input_shape, _Shape shape)
Optional[Tuple[bool, bool]] qbruntime.model._find_memory_format (List[np.ndarray] inputs, List[_Shape] shapes)
Tuple[int, Tuple[bool, bool]] qbruntime.model._find_matching_variant_idx_and_memory_format (model, List[np.ndarray] inputs)
List[np.ndarray] qbruntime.model._build_outputs (List[_Shape] shapes, bool is_hwc, np.dtype dtype)
None qbruntime.model._check_output_shapes (List[np.ndarray] outputs, List[_Shape] shapes, bool is_hwc, np.dtype dtype)
Model qbruntime.model.load (str path, Optional[ModelConfig] model_config=None)
 Single-step inference API.
 qbruntime.type.set_log_level (LogLevel level)
bool qbruntime.type.start_tracing_events (str path)
 Starts event tracing and prepares to save the trace log to a specified file.
 qbruntime.type.stop_tracing_events ()
 Stops event tracing and writes the recorded trace log.
str qbruntime.type.get_model_summary (str mxq_path)
 Generates a structured summary of the specified MXQ model.

Detailed Description

Python API provides wrapper functions for C++ implemented library.

Function Documentation

◆ _is_valid_shape()

bool qbruntime.model._is_valid_shape ( _Shape input_shape,
_Shape shape )
protected

Definition at line 25 of file model.py.

◆ _find_memory_format()

Optional[Tuple[bool, bool]] qbruntime.model._find_memory_format ( List[np.ndarray] inputs,
List[_Shape] shapes )
protected

Definition at line 40 of file model.py.

◆ _find_matching_variant_idx_and_memory_format()

Tuple[int, Tuple[bool, bool]] qbruntime.model._find_matching_variant_idx_and_memory_format ( model,
List[np.ndarray] inputs )
protected

Definition at line 60 of file model.py.

◆ _build_outputs()

List[np.ndarray] qbruntime.model._build_outputs ( List[_Shape] shapes,
bool is_hwc,
np.dtype dtype )
protected

Definition at line 81 of file model.py.

◆ _check_output_shapes()

None qbruntime.model._check_output_shapes ( List[np.ndarray] outputs,
List[_Shape] shapes,
bool is_hwc,
np.dtype dtype )
protected

Definition at line 95 of file model.py.

◆ load()

Model qbruntime.model.load ( str path,
Optional[ModelConfig] model_config = None )

Single-step inference API.

Creates model and uploads the model into NPU immediately.

This operation performs the Accelerator declaration, Model declaration, and launch in a single step.

Definition at line 726 of file model.py.

◆ set_log_level()

qbruntime.type.set_log_level ( LogLevel level)

Definition at line 733 of file type.py.

◆ start_tracing_events()

bool qbruntime.type.start_tracing_events ( str path)

Starts event tracing and prepares to save the trace log to a specified file.

The trace log is recorded in "Chrome Tracing JSON format," which can be viewed at https://ui.perfetto.dev/.

The trace log is not written immediately; it is saved only when stop_tracing_events() is called.

Parameters
[in]pathThe file path where the trace log should be stored.
Returns
True if tracing starts successfully, False otherwise.

Definition at line 814 of file type.py.

◆ stop_tracing_events()

qbruntime.type.stop_tracing_events ( )

Stops event tracing and writes the recorded trace log.

This function finalizes tracing and saves the collected trace data to the file specified when start_tracing_events() was called.

Definition at line 830 of file type.py.

◆ get_model_summary()

str qbruntime.type.get_model_summary ( str mxq_path)

Generates a structured summary of the specified MXQ model.

Returns an overview of the model contained in the MXQ file, including:

  • Target NPU hardware
  • Supported core modes and their associated cores
  • The total number of model variants
  • For each variant:
    • Input and output tensor shapes
    • A list of layers with their types, output shapes, and input layer indices

The summary is returned as a human-readable string in a table and is useful for inspecting model compatibility, structure, and input/output shapes.

Parameters
[in]mxq_pathPath to the MXQ model file.
Returns
A formatted string containing the model summary.

Definition at line 840 of file type.py.