netrans/examples/custom_layer_quant
gwg_xujiao 53faea7d58 docs: correct public documentation and examples 2026-07-23 10:59:03 +08:00
..
README.md docs: correct public documentation and examples 2026-07-23 10:59:03 +08:00
custom_layer_quant.py refactor: rename preprocessing scale parameter to std 2026-07-20 18:19:32 +08:00

README.md

自定义层量化类型示例

业务场景

在量化模型时,可以为特定的输入/输出层指定与其他层不同的量化类型。例如,整体使用 asymu8 量化,但输入层和输出层使用 dfpi16(更高精度)或 symi8

API

model.quantize('asymu8', lid='input_0,output_9', in_out_quantized='dfpi16')
参数 说明
lid 逗号分隔的层 ID 列表。可通过 netrans dump 查看模型中的层名称
in_out_quantized 输入输出层使用的量化类型。取值为 QuantizerType 支持的量化类型名

运行

请先在源码根目录执行 make install 安装 Netrans然后运行示例

cd examples/custom_layer_quant
python3 custom_layer_quant.py

注意事项

  • 单层和逗号分隔的多层场景均受支持,例如 lid='input_0,output_9'
  • lid 必须是模型实际存在的输入层或输出层 ID。