Model quantization method and related device

By using different quantization steps and parameters in the machine learning model to quantify different channels and feature information, the problem of limited terminal device resources is solved, the computational complexity and storage space requirements are reduced, and the model accuracy is maintained.

WO2024175079A1PCT designated stage expired Publication Date: 2024-08-29HUAWEI TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/078233
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-25
Filing Date
2024-02-23
Publication Date
2024-08-29

AI Technical Summary

Technical Problem

When existing machine learning models are deployed on terminal devices, due to model complexity and large number of parameters, hardware requirements are high, and due to limited resources, it is difficult to effectively compress the model, resulting in high computational complexity and high storage space usage.

Method used

Different quantization step sizes are used to quantify the sub-activation values ​​of different channels, which not only retains the abnormality of channels with abnormal distribution, but also avoids the loss of accuracy of channels with normal distribution. By dividing the activation values ​​and feature information into sub-parts for quantification, using different Quantitative parameters to adapt to different distribution situations.

Benefits of technology

It reduces the computational complexity and storage space requirements of the machine learning model, avoids the reduction in the accuracy of prediction results, is suitable for scenarios such as Transformer models, and improves the efficiency of model reasoning and training on terminal devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024078233_29082024_PF_FP_ABST
    Figure CN2024078233_29082024_PF_FP_ABST
Patent Text Reader

Abstract

A model quantization method and a related device. The method can be applied to the field of artificial intelligence to compress models. Quantization of first activation values generated by a first activation layer in a machine learning model comprises: using a first quantization step size to quantize first sub-activation values of the first activation values, and using a second quantization step size to quantize second sub-activation values of the first activation values. In the machine learning model, a first channel corresponds to the first sub-activation values. In the machine learning model, a second channel corresponds to the second sub-activation values. The first quantization step size is different from the second quantization step size. In the present solution, using the different quantization step sizes to quantize the sub-activation values corresponding to the different channels helps to keep the anomaly of the quantized sub-activation values corresponding to the abnormal-distribution channel, and also to avoid the loss of the precision of the quantized sub-activation values corresponding to the normal-distribution channel.
Need to check novelty before this filing date? Find Prior Art

Description

A model quantification method and related equipment

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on February 25, 2023, with application number 202310215082.0 and invention name “A model quantization method and related equipment”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of artificial intelligence, and in particular to a model quantization method and related equipment. Background Art

[0003] Artificial Intelligence (AI) is the theory, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a branch of computer science that seeks to understand the essence of intelligence and develop new intelligent machines that can respond in a manner similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.

[0004] With the development of artificial intelligence (AI) technology, machine learning models are increasingly deployed on terminal devices. However, many machine learning models are complex, require a large number of parameters, and place high demands on the hardware of terminal devices. Given the limited resources of terminal devices, a solution for compressing machine learning models is urgently needed.

[0005] Summary of the Invention

[0006] The embodiments of the present application provide a model quantization method and related equipment. In view of the different distributions of sub-activation values ​​corresponding to different channels, this scheme uses different quantization step sizes to quantize the sub-activation values ​​corresponding to different channels. This is beneficial for retaining the abnormality of the quantized sub-activation values ​​corresponding to channels with abnormal distributions, and is beneficial for avoiding the loss of accuracy of the quantized sub-activation values ​​corresponding to channels with normal distributions.

[0007] To solve the above technical problems, the embodiments of the present application provide the following technical solutions:

[0008] In a first aspect, an embodiment of the present application provides a model quantization method that can be used to compress a model in the field of artificial intelligence. The method is applied to a process of processing data using a first machine learning model. The model quantization method includes quantizing activation values ​​generated by at least one activation layer in the first machine learning model, where the at least one activation layer includes a first activation layer, and the first activation value generated by the first activation layer is any activation value that needs to be quantized. The electronic device quantizing the first activation value generated by the first activation layer includes:

[0009] The electronic device quantizes a first sub-activation value in a first activation value using a first quantization step size, and quantizes a second sub-activation value in the first activation value using a second quantization step size, wherein the first machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different. The electronic device can be a training device for the first model or an execution device on which the first model is deployed.

[0010] In this implementation, a method for quantizing the activation values ​​generated by the activation layer in the first machine learning model is provided, which can reduce the computational complexity of the first machine learning model and reduce the storage space occupied when using the first machine learning model for data processing. In addition, since there may be channels with abnormal sub-activation value distributions among multiple channels, for example, the sub-activation values ​​corresponding to the channels with abnormal distributions are stably too large or too small, if the same quantization step size is used to quantize the sub-activation values ​​corresponding to each channel, the value of the aforementioned quantization step size needs to be larger, and the accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions will be greatly reduced. In view of the different distributions of sub-activation values ​​corresponding to different channels, different quantization step sizes are used in this scheme to quantize the sub-activation values ​​corresponding to different channels, which is beneficial to retaining the abnormality of the quantized sub-activation values ​​corresponding to the channels with abnormal distributions, and is beneficial to avoiding the loss of accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions.

[0011] In one possible implementation, the distribution of the first sub-activation value is different from the distribution of the second sub-activation value. Here, taking the example of an abnormal distribution of the first sub-activation values ​​corresponding to the first channel and a normal distribution of the second sub-activation values ​​corresponding to the second channel, for example, if all first sub-activation values ​​corresponding to the first channel are consistently oversized or undersized, and the first channel is referred to as an abnormal channel; if all second sub-activation values ​​corresponding to the second channel are within a normal range of second sub-activation values, and the second channel is referred to as a normal channel; the values ​​of the first ratio and the second ratio can be the same or different. For example, the values ​​of the first ratio and the second ratio can both be 80%, 85%, 90%, or other ratios, or the values ​​of the first ratio and the second ratio can be different, etc., without limitation here.

[0012] For example, more than 90 percent of all second sub-activation values ​​corresponding to the second channel have first sub-activation values ​​between 20 and 30, and more than 90 percent of all first sub-activation values ​​corresponding to the first channel have first sub-activation values ​​greater than or equal to 50. For another example, more than 85 percent of all second sub-activation values ​​corresponding to the second channel have first sub-activation values ​​between 10 and 20, and more than 85 percent of all first sub-activation values ​​corresponding to the first channel have first sub-activation values ​​less than or equal to 1. For another example, more than 90 percent of all second sub-activation values ​​corresponding to the second channel have first sub-activation values ​​between 10 and 20, and more than 90 percent of all first sub-activation values ​​corresponding to the first channel have first sub-activation values ​​greater than or equal to 60 or less than or equal to 1. It should be noted that these examples are provided only to facilitate understanding of the concept that the "distribution of first sub-activation values ​​corresponding to the first channel" and the "distribution of second sub-activation values ​​corresponding to the second channel" are different, and are not intended to limit this solution.

[0013] In one possible implementation, the first machine learning model is a Transformer model. In this implementation, technicians discovered during research that when the Transformer model is used as the first machine learning model, the difference between the sub-activation values ​​corresponding to channels with abnormal distributions and the sub-activation values ​​corresponding to channels with normal distributions is more obvious. The solution of "using the first step size to quantize the sub-activation values ​​corresponding to the first channel and the second step size to quantize the sub-activation values ​​corresponding to the second channel" is more compatible with the Transformer model. It can reduce the computational complexity of the Transformer model and the number of parameters in the Transformer model while avoiding a reduction in the accuracy of the prediction results output by the Transformer model.

[0014] In one possible implementation, multiple feature information of the input data can be obtained during data processing using the first machine learning model, the multiple feature information including the first feature information, and the model quantization method further includes quantizing the first feature information. The electronic device quantizing the first feature information includes:

[0015] The electronic device divides the first feature information into at least two sub-feature information, the at least two sub-feature information including first sub-feature information and second sub-feature information; the electronic device quantizes the first sub-feature information using a first quantization parameter, and quantizes the second sub-feature information using a second quantization parameter, where the first quantization parameter and the second quantization parameter are different. For example, the quantization parameters used when quantizing the model may include a quantization step size, a quantization bias, or other types of quantization parameters, which are not exhaustive here.

[0016] In this implementation, since the same input data may include semantically different parts, for example, the same image may include multiple semantically different areas, and the same text may include multiple semantically different words, etc., the distribution of the values ​​of the sub-feature information corresponding to the semantically different parts in the same input data has a large difference, and the distribution of the values ​​of the sub-feature information corresponding to the semantically identical parts has a small difference. In this scheme, the first feature information is divided into at least two sub-feature information, and different sub-feature information is quantized using different quantization parameters, which is beneficial to improving the matching degree between the value in the first feature information and the adopted quantization parameter. After performing the quantization operation on the first feature information using this scheme, the distribution characteristics of the sub-feature information corresponding to the semantically identical parts are retained, and the differences of the sub-feature information corresponding to the semantically different parts are retained, which is beneficial to avoid reducing the accuracy of the prediction results output by the first machine learning model.

[0017] In one possible implementation, "the first quantization parameter and the second quantization parameter are different" may mean that the quantization step size 1 used when quantizing the first sub-feature information is different from the quantization step size 2 used when quantizing the second sub-feature information, that is, different sub-feature information in the M sub-feature information uses the same quantization offset. Alternatively, "the first quantization parameter and the second quantization parameter are different" may mean that the quantization step size 1 and the quantization offset 1 used when quantizing the first sub-feature information are different from the quantization step size 2 and the quantization offset 2 used when quantizing the second sub-feature information.

[0018] In one possible implementation, the input data is an image, and the task of the first machine learning model is to perform target detection on the image. In this implementation, since when the machine learning model is used to perform the target detection task on the image, the image is likely to include multiple objects, and usually several tokens in the first feature information focus on the same object in the image. Different tokens in the first feature information may focus on different objects in the image. The distribution of the values ​​of the sub-feature information corresponding to the same object is similar, and the distribution of the sub-feature information corresponding to different objects is different. That is, when the machine learning model is used to perform the target detection task, the input data of the machine learning model is likely to include multiple semantically different regions. "Using different quantization parameters" to quantize different sub-feature information is more compatible with the specific task of "target detection task".

[0019] In one possible implementation, in the process of processing the input data using the first machine learning model, multiple feature information of the input data can be obtained, the multiple feature information includes second feature information, the second feature information includes feature maps of different scales, and the quantization method of the model also includes quantizing the second feature information. Among them, the electronic device quantizing the second feature information includes: the electronic device divides the second feature information into multiple groups, each of the multiple groups includes at least one feature map, and the scales of the feature maps included in different groups are different; different quantization parameters are used to quantize different groups. Exemplarily, the size of the multiple feature maps of different scales of the training sample is the same, and "feature maps of different scales" refers to the feature information of the training sample at different granularities. More details of the training sample can be seen in the feature map with smaller granularity (also called denser), and the overall information of the training sample can be seen in the feature map with larger granularity (also called sparser).

[0020] In this implementation, if the second feature information is obtained in the process of data processing of the training samples using the machine learning model, since the second feature information includes multiple feature maps of different scales, the second feature information is grouped based on the scale of each feature map, and different quantization parameters are used for different groups. That is, different quantization parameters are used for quantization of feature maps of different scales, which is beneficial to retaining the information carried by feature maps of different scales to avoid reducing the accuracy of the prediction results output by the machine learning model.

[0021] In one possible implementation, the input data is an image, and the task of the first machine learning model is any of the following: object detection, semantic segmentation, or super-resolution. This implementation provides multiple application scenarios, which helps to increase the implementation flexibility of this solution.

[0022] In one possible implementation, the process of using the first machine learning model to process data occurs during the inference phase of the first machine learning model, or the process of using the first machine learning model to process data occurs during the training phase of the first machine learning model. In this implementation, whether in the training phase or the inference phase of the machine learning model, as long as the machine learning model is used to process input data, the model quantization method provided in this application can be used. This can not only reduce the amount of computation required by the machine learning model when processing data on the execution device, but also reduce the amount of computation required by the machine learning model when processing data on the training device.

[0023] In a second aspect, an embodiment of the present application provides a model quantization method, which can be used to compress models in the field of artificial intelligence. The method is applied to a process of data processing using a machine learning model. In the process of data processing using a machine learning model, multiple feature information of the input data can be obtained. The multiple feature information includes first feature information. The quantization method of the model includes quantizing the first feature information; wherein, the electronic device quantizes the first feature information including: the electronic device divides the first feature information into at least two sub-feature information, the at least two sub-feature information including first sub-feature information and second sub-feature information; the electronic device uses a first quantization parameter to quantize the first sub-feature information, and uses a second quantization parameter to quantize the first sub-feature information, and the first quantization parameter and the second quantization parameter are different.

[0024] In one possible implementation, the model quantization method also includes quantizing the activation value generated by at least one activation layer in the machine learning model, and the at least one activation layer includes a first activation layer; wherein quantizing the first activation value generated by the first activation layer includes: using a first quantization step size to quantize the first sub-activation value in the first activation value; using a second quantization step size to quantize the second sub-activation value in the second activation value, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different.

[0025] In one possible implementation, the distribution of the first sub-activation values ​​is different from the distribution of the second sub-activation values.

[0026] In one possible implementation, the above-mentioned machine learning model is a Transformer model.

[0027] In one possible implementation, the input data is an image, and the task of the machine learning model is to detect objects in the image.

[0028] In one possible implementation, multiple feature information of the input data can be obtained in the process of processing the input data using a machine learning model, the multiple feature information includes second feature information, the second feature information includes feature maps of different scales, and the quantization method of the model also includes quantizing the second feature information; wherein, quantizing the second feature information includes: dividing the second feature information into multiple groups, each of the multiple groups includes at least one feature map, and different groups in the multiple groups include feature maps of different scales; and using different quantization parameters for quantization of different groups.

[0029] In one possible implementation, the input data is an image, and the task of the machine learning model is any of the following: performing object detection on the image, performing semantic segmentation on the image, or performing super-resolution on the image.

[0030] In one possible implementation, the process of using a machine learning model to process data is in the inference phase of the machine learning model, or the process of using a machine learning model to process data is in the training phase of the machine learning model.

[0031] In the second aspect of this application, the specific implementation methods, meanings of terms and beneficial effects of the steps in each possible implementation method of the second aspect can all be referred to the first aspect and will not be repeated here.

[0032] In a third aspect, an embodiment of the present application provides a model quantization device that can be used to compress a model in the field of artificial intelligence. The model quantization device is applied in a process of processing data using a machine learning model. The model quantization device is used to quantize activation values ​​generated by at least one activation layer in the machine learning model, where the at least one activation layer includes a first activation layer. The model quantization device includes:

[0033] A quantization module is used to quantize a first sub-activation value in a first activation value using a first quantization step size; the quantization module is also used to quantize a second sub-activation value in the first activation value using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different.

[0034] In the third aspect of this application, the quantization device of the model can also be used to execute the steps performed by the electronic device in the first aspect and various possible implementation methods of the first aspect. The specific implementation methods, meanings of terms and beneficial effects brought about by the steps in various possible implementation methods of the third aspect can all be referred to the first aspect and will not be repeated here.

[0035] In a fourth aspect, an embodiment of the present application provides a model quantization device, which can be used to compress models in the field of artificial intelligence. The model quantization device is applied to a process of data processing using a machine learning model. In the process of data processing using a machine learning model, multiple feature information of the input data can be obtained. The multiple feature information includes first feature information. The model quantization device is used to quantize the first feature information; wherein the model quantization device includes: a grouping module, which is used to divide the first feature information into at least two sub-feature information, and the at least two sub-feature information include first sub-feature information and second sub-feature information; a quantization module, which is used to quantize the first sub-feature information using a first quantization parameter; the quantization module is also used to quantize the first sub-feature information using a second quantization parameter, and the first quantization parameter and the second quantization parameter are different.

[0036] In the fourth aspect of this application, the quantization device of the model can also be used to execute the steps performed by the electronic device in the first aspect and various possible implementation methods of the first aspect. The specific implementation methods, meanings of terms and beneficial effects brought about by the steps in various possible implementation methods of the fourth aspect can all be referred to the first aspect and will not be repeated here.

[0037] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a program. When the program is run on a computer, the computer executes the quantization method of the model described in the first aspect above.

[0038] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes the quantization method of the model described in the first aspect above.

[0039] In the seventh aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the processor is coupled to the memory, the memory is used to store programs; and the processor is used to execute the programs in the memory, so that the electronic device executes the quantization method of the model of the first aspect mentioned above.

[0040] In an eighth aspect, the present application provides a chip system, which includes a processor for supporting a terminal device or a communication device to implement the functions involved in the above aspects, for example, sending or processing the data and / or information involved in the above methods. In one possible design, the chip system also includes a memory, which is used to store program instructions and data necessary for the terminal device or communication device. The chip system can be composed of a chip, or it can include a chip and other discrete devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] FIG1 is a schematic diagram of the structure of an artificial intelligence main framework provided in an embodiment of the present application;

[0042] FIG2 is a system architecture diagram of a quantization system of a model provided in an embodiment of the present application;

[0043] FIG3 is a schematic diagram of a process for quantizing a first activation value generated by a first activation layer according to an embodiment of the present application;

[0044] FIG4 is a schematic diagram of a quantization method of a model provided in an embodiment of the present application;

[0045] FIG5 is a flow chart of a method for quantifying a model provided in an embodiment of the present application;

[0046] FIG6 is a schematic diagram of quantifying first feature information according to an embodiment of the present application;

[0047] FIG7 is a schematic diagram of images of different scales provided in an embodiment of the present application;

[0048] FIG8 is a schematic diagram of a quantization method of a model provided in an embodiment of the present application;

[0049] FIG9 is a flow chart of a method for quantifying a model provided in an embodiment of the present application;

[0050] FIG10 is a schematic diagram of a structure of a quantization device of a model provided in an embodiment of the present application;

[0051] FIG11 is another schematic diagram of the structure of a quantization device for a model provided in an embodiment of the present application;

[0052] FIG12 is another schematic diagram of the structure of a quantization device for a model provided in an embodiment of the present application;

[0053] FIG13 is a schematic diagram of a structure of an execution device provided in an embodiment of the present application;

[0054] FIG14 is a schematic diagram of a structure of a training device provided in an embodiment of the present application;

[0055] FIG15 is a schematic structural diagram of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0057] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0058] First, let's describe the overall workflow of an AI system. See Figure 1, which shows a schematic diagram of the AI ​​framework. This framework will be explained from two perspectives: the "intelligent information chain" (horizontal axis) and the "IT value chain" (vertical axis). The "intelligent information chain" reflects the entire process from data acquisition to processing. For example, it could be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. Throughout this process, data undergoes a condensed journey from "data-information-knowledge-wisdom." The "IT value chain," spanning the underlying infrastructure of human intelligence, information (provided and processed by technology), and the system's industrial ecosystem, reflects the value that AI brings to the information technology industry.

[0059] (1) Infrastructure

[0060] The infrastructure provides computing power for AI systems, enabling communication with the outside world and providing support through a basic platform. Communication with the outside world is achieved through sensors; computing power is provided by smart chips, which can specifically adopt hardware acceleration chips such as central processing units (CPUs), embedded neural network processing units (NPUs), graphics processing units (GPUs), application-specific integrated circuits (ASICs), or field programmable gate arrays (FPGAs); the basic platform includes related platform guarantees and support such as distributed computing frameworks and networks, and can include cloud storage and computing, and interconnected networks. For example, sensors communicate with the outside world to obtain data, which is then provided to the smart chips in the distributed computing system provided by the basic platform for calculation.

[0061] (2) Data

[0062] Data above the infrastructure layer represents data sources for AI. This data includes graphics, images, voice, and text, as well as IoT data from traditional devices. This includes business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.

[0063] (3) Data processing

[0064] Data processing generally includes data training, machine learning, deep learning, search, reasoning, decision-making, etc.

[0065] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.

[0066] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.

[0067] Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.

[0068] (4) General ability

[0069] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.

[0070] (5) Smart products and industry applications

[0071] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart manufacturing, smart transportation, smart homes, smart medical care, smart security, autonomous driving, smart cities, etc.

[0072] The model quantization method provided in this application can be applied to various application fields of artificial intelligence technology, specifically for compressing machine learning models in various application fields; this application uses quantization to compress machine learning models. Model quantization is a term in the field of artificial intelligence model acceleration, which refers to the discretization of continuous values ​​(such as activation values, weight parameters, or other information) in a machine learning model.

[0073] For example, the quantization method of the model provided in this application can be applied to fields that require neural network implementation, such as visual perception tasks, natural language synthesis tasks related to speech semantics, and audio and video processing tasks. The following examples illustrate multiple application scenarios of the embodiments of this application.

[0074] Application Scenario 1: Object Detection

[0075] For example, in the field of autonomous driving, autonomous vehicles can collect point cloud data corresponding to the environment around the vehicle through sensors, and perform target detection through a machine learning model based on the collected point cloud data to obtain a prediction result corresponding to the point cloud data. The prediction result is used to indicate the position of at least an object in the environment around the vehicle. The autonomous driving vehicle can plan its driving path based on the aforementioned prediction result.

[0076] It should be noted that the above-mentioned vehicles can be cars, trucks, motorcycles, buses, ships, airplanes, helicopters, lawn mowers, recreational vehicles, amusement park vehicles, construction equipment, trams, golf carts or trains, etc., and the embodiments of the present application do not make special limitations.

[0077] For example, in the field of intelligent monitoring, many cameras are installed in public places and traffic roads. After collecting image information of the surrounding environment, a few intelligent cameras can perform target detection tasks on the collected images.

[0078] For another example, in the field of smart homes, mobile robots (such as sweeping robots, tutoring robots, or other movable robots, etc.) can collect three-dimensional images corresponding to the robot's surrounding environment, and perform target detection based on the collected three-dimensional images through a machine learning model to obtain a prediction result corresponding to the aforementioned three-dimensional image. The prediction result is used to indicate the position of at least one obstacle around the mobile robot.

[0079] Since the computing power of autonomous vehicles, smart cameras, mobile robots or other types of terminal devices is limited, the model quantization method provided in this application can be used to compress the above-mentioned machine learning models, thereby ensuring that some larger models can also perform reasoning tasks well on terminal devices.

[0080] Application Scenario 2: Semantic Segmentation of Images

[0081] Semantic segmentation refers to the classification of all pixels in an image using a machine learning model. The quantization method of the model provided in this application can be used to compress the aforementioned machine learning model.

[0082] Application Scenario 3: Super-resolution of images

[0083] For example, in scenarios such as intelligent monitoring, intelligent medical care, video coding and communication, there is a need to use machine learning models to reconstruct high-resolution images based on observed low-resolution images. The quantization method of the model provided in this application can be used to compress the aforementioned machine learning model.

[0084] Application Scenario 4: Image Classification

[0085] After obtaining the image to be classified, the terminal device (such as a mobile phone, tablet or laptop computer, etc.) can use a machine learning model to obtain the category of the object in the image to be classified, and then classify the image to be classified according to the category of the object in the image to be classified. The quantization method of the model provided in this application can be used to compress the aforementioned machine learning model.

[0086] Application Scenario 5: Natural Language Processing (NLP)

[0087] Natural language processing is the processing of human language. Natural language processing is the process of systematically analyzing, understanding, and extracting information from text data using machine learning models. The quantization method of the model provided in this application can be used to compress the aforementioned machine learning model. By using the aforementioned machine learning model, we can manage very large blocks of text data, or perform a large number of automated tasks, and solve a variety of problems, such as automatic summarization, machine translation (MT), named entity recognition (NER), relation extraction (RE), information extraction (IE), sentiment analysis, speech recognition, question answering, and topic segmentation, etc.

[0088] For example, natural language processing tasks can be divided into the following categories.

[0089] Sequence labeling: Each word in a sentence requires the model to give a classification category based on the context, such as Chinese word segmentation, part-of-speech tagging, named entity recognition, and semantic role labeling.

[0090] Classification task: The entire sentence outputs a classification value, such as text classification.

[0091] Sentence Relationship Inference: Given two sentences, determine whether they have a certain nominal relationship. Examples include question-answering systems, semantic rewriting, and natural language inference.

[0092] Generative tasks: Output a piece of text and generate another piece of text. Examples include machine translation, text summarization, poetry and sentence composition, and picture description.

[0093] It should be noted that the above examples of various application scenarios of this application are only for the convenience of understanding this solution and are not used to limit this solution.

[0094] Before describing the specific implementation method of the quantization method of the model provided in this application, please refer to Figure 2. Figure 2 is a system architecture diagram of the quantization system of the model provided in an embodiment of this application. In Figure 2, the quantization system 200 of the model includes a training device 210, a database 220, an execution device 230, a data storage system 240 and a client device 250, and the execution device 230 includes a computing module 231.

[0095] The database 220 stores a training data set. During the training phase of the first machine learning model 201, the training device 210 generates the first machine learning model 201 and iteratively trains the first machine learning model 201 using the training data set to obtain the trained first machine learning model 201. The first machine learning model 201 can be specifically expressed as a neural network or a non-neural network model.

[0096] The first machine learning model 201 obtained by the training device 210 can be deployed in the computing module 231 of the execution device 230. For example, the execution device 210 can be a mobile phone, a tablet, a laptop, a VR device, a vehicle, or a monitoring system. During the inference phase of the first machine learning model 201, the execution device 230 can input the data to be processed into the first machine learning model 201 and obtain the prediction result corresponding to the data to be processed output by the first machine learning model 201.

[0097] The execution device 230 can call data, code, etc. from the data storage system 240, or store data, instructions, etc. in the data storage system 240. The data storage system 240 can be located in the execution device 230, or the data storage system 240 can be an external memory relative to the execution device 230.

[0098] The quantization method of the model provided in this application can be used in both the training and inference stages of the first machine learning model 201, that is, the training device 210 and the execution device 230 can both be the execution entities of the quantization method of the model provided in this application. The aforementioned method can be applied in the process of using a machine learning model for data processing. The quantization method of the model includes quantizing the activation value generated by at least one activation layer in the machine learning model, the at least one activation layer including a first activation layer, and the first activation layer is any one of the at least one activation layer. Please refer to Figure 3, which is a flow chart of quantizing the first activation value generated by the first activation layer provided in an embodiment of the present application. 301. The electronic device quantizes the first sub-activation value in the first activation value using a first quantization step size. 302. The electronic device quantizes the second sub-activation value in the first activation value using a second quantization step size; wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different. The electronic device that executes steps 301 and 302 may be the training device 210 or the execution device 230 .

[0099] In order to understand this solution more intuitively, please refer to Figure 4, which is a schematic diagram of a quantization method of a model provided in an embodiment of the present application. As shown in Figure 4, after obtaining the first activation value, the electronic device can divide the first activation value into a first sub-activation value corresponding to the first channel and a second sub-activation value corresponding to the second channel. The electronic device quantizes the first sub-activation value using a first quantization step size to obtain a quantized first sub-activation value; and quantizes the second sub-activation value using a second quantization step size to obtain a quantized second sub-activation value; the quantized first sub-activation value and the quantized second sub-activation value constitute the quantized first activation value. It should be understood that the example in Figure 4 is only for the convenience of understanding this solution and is not used to limit this solution.

[0100] In an embodiment of the present application, a method for quantizing activation values ​​generated by an activation layer in a machine learning model is provided, which can reduce the computational complexity of the machine learning model and reduce the storage space occupied when using the machine learning model for data processing. In addition, since there may be channels with abnormal sub-activation value distributions among multiple channels, for example, the sub-activation values ​​corresponding to the channels with abnormal distributions are stably too large or too small, if the same quantization step size is used to quantize the sub-activation values ​​corresponding to each channel, the value of the aforementioned quantization step size needs to be larger, and the accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions will be greatly reduced. In view of the different distributions of sub-activation values ​​corresponding to different channels, different quantization step sizes are used in this scheme to quantize the sub-activation values ​​corresponding to different channels, which is beneficial for retaining the abnormality of the quantized sub-activation values ​​corresponding to the channels with abnormal distributions, and is beneficial for avoiding the loss of accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions.

[0101] In some embodiments of the present application, please refer to Figure 2, the execution device 230 and the client device 250 can be independent devices. The execution device 230 is configured with an input / output (I / O) interface to interact with the client device 250 for data. The "user" can input the data to be processed through the client device 250, and the client device 250 sends the data to be processed to the execution device 230 through the I / O interface. After the execution device 230 generates prediction decision information corresponding to the data to be processed through the first machine learning model / rule 201 in the computing module 231, the aforementioned prediction decision information can be returned to the client device 250 through the I / O interface and provided to the user.

[0102] It is worth noting that FIG2 is only a schematic diagram of the architecture of the quantization system of the two models provided in an embodiment of the present invention, and the positional relationship between the devices, components, modules, etc. shown in the figure does not constitute any limitation. For example, in other embodiments of the present application, the execution device 230 can be configured in the client device 250. As an example, when the client device is a mobile phone or a tablet, the execution device 230 can be a module for performing array image processing in the host processor (Host CPU) of the mobile phone or tablet. The execution device 230 can also be a graphics processing unit (GPU) or a neural network processor (NPU) in the mobile phone or tablet. The GPU or NPU is mounted on the host processor as a coprocessor, and the host processor assigns tasks.

[0103] In combination with the above description, the following describes the specific implementation process of the training phase and reasoning phase of the machine learning model provided in the embodiment of the present application.

[0104] 1. Training Phase

[0105] In the embodiment of the present application, the training phase describes a process in which the training device 210 trains the first machine learning model 201 using the training data in the database 220. Specifically, please refer to FIG5 , which is a flow chart of a quantization method of the model provided in the embodiment of the present application. The quantization method of the model provided in the embodiment of the present application may include:

[0106] 501. The training device inputs the training sample into the first machine learning model, wherein, in the process of using the first machine learning model to process the training sample data, multiple feature information of the training sample and the activation value generated by the activation layer in the first machine learning model can be obtained.

[0107] In an embodiment of the present application, a training data set may be stored in a training device, and the training data set may include multiple training samples and the expected results corresponding to each training sample; wherein, the specific expressions of "training samples" and "expected results corresponding to training samples" need to be determined in combination with the actual application scenario; illustratively, the task performed by the first machine learning model may be any of the following: target detection, semantic segmentation of images, super-resolution processing of images, image classification, natural language processing or other types of tasks, etc.; for the description of "natural language processing" tasks, please refer to the above description, and they will not be listed one by one here.

[0108] For example, if the task of the first machine learning model is to perform target detection in an image, the "training sample" can be represented by an image, and the "expected result corresponding to the training sample" can be represented by the correct position information of at least one object in the image. For another example, if the task of the first machine learning model is to perform semantic segmentation on an image, the "training sample" can be represented by an image, and the "expected result corresponding to the training sample" can be represented by the correct category of each pixel in the image, which can be foreground or background, etc. It should be understood that the examples here are only for the convenience of understanding this solution and are not used to limit this solution.

[0109] The training device can input training samples (also known as "input data" in the training stage) into the first machine learning model to process the training samples through the first machine learning model, and then obtain the expected results corresponding to the training samples; the specific expressions of "prediction results corresponding to training samples" and "expected results corresponding to training samples" are similar and will not be repeated here.

[0110] Among them, the process of using the first machine learning model to process data of training samples includes the process of using the first machine learning model to extract features of training samples. In the process of using the first machine learning model to process data of training samples, multiple feature information of the training samples and the activation value generated by the activation layer in the machine learning model can be obtained.

[0111] Exemplarily, the first machine learning model can be expressed as a Transformer model, a convolutional neural network (CNN), a recurrent neural network, or other types of neural networks, etc., which are not limited here.

[0112] 502. The training device obtains first feature information and divides the first feature information into M sub-feature information, where the first feature information is included in multiple feature information of the training sample, and M is an integer greater than or equal to 2.

[0113] In the embodiment of the present application, steps 502 and 503 are optional steps. During the process of data processing of the training sample by the training device, multiple feature information of the training sample can be obtained. In this case, the training device can obtain first feature information of the training sample during the process of feature extraction of the training sample using the first machine learning model. The first feature information is included in the multiple feature information of the training sample. The training device divides the first feature information into M sub-feature information, where M is an integer greater than or equal to 2.

[0114] Optionally, if one piece of first feature information includes multiple feature maps, the scales of different feature maps in the first feature information are the same; or, one piece of first feature information includes only one feature map.

[0115] 503. The training device quantizes the first sub-feature information using a first quantization parameter and quantizes the second sub-feature information using a second quantization parameter. The M sub-feature information includes the first sub-feature information and the second sub-feature information. The first quantization parameter and the second quantization parameter are different.

[0116] In an embodiment of the present application, after the training device divides the first feature information into M sub-feature information, different quantization parameters may be used to quantize the different sub-feature information. That is, the training device may store M groups of quantization parameters corresponding one-to-one to the M sub-feature information. When quantizing any one of the M sub-feature information (hereinafter referred to as "target sub-feature information" for ease of description), a target quantization parameter corresponding to the target sub-feature information may be obtained from the M groups of quantization parameters, and the target sub-feature information may be quantized using the target quantization parameter to obtain the quantized target sub-feature information.

[0117] Exemplarily, the M sub-feature information includes first sub-feature information and second sub-feature information, and the training device uses a first quantization parameter to quantize the first sub-feature information and uses a second quantization parameter to quantize the second sub-feature information, and the first quantization parameter and the second quantization parameter are different.

[0118] For example, the quantization parameters used when quantizing the model may include a quantization step size, a quantization bias, or other types of quantization parameters, which are not exhaustively listed here. Any one or more of the quantization step size and the quantization bias can be set as learnable parameters, that is, during the training process of the first machine learning model, the quantization step size and / or the quantization bias are continuously updated; or, both the quantization step size and the quantization bias can be set as hyperparameters.

[0119] To further understand this solution, let's first introduce the model quantization process. For example, the formula used when using differentiable quantization parameters (learned step size quantization+, LSQ+) as the quantization algorithm is as follows:

[0120] Among them, q s (X) represents the quantization of X, represents the quantized value obtained after quantizing X, s represents the quantization step size in the quantization parameter, β represents the quantization bias in the quantization parameter, "**" represents the nearest rounding operation, clamp(*,t n ,t p ) represents a clamping operation, The maximum value of t is limited to p Under The minimum value of t is limited to n It should be noted that the above example is only an example to facilitate understanding of this solution. Other quantization algorithms can also be used. The examples here are not used to limit this solution.

[0121] In one implementation, “the first quantization parameter and the second quantization parameter are different” may mean that a quantization step size 1 used when quantizing the first sub-feature information is different from a quantization step size 2 used when quantizing the second sub-feature information, that is, different sub-feature information in the M sub-feature information uses the same quantization bias.

[0122] In another implementation, “the first quantization parameter and the second quantization parameter are different” may mean that the quantization step size 1 and the quantization offset 1 used when quantizing the first sub-feature information are different from the quantization step size 2 and the quantization offset 2 used when quantizing the second sub-feature information.

[0123] In an embodiment of the present application, in one implementation, the training device may adopt the method in steps 502 and 503 to quantize any first feature information to obtain quantized first feature information.

[0124] In another implementation, before using the first feature information for matrix multiplication, the first feature information can be quantized using the method in steps 502 and 503, and the quantized first feature information can be used for matrix multiplication. For example, the feature processing module of the first machine learning model uses a Transformer module, and the attention mechanism is used in the process of extracting features from training samples using the Transformer module; the query matrix, key matrix, and value matrix used in the data processing process based on the attention mechanism can all be quantized using the method in steps 502 and 503, and the quantized query matrix, key matrix, and value matrix can be used for data processing; that is, the query matrix, key matrix, and value matrix are all examples of the first feature information.

[0125] In order to understand this solution more intuitively, please refer to Figure 6, which is a schematic diagram of quantizing the first feature information provided by an embodiment of the present application. In Figure 6, the first feature information includes three feature maps corresponding to three channels as an example, and different quantization steps are used to quantize different areas in the same feature map. As shown in Figure 6, each feature map is divided into three groups of sub-feature information, and the sub-feature information of the upper area of ​​each feature map (that is, the upper two rows in Figure 6) is quantized using a quantization step of 1, the sub-feature information of the middle area of ​​each feature map (that is, the middle two rows in Figure 6) is quantized using a quantization step of 2, and the sub-feature information of the lower area of ​​each feature map (that is, the lower two rows in Figure 6) is quantized using a quantization step of 3. It should be understood that the example in Figure 6 is only for the convenience of understanding this solution and is not used to limit this solution.

[0126] In an embodiment of the present application, since the same input data may include semantically different parts, for example, the same image may include multiple semantically different areas, and the same text may include multiple semantically different words, etc., the distribution of the values ​​of the sub-feature information corresponding to the semantically different parts in the same input data has a large difference, and the distribution of the values ​​of the sub-feature information corresponding to the semantically identical parts has a small difference. In this scheme, the first feature information is divided into at least two sub-feature information, and different sub-feature information is quantized using different quantization parameters, which is beneficial to improving the matching degree between the value in the first feature information and the adopted quantization parameter. After performing the quantization operation on the first feature information using this scheme, both the distribution characteristics of the sub-feature information corresponding to the semantically identical parts and the differences of the sub-feature information corresponding to the semantically different parts are retained, which is beneficial to avoid reducing the accuracy of the prediction results output by the first machine learning model.

[0127] When a machine learning model is used to perform a target detection task on an image, the image is likely to include multiple objects. Usually, several tokens in the first feature information focus on the same object in the image. Different tokens in the first feature information may focus on different objects in the image. The distribution of the values ​​of the sub-feature information corresponding to the same object is similar, and the distribution of the sub-feature information corresponding to different objects is different. That is, when the machine learning model is used to perform a target detection task, the input data of the machine learning model is likely to include multiple semantically different regions. "Using different quantization parameters" to quantize different sub-feature information is more adaptable to the specific task of "target detection task".

[0128] 504. The training device quantizes a first sub-activation value in the first activation value using a first quantization step size, and quantizes a second sub-activation value in the first activation value using a second quantization step size, wherein the first machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different.

[0129] In an embodiment of the present application, step 504 is an optional step. Since the first machine learning model may include one or more activation layers, the training device can generate activation values ​​corresponding to all channels through each activation layer in the first machine learning model during the process of processing data of the training samples using the first machine learning model.

[0130] Exemplarily, the first activation value can be the activation value generated by any activation layer, that is, the activation values ​​generated by each activation layer in the first machine learning model are quantized in the manner of step 504; or, only the activation values ​​generated by some preset activation layers in the first machine learning model are quantized in the manner of step 504, etc. Which activation layers in the first machine learning model are quantized in the manner of step 504 can be flexibly determined based on actual conditions, and is not limited in the embodiments of the present application.

[0131] After obtaining the first activation value generated by the first activation layer, the training device may divide the first activation value into N groups corresponding to N channels, where N is an integer greater than or equal to 2; optionally, the distribution of sub-activation values ​​corresponding to different channels in the N channels is different, that is, the distribution of sub-activation values ​​included in different groups in the N groups is different. The training device uses different quantization step sizes to quantize the values ​​of different groups in the N groups.

[0132] Optionally, the quantization offsets used by the values ​​of different groups in the N groups may be the same or different.

[0133] Exemplarily, the N groups include a first sub-activation value and a second sub-activation value. The training device can obtain the first sub-activation value and the second sub-activation value from the first activation value, quantize the first sub-activation value in the first activation value using a first quantization step size, and quantize the second sub-activation value in the first activation value using a second quantization step size.

[0134] The first machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, the first quantization step size and the second quantization step size are different. Optionally, a distribution of the first sub-activation value is different from a distribution of the second sub-activation value.

[0135] Here, we take the example of an abnormal distribution of first sub-activation values ​​corresponding to a first channel and a normal distribution of second sub-activation values ​​corresponding to a second channel. For example, if all first sub-activation values ​​corresponding to a first channel are consistently overly large or underlying, and all second sub-activation values ​​corresponding to a second channel are within a normal range, then the second channel can also be called a normal channel. The first and second ratios can be the same or different. For example, both the first and second ratios can be 80%, 85%, 90%, or other ratios, or they can be different, without limitation.

[0136] For example, more than 90% of the first sub-activation values ​​of all the second sub-activation values ​​corresponding to the second channel are between 20 and 30; and more than 90% of the first sub-activation values ​​of all the first sub-activation values ​​corresponding to the first channel are greater than or equal to 50.

[0137] For another example, more than 85% of the first sub-activation values ​​of all the second sub-activation values ​​corresponding to the second channel are between 10 and 20, and more than 85% of the first sub-activation values ​​of all the first sub-activation values ​​corresponding to the first channel are less than or equal to 1.

[0138] For another example, more than 90 percent of the first sub-activation values ​​of all second sub-activation values ​​corresponding to the second channel are between 10 and 20, and more than 90 percent of the first sub-activation values ​​of all first sub-activation values ​​corresponding to the first channel are either greater than or equal to 60 or less than or equal to 1. It should be noted that this example is merely for facilitating understanding of the difference between the "distribution of first sub-activation values ​​corresponding to the first channel" and the "distribution of second sub-activation values ​​corresponding to the second channel," and is not intended to limit this solution.

[0139] Optionally, the training device can input a small amount of training samples into the first machine learning model, and count the distribution of sub-activation values ​​corresponding to different channels each time a training sample is input to determine which channels in the first machine learning model have abnormal distributions and which channels have normal distributions, and then mark which channels in the first machine learning model are first channels and which channels are second channels.

[0140] Exemplarily, in one implementation, the training device may input a training sample into the first machine learning model to obtain all sub-activation values ​​corresponding to each channel. For any channel in the first machine learning model (hereinafter referred to as the "target channel" for the convenience of description), the training device determines the first number of sub-activation values ​​corresponding to the target channel that are greater than the first value, and determines the second number of all sub-activation values ​​corresponding to the target channel. If the ratio between the first number and the second number is greater than or equal to the first ratio, the target channel is determined to be a channel with abnormal distribution; if the ratio between the first number and the second number is less than the first ratio, the target channel is determined to be a channel with normal distribution. The training device performs the above operation on each channel to determine which channels in the first machine learning model are normally distributed and which channels are abnormally distributed.

[0141] In another implementation, the training device can obtain T training samples, input one of the T training samples into the first machine learning model, and obtain all sub-activation values ​​corresponding to each channel. The training device determines the first number and the second number corresponding to the target channel. If the ratio between the first number and the second number is greater than or equal to the first ratio, the number of times the target channel is determined to be a channel with abnormal distribution is increased by one; if the ratio between the first number and the second number is less than the first ratio, the number is not increased. After the training device inputs all T training samples into the first machine learning model, the total number of times the target channel is determined to be a channel with abnormal distribution is obtained. If the ratio between the total number of times the target channel is determined to be a channel with abnormal distribution and T is greater than or equal to the second ratio, the target channel is determined to be a channel with abnormal distribution; if the ratio between the total number of times the target channel is determined to be a channel with abnormal distribution and T is less than the second ratio, the target channel is determined to be a channel with normal distribution. The training device performs the above operation on each channel to determine which channels are normally distributed and which channels are abnormally distributed in the first machine learning model.

[0142] It should be noted that the training device can also use other methods to determine which channels in the first machine learning model have abnormal distribution and which channels have normal distribution. The examples here are only used to prove the feasibility of this solution and are not used to limit this solution.

[0143] To further understand this solution, here, taking the case where the first sub-activation value corresponds to a channel with normal distribution, and the second sub-activation value corresponds to a channel with abnormal distribution as an example, an example of a formula for obtaining the first sub-activation value and the second sub-activation value from the first activation value is disclosed:

[0144] in, Represents the first sub-activation value, represents the second sub-activation value, X c Represents any sub-activation value in the first activation value, outlier(c) represents the identification category of each sub-activation value in the first activation value. When outlier(c) is 0, it means that the sub-activation value is the sub-activation value corresponding to the channel with normal distribution. When outlier(c) is 1, it means that the sub-activation value is the sub-activation value corresponding to the channel with abnormal distribution. According to the above formula, the first activation value can be split into two parts, one part only includes multiple first sub-activation values, and the other part only includes multiple second sub-activation values. It should be understood that the example here is only for the convenience of understanding this solution and is not used to limit this solution.

[0145] In an embodiment of the present application, since there may be channels with abnormal sub-activation value distributions among multiple channels, for example, the sub-activation values ​​corresponding to the channels with abnormal distributions are stably too large or too small, if the same quantization step size is used to quantize the sub-activation values ​​corresponding to each channel, the value of the aforementioned quantization step size needs to be larger, and the accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions will be greatly reduced. In view of the different distributions of sub-activation values ​​corresponding to different channels, different quantization step sizes are used in this scheme to quantize the sub-activation values ​​corresponding to different channels, which is beneficial for retaining the abnormality of the quantized sub-activation values ​​corresponding to the channels with abnormal distributions, and is beneficial for avoiding the loss of accuracy of the quantized sub-activation values ​​corresponding to the channels with normal distributions.

[0146] During their research, technicians discovered that when the first machine learning model uses the Transformer model, the difference between the sub-activation values ​​corresponding to channels with abnormal distribution and the sub-activation values ​​corresponding to channels with normal distribution is more obvious. The scheme of "using the first step size to quantize the sub-activation values ​​corresponding to the first channel, and using the second step size to quantize the sub-activation values ​​corresponding to the second channel" is more compatible with the Transformer model. It can reduce the computational complexity of the Transformer model, reduce the number of parameters in the Transformer model, and avoid a reduction in the accuracy of the prediction results output by the Transformer model.

[0147] Optionally, the training device can impose linear constraints on the first quantization step size and the second quantization step size, making the values ​​of the first quantization step size and the second quantization step size more hardware-friendly. To more intuitively understand this solution, the following example discloses an example of the constraint relationship between the first quantization step size and the second quantization step size, taking the quantization step size used for the sub-activation value corresponding to the channel with normal distribution and the quantization step size used for the sub-activation value corresponding to the channel with abnormal distribution as an example:

[0148] Among them, s outller Represents the first quantization step size, s normal Represents the second quantization step size, max(X outlier ) represents the maximum value of all second sub-activation values ​​corresponding to all channels with abnormal distribution, max(X normal ) represents the maximum value of all first sub-activation values ​​corresponding to all channels with normal distribution. It should be understood that the example here is only for the convenience of understanding this solution and is not used to limit this solution.

[0149] 505. The training device divides the second feature information into multiple groups, each of the multiple groups includes at least one feature map, and different groups in the multiple groups include feature maps with different scales, wherein the first feature information is included in multiple feature information of the training sample, and the second feature information includes feature maps of different scales.

[0150] In the embodiment of the present application, steps 505 and 506 are optional steps. If the training device is able to obtain second feature information of the training sample during data processing of the training sample, and one piece of second feature information of the training sample includes multiple feature maps of different scales, that is, the multiple pieces of feature information of the training sample obtained by the training device during data processing of the training sample include the second feature information, the training device may divide the second feature information into multiple groups, each of the multiple groups including at least one feature map, and different groups within the multiple groups include feature maps of different scales.

[0151] For example, when the task of the first machine learning model is any of the following, the second feature information of the training sample can be obtained during the data processing of the training sample: target detection on an image, semantic segmentation on an image, super-resolution on an image, or other types of image processing tasks. In the embodiments of the present application, a variety of application scenarios are provided to help improve the implementation flexibility of the present solution.

[0152] It should be noted that the first feature information and the second feature information are different feature information. One first feature information includes one feature map, or one first feature information includes multiple feature maps with the same scale; and one second feature information includes multiple feature maps with different scales.

[0153] For example, the sizes of multiple feature maps of different scales of the training sample are the same. "Feature maps of different scales" refer to the feature information of the training sample at different granularities. More details of the training sample can be seen in the feature map with smaller granularity (also called denser granularity), and the overall information of the training sample can be seen in the feature map with larger granularity (also called sparser granularity).

[0154] In order to understand the present solution more intuitively, please refer to Figure 7, which is a schematic diagram of images of different scales provided in an embodiment of the present application. Figure 7 includes two left and right sub-schematic diagrams, and the left sub-schematic diagram and the right sub-schematic diagram of Figure 7 have the same size. In the left sub-schematic diagram of Figure 7, there are dogs, grass, trees and houses in the background in the image. After feature extraction of the left sub-schematic diagram of Figure 7, global features are obtained; in the right sub-schematic diagram of Figure 7, a partial area is extracted from the left sub-schematic diagram of Figure 7, which is enlarged to the same size as the left sub-schematic diagram of Figure 7. Feature extraction of the right sub-schematic diagram of Figure 7 obtains detailed feature information of the local area; the left sub-schematic diagram and the right sub-schematic diagram of Figure 7 represent images of different scales. It should be understood that the example in Figure 7 is only for the convenience of understanding the present solution and is not used to limit the present solution.

[0155] 506. The training device quantizes different groups in the second feature information using different quantization parameters.

[0156] In the embodiment of the present application, after the training device divides the second feature information of the training sample into multiple groups, it can use different quantization parameters to quantize different groups in the second feature information.

[0157] Optionally, if a second feature information of a training sample includes feature maps of L scales, the aforementioned second feature information can be divided into L groups in the training device, and L groups of quantization parameters corresponding one-to-one to the L groups (that is, L groups of quantization parameters corresponding one-to-one to the L scales) are stored on the training device, so that different groups in the second feature information are quantized using different quantization parameters; the meaning of "different quantization parameters" can be found in the above description and will not be repeated here.

[0158] To further understand this solution, the following is an example of the formula used to quantify the second characteristic information: q s (X1)=[q s1 (X 1 );q s2 (X 2 );q s3 (X 3 );…;q sL (X L )]

[0159] Among them, q s (X1) represents the quantization of the second feature information X1, X 1 、X 2 、X 3 …X L Represents the L groups included in the second feature information X1, where different groups in the L groups have different scales of feature maps, q s1 (X 1 ) represents the use of the first set of quantization parameters for X 1 The values ​​in are quantized, q s2 (X 2 ) represents the use of the second set of quantization parameters for X 2 The values ​​in are quantized, q s3 (X 3 ) represents the use of the third set of quantization parameters for X 3 The values ​​in are quantized, q sL (X L ) represents the Lth set of quantization parameters for X L The values ​​in are quantized, that is, different quantization parameters are used to quantize different groups in the L groups. It should be understood that the examples here are only for the convenience of understanding this solution and are not used to limit this solution.

[0160] Exemplarily, the training device can quantize each second feature information of the training sample using the method in steps 505 and 506; alternatively, the training device can also quantize part of the second feature information of the training sample using the method in steps 505 and 506. The specific second feature information to be quantified using the method in steps 505 and 506 can be flexibly determined based on the actual application scenario, and is not limited in the embodiments of this application.

[0161] In an embodiment of the present application, if the second feature information is obtained in the process of data processing of the training sample using the machine learning model, since the second feature information includes multiple feature maps of different scales, the second feature information is grouped based on the scale of each feature map, and different quantization parameters are used for different groups, that is, different quantization parameters are used for quantization of feature maps of different scales, which is beneficial to retaining the information carried by feature maps of different scales to avoid reducing the accuracy of the prediction results output by the machine learning model.

[0162] It should be noted that steps 502 and 503, step 504, and steps 505 and 506 are all optional steps. If steps 502 and 503, step 504, and / or steps 505 and 506 are executed, the embodiment of the present application does not limit the execution order of steps 502 and 503, step 504, and steps 505 and 506, nor does it limit the number of executions of steps 502 and 503, step 504, and steps 505 and 506. The specific execution times can be flexibly determined based on actual conditions and are not limited here.

[0163] For a more intuitive understanding of this solution, please refer to Figure 8, which is a schematic diagram of a quantization method for a model provided in an embodiment of the present application. In Figure 8, the task of the first model is target detection. The first model includes a feature extraction module (backbone), a feature processing module (neck), and a detection head module (head). As an example, the feature extraction module (backbone) and the feature processing module (neck) both contain transformer modules based on the attention mechanism, and the detection head module (head) is used to detect the category of the object and the position of the object, respectively.

[0164] As shown in FIG8 , during data processing of training samples using the first model, the feature extraction module (backbone), feature processing module (neck), and detection head module (head) in the first model can all generate first feature information of the training samples. The first feature information can then be quantified using the methods in steps 502 and 503. The activation layer in the feature extraction module (backbone) and the activation layer in the feature processing module (neck) can both generate activation values. The activation values ​​can then be quantified using the method in step 504. It should be understood that the example in FIG8 is merely for facilitating understanding of this solution and is not intended to limit this solution.

[0165] 507. The training device obtains the prediction result output by the first machine learning model, and trains the first machine learning model according to the expected result, prediction result and loss function corresponding to the training sample.

[0166] In an embodiment of the present application, after inputting a training sample into a first machine learning model and performing data processing on the training sample through the first machine learning model, the training device can obtain a prediction result output by the first machine learning model and generate a function value of a loss function based on the expected result corresponding to the training sample and the aforementioned prediction result. The aforementioned loss function indicates the similarity between the predicted result corresponding to the training sample and the expected result. Based on the function value of the loss function, the training device uses a backpropagation algorithm to update the weight parameters in the first machine learning model and some quantization parameters in steps 502 to 506, thereby completing a single training of the first machine learning model.

[0167] In the process of training the first machine learning model, because it is hoped that the output of the first machine learning model will be as close as possible to the desired value, the predicted value output by the first machine learning model can be compared with the desired expected value, and then the weight vector of each layer of the neural network can be updated according to the difference between the two (of course, there is usually an initialization process before the first update, that is, pre-configuring parameters for each layer in the first machine learning model). For example, if the model's predicted value is high, the weight vector is adjusted to make it predict lower, and the adjustment is continued until the first machine learning model can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to pre-define "how to compare the difference between the predicted value and the target value", which is the loss function or objective function. They are important equations used to measure the difference between the predicted value and the target value. Taking the loss function as an example, the higher the output value (loss) of the loss function, the greater the difference, so the training of the deep neural network becomes a process of minimizing this loss as much as possible.

[0168] Optionally, the training device may also quantify the weight parameters in the first machine learning model and adopt the quantized weight parameters in the next round of training of the first machine learning model.

[0169] The training device repeatedly executes steps 501 to 507 until the convergence condition of the loss function is met, so as to realize iterative training of the first machine learning model and obtain the trained first machine learning model and multiple sets of quantization parameters; the aforementioned multiple sets of quantization parameters are used to quantize the feature information and / or activation values ​​generated by the first machine learning model during the inference phase of the first machine learning model.

[0170] 2. Reasoning Stage

[0171] In the embodiment of the present application, the inference stage describes the process in which the execution device 230 uses the trained first machine learning model 201 to process the data to be processed and outputs a prediction result corresponding to the data to be processed. Specifically, please refer to Figure 9, which is a flow chart of a quantization method of the model provided in the embodiment of the present application. The quantization method of the model provided in the embodiment of the present application may include:

[0172] 901. The execution device inputs the data to be processed into the first machine learning model, wherein, in the process of processing the data to be processed using the first machine learning model, multiple feature information of the data to be processed and the activation value generated by the activation layer in the first machine learning model can be obtained.

[0173] 902. The execution device obtains first feature information and divides the first feature information into M sub-feature information, where the first feature information is included in multiple feature information of the data to be processed, and M is an integer greater than or equal to 2.

[0174] 903. The execution device quantizes the first sub-feature information using a first quantization parameter and quantizes the second sub-feature information using a second quantization parameter. The M sub-feature information includes the first sub-feature information and the second sub-feature information. The first quantization parameter and the second quantization parameter are different.

[0175] 904. The execution device quantizes a first sub-activation value in the first activation value using a first quantization step size, and quantizes a second sub-activation value in the first activation value using a second quantization step size, wherein the first machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, a distribution of first sub-activation values ​​corresponding to the first channel and a distribution of second sub-activation values ​​corresponding to the second channel are different, and the first quantization step size and the second quantization step size are different.

[0176] 905. The execution device divides the second feature information into multiple groups, each of the multiple groups includes at least one feature graph, and different groups in the multiple groups include feature graphs with different scales, wherein the first feature information is included in multiple feature information of the data to be processed, and the second feature information includes feature graphs of different scales.

[0177] 906. The execution device quantizes different groups in the second feature information using different quantization parameters.

[0178] 907. The execution device obtains the prediction result output by the first machine learning model.

[0179] In the embodiments of the present application, the specific implementation methods of steps 901 to 907 and the meanings of each noun in steps 901 to 907 can be found in the descriptions of the embodiments corresponding to Figure 5. The difference is that the "training sample" in the embodiment corresponding to Figure 5 is replaced by the "data to be processed" in the embodiment corresponding to Figure 9. The "data to be processed" is another name for the "input data" in the inference stage, and will not be repeated here one by one.

[0180] It should be noted that steps 902 and 903, step 904, and steps 905 and 906 are all optional steps. If steps 902 and 903, step 904, and / or steps 905 and 906 are executed, the embodiment of the present application does not limit the execution order of steps 902 and 903, step 904, and steps 905 and 906, nor does it limit the number of executions of steps 902 and 903, step 904, and steps 905 and 906. The specific execution times can be flexibly determined based on actual conditions and are not limited here.

[0181] In the embodiments of the present application, whether in the training stage or the inference stage of the machine learning model, as long as the machine learning model is used to process the input data, the quantization method of the model provided in the present application can be adopted, that is, not only the amount of computation when the machine learning model processes data on the execution device can be reduced, but also the amount of computation when the machine learning model processes data on the training device can be reduced.

[0182] In order to have a more intuitive understanding of the beneficial effects brought about by the quantification method of the model provided in this application, the following is explained in conjunction with the experimental data shown in Table 1 below.

[0183] Table 1

[0184] Among them, the DETR with improved denoising anchor boxes for end to end object detection (DINO) and the deformable detection transformer (Deformable DETR) of the Transformer model for performing target detection tasks are two machine learning models, floating point operations per second (FLOPs) is an indicator representing the amount of calculation, mAP is an indicator representing the accuracy, and channel-wise is an existing quantization method. As shown in Table 1, the quantization method of the model provided by this application not only greatly reduces the number of parameters of the machine learning model, reduces the amount of calculation of the machine learning model, but also avoids the reduction of the accuracy of the prediction results output by the model.

[0185] On the basis of the embodiments corresponding to Figures 1 to 9 , in order to better implement the above-mentioned solutions of the embodiments of the present application, the following also provides related devices for implementing the above-mentioned solutions. Specifically, refer to Figure 10 , which is a structural schematic diagram of a quantization device for a model provided in an embodiment of the present application. The quantization device 1000 of the model is applied in the process of data processing using a machine learning model. The quantization device of the model is used to quantize the activation values ​​generated by at least one activation layer in the machine learning model, where the at least one activation layer includes a first activation layer;

[0186] In which, the quantization device 1000 of the model includes: a quantization module 1001, which is used to quantize the first sub-activation value in the first activation value using a first quantization step size; the quantization module 1001 is also used to quantize the second sub-activation value in the first activation value using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different.

[0187] In one possible design, the distribution of the first sub-activation values ​​is different from the distribution of the second sub-activation values.

[0188] In one possible design, the machine learning model is a Transformer model.

[0189] In one possible design, multiple feature information of the input data can be obtained during data processing using a machine learning model, the multiple feature information including first feature information, and the quantization device 1000 of the model is further used to quantize the first feature information;

[0190] Please refer to Figure 11, which is another structural schematic diagram of the quantization device of the model provided in an embodiment of the present application. The quantization device 1000 of the model also includes: a grouping module 1002, which is used to divide the first feature information into at least two sub-feature information, where the at least two sub-feature information include first sub-feature information and second sub-feature information; the quantization module 1002 is further used to quantize the first sub-feature information using a first quantization parameter; the quantization module 1002 is further used to quantize the second sub-feature information using a second quantization parameter, where the first quantization parameter and the second quantization parameter are different.

[0191] In one possible design, the input data is an image, and the task of the machine learning model is to detect objects in the image.

[0192] In one possible design, multiple feature information of the input data can be obtained during data processing using a machine learning model. The multiple feature information includes second feature information, and the second feature information includes feature maps of different scales. The quantization device 1000 of the model is further used to quantize the second feature information.

[0193] Please refer to Figure 11. The quantization device 1000 of the model also includes: a grouping module 1002, which is used to divide the second feature information into multiple groups, each of the multiple groups includes at least one feature map, and different groups in the multiple groups include feature maps with different scales; a quantization module 1001, which is also used to quantize different groups using different quantization parameters.

[0194] In one possible design, the input data is an image, and the task of the machine learning model is any of the following: object detection on the image, semantic segmentation on the image, or super-resolution on the image.

[0195] In one possible design, the process of using a machine learning model to process data is in the inference phase of the machine learning model, or the process of using a machine learning model to process data is in the training phase of the machine learning model.

[0196] It should be noted that the information interaction, execution process, etc. between the modules / units in the model quantization device 1000 are based on the same concept as the various method embodiments corresponding to Figures 3 to 9 in this application. For specific contents, please refer to the description in the method embodiments shown above in this application, and will not be repeated here.

[0197] Please refer to FIG. 12 , which is another schematic diagram of the structure of a quantization device for a model provided in an embodiment of the present application. The quantization device 1200 for the model is applied to a process of processing data using a machine learning model. During the process of processing input data using the machine learning model, multiple feature information of the input data can be obtained. The multiple feature information includes first feature information. The quantization device 1200 for the model is used to quantize the first feature information.

[0198] The quantization device 1200 of the model includes: a grouping module 1201, configured to divide the first feature information into at least two sub-feature information, where the at least two sub-feature information include first sub-feature information and second sub-feature information; a quantization module 1202, configured to quantize the first sub-feature information using a first quantization parameter; and the quantization module 1202, further configured to quantize the first sub-feature information using a second quantization parameter, where the first quantization parameter and the second quantization parameter are different.

[0199] In one possible design, the model quantization device 1200 is further configured to quantize activation values ​​generated by at least one activation layer in the machine learning model, the at least one activation layer including a first activation layer;

[0200] Among them, the quantization module 1202 is further used to quantize the first sub-activation value in the first activation value using a first quantization step size; the quantization module 1202 is further used to quantize the second sub-activation value in the second activation value using a second quantization step size, wherein the machine learning model includes multiple channels, the first sub-activation value corresponds to a first channel among the multiple channels, the second sub-activation value corresponds to a second channel among the multiple channels, and the first quantization step size and the quantization step size are different.

[0201] It should be noted that the information interaction, execution process, etc. between the modules / units in the model quantization device 1200 are based on the same concept as the various method embodiments corresponding to Figures 3 to 9 in this application. For specific contents, please refer to the description in the method embodiments shown above in this application, and will not be repeated here.

[0202] Next, an electronic device provided in an embodiment of the present application is introduced. The electronic device can be expressed as a training device for a first machine learning model, or as an execution device for configuring a first machine learning model. When the electronic device is expressed as an execution device, please refer to Figure 13. Figure 13 is a structural schematic diagram of an execution device provided in an embodiment of the present application. The execution device 1300 can be specifically expressed as a virtual reality (VR) device, a mobile phone, a tablet, a laptop, a smart wearable device, a monitoring data processing device, or a radar data processing device, etc., which is not limited here. Specifically, the execution device 1300 includes: a receiver 1301, a transmitter 1302, a processor 1303, and a memory 1304 (wherein the number of processors 1303 in the execution device 1300 can be one or more, and Figure 13 takes one processor as an example), wherein the processor 1303 may include an application processor 13031 and a communication processor 13032. In some embodiments of the present application, the receiver 1301, the transmitter 1302, the processor 1303, and the memory 1304 may be connected via a bus or other means.

[0203] Memory 1304 may include read-only memory and random access memory, and provides instructions and data to processor 1303. A portion of memory 1304 may also include non-volatile random access memory (NVRAM). Memory 1304 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.

[0204] Processor 1303 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.

[0205] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1303. Processor 1303 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits or software instructions in processor 1303. The above processor 1303 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 1303 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 1304, and processor 1303 reads the information in memory 1304 and, in conjunction with its hardware, completes the steps of the above method.

[0206] Receiver 1301 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 1302 can be used to output digital or character information through the first interface. Transmitter 1302 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 1302 can also include a display device such as a display screen.

[0207] In one embodiment of the present application, the application processor 13031 in the processor 1303 is configured to execute the quantization method for the model executed by the execution device in the embodiments corresponding to Figures 3 to 9. It should be noted that the specific manner in which the application processor 13031 executes the above-mentioned steps is based on the same concept as the various method embodiments corresponding to Figures 3 to 9 in the present application, and the technical effects brought about are the same as the various method embodiments corresponding to Figures 3 to 9 in the present application. For specific details, please refer to the description of the method embodiments shown above in the present application, and will not be repeated here.

[0208] When the electronic device is a training device, please refer to Figure 14, which is a schematic diagram of the structure of a training device provided in an embodiment of the present application. Specifically, the training device 1400 is implemented by one or more servers. The training device 1400 may vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1422 (for example, one or more processors) and memory 1432, and one or more storage media 1430 (for example, one or more mass storage devices) storing application programs 1442 or data 1444. Memory 1432 and storage medium 1430 can be temporary storage or permanent storage. The program stored in storage medium 1430 may include one or more modules (not shown), each of which may include a series of instruction operations in the training device. Furthermore, the CPU 1422 may be configured to communicate with the storage medium 1430 to execute the series of instruction operations in the storage medium 1430 on the training device 1400.

[0209] The training device 1400 may also include one or more power supplies 1426, one or more wired or wireless network interfaces 1450, one or more input and output interfaces 1458, and / or one or more operating systems 1441, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0210] In the embodiment of the present application, the central processing unit 1422 is used to execute the quantization method of the model executed by the training device in the embodiment corresponding to Figure 12. It should be noted that the specific manner in which the central processing unit 1422 executes the above-mentioned steps is based on the same concept as the various method embodiments corresponding to Figure 12 in the present application, and the technical effects brought about are the same as the various method embodiments corresponding to Figure 12 in the present application. For specific details, please refer to the description of the method embodiments shown above in the present application, and will not be repeated here.

[0211] An embodiment of the present application also provides a computer program product, which, when running on a computer, enables the computer to execute the steps performed by the training device in the method described in the embodiments shown in Figures 3 to 8 above, or enables the computer to execute the steps performed by the execution device in the method described in the embodiment shown in Figure 9 above.

[0212] A computer-readable storage medium is also provided in an embodiment of the present application. The computer-readable storage medium stores a program for signal processing. When the computer-readable storage medium is run on a computer, the computer executes the steps executed by the training device in the method described in the embodiments shown in Figures 3 to 8 above, or the computer executes the steps executed by the execution device in the method described in the embodiment shown in Figure 9 above.

[0213] The execution device, training device or model quantization device provided in the embodiments of the present application can be a chip, and the chip includes: a processing unit and a communication unit, the processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, a pin or a circuit, etc. The processing unit can execute the computer execution instructions stored in the storage unit so that the chip executes the quantization method of the model described in the embodiments shown in Figures 3 to 9 above. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit can also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0214] Specifically, see Figure 15 , which is a schematic diagram of the structure of a chip provided in an embodiment of the present application. The chip can be implemented as a neural network processor NPU 150. NPU 150 is mounted on the host CPU (host CPU) as a coprocessor and is assigned tasks by the host CPU. The core of the NPU is the arithmetic circuit 150, which controls the arithmetic circuit 1503 through the controller 1504 to extract matrix data from the memory and perform multiplication operations.

[0215] In some implementations, arithmetic circuit 1503 includes multiple processing units (PEs). In some implementations, arithmetic circuit 1503 is a two-dimensional systolic array. Arithmetic circuit 1503 can also be a one-dimensional systolic array or other electronic circuitry capable of performing mathematical operations such as multiplication and addition. In some implementations, arithmetic circuit 1503 is a general-purpose matrix processor.

[0216] For example, assume there are input matrix A, weight matrix B, and output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from weight memory 1502 and caches it on each PE in the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from input memory 1501 and performs a matrix operation on matrix B. The partial or final matrix result is stored in accumulator 1508.

[0217] Unified memory 1506 is used to store input and output data. Weight data is directly transferred to weight memory 1502 through the Direct Memory Access Controller (DMAC) 1505. Input data is also transferred to unified memory 1506 through the DMAC.

[0218] BIU stands for Bus Interface Unit 1510 , which is used for interaction between the AXI bus, DMAC, and instruction fetch buffer (IFB) 1509 .

[0219] The bus interface unit 1510 (BIU) is used for the instruction fetch memory 1509 to obtain instructions from the external memory, and is also used for the storage unit access controller 1505 to obtain the original data of the input matrix A or the weight matrix B from the external memory.

[0220] DMAC is mainly used to transfer input data in the external memory DDR to the unified memory 1506 or transfer weight data to the weight memory 1502 or transfer input data to the input memory 1501.

[0221] The vector calculation unit 1507 includes multiple operation processing units. When necessary, it further processes the output of the operation circuit, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional / fully connected layer network calculations in neural networks, such as batch normalization, pixel-level summation, and upsampling of feature planes.

[0222] In some implementations, the vector calculation unit 1507 can store the processed output vector to the unified memory 1506. For example, the vector calculation unit 1507 can apply a linear function and / or a nonlinear function to the output of the operation circuit 1503, such as linear interpolation of the feature plane extracted by the convolution layer, or accumulate a vector of values ​​to generate an activation value. In some implementations, the vector calculation unit 1507 generates a normalized value, a pixel-level summed value, or both. In some implementations, the processed output vector can be used as an activation input to the operation circuit 1503, such as for use in subsequent layers in a neural network.

[0223] An instruction fetch buffer 1509 connected to the controller 1504 is used to store instructions used by the controller 1504;

[0224] Unified memory 1506, input memory 1501, weight memory 1502, and instruction fetch memory 1509 are all on-chip memories. External memories are private to the NPU hardware architecture.

[0225] In which, the operations of each layer in the first machine learning model shown in the above embodiments can be performed by the operation circuit 1503 or the vector calculation unit 1507.

[0226] The processor mentioned in any of the above places can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the program of the above-mentioned first aspect method.

[0227] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.

[0228] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by dedicated hardware including application-specific integrated circuits, dedicated CPUs, dedicated memories, dedicated components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits, or dedicated circuits. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.

[0229] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0230] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

Claims

1. A quantization method of a model, characterized in that: The method is applied in a process of processing data using a machine learning model, wherein the quantization method of the model includes quantizing an activation value generated by at least one activation layer in the machine learning model, wherein the at least one activation layer includes a first activation layer; wherein quantizing a first activation value generated by the first activation layer includes: quantizing a first sub-activation value in the first activation value using a first quantization step size; A second sub-activation value in the first activation value is quantized using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size and the second quantization step size are different.

2. The method according to claim 1, characterized in that: A distribution of the first sub-activation values ​​is different from a distribution of the second sub-activation values.

3. The method according to claim 1 or 2, characterized in that: The machine learning model is a Transformer model.

4. The method according to any one of claims 1 to 3, characterized in that: In the process of processing the input data using the machine learning model, multiple feature information of the input data can be obtained, the multiple feature information includes first feature information, and the quantization method of the model also includes quantizing the first feature information; wherein the quantizing the first feature information includes: Dividing the first feature information into at least two sub-feature information, wherein the at least two sub-feature information include first sub-feature information and second sub-feature information; quantizing the first sub-feature information using a first quantization parameter; The second sub-feature information is quantized using a second quantization parameter, and the first quantization parameter is different from the second quantization parameter.

5. The method according to claim 4, characterized in that The input data is an image, and the task of the machine learning model is to perform target detection on the image.

6. The method according to any one of claims 1 to 5, characterized in that: In the process of processing the input data using the machine learning model, multiple feature information of the input data can be obtained, the multiple feature information includes second feature information, the second feature information includes feature maps of different scales, and the quantization method of the model also includes quantizing the second feature information; wherein the quantizing the second feature information includes: Dividing the second feature information into a plurality of groups, each of the plurality of groups comprising at least one feature graph, and feature graphs included in different groups of the plurality of groups have different scales; Different quantization parameters are used to perform quantization on the different groups.

7. The method according to claim 6, characterized in that The input data is an image, and the task of the machine learning model is any one of the following: performing target detection on the image, performing semantic segmentation on the image, or performing super-resolution processing on the image.

8. The method according to any one of claims 1 to 7, characterized in that: The process of using the machine learning model to process data is in the inference phase of the machine learning model, or the process of using the machine learning model to process data is in the training phase of the machine learning model.

9. A method for quantifying a model, characterized in that: The method is applied in a process of processing data using a machine learning model. In the process of processing input data using the machine learning model, multiple feature information of the input data can be obtained, and the multiple feature information includes first feature information. The quantization method of the model includes quantizing the first feature information; wherein the quantizing the first feature information includes: Dividing the first feature information into at least two sub-feature information, wherein the at least two sub-feature information include first sub-feature information and second sub-feature information; quantizing the first sub-feature information using a first quantization parameter; The first sub-feature information is quantized using a second quantization parameter, where the first quantization parameter is different from the second quantization parameter.

10. The method according to claim 9, characterized in that The quantization method of the model further includes quantizing an activation value generated by at least one activation layer in the machine learning model, wherein the at least one activation layer includes a first activation layer; wherein quantizing a first activation value generated by the first activation layer includes: quantizing a first sub-activation value in the first activation value using a first quantization step size; The second sub-activation value in the second activation value is quantized using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size is different from the second quantization step size.

11. A quantization device for a model, characterized in that: The quantization device of the model is applied in a process of processing data using a machine learning model, and the quantization device of the model is used to quantize activation values ​​generated by at least one activation layer in the machine learning model, and the at least one activation layer includes a first activation layer; Wherein, the quantization device of the model includes: a quantization module, configured to quantize a first sub-activation value in the first activation value by using a first quantization step size; The quantization module is further used to quantize a second sub-activation value in the first activation value using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size is different from the second quantization step size.

12. The device according to claim 11, characterized in that A distribution of the first sub-activation values ​​is different from a distribution of the second sub-activation values.

13. The device according to claim 11 or 12, characterized in that The machine learning model is a Transformer model.

14. The device according to any one of claims 11 to 13, characterized in that In the process of processing the input data using the machine learning model, multiple feature information of the input data can be obtained, the multiple feature information includes first feature information, and the quantization device of the model is also used to quantize the first feature information; The quantization device of the model further includes: a grouping module, used to divide the first feature information into at least two sub-feature information, the at least two sub-feature information including first sub-feature information and second sub-feature information; The quantization module is further configured to quantize the first sub-feature information using a first quantization parameter; The quantization module is further configured to quantize the second sub-feature information by using a second quantization parameter, where the first quantization parameter is different from the second quantization parameter.

15. The device according to claim 14, characterized in that The input data is an image, and the task of the machine learning model is to perform target detection on the image.

16. The device according to any one of claims 11 to 15, characterized in that In the process of processing the input data using the machine learning model, multiple feature information of the input data can be obtained, the multiple feature information includes second feature information, the second feature information includes feature maps of different scales, and the quantization device of the model is also used to quantize the second feature information; The quantization device of the model further includes: a grouping module, used to divide the second feature information into a plurality of groups, each of the plurality of groups includes at least one feature map, and the feature maps included in different groups in the plurality of groups have different scales; The quantization module is further used to quantize the different groups using different quantization parameters.

17. The device according to claim 16, characterized in that The input data is an image, and the task of the machine learning model is any one of the following: performing target detection on the image, performing semantic segmentation on the image, or performing super-resolution processing on the image.

18. The device according to any one of claims 11 to 17, characterized in that The process of using the machine learning model to process data is in the inference phase of the machine learning model, or the process of using the machine learning model to process data is in the training phase of the machine learning model.

19. A quantization device for a model, characterized in that: The quantization device of the model is applied in the process of data processing by using the machine learning model. In the process of data processing by using the machine learning model, multiple feature information of the input data can be obtained, and the multiple feature information includes first feature information. The quantization device of the model is used to quantize the first feature information; wherein the quantization device of the model includes: A grouping module, used for dividing the first feature information into at least two sub-feature information, wherein the at least two sub-feature information include first sub-feature information and second sub-feature information; A quantization module, configured to quantize the first sub-feature information using a first quantization parameter; The quantization module is further configured to quantize the first sub-feature information by using a second quantization parameter, where the first quantization parameter is different from the second quantization parameter.

20. The device according to claim 19, characterized in that The quantization device of the model is also used to quantize the activation value generated by at least one activation layer in the machine learning model, and the at least one activation layer includes a first activation layer; wherein, The quantization module is further configured to quantize a first sub-activation value in the first activation value by using a first quantization step size; The quantization module is further used to quantize a second sub-activation value in the second activation value using a second quantization step size, wherein the machine learning model includes multiple channels, the multiple channels include a first channel and a second channel, the first sub-activation value corresponds to the first channel, the second sub-activation value corresponds to the second channel, and the first quantization step size is different from the second quantization step size.

21. A computer program product, characterized in that The computer program product comprises a program, and when the program is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 10 .

22. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program, and when the program is executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 10.

23. An electronic device, characterized in that: comprising a processor and a memory, the processor being coupled to the memory, The memory is used to store programs; The processor is configured to execute the program in the memory so that the execution device executes the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Deep learning feature compression and decompression method, system and terminal

    CN113163203A

  • Optimizing low precision inference models for deployment of deep neural networks

    CN115053230A

  • Model quantification method and related equipment

    CN116362301A

  • Per-embedding-group activation quantization

    US20230139347A1