Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Alibaba MNN CMake Build Quantools

From Leeroopedia


Field Value
Implementation Name CMake_Build_Quantools
Type API Doc
Topic Model_Compression
Workflow Model_Compression
Description CMake build commands and options for compiling MNN model compression tools
Source File(s) CMakeLists.txt:L49,L51
Last Updated 2026-02-10 14:00 GMT

API Signature

cmake -DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_QUANTOOLS=ON .. && make -j8

Source Definition

From CMakeLists.txt (lines 49 and 51):

option(MNN_BUILD_QUANTOOLS "Build Quantized Tools or not" OFF)
option(MNN_BUILD_CONVERTER "Build Converter" OFF)

Both options default to OFF and must be explicitly enabled to compile the compression tool binaries.

Parameters

Parameter Type Default Description
-DMNN_BUILD_CONVERTER BOOL OFF Enables compilation of the MNNConvert binary. This tool handles model format conversion (ONNX, TF, Caffe, TFLite to MNN), weight quantization (2-8 bit), FP16 half-precision storage, and HQQ quantization.
-DMNN_BUILD_QUANTOOLS BOOL OFF Enables compilation of the quantized.out binary. This tool performs offline INT8 quantization using calibration data with KL-divergence, ADMM, or EMA feature quantization methods.
-DMNN_LOW_MEMORY BOOL OFF Optional. Enables dynamic weight dequantization support in the MNN runtime library for accelerated inference on weight-quantized models. Defined at CMakeLists.txt:L79.

Inputs

  • MNN source tree -- The complete MNN repository checked out from source control.
  • CMake 3.6+ -- Required build system generator.
  • C/C++ toolchain -- A compiler supporting C99 and C++11 standards.

Outputs

Output Description
MNNConvert Command-line binary for model conversion and weight quantization. Supports --weightQuantBits, --fp16, --hqq, --weightQuantBlock, and --compressionParamsFile flags.
quantized.out Command-line binary for offline INT8 quantization. Takes a float MNN model, a destination path, and a JSON calibration configuration file as positional arguments.
mnnconvert (Python) Python wrapper for MNNConvert, installed via pip install MNN.
mnnquant (Python) Python wrapper for quantized.out, installed via pip install MNN.
mnn (Python) Unified Python CLI entry point for all MNN tools.

Usage Example

C++ Build (Production)

cd MNN
mkdir build && cd build
cmake .. -DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_QUANTOOLS=ON
make -j8

Python Install (Experimentation)

pip install MNN

After installation, both mnnconvert and mnnquant are available on the command line.

Verify Build Outputs

# Weight quantization tool
./MNNConvert --help

# Offline INT8 quantization tool
./quantized.out
# Usage: ./quantized.out src.mnn dst.mnn preTreatConfig.json

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment