---
title: record记录文件
description: "record文件，为基于protobuf协议的序列化数据结构文件，记录量化场景量化因子scale/offset，稀疏场景各稀疏层间的级联关系等，通过该文件、压缩配置文件以及原始网络模型文件，生成压缩后的模型文件。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/devaids/amct/atlasamct_16_0248.html
sourcePath: /source/zh/canncommercial/900/devaids/amct/atlasamct_16_0248.html
indexId: 343780ca377ad4d8d33429930d3ea58187d7dd13d9fee3489acf9f85159624fa65
---
# record记录文件

record文件，为基于protobuf协议的序列化数据结构文件，记录量化场景量化因子scale/offset，稀疏场景各稀疏层间的级联关系等，通过该文件、压缩配置文件以及原始网络模型文件，生成压缩后的模型文件。

#### convert_model接口record原型定义

convert_model接口场景record文件对应的protobuf原型定义为（或查看AMCT安装目录/amct_tensorflow/proto/scale_offset_record_tf.proto文件）：
```
syntax = "proto2";
package AMCTTensorflow;
// this proto is designed for convert_model API
message SingleLayerRecord {
optional float scale_d = 1;
optional int32 offset_d = 2;
repeated float scale_w = 3;
repeated int32 offset_w = 4;
// convert_model does not support this field [shift_bit] yet
repeated uint32 shift_bit = 5;
optional bool skip_fusion = 9 [default = false];
optional string act_type = 14 [default = 'INT8'];
optional string wts_type = 15 [default = 'INT8'];
}
message MapFiledEntry {
optional string key = 1;
optional SingleLayerRecord value = 2;
}
message ScaleOffsetRecord {
repeated MapFiledEntry record = 1;
}
```


该场景下对应参数说明如下：

| 消息 | 是否必填 | 类型 | 字段 | 说明 |
| --- | --- | --- | --- | --- |
| SingleLayerRecord | \- | \- | \- | 包含了量化层所需要的所有量化因子记录信息。 |
| SingleLayerRecord | optional | float | scale\_d | 数据量化scale因子，仅支持对数据进行统一量化。 |
| SingleLayerRecord | optional | int32 | offset\_d | 数据量化offset因子，仅支持对数据进行统一量化。 |
| SingleLayerRecord | repeated | float | scale\_w | 权重量化scale因子，支持标量（对当前层的权重进行统一量化），向量（对当前层的权重按channel\_wise方式进行量化）两种模式，仅支持卷积层(Conv2D)、Depthwise卷积层（DepthwiseConv2dNative）、反卷积层（Conv2DBackpropInput）类型进行channel\_wise量化模式。 |
| SingleLayerRecord | repeated | int32 | offset\_w | 权重量化offset因子，同scale\_w一样支持标量和向量两种模式，且需要同scale\_w维度一致，当前不支持权重带offset量化模式，offset\_w仅支持0。 |
| SingleLayerRecord | repeated | uint32 | shift\_bit | 移位因子。convert\_model接口场景下预留字段，当前不支持，不需要配置。 |
| SingleLayerRecord | optional | bool | skip\_fusion | 配置当前层是否要跳过Conv+BN融合、Depthwise\_Conv+BN融合、Group\_conv+BN融合、BatchNorm融合，默认为false，即当前层要做上述融合。 |
| SingleLayerRecord | optional | string | act\_type | 激活量化数据类型，当前仅支持配置为INT8。 |
| SingleLayerRecord | optional | string | wts\_type | 权重量化数据类型。当前仅支持配置为INT8。 |
| ScaleOffsetRecord | \- | \- | \- | map结构，为保证兼容性，采用离散的map结构。 |
| ScaleOffsetRecord | repeated | MapFiledEntry | record | 每个record对应一个量化层的量化因子记录；record包括两个成员： key为所记录量化层的layer name。 value对应SingleLayerRecord定义的具体量化因子。 |
| MapFiledEntry | optional | string | key | 层名。 |
| MapFiledEntry | optional | SingleLayerRecord | value | 量化因子配置。 |


对于optional字段，由于protobuf协议未对重复出现的值报错，而是采用覆盖处理，因此出现重复配置的optional字段内容时会默认保留最后一次配置的值，需要用户自己保证文件的正确性。


#### 量化、稀疏场景record原型定义

量化或稀疏场景record文件对应的protobuf原型定义为（或查看AMCT安装目录/amct_tensorflow/proto/inner_scale_offset_record_tf.proto文件）：
```
syntax = "proto2";
import "amct_tensorflow/proto/basic_info.proto";
package AMCTTensorflow;
// this proto is designed for amct tools
message InnerSingleLayerRecord {
optional float scale_d = 1;
optional int32 offset_d = 2;
repeated float scale_w = 3;
repeated int32 offset_w = 4;
repeated uint32 shift_bit = 5;
// the cluster of nuq, only nuq layer has this field;
repeated int32 cluster = 6;
optional bool skip_fusion = 9 [default = false];
optional string dst_type = 10 [default = 'INT8'];
repeated string prune_producer = 11;
repeated string prune_consumer = 12;
repeated float tensor_balance_factor = 13;
optional string act_type = 14 [default = 'INT8'];
optional string wts_type = 15 [default = 'INT8'];
}
message InnerMapFiledEntry {
optional string key = 1;
optional InnerSingleLayerRecord value = 2;
}
message InnerScaleOffsetRecord {
repeated InnerMapFiledEntry record = 1;
repeated PruneRecord prune_record = 2;
}
message PruneRecord {
repeated PruneNode producer = 1;
repeated PruneNode consumer = 2;
optional PruneNode selective_prune = 3;
}
message PruneNode {
required string name = 1;
repeated AMCTProto.AttrProto attr = 2;
}
```


该场景下对应参数说明如下：

| 消息 | 是否必填 | 类型 | 字段 | 说明 |
| --- | --- | --- | --- | --- |
| InnerSingleLayerRecord | \- | \- | \- | 包含了量化层所需要的所有量化因子记录信息。 |
| InnerSingleLayerRecord | optional | float | scale\_d | 数据量化scale因子，仅支持对数据进行统一量化。 |
| InnerSingleLayerRecord | optional | int32 | offset\_d | 数据量化offset因子，仅支持对数据进行统一量化。 |
| InnerSingleLayerRecord | repeated | float | scale\_w | 权重量化scale因子，支持标量（对当前层的权重进行统一量化），向量（对当前层的权重按channel\_wise方式进行量化）两种模式，仅支持卷积层(Conv2D)、Depthwise卷积层（DepthwiseConv2dNative）、反卷积层（Conv2DBackpropInput）类型进行channel\_wise量化模式。 |
| InnerSingleLayerRecord | repeated | int32 | offset\_w | 权重量化offset因子，同scale\_w一样支持标量和向量两种模式，且需要同scale\_w维度一致，当前不支持权重带offset量化模式，offset\_w仅支持0。 |
| InnerSingleLayerRecord | repeated | uint32 | shift\_bit | 移位因子。只有训练后量化简易配置文件配置了joint\_quant参数，shift\_bit参数才会写入record文件。 |
| InnerSingleLayerRecord | repeated | int32 | cluster | 聚类中心。只有非均匀量化场景下需要使能该字段，不支持该字段。 |
| InnerSingleLayerRecord | optional | bool | skip\_fusion | 配置当前层是否要跳过Conv+BN融合、Depthwise\_Conv+BN融合、Group\_conv+BN融合、BatchNorm融合，默认为false，即当前层要做上述融合。 |
| InnerSingleLayerRecord | optional | string | dst\_type | 量化数据类型，包括INT8和INT4两种类型。该字段仅量化感知训练场景使用。 |
| InnerSingleLayerRecord | repeated | string | prune\_producer | 稀疏的producer，可稀疏节点间级联关系的根节点。该字段仅稀疏场景下使用。 |
| InnerSingleLayerRecord | repeated | string | prune\_consumer | 稀疏的consumer，可稀疏节点间级联关系的下游节点。该字段仅稀疏场景下使用。 |
| InnerSingleLayerRecord | repeated | float | tensor\_balance\_factor | 均衡量化因子。该字段仅量化数据均衡预处理场景使用。 |
| InnerSingleLayerRecord | optional | string | act\_type | 激活量化数据类型，包括INT8和INT16两种量化类型。该字段仅训练后量化场景使用。当前版本仅支持INT8量化。 |
| InnerSingleLayerRecord | optional | string | wts\_type | 权重量化数据类型。该字段仅训练后量化场景使用。 当前INT6、INT7量化后的量化因子仍保存为INT8类型。 |
| InnerScaleOffsetRecord | \- | \- | \- | map结构，为保证兼容性，采用离散的map结构。 |
| InnerScaleOffsetRecord | repeated | InnerMapFiledEntry | record | 每个record对应一个量化层的量化因子记录；record包括两个成员： key为所记录量化层的layer name。 value对应SingleLayerRecord定义的具体量化因子。 |
| InnerScaleOffsetRecord | repeated | PruneRecord | prune\_record | 稀疏信息的记录。 |
| InnerMapFiledEntry | optional | string | key | 层名。 |
| InnerMapFiledEntry | optional | InnerSingleLayerRecord | value | 量化因子配置。 |
| PruneRecord | \- | \- | \- | 稀疏信息的记录。 |
| PruneRecord | repeated | PruneNode | producer | 稀疏的producer，可稀疏结点间级联关系的根节点。 例如conv1>bn>relu>conv2都可以稀疏，且bn、relu、conv2都会受到conv1稀疏的影响，则bn、relu、conv2是conv1的consumer；conv1是bn、relu、conv2的producer。 |
| PruneRecord | repeated | PruneNode | consumer | 稀疏的consumer，可稀疏结点间级联关系的下游节点。 例如conv1>bn>relu>conv2都可以稀疏，且bn、relu、conv2都会受到conv1稀疏的影响，则bn、relu、conv2是conv1的consumer；conv1是bn、relu、conv2的producer。 |
| PruneRecord | optional | PruneNode | selective\_prune | 4选2结构化稀疏节点。 由于硬件约束， Atlas 推理系列产品 、 Atlas 训练系列产品 、Atlas 350 加速卡不支持4选2结构化稀疏特性。 |
| PruneNode | \- | \- | \- | 稀疏的节点。 |
| PruneNode | required | string | name | 节点名称。 |
| PruneNode | repeated | AMCTProto.AttrProto | attr | 节点属性。 |


对于optional字段，由于protobuf协议未对重复出现的值报错，而是采用覆盖处理，因此出现重复配置的optional字段内容时会默认保留最后一次配置的值，需要用户自己保证文件的正确性。


#### record记录文件

最终生成的record文件格式为record.txt，文件内容根据特性不同划分如下。

- 训练后量化特性record文件

```
record {
key: "
conv2d/Conv2D
"
value {
scale_d: 1.541161146e-05
offset_d: -32768
scale_w: 0.007854792
scale_w: 0.0077705383
offset_w: 0
offset_w: 0
shift_bit: 12         //只有
训练后量化简易配置文件
配置了joint_quant参数，record文件中才会记录shift_bit信息
shift_bit: 13
act_type: "INT8"
wts_type: "INT8"
}
}
```


- 量化感知训练特性record文件
  对于一般量化层配置需要包含scale_d、offset_d、scale_w、offset_w、shift_bit参数，对于AvgPool因为没有权重，因此不能配置scale_w、offset_w参数。文件内容示例如下（如下示例以inner_scale_offset_record.proto原型文件对应的量化因子为例进行说明）：

```
record {
key: "
fc4/Tensordot/MatMul
"
value {
scale_d: 0.0798481479
offset_d: 1
scale_w: 0.00297622895
offset_w: 0
shift_bit: 1
dst_type: "INT8"
}
}
record {
key: "
conv2d/Conv2D
"
value {
scale_d: 0.00392156886
offset_d: -128
scale_w: 0.00106807391
scale_w: 0.00104224426
offset_w: 0
offset_w: 0
shift_bit: 1
shift_bit: 1
dst_type: "
INT8
"
}
}
```


- 量化数据均衡预处理特性record文件，内容示例如下：

```
record {
key: "
matmul_1
"
value {
scale_d: 0.00784554612
offset_d: -1
scale_w: 0.00778095098
offset_w: 0
shift_bit: 2
tensor_balance_factor: 0.948409557
tensor_balance_factor: 0.984379828
}
}
record {
key: "conv_1"
value {
scale_d: 0.00759239076
offset_d: -4
scale_w: 0.0075149606
offset_w: 0
shift_bit: 1
tensor_balance_factor: 1.04744744
tensor_balance_factor: 1.44586647
}
}
```


- 通道稀疏特性record文件记录各稀疏层间的级联关系，文件内容示例如下：

```
prune_record {
producer {
name: "conv_1"
attr {
name: "type"
type: STRING
s: "Conv2D"
}
attr {
name: "begin"
type: INT
i: 0
}
attr {
name: "end"
type: INT
i: 64
}
}
consumer {
name: "BN_1"
attr {
name: "type"
type: STRING
s: "FusedBatchNormV3"
}
attr {
name: "begin"
type: INT
i: 0
}
attr {
name: "end"
type: INT
i: 64
}
}
}
```


- 结构化稀疏特性record文件内容示例如下：

```
prune_record {
selective_prune {
name: "
conv2d/Conv2D
"
attr {
name: "mask_shape"
type: INTS
ints: 3
ints: 3
ints: 3
ints: 32
}
}
}
```
