record文件,为基于protobuf协议的序列化数据结构文件,记录量化场景量化因子Scale/Offset,通过该文件、压缩配置文件以及原始网络模型文件,生成压缩后的模型文件。
该文件与record记录文件区别是:本章节内容仅适用于基于Torch API训练后量化特性;而record记录文件适用于除去基于Torch API训练后量化特性的其他特性,比如量化感知训练,稀疏等。
record文件对应的protobuf原型定义为(或查看AMCT安装目录/amct_pytorch/proto/post_quant_record_pytorch.proto文件):
syntax = "proto2"; import "amct_pytorch/proto/basic_info.proto"; package AMCTPytorchRecordProto; message SingleLayerRecord { repeated float scale_d = 1; repeated int32 offset_d = 2; repeated float scale_w = 2; optional string act_type = 11; optional string wts_type = 12; optional string round_mode = 21; optional bool weight_compress_only = 22; optional string awq_result_path = 23; } message MapFiledEntry { optional string key = 1; optional SingleLayerRecord value = 2; } message ScaleOffsetRecord { repeated MapFiledEntry record = 1; }
参数说明如下:
消息 |
是否必填 |
类型 |
字段 |
说明 |
---|---|---|---|---|
SingleLayerRecord |
- |
- |
- |
包含了量化层所需要的所有量化因子记录信息。 |
repeated |
float |
scale_d |
数据量化scale因子,仅支持对数据进行统一量化。 |
|
repeated |
int32 |
offset_d |
数据量化offset因子,仅支持对数据进行统一量化。 |
|
repeated |
float |
scale_w |
权重量化scale因子,支持标量(对当前层的权重进行统一量化),向量(对当前层的权重按channel_wise方式进行量化)两种模式,仅支持Conv2d类型进行channel_wise量化模式。 |
|
optional |
string |
act_type |
数据量化位宽,支持FP8_E4M3/HiF8两种类型。 |
|
optional |
string |
wts_type |
权重量化位宽,支持FP8_E4M3/HiF8两种类型。 |
|
optional |
string |
round_mode |
数据类型舍入模式,支持如下几种方式: |
|
optional |
bool |
weight_compress_only |
是否仅权重量化。
|
|
optional |
string |
awq_result_path |
配置AWQ权重压缩算法时,生成的量化因子文件路径。 |
|
MapFiledEntry |
optional |
string |
key |
层名。 |
optional |
SingleLayerRecord |
value |
量化因子配置。 |
|
ScaleOffsetRecord |
- |
- |
- |
map结构,为保证兼容性,采用离散的map结构。 |
repeated |
MapFiledEntry |
record |
每个record对应一个量化层的量化因子记录;record包括两个成员:
|
最终生成的record文件格式为record.txt,文件示例如下:
record { key: "linear_1" value { scale_d: 0.03125 scale_w: 0.03125 act_type: "FLOAT8_E4M3FN" wts_type: "FLOAT8_E4M3FN" round_mode: "RINT" } } record { key: "conv_1" value { scale_d: 0.03125 scale_w: 0.03125 act_type: "FLOAT8_E4M3FN" wts_type: "FLOAT8_E4M3FN" round_mode: "RINT" } }
record { key: "linear_1" value { wts_type: "MXFP4_E2M1" round_mode: "RINT" weight_compress_only: true awq_result_path: "/testcase/amct_file/awq_result.pt" } } record { key: "linear_2" value { wts_type: "MXFP4_E2M1" round_mode: "RINT" weight_compress_only: true awq_result_path: "/testcase/amct_file/awq_result.pt" } }