# US 2023/0055313 A1 · Hardware environment-based data quantization method and apparatus, and readable storage medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2023/0055313 A1
- Document ID: US20230055313A1
- Status: Published application
- Kind: A1
- Application number: 17/794,110
- Filed: 2020-11-16
- Published: 2023-02-23
- Earliest claimed: 2020-01-21
- Assignees: Inspur Suzhou Intelligent Technology Co., Ltd.
- Applicants: Inspur Suzhou Intelligent Technology Co., Ltd.
- Inventors: Qichun CAO; Yaqian ZHAO; Gang DONG; Lingyan LIANG; Wenfeng YIN
- Web page: https://patentgrep.com/patent/US20230055313A1

## CPC

- G06F 8/427: {Parsing}
- G06V 10/28: Quantising the image, e.g. histogram thresholding for discrimination between background and foreground patterns
- G06V 10/82: using neural networks
- G06V 10/94: Hardware or software architectures specially adapted for image or video understanding
- G06F 8/10: Requirements analysis; Specification techniques
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06V: IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING

## Abstract

A hardware environment-based data quantization method includes: parsing a model file under a current deep learning framework to obtain intermediate computational graph data and weight data that are independent of a hardware environment; performing calculation on image data in an input data set through a process indicated by an intermediate computational graph to obtain feature map data; separately performing uniform quantization on the weight data and the feature map data of each layer according to a preset linear quantization method, and calculating a weight quantization factor and a feature map quantization factor (S103); combining the weight quantization factor and the feature map quantization factor to obtain a quantization parameter that makes hardware use shift instead of division; and finally, writing the quantization parameter and the quantized weight data to a bin file according to a hardware requirement so as to generate quantized file data (S105).

## Claims

### Claim 1

A hardware environment-based data quantization method, comprising:
performing parsing according to a model file under a current deep learning framework to obtain intermediate computational graph data and weight data that are independent of a hardware environment;
performing, based on the intermediate computational graph data and the weight data, calculation on image data in an input data set through a process indicated by an intermediate computational graph to obtain feature map data;
separately performing uniform quantization on the weight data and the feature map data of each layer according to a preset linear quantization method, and calculating a weight quantization factor and a feature map quantization factor;
combining the weight quantization factor and the feature map quantization factor to obtain a quantization parameter, wherein the quantization parameter is a parameter that makes hardware use shift instead of division; and
writing the quantization parameter and quantized weight data to a bin file according to a hardware requirement so as to generate quantized file data.

### Claim 2 (depends on 1)

The hardware environment-based data quantization method according to claim 1, wherein before the step of writing the quantization parameter and the quantized weight data to the bin file according to the hardware requirement, the method further comprises:
reordering the quantization parameter and the quantized weight data such that a data format of the quantization parameter and the quantized weight data is a 64-channel parallel format.

### Claim 3 (depends on 2)

The hardware environment-based data quantization method according to claim 2, wherein the step of performing parsing to obtain intermediate computational graph data and weight data of the current deep learning framework comprises:
parsing the model file by use of a Neural Network Virtual Machine (NNVM) component in an NNVM compiler to obtain the intermediate computational graph data; and
by use of a Tensor Virtual Machine (TVM) component in the NNVM compiler, executing an operator of the intermediate computational graph, and calculating a tensor form of the weight data.

### Claim 4 (depends on 3)

The hardware environment-based data quantization method according to claim 3, wherein the step of combining the weight quantization factor and the feature map quantization factor comprises:
combining the weight quantization factor and the feature map quantization factor according to a quantization factor combination calculation formula, wherein the quantization factor combination calculation formula is:
y
w
*
y
f
≈
1
2
n
,
wherein yw represents the weight quantization factor, yf represents the feature map quantization factor, and n represents the quantization parameter.

### Claim 5 (depends on 4)

The hardware environment-based data quantization method according to claim 4, wherein the step of separately performing uniform quantization on the weight data and the feature map data of each layer according to the preset linear quantization method and calculating the weight quantization factor and the feature map quantization factor comprises:
calculating an average value of the feature map data of each layer as feature map average data of each layer;
statistically obtaining data distributions of the weight data and the feature map average data of each layer, and calculating corresponding limit values;
limiting the weight data and the feature map average data of each layer within corresponding limit ranges to yield limited data, wherein the limit range is determined according to the corresponding limit value; and
uniformly quantizing the limited data between −127 and +127 of int8 data accuracy, and calculating the weight quantization factor and the feature map quantization factor.

### Claim 6 (depends on 5)

The hardware environment-based data quantization method according to claim 5, wherein the step of calculating corresponding limit values comprises:
calculating a weight limit value of the weight data according to a weight limit value calculation formula, wherein the weight limit value calculation formula is xw=max(|w|), where xw represents the weight limit value, w represents the weight data, and correspondingly, the limit range of the weight data is (−xw, +xw); and
calculating a feature map limit value of the feature map average data of each layer according to a feature map limit value calculation formula, wherein the feature map limit value calculation formula is xf=max(|F|), where xf represents the feature map limit value, F represents the feature map average data of each layer, and correspondingly, the limit range of the feature map average data of each layer is (−xf, +xf).

### Claim 7

(canceled)

### Claim 8

(canceled)

### Claim 9

A hardware environment-based data quantization apparatus, comprising a processor configured to execute a computer program stored in a memory to implement any steps of:
performing parsing according to a model file under a current deep learning framework to obtain intermediate computational graph data and weight data that are independent of a hardware environment;
performing, based on the intermediate computational graph data and the weight data, calculation on image data in an input data set through a process indicated by an intermediate computational graph to obtain feature map data;
separately performing uniform quantization on the weight data and the feature map data of each layer according to a preset linear quantization method, and calculating a weight quantization factor and a feature map quantization factor;
combining the weight quantization factor and the feature map quantization factor to obtain a quantization parameter, wherein the quantization parameter is a parameter that makes hardware use shift instead of division; and
writing the quantization parameter and quantized weight data to a bin file according to a hardware requirement so as to generate quantized file data.

### Claim 10

A computer readable storage medium configured to store a hardware environment-based data quantization program that is executed by a processor to implement any steps of:
performing parsing according to a model file under a current deep learning framework to obtain intermediate computational graph data and weight data that are independent of a hardware environment;
performing, based on the intermediate computational graph data and the weight data, calculation on image data in an input data set through a process indicated by an intermediate computational graph to obtain feature map data;
separately performing uniform quantization on the weight data and the feature map data of each layer according to a preset linear quantization method, and calculating a weight quantization factor and a feature map quantization factor;
combining the weight quantization factor and the feature map quantization factor to obtain a quantization parameter, wherein the quantization parameter is a parameter that makes hardware use shift instead of division; and
writing the quantization parameter and quantized weight data to a bin file according to a hardware requirement so as to generate quantized file data.

### Claim 11 (depends on 9)

The hardware environment-based data quantization apparatus according to claim 9, wherein the processor is configured to implement following step:
reordering the quantization parameter and the quantized weight data such that a data format of the quantization parameter and the quantized weight data is a 64-channel parallel format.

### Claim 12 (depends on 11)

The hardware environment-based data quantization apparatus according to claim 11, wherein the processor is configured to implement following steps:
parsing the model file by use of a Neural Network Virtual Machine (NNVM) component in an NNVM compiler to obtain the intermediate computational graph data; and
by use of a Tensor Virtual Machine (TVM) component in the NNVM compiler, executing an operator of the intermediate computational graph, and calculating a tensor form of the weight data.

### Claim 13 (depends on 12)

The hardware environment-based data quantization apparatus according to claim 12, wherein the processor is configured to implement following steps:
combining the weight quantization factor and the feature map quantization factor according to a quantization factor combination calculation formula, wherein the quantization factor combination calculation formula is:
y
w
*
y
f
≈
1
2
n
,
wherein yw represents the weight quantization factor, yf represents the feature map quantization factor, and n represents the quantization parameter.

### Claim 14 (depends on 13)

The hardware environment-based data quantization apparatus according to claim 13, wherein the processor is configured to implement following steps:
calculating an average value of the feature map data of each layer as feature map average data of each layer;
statistically obtaining data distributions of the weight data and the feature map average data of each layer, and calculating corresponding limit values;
limiting the weight data and the feature map average data of each layer within corresponding limit ranges to yield limited data, wherein the limit range is determined according to the corresponding limit value; and
uniformly quantizing the limited data between −127 and +127 of int8 data accuracy, and calculating the weight quantization factor and the feature map quantization factor.

### Claim 15 (depends on 14)

The hardware environment-based data quantization apparatus according to claim 14, wherein the processor is configured to implement following steps:
calculating a weight limit value of the weight data according to a weight limit value calculation formula, wherein the weight limit value calculation formula is xw=max(|w|), where xw represents the weight limit value, w represents the weight data, and correspondingly, the limit range of the weight data is (−xw, +xw); and
calculating a feature map limit value of the feature map average data of each layer according to a feature map limit value calculation formula, wherein the feature map limit value calculation formula is xf=max(|F|), where xf represents the feature map limit value, F represents the feature map average data of each layer, and correspondingly, the limit range of the feature map average data of each layer is (−xf, +xf).

### Claim 16 (depends on 10)

The computer readable storage medium according to claim 10, wherein the hardware environment-based data quantization program executed by the processor is configured to implement following step:
reordering the quantization parameter and the quantized weight data such that a data format of the quantization parameter and the quantized weight data is a 64-channel parallel format.

### Claim 17 (depends on 16)

The computer readable storage medium according to claim 16, wherein the hardware environment-based data quantization program executed by the processor is configured to implement following steps:
parsing the model file by use of a Neural Network Virtual Machine (NNVM) component in an NNVM compiler to obtain the intermediate computational graph data; and
by use of a Tensor Virtual Machine (TVM) component in the NNVM compiler, executing an operator of the intermediate computational graph, and calculating a tensor form of the weight data.

### Claim 18 (depends on 17)

The computer readable storage medium according to claim 17, wherein the hardware environment-based data quantization program executed by the processor is configured to implement following steps:
combining the weight quantization factor and the feature map quantization factor according to a quantization factor combination calculation formula, wherein the quantization factor combination calculation formula is:
y
w
*
y
f
≈
1
2
n
,
wherein yw represents the weight quantization factor, yf represents the feature map quantization factor, and n represents the quantization parameter.

### Claim 19 (depends on 18)

The computer readable storage medium according to claim 18, wherein the hardware environment-based data quantization program executed by the processor is configured to implement following steps:
calculating an average value of the feature map data of each layer as feature map average data of each layer;
statistically obtaining data distributions of the weight data and the feature map average data of each layer, and calculating corresponding limit values;
limiting the weight data and the feature map average data of each layer within corresponding limit ranges to yield limited data, wherein the limit range is determined according to the corresponding limit value; and
uniformly quantizing the limited data between −127 and +127 of int8 data accuracy, and calculating the weight quantization factor and the feature map quantization factor.

### Claim 20 (depends on 19)

The computer readable storage medium according to claim 19, wherein the hardware environment-based data quantization program executed by the processor is configured to implement following steps:
calculating a weight limit value of the weight data according to a weight limit value calculation formula, wherein the weight limit value calculation formula is xw=max(|w|), where xw represents the weight limit value, w represents the weight data, and correspondingly, the limit range of the weight data is (−xw, +xw); and
calculating a feature map limit value of the feature map average data of each layer according to a feature map limit value calculation formula, wherein the feature map limit value calculation formula is xf=max(|F|), where xf represents the feature map limit value, F represents the feature map average data of each layer, and correspondingly, the limit range of the feature map average data of each layer is (−xf, +xf).

### Claim 21 (depends on 1)

The hardware environment-based data quantization method according to claim 1, wherein the quantization parameter is a multiple of 2.

### Claim 22 (depends on 9)

The hardware environment-based data quantization apparatus according to claim 9, wherein the quantization parameter is a multiple of 2.
