# MTK Converter Cheat Sheet

**URL:** <https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479>\
**Category:** NeuroPilot - Analytical AI\
**Tags:** Android, AI, IoT-Yocto\
**Created:** [June 19, 2025, 8:04am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479 "2025-06-19T08:04:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joying.kuo](https://yyz2.discourse-cdn.com/flex004/user_avatar/genio-community.mediatek.com/joying.kuo/32/167_2.png) [@joying.kuo](https://genio-community.mediatek.com/u/joying.kuo)\
**Post date:** [June 19, 2025, 8:04am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479/1 "2025-06-19T08:04:52Z")

</div>

Here post some tips for the parameter setting of MTK Converter

---

<div class="post-metadata">

**Author:** ![joying.kuo](https://yyz2.discourse-cdn.com/flex004/user_avatar/genio-community.mediatek.com/joying.kuo/32/167_2.png) [@joying.kuo](https://genio-community.mediatek.com/u/joying.kuo)\
**Post date:** [June 19, 2025, 8:05am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479/2 "2025-06-19T08:05:44Z")

</div>



---

<div class="post-metadata">

**Author:** ![joying.kuo](https://yyz2.discourse-cdn.com/flex004/user_avatar/genio-community.mediatek.com/joying.kuo/32/167_2.png) [@joying.kuo](https://genio-community.mediatek.com/u/joying.kuo)\
**Post date:** [July 5, 2025, 6:04am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479/3 "2025-07-05T06:04:44Z")

</div>

# How to Ensure Full Integer Quantization (uint8) for All Tensors During Model Conversion?

## Question

When converting a model to `uint8`, users may find that the inputs, outputs, and intermediate tensors remain in `float32` despite quantization settings. How can one properly apply post-training quantization (PTQ) so that the entire model—including inputs, outputs, and all tensors—are quantized to `uint8` as expected? Which converter parameters control this behavior?

## Answer

If the `use_dynamic_quantization=True` parameter is set, only constant weights are quantized; all activation tensors, including inputs, outputs, and intermediates, remain as `float32`.  
To achieve **full integer quantization** using PTQ:

- Set `use_dynamic_quantization=False` when converting the model.
- This ensures that activations, inputs, and outputs are quantized to `uint8` as desired.

Refer to the converter’s official documentation for parameter support and compatibility.

---

<div class="post-metadata">

**Author:** ![joying.kuo](https://yyz2.discourse-cdn.com/flex004/user_avatar/genio-community.mediatek.com/joying.kuo/32/167_2.png) [@joying.kuo](https://genio-community.mediatek.com/u/joying.kuo)\
**Post date:** [July 5, 2025, 6:07am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479/4 "2025-07-05T06:07:01Z")

</div>

# How to Reduce or Avoid Generating MTK\_EXT\_OP When Converting Models?

## Question

During model conversion for MediaTek platforms, excessive `MTK_EXT_OP` operators are sometimes generated. What are the recommended workflows or parameter adjustments to minimize or avoid `MTK_EXT_OP`, and are there alternative tools to achieve fully standard operator sets?

## Answer

- First, try setting the parameter `use_per_output_channel_quantization=False`.  
This reduces the likelihood of `MTK_EXT_OP` being generated by disabling certain optimizations.
- However, disabling this option does **not guarantee** the elimination of `MTK_EXT_OP`, since the converter is specifically optimized for MediaTek NPUs, and compiler decisions are complex.
- For conversion results without any `MTK_EXT_OP`, it is recommended to use the official open-source TensorFlow converter.

---

<div class="post-metadata">

**Author:** ![jing\_liao](https://yyz2.discourse-cdn.com/flex004/user_avatar/genio-community.mediatek.com/jing_liao/32/294_2.png) [@jing\_liao](https://genio-community.mediatek.com/u/jing_liao)\
**Post date:** [July 7, 2025, 6:27am UTC](https://genio-community.mediatek.com/t/mtk-converter-cheat-sheet/479/5 "2025-07-07T06:27:31Z")

</div>

# How to Convert a PyTorch Model with Multiple Inputs Using mtk\_pytorch\_converter

### Question

When converting a PyTorch model that accepts multiple input tensors using `mtk_pytorch_converter`, users may encounter errors if input shapes are not correctly specified. Incorrect or missing shape information can cause conversion failures or wrongly-shaped outputs.

### Answer

Use the `--input_shapes` argument to specify each input’s shape. Ensure that:

- The number and order of input shapes match those expected by the model’s `forward()` method.
- Each input shape is separated by a comma, and dimensions within each shape are separated by a colon (`:`).

### Example Command

Convert a model with three input tensors, each of shape `[1, 128]`:

```bash
mtk_pytorch_converter \
    --input_script_module_file=xxx.pt \
    --output_file=xxx.tflite \
    --input_shapes=1:128,1:128,1:128

```

### Notes

- The order of shapes in `--input_shapes` **must** exactly match the order of input tensors expected by the model.
- Always review the model’s `forward()` method or refer to TorchScript documentation to confirm the correct input order and shapes.
- Providing incorrect shape or count may lead to conversion errors.
