> Documentation Index
> Fetch the complete documentation index at: https://docs.mobilint.com/compiler/kr/v1.0/llms.txt
> Use this file to discover all available pages before exploring further.
> Append index.md to any page URL for its Markdown.
> All Mobilint manuals: https://docs.mobilint.com/llms.txt

# qbcompiler.frontend

## Model\_Dict

```python
class Model_Dict(Compiler)
```

Wrapper around the Mobilint compiler to support compilation and inference workflows.

Capabilities include:

- Compilation of models into MXQ artifacts runnable on Mobilint NPUs.
- Inference using the full-precision high-level compiled model on CPU or GPU.
- Inference with the quantized model on CPU or GPU.

### Methods

| Name | Description |
| --- | --- |
| [`__init__`](<#model-dict-init>) | Initialize the Mobilint compiler wrapper. |
| [`compile`](<#model-dict-compile>) | Compile the wrapped model into an MXQ artifact. |

#### \_\_init\_\_

```python
def __init__(
    self,
    model,
    backend="onnx",
    device="cpu",
    feed_dict=None,
    dynamic_axes=None,
    in_dformats=None,
    yolo_decode_include=False,
    use_custom_mask=False,
    exclude_first_subgraph=False,
    **kwargs,
)
```

Initialize the Mobilint compiler wrapper.

**Parameters**

- `model` — string or model instance. Model path or in-memory model to compile.
- `backend` — string. Framework identifier for the model (for example "onnx"). Defaults to "onnx".
- `device` — string. Target device for inference ("cpu" or "gpu"). Defaults to "cpu".
- `feed_dict` — dict. Example inputs for shape resolution.
- `dynamic_axes` — dict. Marks model axes as dynamic.
- `in_dformats` — dict. Describes input data formats.
- `yolo_decode_include` — bool. Runs YOLO decode on NPU when `True`.
- `use_custom_mask` — bool. For non-LLM models that include a mask, use a custom mask provided as a separate input instead of the causal mask.
- `exclude_first_subgraph` — bool. Applies only when CPU offloading is enabled: exclude the first subgraph from the final graph if it is unsupported.
- `kwargs` — dict. Additional compiler arguments.

#### compile

```python
def compile(
    self,
    calib_data_path: str = None,
    save_path: str = None,
    save_subgraph_type: int = 0,
    output_subgraph_path="",
    model_nickname: str = None,
    save_sample=False,
    use_random_calib=False,
    inference_scheme="single",
    cpu_offload=False,
    optimize_option=1,
    sample_dtype: str = "float",
    buffer_mode=1,
    compile_config=None,  # CompileConfig object
    **kwargs,
)
```

Compile the wrapped model into an MXQ artifact.

**Parameters**

- `calib_data_path` — string. Calibration dataset directory or meta file (.txt/.json) listing NumPy samples.
- `save_path` — string. Output MXQ filename.
- `save_subgraph_type` — int. Controls optional MBLT exports: 0 disables; 1 saves graph structure; 2 saves structure and weights; 3 splits structure into multiple subgraphs; 4 splits structure and weights.
- `output_subgraph_path` — string. Destination for exported .mblt when `save_subgraph_type` is 1–4.
- `model_nickname` — string. Friendly name stored in qbcompiler for faster recompile.
- `save_sample` — bool. Persists inputs/outputs for debugging in ./sampleInOut.
- `use_random_calib` — bool. Uses randomly generated calibration samples when `True`.
- `inference_scheme` — string. NPU inference configuration ("single", "multi", "global", etc.).
- `cpu_offload` — bool. Enables CPU offload for unsupported groups.
- `optimize_option` — int. Compiler optimization selector.
- `sample_dtype` — string. Data type used for saved sample outputs.
- `buffer_mode` — int. Buffer serialization mode (0 naive, 1 mmap).
- `compile_config` — [CompileConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.compile_config/#compileconfig>). Compile configuration object.
- `kwargs` — dict. Additional arguments forwarded to the compiler.

## Functions

| Name | Description |
| --- | --- |
| [`mxq_compile`](<#mxq-compile>) | Compile a model into a Mobilint eXeCUtable (MXQ) package for execution on Mobilint NPUs. |
| [`mblt_compile`](<#mblt-compile>) | Export a model to the Mobilint .mblt format without producing an MXQ package. |
| [`run_mblt_model`](<#run-mblt-model>) |  |

### mxq\_compile

```python
def mxq_compile(
    model,
    calib_data_path: str = "",
    save_subgraph_type: int = 0,
    output_subgraph_path="",
    model_nickname: str = None,
    save_path: str = None,
    backend="onnx",
    device="cpu",
    feed_dict=None,
    dynamic_axes=None,
    in_dformats=None,
    save_sample=False,
    inference_scheme="single",
    yolo_decode_include=False,
    use_random_calib=False,
    cpu_offload=False,
    optimize_option=1,
    sample_dtype="float",
    buffer_mode=1,
    input_shape_dict=dict(),
    use_custom_mask=False,
    exclude_first_subgraph=False,
    compile_config: Optional[CompileConfig] = None,
    resource_management_config: Optional[ResourceManagementConfig] = None,
    quantization_config: Optional[QuantizationConfig] = None,
    advanced_quantization_config: Optional[AdvancedQuantizationConfig] = None,
    llm_config: Optional[LlmConfig] = None,
    input_process_config: Optional[InputProcessConfig] = None,
    **kwargs,
)
```

Compile a model into a Mobilint eXeCUtable (MXQ) package for execution on Mobilint NPUs.

**Parameters**

- `model` — string or model instance. Model path. When using `backend="onnx"`, this should be the path to an ONNX model file. When `backend` is "torchscript", provide a TorchScript module; when "torch", provide a standard PyTorch model. For `backend="tf"`, pass the directory that contains the TensorFlow SavedModel graph and assets. For `backend="tflite"`, pass the TF Lite model path.
- `calib_data_path` — string. Path to the calibration dataset. Accepts either a text/json file that lists NumPy files or a directory that contains the pre-processed NumPy files.
- `save_subgraph_type` — int. Controls optional MBLT subgraph exports: 0 disables exports; 1 saves only the graph structure; 2 saves graph structure plus weights; 3 saves the graph structure split into multiple subgraphs; 4 saves both structure and weights split into multiple subgraphs.
- `output_subgraph_path` — string. Destination path for the exported .mblt file when `save_subgraph_type` is 1, 2, 3, or 4. The resulting file can be used for visualization.
- `model_nickname` — string. Friendly name stored in qbcompiler. Defaults to the model basename (for example, the file "/workspace/onnx/resnet50.onnx" becomes "resnet50"). Falls back to "temporary" when it cannot be inferred.
- `save_path` — string. Output MXQ filename. Defaults to "{model\_nickname}.mxq" when omitted.
- `backend` — string. Framework used to generate the Mobilint IR. Must be one of "onnx", "tf", "tflite", "torchscript", or "torch". Defaults to "onnx".
- `device` — string. Compilation and inference device: "cpu" or "gpu". Defaults to "cpu".
- `feed_dict` — dict. Example input tensors for shape inference and inference validation.
- `dynamic_axes` — dict. Marks model axes as dynamic. Keys are input names and values map dimension indices to aliases (for example {"input": {2: "seq\_len"}}).
- `in_dformats` — dict. Describes input tensor data formats.
- `save_sample` — bool. Stores input/output tensors in ./sampleInOut when `True` to aid debugging. Defaults to `False`.
- `inference_scheme` — string. NPU inference scheme. One of "single", "multi", "global", "global4", or "global8".
- `yolo_decode_include` — bool. Determines whether YOLO decode runs on NPU.
- `use_random_calib` — bool. Generates random calibration data to validate model compilability. Defaults to `False`.
- `cpu_offload` — bool. Enables CPU offloading during NPU inference. Defaults to `False`.
- `optimize_option` — int. Compiler optimization strategy selector.
- `sample_dtype` — string. Data type for saved sample inference outputs: "float" or "int8".
- `buffer_mode` — int. Buffer serialization mode: 0 uses a naïve buffer, 1 uses an mmap-backed buffer. Defaults to 1.
- `input_shape_dict:multi-shape` — compilation specification for STT/TTS models only (e.g., Conformer-CTC, MeloTTS). The dynamic axis is defined with respect to each input tensor’s shape. During compilation, the same axis is varied across all model inputs using the provided values. Currently, only a single entry key ("multi\_shape0") is supported. Example: {"multi\_shape0": {"axis": 2, "values": \[100, 200, 300\]}}
- `use_custom_mask` — bool. For non-LLM models that include a mask, use a custom mask provided as a separate input instead of the causal mask. For LLMs that incorporate RoPE, setting LLMConfig.dynamic\_rope to True not only enables the use of dynamic RoPE provided via an additional input, but also activates the custom mask.
- `exclude_first_subgraph` — bool. Applies only when CPU offloading is enabled: exclude the first subgraph from the final graph if it is unsupported.
- `compile_config` — string. Path to JSON configuration file containing all quantization-related settings (resourceManagement, quantization, advancedQuantization, llmConfig). If provided, this takes precedence over individual sub-config parameters.
- `resource_management_config` — [ResourceManagementConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.resource_management_config/#resourcemanagementconfig>). Resource management configuration object.
- `quantization_config` — [QuantizationConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.quantization_config/#quantizationconfig>). Quantization configuration object.
- `advanced_quantization_config` — [AdvancedQuantizationConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.advanced_quantization_config/#advancedquantizationconfig>). Advanced quantization configuration object.
- `llm_config` — [LlmConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.llm_config/#llmconfig>). LLM configuration object.
- `input_process_config` — [InputProcessConfig](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.input_process_config/#inputprocessconfig>). Unified input processing configuration containing uint8 input handling, image channels, and preprocessing pipeline settings.
- `kwargs` — dict. Additional compiler arguments propagated to the backend implementation. Moreover, If you want to override only a subset of configuration values, you can pass them to `mxq_compile` as keyword arguments (`kwargs`), and they will be applied. Note that [`AdvancedQuantizationConfig`](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.advanced_quantization_config/#advancedquantizationconfig>) and its sub-configurations are not updated automatically from `kwargs`. In contrast, [`ResourceManagementConfig`](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.resource_management_config/#resourcemanagementconfig>), [`QuantizationConfig`](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.quantization_config/#quantizationconfig>), and [`LlmConfig`](<https://docs.mobilint.com/compiler/kr/v1.0/api/python/qbcompiler.configs.llm_config/#llmconfig>) support automatic updates via each configuration class’s `from_kwargs` method. See Example 3 below for a usage example.

**Returns**

None.

**Using configuration**

There are two ways to configure quantization settings:

1. Load all settings from a JSON config file:

   ```py
   from qbcompiler import mxq_compile

   mxq_compile(
       model="path/to/model.onnx",
       calib_data_path="path/to/calib",
       compile_config="path/to/config.json",
       device="gpu",
   )
   ```
2. Pass individual sub-config objects:

   ```py
   from qbcompiler import mxq_compile
   from qbcompiler.configs import (
       ResourceManagementConfig,
       QuantizationConfig,
       AdvancedQuantizationConfig,
       LlmConfig,
   )

   resource_mgmt = ResourceManagementConfig(weight_dtype="float32")
   quant_cfg = QuantizationConfig(...)
   adv_quant_cfg = AdvancedQuantizationConfig(...)
   llm_cfg = LlmConfig(...)

   mxq_compile(
       model="path/to/model.onnx",
       calib_data_path="path/to/calib",
       resource_management_config=resource_mgmt,
       quantization_config=quant_cfg,
       advanced_quantization_config=adv_quant_cfg,
       llm_config=llm_cfg,
       device="gpu",
   )
   ```
3. Automatically applied partial configuration overrides:

   ```py
   from qbcompiler import mxq_compile

   mxq_compile(
       model="path/to/model.onnx",
       calib_data_path="path/to/calib",
       quantization_method=1, # per channel quantization
       quantization_mode=1, # max percentile quantization
       percentile=0.999, # percentile value for max percentile quantization
       quantization_output=0, # per layer quantization for the output layer
       device="gpu",
   )
   ```

Please refer to the mxq\_compile function and the quantization configuration section for the meaning of the quantization-related numeric values.

**Compiling models with custom inputs (ONNX/Torch/TensorFlow)**

Provide NumPy inputs whenever the model omits shape information so that qbcompiler can infer unknown dimensions and data formats.

```py
from qbcompiler import mxq_compile
import numpy as np

example_input = {
    "input_node_name_1": np.random.randn(1, 3, 224, 224).astype(np.float32),
    "input_node_name_2": np.random.randn(1, 8, 224, 224).astype(np.float32),
    "input_node_name_3": np.random.randn(1, 4, 56, 56).astype(np.float32),
}

in_dformats = {
    "input_node_name_1": "NCHW",
    "input_node_name_2": "NCHW",
    "input_node_name_3": "NCHW",
}

onnx_model_path = "path/to/your/model.onnx"
mxq_compile(
    model=onnx_model_path,
    feed_dict=example_input,
    in_dformats=in_dformats,
    backend="onnx",
    compile_config="path/to/config.json",
)
```

### mblt\_compile

```python
def mblt_compile(
    model: str | Any,
    mblt_save_path: str,
    backend="onnx",
    device="cpu",
    feed_dict=None,
    dynamic_axes=None,
    in_dformats=None,
    yolo_decode_include=False,
    cpu_offload=False,
    use_custom_mask=False,
    exclude_first_subgraph=False,
    **kwargs,
)
```

Export a model to the Mobilint .mblt format without producing an MXQ package.

**Parameters**

- `model` — string or model instance. Source model or path to compile.
- `mblt_save_path` — string. Output path for the .mblt artifact.
- `backend` — string. Framework identifier ("onnx", "tf", "tflite", "torchscript", or "torch"). Defaults to "onnx".
- `device` — string. Compilation device ("cpu" or "gpu"). Defaults to "cpu".
- `feed_dict` — dict. Example inputs used for shape inference.
- `dynamic_axes` — dict. Declares dynamic axes per input name.
- `in_dformats` — dict. Input dataformat metadata.
- `yolo_decode_include` — bool. Runs YOLO decode on NPU when True.
- `cpu_offload` — bool. Enables CPU offloading for unsupported groups.
- `use_custom_mask` — bool. For non-LLM models that include a mask, use a custom mask provided as a separate input instead of the causal mask. For LLMs that incorporate RoPE, setting LLMConfig.dynamic\_rope to True not only enables the use of dynamic RoPE provided via an additional input, but also activates the custom mask.
- `exclude_first_subgraph` — bool. Applies only when CPU offloading is enabled: exclude the first subgraph from the final graph if it is unsupported.
- `kwargs` — dict. Additional arguments forwarded to the compiler.

**Returns**

None.

### run\_mblt\_model

```python
def run_mblt_model(
    path_to_mblt: str,
    save_all_outputs: bool = True,
    inference_output_path: Optional[str] = None,
    target_subgraph: Optional[int] = None,
)
```
