Quantization method, device, electronic device and storage medium of neural network model
Through frequency domain information processing and quantization operation, the quantitative method of the neural network model solves the problem of selecting weight parameters accuracy, improves the accuracy and calculation efficiency of the model, and is suitable for edge-side calculations.
Patent Information
- Application Number
- CN202210834679.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-14
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-07-14
AI Technical Summary
The existing neural network model quantization method is difficult to accurately select the appropriate quantization accuracy of weight parameters of each layer, resulting in reduced accuracy and poor computational efficiency.
By obtaining the frequency domain information of the channel weights of the layer to be quantized, high-frequency information is extracted, weights are updated, and quantized the layer based on these updated weights. Considering the influence of high and low frequency information between weights, the appropriate quantization bit is selected. Width.
It improves the accuracy and computing efficiency of neural network model quantization, and is suitable for edge-end computing environments.
Smart Images

Figure CN115115051B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, in particular to the field of artificial intelligence technology, and specifically to a quantization method, device, electronic device, computer-readable storage medium, and computer program product for a neural network model. Background Art
[0002] Artificial intelligence is a discipline that studies how to use computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0003] Nowadays, more and more deep learning-related solutions are being applied, and the neural network model is the top priority of the entire process during the deployment phase. This process involves two important indicators: model running speed and model transmission bandwidth. The faster the running speed, the smaller the bandwidth required for model transmission, which can effectively improve efficiency and save computing power for customers. Quantization of neural networks is one of the effective ways to solve this problem. Quantization can effectively reduce the size of the model and increase the running speed.
[0004] The methods described in this section are not necessarily methods that have been previously conceived or employed. Unless otherwise indicated, it should not be assumed that any method described in this section is considered to be prior art simply because it is included in this section. Similarly, unless otherwise indicated, the issues mentioned in this section should not be considered to have been recognized in any prior art. Summary of the invention
[0005] The present disclosure provides a quantization method, device, electronic device, computer-readable storage medium and computer program product for a neural network model.
[0006] According to one aspect of the present disclosure, a quantization method for a neural network model is provided, comprising: obtaining a layer to be quantized in the neural network model, the layer to be quantized comprising multiple channels, each of the multiple channels having a corresponding weight; for each of the multiple channels, based on the corresponding weight of the channel, obtaining high-frequency information in frequency domain information corresponding to the corresponding weight; based on the high-frequency information in the frequency domain information corresponding to the corresponding weight of each channel in the multiple channels, obtaining an updated weight of the channel; and performing a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels.
[0007] According to another aspect of the present disclosure, a quantization device for a neural network model is provided, comprising: a first acquisition unit, configured to obtain a layer to be quantized in the neural network model, the layer to be quantized comprising multiple channels, each of the multiple channels having a corresponding weight; a second acquisition unit, configured to obtain, for each of the multiple channels, high-frequency information in frequency domain information corresponding to the corresponding weight based on the corresponding weight of the channel; a third acquisition unit, configured to obtain an updated weight of the channel based on the high-frequency information in the frequency domain information corresponding to the corresponding weight of each channel in the multiple channels; and a quantization unit, configured to perform a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels.
[0008] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to an embodiment of the present disclosure.
[0009] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method according to the embodiment of the present disclosure.
[0010] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the method according to the embodiment of the present disclosure is implemented.
[0011] According to one or more embodiments of the present disclosure, the accuracy of quantization of a neural network model can be improved.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0014] Figure 1 A schematic diagram showing an exemplary system in which the various methods described herein may be implemented according to an embodiment of the present disclosure;
[0015] Figure 2 A flowchart of a quantization method of a neural network model according to an embodiment of the present disclosure is shown;
[0016] Figure 3 A flowchart showing a process of obtaining high-frequency information in frequency domain information corresponding to the corresponding weight value based on the corresponding weight value of the channel in a quantization method of a neural network model according to an embodiment of the present disclosure;
[0017] Figure 4 A flowchart showing a process of performing a filtering operation on frequency domain information corresponding to corresponding weights in a quantization method of a neural network model according to an embodiment of the present disclosure is shown;
[0018] Figure 5 A flowchart showing a process of performing a quantization operation on a to-be-quantized layer based on an updated weight value of each channel in a plurality of channels in a quantization method of a neural network model according to an embodiment of the present disclosure is shown;
[0019] Figure 6 A flowchart of a process of obtaining the corresponding sensitivity of a layer to be quantized based on an updated weight of each of a plurality of channels in a quantization method of a neural network model according to an embodiment of the present disclosure is shown;
[0020] Figure 7 A structural block diagram of a quantization device for a neural network model according to an embodiment of the present disclosure is shown; and
[0021] Figure 8 A structural block diagram of an exemplary electronic device that can be used to implement the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0022] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0023] In the present disclosure, unless otherwise specified, the use of the terms "first", "second", etc. to describe various elements is not intended to limit the positional relationship, temporal relationship, or importance relationship of these elements, and such terms are only used to distinguish one element from another element. In some examples, the first element and the second element may refer to the same instance of the element, and in some cases, based on the description of the context, they may also refer to different instances.
[0024] The terms used in the description of various examples in this disclosure are only for the purpose of describing specific examples and are not intended to be limiting. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element can be one or more. In addition, the term "and / or" used in this disclosure covers any one of the listed items and all possible combinations.
[0025] The embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
[0026] Figure 1 FIG. 1 is a schematic diagram of an exemplary system 100 in which various methods and apparatuses described herein may be implemented according to an embodiment of the present disclosure. Figure 1 , the system 100 includes one or more client devices 101, 102, 103, 104, 105, and 106, a server 120, and one or more communication networks 110 coupling the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105, and 106 may be configured to execute one or more applications.
[0027] In an embodiment of the present disclosure, the server 120 may run one or more services or software applications that enable execution of a quantization method for a neural network model.
[0028] In some embodiments, server 120 may also provide other services or software applications, which may include non-virtualized environments and virtualized environments. In some embodiments, these services may be provided as web-based services or cloud services, such as provided to users of client devices 101, 102, 103, 104, 105, and / or 106 under a software as a service (SaaS) model.
[0029] exist Figure 1 In the configuration shown, the server 120 may include one or more components that implement the functions performed by the server 120. These components may include software components, hardware components, or a combination thereof that can be executed by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and / or 106 may in turn utilize one or more client applications to interact with the server 120 to utilize the services provided by these components. It should be understood that a variety of different system configurations are possible, which may differ from the system 100. Therefore, Figure 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.
[0030] The user may use client devices 101, 102, 103, 104, 105 and / or 106 to receive the quantization results of the neural network model. The client device may provide an interface that enables the user of the client device to interact with the client device. The client device may also output information to the user via the interface. Figure 1 Only six client devices are depicted, but one skilled in the art will appreciate that the present disclosure may support any number of client devices.
[0031] Client devices 101, 102, 103, 104, 105 and / or 106 may include various types of computer devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, game systems, thin clients, various messaging devices, sensors or other sensing devices, etc. These computer devices may run various types and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as GOOGLE Chrome OS); or include various mobile operating systems, such as MICROSOFT Windows Mobile OS, iOS, Windows Phone, Android. Portable handheld devices may include cellular phones, smart phones, tablet computers, personal digital assistants (PDAs), etc. Wearable devices may include head-mounted displays (such as smart glasses) and other devices. Game systems may include various handheld game devices, Internet-enabled game devices, etc. Client devices are capable of executing various different applications, such as various Internet-related applications, communication applications (such as email applications), short message service (SMS) applications, and may use various communication protocols.
[0032] The network 110 may be any type of network known to those skilled in the art that may support data communications using any of a variety of available protocols, including but not limited to TCP / IP, SNA, IPX, etc. By way of example only, the one or more networks 110 may be a local area network (LAN), an Ethernet-based network, a token ring, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a blockchain network, a public switched telephone network (PSTN), an infrared network, a wireless network (e.g., Bluetooth, WIFI), and / or any combination of these and / or other networks.
[0033] Server 120 may include one or more general purpose computers, dedicated server computers (e.g., PC (personal computer) servers, UNIX servers, mid-range servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and / or combination. Server 120 may include one or more virtual machines running virtual operating systems, or other computing architectures involving virtualization (e.g., one or more flexible pools of logical storage devices that may be virtualized to maintain a server's virtual storage device). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.
[0034] The computing units in the server 120 may run one or more operating systems including any of the above operating systems and any commercially available server operating systems. The server 120 may also run any of a variety of additional server applications and / or middle-tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.
[0035] In some implementations, server 120 may include one or more applications to analyze and consolidate data feeds and / or event updates received from users of client devices 101, 102, 103, 104, 105, and / or 106. Server 120 may also include one or more applications to display data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and / or 106.
[0036] In some embodiments, the server 120 may be a server of a distributed system, or a server combined with a blockchain. The server 120 may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. A cloud server is a host product in a cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and virtual private servers (VPS) services.
[0037] The system 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of the databases 130 may be used to store information such as audio files and video files. The databases 130 may reside in various locations. For example, the database used by the server 120 may be local to the server 120, or may be remote from the server 120 and may communicate with the server 120 via a network-based or dedicated connection. The databases 130 may be of different types. In some embodiments, the databases used by the server 120 may be, for example, relational databases. One or more of these databases may store, update, and retrieve data to and from the databases in response to commands.
[0038] In some embodiments, one or more of the databases 130 may also be used by applications to store application data. The databases used by the applications may be different types of databases, such as a key-value store, an object store, or a conventional store backed by a file system.
[0039] Figure 1 The system 100 may be configured and operated in various ways to enable the application of various methods and apparatuses described in the present disclosure.
[0040] The quantization precision used in the process of quantizing the neural network model mainly includes FP32, FP16, INT8, INT4, INT2, etc. Among them, FP32 has high precision because it uses floating-point operations, and neural networks are generally trained with FP32, so FP32 precision can well reflect the precision obtained by training in reasoning; F16 and INT8 are second, using half-precision or integer to represent a number. The intuitive feeling is that the bit width occupied by a number in the storage weight is small, and the overall storage capacity is naturally small. Secondly, using a number with a small bit width for calculation, the required computing power becomes smaller, and the lower bit quantization precision corresponds to smaller storage, faster transmission, and faster calculation, which is especially important for terminals with limited computing power at the edge, but the corresponding accuracy will also be reduced to a certain extent. This naturally leads to a problem. If the hardware allows, mixed precision can be selected for quantization. For example, some weights can be calculated with FP16 precision, and the other weights can be calculated with INT8 precision, or even with lower bit INT4 or INT2 precision. How to choose appropriate quantization accuracy for the weight parameters of each layer in the neural network model is an issue that needs to be explored in the quantization process of the neural network model.
[0041] According to one aspect of the present disclosure, a quantization method for a neural network model is provided. Figure 2 As shown, the quantization method 200 of the neural network model according to some embodiments of the present disclosure includes:
[0042] Step S210: obtaining a layer to be quantized in the neural network model, wherein the layer to be quantized includes a plurality of channels, and each of the plurality of channels has a corresponding weight;
[0043] Step S220: for each channel of the plurality of channels, based on a corresponding weight of the channel, obtaining high-frequency information in the frequency domain information corresponding to the corresponding weight;
[0044] Step S230: obtaining an updated weight value of each channel in the plurality of channels based on the high frequency information in the frequency domain information corresponding to the corresponding weight value of the channel; and
[0045] Step S240: performing a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels.
[0046] In the related art, the methods of quantizing neural network models include manual experience selection and automatic selection. Manual experience selection, based on application engineering experience, generally selects high precision such as FP32 floating point format for the first and last layers, and other methods such as layernorm and softmax generally use FP32 floating point format, etc.; and automatic selection can also be divided into two methods, automatic search and learning methods and methods based on model accuracy sensitivity. The automatic search and learning method is time-consuming and labor-intensive. With each additional layer of weight quantization, the search space grows exponentially, requiring large-scale computing resources and a long search time, making it difficult to achieve rapid response in actual engineering. At the same time, the method based on model accuracy sensitivity directly uses the sum of the absolute values of the weights to average, and determines the model sensitivity based on the global average value. It only considers the size of the weights, but does not consider the influence between the weights, making the quantization results of the neural network model inaccurate.
[0047] According to an embodiment of the present disclosure, by obtaining the arrangement of corresponding weights in the frequency domain (i.e., frequency domain information) of each channel of the layer to be quantized, and obtaining updated weights corresponding to each channel for high-frequency information, the layer to be quantized is quantized based on the updated weights of each channel, so that the influence of high- and low-frequency information between multiple weights of the same layer is considered in the model quantization process, that is, the influence between weights is considered, so that the quantization of the neural network model is more accurate.
[0048] The weight frequency and weight size are different. From the perspective of bionics, the weights of a neural network are similar to neurons in the human brain, and neurons are related to each other. If the intuitive relationship in the time domain is the difference between the weight sizes, then in the frequency domain it is the difference between amplitude and phase. Considering that high-frequency areas in the frequency domain are also more sensitive areas in the time domain. By obtaining high-frequency information in the frequency domain information, more sensitive weights can be obtained, and then the quantization bit width of the more sensitive weights can be selected, so that the selected quantization bit width is accurate, that is, the quantization of the neural network model is accurate.
[0049] In some embodiments, the neural network model can be any trained neural network model, such as a face recognition model, an image classification model, etc., which is not limited here.
[0050] In some embodiments, the layer to be quantized may be any network layer in a neural network model, for example, a convolutional layer, an input layer, an output layer, etc.
[0051] In some embodiments, in step S210, a network layer specified by an expert based on experience is used as a layer to be quantized. For example, the expert specifies a convolutional layer to be quantized, and the convolutional layer is used as a layer to be quantized.
[0052] In some embodiments, each network layer in the neural network model is used as a layer to be quantized.
[0053] In some embodiments, in response to obtaining the layer to be quantized, a weight parameter of the layer to be quantized is obtained, wherein the weight parameter includes a weight value of each channel of a plurality of channels corresponding to the layer to be quantized.
[0054] In one example, the weight parameters are represented as a 64×128×128 matrix, where there are 64 channels and the corresponding weight of each channel can be represented as a 128×128 matrix.
[0055] In some embodiments, in step S220, a time-frequency transform is performed on each of the multiple channels to obtain frequency domain information corresponding to the channel.
[0056] In some embodiments, Figure 3 As shown, based on the corresponding weight of the channel, obtaining the high-frequency information in the frequency domain information corresponding to the corresponding weight includes:
[0057] Step S310: performing time-frequency transformation on the corresponding weights to obtain frequency domain information corresponding to the corresponding weights; and
[0058] Step S320: performing a filtering operation on the frequency domain information corresponding to the corresponding weight value to obtain high frequency information in the frequency domain information corresponding to the corresponding weight value.
[0059] The purpose of time-frequency transformation is to reflect the relationship in the time domain in the frequency domain through transformation. Through time-frequency transformation, the relationship between weights in the time domain can be transformed into the information of weights in the frequency domain. The information of weights in the frequency domain includes the influence between weights.
[0060] At the same time, high-frequency information is obtained by performing filtering operations on frequency domain information corresponding to corresponding weights, so that the method for obtaining high-frequency information is simple and the amount of data processing is small.
[0061] In some embodiments, the time-frequency transform is performed by performing Fourier transform on the corresponding weights.
[0062] In some embodiments, the frequency domain information includes information within a certain frequency range, wherein the frequency greater than a preset frequency threshold is high-frequency information, and vice versa is low-frequency information.
[0063] In some embodiments, the frequency domain information includes a spectrum graph, and the spectrum graph from the edge to the center of the spectrum graph corresponds to the information from the lowest to the highest frequency in the frequency domain information, such as Figure 4 As shown, performing a filtering operation on the frequency domain information corresponding to the corresponding weight includes:
[0064] Step S410: performing a shift operation on the frequency spectrum corresponding to the corresponding weight value to obtain an updated frequency spectrum corresponding to the corresponding weight value, wherein the information at the lowest frequency in the frequency domain information corresponding to the weight parameter corresponds to the center of the updated frequency spectrum; and
[0065] Step S420: removing a preset area surrounding the center in the updated spectrum graph corresponding to the corresponding weight to obtain a residual spectrum graph corresponding to the corresponding weight, wherein the spectrum in the residual spectrum graph corresponds to high-frequency information in the frequency domain information of the corresponding weight.
[0066] By means of the shift operation, the updated spectrum diagram is obtained, so that the method of obtaining the high-frequency information in the frequency domain information corresponding to the corresponding weight value is simple and the amount of data processing is small.
[0067] In one example, the low-frequency information is located at the four corners of the square spectrum graph, and an updated spectrum graph is obtained by shifting the four corners of the spectrum graph to the center of the spectrum graph, and the updated spectrum graph is still square.
[0068] In some embodiments, the preset area occupies 1 / 3 to 1 / 2 of the entire area of the updated spectrum graph.
[0069] The preset area occupies 1 / 3-1 / 2 of the total area, which makes the high-frequency information obtained accurate while ensuring that the subsequent data processing volume is small.
[0070] In some embodiments, step S230, based on the high frequency information in the frequency domain information corresponding to the corresponding weight of each channel in the multiple channels, obtaining the updated weight of the channel includes:
[0071] Based on the high frequency information corresponding to the corresponding weight of each channel in the multiple channels, an inverse time-frequency transform is performed to obtain an updated weight of the channel.
[0072] By performing inverse time-frequency transform on high-frequency information, updated weights are obtained to reduce the amount of data processing.
[0073] By performing an inverse video transform on the high-frequency information corresponding to the corresponding weights of each channel and transforming the high-frequency information into time domain information, a more sensitive weight in the time domain can be obtained (i.e., the updated weight reflects the time domain sensitivity of the weight), and quantization operations are performed based on these weights, so that the quantization accuracy is high.
[0074] In one example, the corresponding weight of each channel is represented as a 128×128 matrix. After step S230, the obtained updated weight of each channel is represented as a 128×128 matrix.
[0075] In some embodiments, Figure 5 As shown, based on the updated weight of each channel in the multiple channels, performing a quantization operation on the layer to be quantized includes:
[0076] Step S510: obtaining the corresponding sensitivity of the layer to be quantized based on the updated weight of each channel in the multiple channels; and
[0077] Step S520: obtaining a quantization bit width corresponding to the sensitivity from a plurality of quantization bit widths in the mixed precision quantization space, and determining the quantization bit width as the quantization bit width of the layer to be quantized.
[0078] Since updating the weights reflects the time domain sensitivity of the weights, by updating the weights, calculating the sensitivity, and determining the quantization bit width based on the sensitivity, the quantization accuracy is high.
[0079] In some embodiments, Figure 6 As shown, based on the updated weight of each channel in the multiple channels, obtaining the corresponding sensitivity of the layer to be quantized includes:
[0080] Step S610: obtaining the sum of the absolute values of the updated weights of each channel in the plurality of channels; and
[0081] Step S620: Obtain the corresponding sensitivity of the layer to be quantized based on the sum of multiple absolute values corresponding to the multiple channels.
[0082] The sensitivity is calculated by obtaining the sum of the absolute values of each channel in the multiple channels, thereby realizing the calculation of the sensitivity.
[0083] For example, the updated weights of each channel are represented as a 128×128 matrix, and the absolute value sum of the channel is obtained by taking the absolute value of each element in the matrix and calculating the sum of the absolute values of all elements in the matrix.
[0084] In some embodiments, the sensitivity includes at least one of the following:
[0085] an average of the sums of the plurality of absolute values; and
[0086] A ratio between a difference between a maximum value and a minimum value in the plurality of absolute value sums and the number of the plurality of channels.
[0087] For example, the sum of multiple absolute values corresponding to n channels of the layer to be quantized is expressed as Mn1, Mn2…Mnn, then
[0088] The sensitivity can be calculated by formula (1) or formula (2):
[0089]
[0090]
[0091] It can be understood that the above method of obtaining sensitivity using formula (1) or (2) is merely exemplary, and those skilled in the art should understand that other arbitrary mathematical statistical methods (for example, taking the variance of the sum of the absolute values of the weights of each channel, etc.) can also be used to calculate the sensitivity.
[0092] In some embodiments, during quantization of a neural network model, a selection is made from the following quantization bit widths: FP32, FP16, INT8, INT4, INT2.
[0093] In some embodiments, each quantization bit width corresponds to a corresponding sensitivity interval, and in response to the sensitivity of the layer to be quantized being in a first sensitivity interval, the quantization bit width corresponding to the first sensitivity interval is determined as the quantization bit width of the layer to be quantized.
[0094] In some embodiments, the neural network model includes multiple layers to be quantized. After executing steps S210-S240 on each layer to be quantized in the neural network model, the sensitivity of each layer to be quantized is obtained. By sorting the multiple sensitivities corresponding to the multiple layers to be quantized, the quantization bit width of the layer to be quantized corresponding to the top-ranked (for example, the top three) sensitivities is determined as a high-precision quantization bit width, such as FP32.
[0095] In some embodiments, the sensitivity corresponding to each of the multiple layers to be quantized includes multiple types, for example, including the first sensitivity obtained by the above formula (1) and the second sensitivity obtained by formula (2). In the process of determining the quantization bit width based on the sensitivity, for each sensitivity, the corresponding types of sensitivities of the multiple layers to be quantized are sorted to obtain multiple sortings. For the quantization layer corresponding to the sensitivity that is at the front of each sorting (for example, the top three) in the multiple sortings, the quantization bit width of the layer to be quantized is determined to be a high-precision quantization bit width, such as FP32. In this process, by sorting the corresponding types of sensitivities of multiple quantized layers based on multiple sensitivities, the sensitivity considered in the sorting process is comprehensive and accurate. Further, the accuracy of quantizing the neural network model is improved.
[0096] According to another aspect of the present disclosure, a quantization device for a neural network model is also provided, such as Figure 7 As shown, the device 700 includes: a first acquisition unit 710, configured to obtain a layer to be quantized in the neural network model, wherein the layer to be quantized includes multiple channels, and each of the multiple channels has a corresponding weight; a second acquisition unit 720, configured to obtain, for each of the multiple channels, high-frequency information in the frequency domain information corresponding to the corresponding weight based on the corresponding weight of the channel; a third acquisition unit 730, configured to obtain an updated weight of the channel based on the high-frequency information in the frequency domain information corresponding to the corresponding weight of each channel in the multiple channels; and a quantization unit 740, configured to perform a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels.
[0097] In some embodiments, the second acquisition unit 720 includes: a time-frequency transformation unit, configured to perform a time-frequency transformation on the corresponding weights to obtain frequency domain information corresponding to the corresponding weights; and a filtering unit, configured to perform a filtering operation on the frequency domain information corresponding to the corresponding weights to obtain high-frequency information in the frequency domain information corresponding to the corresponding weights.
[0098] In some embodiments, the frequency domain information includes a spectrum graph, and the spectrum graph from the edge to the center of the spectrum graph corresponds to the information from the lowest to the highest frequency in the frequency domain information, and the filtering unit includes: a shift unit, configured to perform a shift operation on the spectrum graph corresponding to the corresponding weight to obtain an updated spectrum graph corresponding to the corresponding weight, wherein the information at the lowest frequency in the frequency domain information corresponding to the weight parameter corresponds to the center of the updated spectrum graph; and a filtering subunit, configured to remove a preset area surrounding the center in the updated spectrum graph corresponding to the corresponding weight to obtain a residual spectrum graph corresponding to the corresponding weight, wherein the spectrum in the residual spectrum graph corresponds to the high-frequency information in the frequency domain information of the corresponding weight.
[0099] In some embodiments, the preset area occupies 1 / 3 to 1 / 2 of the entire area of the updated spectrum graph.
[0100] In some embodiments, the third acquisition unit includes: an inverse time-frequency transform unit configured to perform an inverse time-frequency transform based on high-frequency information corresponding to the corresponding weight of each channel in the multiple channels to obtain an updated weight of the channel.
[0101] In some embodiments, the quantization unit includes: a sensitivity calculation unit, configured to obtain the corresponding sensitivity of the layer to be quantized based on the updated weights of each of the multiple channels; and a determination unit, configured to obtain a quantization bit width corresponding to the sensitivity from multiple quantization bit widths in the mixed precision quantization space, and determine it as the quantization bit width of the layer to be quantized.
[0102] In some embodiments, the sensitivity calculation unit includes: an absolute value sum acquisition unit, configured to obtain the sum of the absolute values of the updated weights of each of the multiple channels; and a calculation subunit, configured to obtain the corresponding sensitivity of the layer to be quantized based on the sum of multiple absolute values corresponding to the multiple channels.
[0103] In some embodiments, the sensitivity includes at least one of: an average value of the plurality of sums of absolute values; and a ratio between a difference between a maximum value and a minimum value in the plurality of sums of absolute values and the number of the plurality of channels.
[0104] According to an embodiment of the present disclosure, an electronic device, a readable storage medium and a computer program product are also provided.
[0105] refer to Figure 8, a block diagram of an electronic device 800 that can be used as a server or client of the present disclosure will now be described, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0106] like Figure 8 As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0107] Multiple components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 can be any type of device that can input information to the electronic device 800. The input unit 806 can receive input digital or character information and generate key signal input related to user settings and / or function control of the electronic device, and can include but is not limited to a mouse, a keyboard, a touch screen, a track pad, a track ball, a joystick, a microphone, and / or a remote controller. The output unit 807 can be any type of device that can present information, and can include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 can include but is not limited to a disk, an optical disk. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can include but is not limited to a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, an 802.11 device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0108] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as method 200. For example, in some embodiments, the method 200 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the method 200 described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the method 200 in any other appropriate manner (e.g., by means of firmware).
[0109] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0110] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0111] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0112] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0113] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0114] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0115] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0116] Although the embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above-mentioned methods, systems and devices are merely exemplary embodiments or examples, and the scope of the present invention is not limited by these embodiments or examples, but only by the claims after authorization and their equivalent scope. Various elements in the embodiments or examples can be omitted or replaced by their equivalent elements. In addition, each step can be performed in an order different from that described in the present disclosure. Further, the various elements in the embodiments or examples can be combined in various ways. It is important that with the evolution of technology, many elements described herein can be replaced by equivalent elements that appear after the present disclosure.
Claims
1. A quantization method for a neural network model, wherein the neural network model is a face recognition model or an image classification model, wherein the method include: Obtaining a layer to be quantized in the neural network model, wherein the layer to be quantized includes a plurality of channels, and each of the plurality of channels has a corresponding weight; For each of the multiple channels, based on the corresponding weight of the channel, obtaining high-frequency information in the frequency domain information corresponding to the corresponding weight, including: Performing a time-frequency transformation on the corresponding weights to obtain frequency domain information corresponding to the corresponding weights; and A filtering operation is performed on the frequency domain information corresponding to the corresponding weight to obtain high-frequency information in the frequency domain information corresponding to the corresponding weight, wherein the frequency domain information includes a spectrum graph, and the spectrum graph from the edge to the center of the spectrum graph corresponds to the information of the frequency from the lowest to the highest in the frequency domain information, and the filtering operation on the frequency domain information corresponding to the corresponding weight includes: Performing a shift operation on the frequency spectrum corresponding to the corresponding weight value to obtain an updated frequency spectrum corresponding to the corresponding weight value, wherein the information at the lowest frequency in the frequency domain information corresponding to the weight parameter corresponds to the center of the updated frequency spectrum; and Removing a preset area surrounding the center in the updated spectrum graph corresponding to the corresponding weight to obtain a residual spectrum graph corresponding to the corresponding weight, wherein the spectrum in the residual spectrum graph corresponds to high-frequency information in the frequency domain information of the corresponding weight; Obtaining an updated weight value of each channel in the plurality of channels based on high frequency information in the frequency domain information corresponding to a corresponding weight value of the channel; and Based on the updated weight of each channel in the multiple channels, a quantization operation is performed on the layer to be quantized.
2. The method according to claim 1, in, The preset area occupies 1 / 3 to 1 / 2 of the entire area of the updated spectrum graph.
3. The method according to claim 1, in, The obtaining of the updated weight of each channel based on the high frequency information in the frequency domain information corresponding to the corresponding weight of each channel in the plurality of channels comprises: Based on the high frequency information corresponding to the corresponding weight of each channel in the multiple channels, an inverse time-frequency transform is performed to obtain an updated weight of the channel.
4. The method according to claim 1, in, The step of performing a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels includes: Obtaining the corresponding sensitivity of the layer to be quantized based on the updated weight of each channel in the multiple channels; and A quantization bit width corresponding to the sensitivity is obtained from multiple quantization bit widths in the mixed precision quantization space, and is determined as the quantization bit width of the layer to be quantized.
5. The method according to claim 4, in, The obtaining of the corresponding sensitivity of the layer to be quantized based on the updated weight of each channel in the multiple channels comprises: Obtaining a sum of absolute values of updated weights of each of the plurality of channels; and Based on the sum of multiple absolute values corresponding to the multiple channels, the corresponding sensitivity of the layer to be quantized is obtained.
6. The method according to claim 5, in, The sensitivity includes at least one of the following: an average of the sums of the plurality of absolute values; and A ratio between a difference between a maximum value and a minimum value in the plurality of absolute value sums and the number of the plurality of channels.
7. A quantization device for a neural network model, wherein the neural network model is a face recognition model or an image classification model, wherein the device include: A first acquisition unit is configured to obtain a layer to be quantized in the neural network model, wherein the layer to be quantized includes a plurality of channels, and each of the plurality of channels has a corresponding weight; A second acquisition unit is configured to obtain, for each channel of the multiple channels, high-frequency information in the frequency domain information corresponding to the corresponding weight based on the corresponding weight of the channel, the second acquisition unit comprising: a time-frequency transform unit configured to perform time-frequency transform on the corresponding weights to obtain frequency domain information corresponding to the corresponding weights; and A filtering unit is configured to perform a filtering operation on the frequency domain information corresponding to the corresponding weight to obtain high-frequency information in the frequency domain information corresponding to the corresponding weight, wherein the frequency domain information includes a spectrum graph, and the spectrum graph from the edge to the center of the spectrum graph corresponds to the information from the lowest to the highest frequency in the frequency domain information, and the filtering unit includes: a shifting unit configured to perform a shift operation on the frequency spectrum corresponding to the corresponding weight value to obtain an updated frequency spectrum corresponding to the corresponding weight value, wherein the information at the lowest frequency in the frequency domain information corresponding to the weight parameter corresponds to the center of the updated frequency spectrum; and A filtering subunit is configured to remove a preset area surrounding the center in the updated spectrum graph corresponding to the corresponding weight to obtain a residual spectrum graph corresponding to the corresponding weight, wherein the spectrum in the residual spectrum graph corresponds to high-frequency information in the frequency domain information of the corresponding weight; a third acquisition unit configured to obtain an updated weight of each channel in the plurality of channels based on high frequency information in the frequency domain information corresponding to a corresponding weight of the channel; and The quantization unit is configured to perform a quantization operation on the layer to be quantized based on the updated weight of each channel in the multiple channels.
8. The device according to claim 7, in, The preset area occupies 1 / 3 to 1 / 2 of the entire area of the updated spectrum graph.
9. The device according to claim 7, in, The third acquisition unit includes: The inverse time-frequency transform unit is configured to perform an inverse time-frequency transform based on the high-frequency information corresponding to the corresponding weight of each channel in the multiple channels to obtain an updated weight of the channel.
10. The device according to claim 7, in, The quantization unit comprises: a sensitivity calculation unit configured to obtain a corresponding sensitivity of the layer to be quantized based on an updated weight of each of the multiple channels; and The determination unit is configured to obtain a quantization bit width corresponding to the sensitivity from multiple quantization bit widths in the mixed precision quantization space, and determine it as the quantization bit width of the layer to be quantized.
11. The device according to claim 10, in, The sensitivity calculation unit comprises: an absolute value sum obtaining unit configured to obtain the absolute value sum of the updated weights of each of the plurality of channels; and The calculation subunit is configured to obtain the corresponding sensitivity of the layer to be quantized based on the sum of multiple absolute values corresponding to the multiple channels.
12. The device according to claim 11, in, The sensitivity includes at least one of the following: an average of the sums of the plurality of absolute values; and A ratio between a difference between a maximum value and a minimum value in the plurality of absolute value sums and the number of the plurality of channels.
13. An electronic device, include: at least one processor; as well as a memory communicatively coupled to the at least one processor; in The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-6.
15. A computer program product comprising a computer program, in, When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
