Model compression method, system, computer device and computer readable storage medium

By converting and compressing the storage space values ​​of the model and building an auxiliary parameter matrix, the problem of accuracy loss caused by model compression in the prior art is solved, and the possibility of running a high-precision large model on poorly configured devices is realized.

CN112039530BActive Publication Date: 2025-04-01PING AN ASSET MANAGEMENT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010906612.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-01
Publication Date
2025-04-01
Estimated Expiration
2040-09-01

AI Technical Summary

Technical Problem

While reducing the size of the model, existing model compression methods often lose the accuracy of the model, making it difficult to run high-precision large models on poorly configured machines or mobile phones.

Method used

By obtaining the storage space value of the model, setting a new data type, compressing the storage space value based on the new data type, and building an auxiliary parameter matrix, stitching the second model to improve the compression accuracy of the model.

Benefits of technology

It realizes that the model size is significantly reduced while maintaining model accuracy, so that high-precision large models can run on poorly configured devices and require less manual intervention, which is suitable for short-term iterations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112039530B_ABST
    Figure CN112039530B_ABST
Patent Text Reader

Abstract

The present invention discloses a model compression method, comprising: obtaining a first storage space value of a first model, the first storage space value comprising a first parameter matrix and a first data type; obtaining a first storage value, and setting a second data type according to the first storage value; compressing the first storage space value based on the second data type to obtain a second storage space value; constructing a third storage space value according to the first parameter matrix, the first data type and the second data type; and constructing a second model based on the second storage space value and the third storage space value. The present invention also provides a model compression system, a computer device and a storage medium. The beneficial effect of the embodiments of the present invention is that the accuracy of model compression is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of model building, and in particular to a model compression method, system, computer device, and computer-readable storage medium. Background Art

[0002] The main application scenario of model compression is to reduce the size of high-precision large models that can only be loaded and run on machines with large memory and GPU servers by certain means, with less loss of accuracy, so that the models can be run on machines with poor configuration or mobile phones. For example, the original 500M Bert model originally needed to be run on a GPU server of at least 1G (usually deployed in the cloud) to provide services to users. If it can be compressed to 20M with almost no loss of accuracy, it can even be deployed on mobile phones (currently some of Google's input methods and translation models can be deployed on Google Lite through compression).

[0003] The main compression methods currently used in the industry are: distillation, quantization, and pruning. The common point of these methods is that they can reduce the size of the model to a certain extent, but they will lose accuracy. Summary of the invention

[0004] In view of this, an object of an embodiment of the present invention is to provide a model compression method, system, computer device and computer-readable storage medium, which improve the accuracy of model compression.

[0005] To achieve the above object, an embodiment of the present invention provides a model compression method, comprising:

[0006] Acquire a first storage space value of a first model, wherein the first storage space value includes a first parameter matrix and a first data type;

[0007] Obtaining a first stored value, and setting a second data type according to the first stored value;

[0008] Compressing the first storage space value based on the second data type to obtain a second storage space value;

[0009] Constructing a third storage space value according to the first parameter matrix, the first data type and the second data type;

[0010] A second model is constructed based on the second storage space value and the third storage space value.

[0011] Further, the obtaining of a first storage space value of the first model, wherein the first storage space value includes a first parameter matrix and a first data type, includes:

[0012] Acquire a storage vector of a plurality of storage data pre-stored in the first model, wherein the storage vector includes a plurality of storage values;

[0013] Constructing a first parameter matrix according to the stored vectors, wherein each of the stored values ​​corresponds one-to-one to a matrix element of the first parameter matrix;

[0014] querying a second storage value of the first server, and determining a first data type according to the second storage value and the first parameter matrix;

[0015] Each storage value of the first parameter matrix is ​​represented by the first storage bit of the first data type to obtain the first storage space value.

[0016] Further, the obtaining the first stored value and setting the second data type according to the first stored value includes:

[0017] querying a first storage value of a second server;

[0018] A second data type is set according to the first stored value and the first parameter matrix.

[0019] Further, compressing the first storage space value based on the second data type to obtain the second storage space value includes:

[0020] Obtain a first storage value of the first storage space value and a first storage bit of the first storage value;

[0021] According to the second storage bit of the second data type, a first storage value of the first storage bit is intercepted to obtain a second storage value;

[0022] The second storage value is represented by the second storage bit and re-input into the first storage space value to obtain a second storage space value.

[0023] Further, constructing a third storage space value according to the first parameter matrix, the first data type and the second data type includes:

[0024] Creating an empty matrix according to the matrix elements of the first parameter matrix;

[0025] Acquire multiple values ​​based on Gaussian noise, and represent the values ​​with second storage bits of a second data type to obtain a third storage value;

[0026] Inputting the third stored value into the empty matrix to obtain an auxiliary parameter matrix;

[0027] Shift all the second storage bits of the auxiliary parameter matrix right by K times to obtain a fourth storage value and a fourth storage bit corresponding to the fourth storage value, where K is an arbitrary integer;

[0028] The fourth storage value and a fourth storage bit corresponding to the fourth storage value are substituted into the auxiliary parameter matrix to obtain a third storage space value, where the third storage space value includes a third data type.

[0029] Further, constructing a second model based on the second storage space value and the third storage space value includes:

[0030] concatenating the second storage value of the second storage space value with the fourth storage value of the third storage space value to obtain a second model;

[0031] The second model is uploaded to the blockchain.

[0032] Further, the constructing a second model based on the second storage space value and the third storage space value further includes:

[0033] Setting a first weight value for the second storage space value;

[0034] Setting a second weight value for the third storage space value, wherein the first weight value is greater than the second weight value;

[0035] The second model is constructed based on the first weight value of the second storage space value and the second weight value of the third storage space value.

[0036] To achieve the above purpose, an embodiment of the present invention further provides a model compression system, comprising:

[0037] An acquisition module, configured to acquire a first storage space value of a first model, wherein the first storage space value includes a first parameter matrix and a first data type;

[0038] A setting module, used for acquiring a first stored value, and setting a second data type according to the first stored value;

[0039] a compression module, configured to compress the first storage space value based on the first data type and the second data type to obtain a second storage space value;

[0040] A first construction module, configured to construct a third storage space value according to the first parameter matrix and the second data type;

[0041] The second construction module is used to construct a second model based on the second storage space value and the third storage space value.

[0042] To achieve the above-mentioned purpose, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the steps of the model compression method described above are implemented.

[0043] To achieve the above objectives, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. The computer program can be executed by at least one processor so that the at least one processor performs the steps of the model compression method as described above.

[0044] The model compression method, system, computer device and computer-readable storage medium provided by the embodiment of the present invention compress the first storage space value of the first model to obtain the second storage space value, and construct the third storage space value by constructing an auxiliary parameter matrix, and splicing the second storage space value and the third storage space value to obtain the second model, and the construction of the auxiliary parameter matrix improves the accuracy of the second model. The accuracy can be arbitrarily improved, and the auxiliary matrix parameters can even be set to be particularly large, and a new model (with higher accuracy) larger than the original model can be obtained after retraining. Compared with traditional model compression, the present invention requires less manual intervention and is more likely to iterate suitable results in a short period of time. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 This is a flow chart of Example 1 of the model compression method of the present invention.

[0046] Figure 2 This is a flowchart of step S101 in the first embodiment of the present invention.

[0047] Figure 3 This is a flowchart of step S120 in the first embodiment of the present invention.

[0048] Figure 4 This is a flowchart of step S140 in the first embodiment of the present invention.

[0049] Figure 5 This is a flow chart of step S160 in the first embodiment of the present invention.

[0050] Figure 6 This is a flowchart of step S180 in the first embodiment of the present invention.

[0051] Figure 7 This is a flowchart of another embodiment of step S180 in the first embodiment of the present invention.

[0052] Figure 8 This is a schematic diagram of the program modules of the second embodiment of the model compression system of the present invention.

[0053] Fig. 9 This is a schematic diagram of the hardware structure of the computer device embodiment 3 of the present invention. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0055] Embodiment 1

[0056] See also Figure 1 , shows a flow chart of the steps of the model compression method of the first embodiment of the present invention. It can be understood that the flow chart in the embodiment of the method is not used to limit the order of executing the steps. The following is an exemplary description with the computer device 2 as the execution subject. The details are as follows.

[0057] Step S100, obtaining a first storage space value of a first model, wherein the first storage space value includes a first parameter matrix and a first data type.

[0058] Specifically, a first model trained in a standard manner is obtained on a server of a GPU with a large storage capacity. The first model may be a model such as a Bert model. The data in the first model is stored in a first parameter matrix in the form of a first data type, each data is represented by a vector, and multiple data constitute the first parameter matrix. The first data type is generally float64, and the first parameter matrix can be represented by Wn*m, where n represents the number of data and m represents the dimension of the vector, and the first storage space value is Wn*m*64. The float type follows the IEEE754 standard, and IEEE754 uses binary scientific notation to represent floating point numbers. For example, a 32-bit floating point number is represented in binary. For a float floating point number, 1 bit is used to represent the sign of the number (the positive and negative nature of the floating point number, 0 positive and 1 negative), 8 bits are used to represent the exponent (the base is 2), and 23 bits are used to represent the mantissa.

[0059] For example, see Figure 2 , before step S100, comprising step S101:

[0060] Step S101A: obtaining a plurality of storage vectors of storage data pre-stored in the first model, wherein the storage vectors include a plurality of storage values.

[0061] Specifically, when training the first model, a plurality of storage data are first stored to constrain the model, which can become a constraint factor. The storage data is vectorized to obtain a storage vector, the column of the storage vector is a fixed value, and the vectorization algorithm can be Doc2vec, str2vec, para2vec algorithm, etc.

[0062] Step S101B: construct a first parameter matrix according to the stored vectors, wherein each of the stored values ​​corresponds one-to-one to a matrix element of the first parameter matrix.

[0063] Specifically, the stored vectors are concatenated to obtain a first parameter matrix, each stored value corresponds to a matrix element, the rows of the first parameter matrix correspond to the number of stored data, and the columns of the first parameters correspond to the columns of the stored vectors.

[0064] Step S101C: query the second storage value of the first server, and determine the first data type according to the second storage value and the first parameter matrix.

[0065] Specifically, if the first model is to be run on the first server, the first data type of the first model can be determined according to the second storage value of the first server, so that the first model can be run on the first server.

[0066] Step S101D: represent each storage value of the first parameter matrix with the first storage bit of the first data type to obtain the first storage space value.

[0067] Specifically, the first storage bit of the first data type fioat64 is 64 bits. The storage value is represented by the first data type, whose first storage bit is 64 bits, and is substituted into the first parameter matrix to obtain the first storage space value.

[0068] Step S120, obtaining a first stored value, and setting a second data type according to the first stored value.

[0069] Specifically, the second storage space value of the first model is obtained, and the second data type is obtained according to the analysis of the second storage space value and the first storage space value. According to the memory requirements, the second data type is pre-set, and the first storage space value of the first model is converted into the second storage space value. For example, the Bert model with an original storage value of 500M originally needs to be run on a GPU server of at least 1G (usually deployed in the cloud) to provide services to users. Now the storage value needs to be reduced to 20M. The second data type is smaller than the first data type, and the second data type can be float48, float32, float16 or float8.

[0070] For example, see Figure 3 , the step S120 comprises:

[0071] Step S121, querying the first storage value of the second server.

[0072] Specifically, the first storage value of the second server is smaller than the second storage value of the first server.

[0073] Step S122: setting a second data type according to the first stored value and the first parameter matrix.

[0074] Specifically, the data type of the first parameter matrix is ​​the first data type, and when the first model is placed in the second server, the first model needs to be compressed to ensure that the first model can run effectively. The data type of the compressed first model is determined according to the first storage value to obtain the second data type.

[0075] Step S140: compress the first storage space value based on the second data type to obtain a second storage space value.

[0076] Specifically, the first data type float64 in the first parameter matrix Wn*m can be changed to a second data type, preferably float16, and the decimal point beyond the first storage bit of the first data type is directly discarded to obtain a second storage space value Wn*m*16.

[0077] For example, see Figure 4 , the step S140 comprises:

[0078] Step S141, obtaining a first storage value of the first storage space value and a first storage bit of the first storage value.

[0079] Specifically, according to the first data type of the first storage space value, the first storage bit can be obtained, for example, the first storage bit of the first data type float64 is 64 bits.

[0080] Step S142: intercepting the first storage value of the first storage bit according to the second storage bit of the second data type to obtain a second storage value.

[0081] Specifically, according to the second data type of the second storage space value, the second storage bit can be obtained. For example, the first storage bit of the first data type float16 is 16 bits. The value of the first 16 bits of the second storage bit of the second data type of the first storage bit 64 bits in the first data type in the first data type is intercepted as the second storage value.

[0082] Step S143: The second storage value is represented by the second storage bit and re-input into the first storage space value to obtain a second storage space value.

[0083] Specifically, the intercepted second storage value of the first second storage bit is stored again in the first storage space to obtain the second storage space value Wn*m*16.

[0084] Step S160: construct a third storage space value according to the first parameter matrix, the first data type and the second data type.

[0085] Specifically, construct an auxiliary parameter matrix N1*m, the data type of the auxiliary parameter matrix is ​​the second data type, and shift the auxiliary parameter matrix right by K bits or K times. It can be understood that the storage value of the auxiliary parameter matrix is ​​copied K bits or K times again, and spliced ​​to obtain a third storage space value. For example, the auxiliary parameter matrix is ​​copied twice more, and the three are called auxiliary parameter matrices A, B, and C. The 16-bit auxiliary parameter matrix A is merged with the auxiliary parameter matrix B shifted right by 32 bits, and then merged with the auxiliary parameter matrix C shifted right by 48 bits to obtain the second parameter matrix, which is similar to constructing an auxiliary parameter matrix of float16+float16+float16=float48. Re-shift the part of the auxiliary parameter matrix right by K bits to improve the accuracy of the second model as much as possible.

[0086] For example, see Figure 5 , the step S160 comprises:

[0087] Step S161: Create an empty matrix according to the matrix elements of the first parameter matrix.

[0088] Specifically, a single-row empty matrix is ​​constructed, the columns of the single-row empty matrix are consistent with the columns of the first parameter matrix, and the data type of the empty matrix is ​​the second data type.

[0089] Step S162, obtaining a plurality of numerical values ​​based on Gaussian noise, and representing the numerical values ​​with second storage bits of a second data type to obtain a third storage value.

[0090] Specifically, the initialization method is Gaussian noise with a mean of 0 and a variance of 0.002, a plurality of numerical values ​​are obtained in the Gaussian noise based on a random algorithm, and the plurality of numerical values ​​are converted into the second data type to obtain a plurality of third storage values.

[0091] Step S163: input the third stored value into the empty matrix to obtain an auxiliary parameter matrix.

[0092] Specifically, a plurality of third stored values ​​are randomly stored in an empty matrix, each third stored value corresponds to a matrix element of the empty matrix, and an auxiliary parameter matrix is ​​obtained.

[0093] Step S164, right-shift all the second storage bits of the auxiliary parameter matrix by K times to obtain a fourth storage value and a fourth storage bit corresponding to the fourth storage value, where K is an arbitrary integer.

[0094] Specifically, the second storage bit 16 of the auxiliary parameter matrix is ​​all right-shifted by K times (bits), which is equivalent to expanding the second storage bit by K times (bits), and its third storage value is correspondingly right-shifted by K times (bits), and the fourth storage bit obtained after right shift is 16K bits, or (16+K) bits. For example, the third storage value is 0111110001101001, and when the third storage value is right-shifted by 16 bits, or 1 times, the fourth storage bit is 32, and the fourth storage value is 01111100011010010111110001101001.

[0095] Step S165: Substitute the fourth storage value and the fourth storage bit corresponding to the fourth storage value into the auxiliary parameter matrix to obtain a third storage space value, where the third storage space value includes a third data type.

[0096] Specifically, the fourth storage value is substituted into each matrix element corresponding to the auxiliary parameter matrix to obtain a third storage space value Wn*m*48, the third data type is float48, and the fourth storage bit is 48.

[0097] Step S180: construct a second model based on the second storage space value and the third storage space value.

[0098] For example, see Figure 6 , the step S180 comprises:

[0099] Step S181, concatenating the second storage value of the second storage space value with the fourth storage value of the third storage space value to obtain a second model.

[0100] Specifically, the second storage bit of the second storage space value is spliced ​​with the fourth storage bit of the third storage space. Since the second storage value is represented by the second data type and the fourth storage bit of the third storage space value is represented by the third data type, during splicing, their data bits are spliced ​​to obtain the second model Wn*m*(16+48).

[0101] Step S182: upload the second model to the blockchain.

[0102] Specifically, uploading the second model to the blockchain can ensure its security and fairness and transparency to users. The user device can download the second model from the blockchain to verify whether the model data has been tampered with. The blockchain referred to in this example is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database. It is a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. The blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer.

[0103] For example, see Figure 7 , the step S180 further includes:

[0104] Step S180A, setting a first weight value for the second storage space value.

[0105] Specifically, a first weight value is set for the second storage space value according to the model accuracy.

[0106] Step S180B: setting a second weight value for the third storage space value, wherein the first weight value is greater than the second weight value.

[0107] Specifically, the second weight value is set for the third storage space value according to the model accuracy, and the first weight value is much larger than the second weight value to achieve a model accuracy selection similar to the 80 / 20 rule. For example, if the data type of the first storage space value is 16 bits, which contributes more than 80% of the accuracy, and its first weight value is 0.8, then the second weight value of the third storage space value is 0.2.

[0108] Step S180C: construct the second model based on the first weight value of the second storage space value and the second weight value of the third storage space value.

[0109] Specifically, the second storage space value and the third storage space value are spliced ​​for storage bits to construct a second model, and the first weight value is associated with the second storage space value, and the second weight value is associated with the third storage space value.

[0110] Embodiment 2

[0111] Please continue reading Figure 8, showing a schematic diagram of the program modules of the second embodiment of the model compression system of the present invention. In this embodiment, the model compression system 20 may include or be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the present invention and implement the above-mentioned model compression method. The program module referred to in the embodiment of the present invention refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the model compression system 20 in the storage medium than the program itself. The following description will specifically introduce the functions of each program module of this embodiment:

[0112] The acquisition module 200 is used to acquire a first storage space value of a first model, where the first storage space value includes a first parameter matrix and a first data type.

[0113] Specifically, a first model trained in a standard manner is obtained on a server of a GPU with a large storage capacity. The first model may be a model such as a Bert model. The data in the first model is stored in a first parameter matrix in the form of a first data type, each data is represented by a vector, and multiple data constitute the first parameter matrix. The first data type is generally float64, and the first parameter matrix can be represented by Wn*m, where n represents the number of data and m represents the dimension of the vector, and the first storage space value is Wn*m*64. The float type follows the IEEE754 standard, and IEEE754 uses binary scientific notation to represent floating point numbers. For example, a 32-bit floating point number is represented in binary. For a float floating point number, 1 bit is used to represent the sign of the number (the positive and negative nature of the floating point number, 0 positive and 1 negative), 8 bits are used to represent the exponent (the base is 2), and 23 bits are used to represent the mantissa.

[0114] The setting module 202 is used to obtain a first stored value and set a second data type according to the first stored value.

[0115] Specifically, the second storage space value of the first model is obtained, and the second data type is obtained according to the analysis of the second storage space value and the first storage space value. According to the memory requirements, the second data type is pre-set, and the first storage space value of the first model is converted into the second storage space value. For example, the Bert model with an original storage value of 500M originally needs to be run on a GPU server of at least 1G (usually deployed in the cloud) to provide services to users. Now the storage value needs to be reduced to 20M. The second data type is smaller than the first data type, and the second data type can be float48, float32, float16 or float8.

[0116] Exemplarily, the setting module 202 is further used for:

[0117] The second server is queried for the first stored value.

[0118] Specifically, the first storage value of the second server is smaller than the second storage value of the first server.

[0119] A second data type is set according to the first stored value and the first parameter matrix.

[0120] Specifically, the data type of the first parameter matrix is ​​the first data type, and when the first model is placed in the second server, the first model needs to be compressed to ensure that the first model can run effectively. The data type of the compressed first model is determined according to the first storage value to obtain the second data type.

[0121] The compression module 204 is configured to compress the first storage space value based on the first data type and the second data type to obtain a second storage space value.

[0122] Specifically, the first data type float64 in the first parameter matrix Wn*m can be changed to a second data type, preferably float16, and the decimal point beyond the first storage bit of the first data type is directly discarded to obtain a second storage space value Wn*m*16.

[0123] Exemplarily, the compression module 204 is further configured to:

[0124] A first storage value of the first storage space value and a first storage bit of the first storage value are obtained.

[0125] Specifically, according to the first data type of the first storage space value, the first storage bit can be obtained, for example, the first storage bit of the first data type float64 is 64 bits.

[0126] The first storage value of the first storage bit is intercepted according to the second storage bit of the second data type to obtain a second storage value.

[0127] Specifically, according to the second data type of the second storage space value, the second storage bit can be obtained. For example, the first storage bit of the first data type float16 is 16 bits. The value of the first 16 bits of the second storage bit of the second data type of the first storage bit 64 bits in the first data type in the first data type is intercepted as the second storage value.

[0128] The second storage value is represented by the second storage bit and re-input into the first storage space value to obtain a second storage space value.

[0129] Specifically, the intercepted second storage value of the first second storage bit is stored again in the first storage space to obtain the second storage space value Wn*m*16.

[0130] The first constructing module 206 is configured to construct a third storage space value according to the first parameter matrix and the second data type.

[0131] Specifically, construct an auxiliary parameter matrix N1*m, the data type of the auxiliary parameter matrix is ​​the second data type, and shift the auxiliary parameter matrix right by K bits or K times. It can be understood that the storage value of the auxiliary parameter matrix is ​​copied K bits or K times again, and spliced ​​to obtain a third storage space value. For example, the auxiliary parameter matrix is ​​copied twice more, and the three are called auxiliary parameter matrices A, B, and C. The 16-bit auxiliary parameter matrix A is merged with the auxiliary parameter matrix B shifted right by 32 bits, and then merged with the auxiliary parameter matrix C shifted right by 48 bits to obtain the second parameter matrix, which is similar to constructing an auxiliary parameter matrix of float16+float16+float16=float48. Re-shift the part of the auxiliary parameter matrix right by K bits to improve the accuracy of the second model as much as possible.

[0132] Exemplarily, the first building module 206 is further used for:

[0133] Create an empty matrix from the matrix elements of the first parameter matrix.

[0134] Specifically, a single-row empty matrix is ​​constructed, the columns of the single-row empty matrix are consistent with the columns of the first parameter matrix, and the data type of the empty matrix is ​​the second data type.

[0135] A plurality of numerical values ​​are acquired based on Gaussian noise, and the numerical values ​​are represented by second storage bits of a second data type to obtain a third storage value.

[0136] Specifically, the initialization method is Gaussian noise with a mean of 0 and a variance of 0.002, a plurality of numerical values ​​are obtained in the Gaussian noise based on a random algorithm, and the plurality of numerical values ​​are converted into the second data type to obtain a plurality of third storage values.

[0137] The third stored value is input into the empty matrix to obtain an auxiliary parameter matrix.

[0138] Specifically, a plurality of third stored values ​​are randomly stored in an empty matrix, each third stored value corresponds to a matrix element of the empty matrix, and an auxiliary parameter matrix is ​​obtained.

[0139] All second storage bits of the auxiliary parameter matrix are right-shifted K times to obtain a fourth storage value and a fourth storage bit corresponding to the fourth storage value, where K is an arbitrary integer.

[0140] Specifically, the second storage bit 16 of the auxiliary parameter matrix is ​​all right-shifted by K times (bits), which is equivalent to expanding the second storage bit by K times (bits), and its third storage value is correspondingly right-shifted by K times (bits), and the fourth storage bit obtained after right shift is 16K bits, or (16+K) bits. For example, the third storage value is 0111110001101001, and when the third storage value is right-shifted by 16 bits, or 1 times, the fourth storage bit is 32, and the fourth storage value is 01111100011010010111110001101001.

[0141] The fourth storage value and a fourth storage bit corresponding to the fourth storage value are substituted into the auxiliary parameter matrix to obtain a third storage space value, where the third storage space value includes a third data type.

[0142] Specifically, the fourth storage value is substituted into each matrix element corresponding to the auxiliary parameter matrix to obtain a third storage space value Wn*m*48, the third data type is float48, and the fourth storage bit is 48.

[0143] The second constructing module 208 is configured to construct a second model based on the second storage space value and the third storage space value.

[0144] Exemplarily, the second building module 208 is further used for:

[0145] The second storage value of the second storage space value and the fourth storage value of the third storage space value are concatenated to obtain a second model.

[0146] Specifically, the second storage bit of the second storage space value is spliced ​​with the fourth storage bit of the third storage space. Since the second storage value is represented by the second data type and the fourth storage bit of the third storage space value is represented by the third data type, during splicing, their data bits are spliced ​​to obtain the second model Wn*m*(16+48).

[0147] The second model is uploaded to the blockchain.

[0148] Specifically, uploading the second model to the blockchain can ensure its security and fairness and transparency to users. The user device can download the second model from the blockchain to verify whether the model data has been tampered with. The blockchain referred to in this example is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database. It is a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. The blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer.

[0149] Exemplarily, the second building module 208 is further used for:

[0150] A first weight value is set for the second storage space value.

[0151] Specifically, a first weight value is set for the second storage space value according to the model accuracy.

[0152] A second weight value is set for the third storage space value, wherein the first weight value is greater than the second weight value.

[0153] Specifically, the second weight value is set for the third storage space value according to the model accuracy, and the first weight value is much larger than the second weight value to achieve a model accuracy selection similar to the 80 / 20 rule. For example, if the data type of the first storage space value is 16 bits, which contributes more than 80% of the accuracy, and its first weight value is 0.8, then the second weight value of the third storage space value is 0.2.

[0154] The second model is constructed based on the first weight value of the second storage space value and the second weight value of the third storage space value.

[0155] Specifically, the second storage space value and the third storage space value are spliced ​​for storage bits to construct a second model, and the first weight value is associated with the second storage space value, and the second weight value is associated with the third storage space value.

[0156] Embodiment 3

[0157] See also Fig. 9 , is a schematic diagram of the hardware architecture of the computer device of the third embodiment of the present invention. In this embodiment, the computer device 2 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The computer device 2 can be a rack server, a blade server, a tower server or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Fig. 9 As shown, the computer device 2 at least includes, but is not limited to, a memory 21, a processor 22, a network interface 23, and a model compression system 20 that can be interconnected and communicated via a system bus.

[0158] In this embodiment, the memory 21 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 21 can be an internal storage unit of the computer device 2, such as a hard disk or memory of the computer device 2. In other embodiments, the memory 21 can also be an external storage device of the computer device 2, such as a plug-in hard disk equipped on the computer device 2, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 21 can also include both the internal storage unit of the computer device 2 and its external storage device. In this embodiment, the memory 21 is generally used to store the operating system and various application software installed on the computer device 2, such as the program code of the model compression system 20 of the second embodiment. In addition, the memory 21 can also be used to temporarily store various types of data that have been output or are to be output.

[0159] The processor 22 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 22 is generally used to control the overall operation of the computer device 2. In this embodiment, the processor 22 is used to run the program code stored in the memory 21 or process data, such as running the model compression system 20 to implement the model compression method of the first embodiment.

[0160] The network interface 23 may include a wireless network interface or a wired network interface, and the network interface 23 is generally used to establish a communication connection between the server 2 and other electronic devices. For example, the network interface 23 is used to connect the server 2 to an external terminal through a network, to establish a data transmission channel and a communication connection between the server 2 and the external terminal, etc. The network may be an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi and other wireless or wired networks. It should be pointed out that Fig. 9Computer device 2 is shown only with components 20 - 23 , but it should be understood that implementation of all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0161] In this embodiment, the model compression system 20 stored in the memory 21 can also be divided into one or more program modules, and the one or more program modules are stored in the memory 21 and executed by one or more processors (processor 22 in this embodiment) to complete the present invention.

[0162] For example, Figure 8 The program module schematic diagram of the second embodiment of the model compression system 20 is shown. In this embodiment, the model compression system 20 can be divided into an acquisition module 200, a setting module 202, a compression module 204, a first construction module 206 and a second construction module 208. The program module referred to in the present invention refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the model compression system 20 in the computer device 2 than a program. The specific functions of the program modules 200-208 have been described in detail in the second embodiment and will not be repeated here.

[0163] Embodiment 4

[0164] This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, and the program implements the corresponding function when executed by the processor. The computer-readable storage medium of this embodiment is used to store a computer program, and when executed by the processor, the model compression method of the first embodiment is implemented.

[0165] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0166] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0167] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A model compression method, characterized in that: include: Acquire a first storage space value of a first model, wherein the first storage space value includes a first parameter matrix and a first data type; Obtaining a first stored value, and setting a second data type according to the first stored value; Compressing the first storage space value based on the second data type to obtain a second storage space value; Constructing a third storage space value according to the first parameter matrix, the first data type and the second data type; constructing a second model based on the second storage space value and the third storage space value; The step of obtaining a first storage space value of the first model, wherein the first storage space value includes a first parameter matrix and a first data type, includes: Acquire a storage vector of a plurality of storage data pre-stored in the first model, wherein the storage vector includes a plurality of storage values; Constructing a first parameter matrix according to the stored vectors, wherein each of the stored values ​​corresponds one-to-one to a matrix element of the first parameter matrix; querying a second storage value of the first server, and determining a first data type according to the second storage value and the first parameter matrix; Each storage value of the first parameter matrix is ​​represented by the first storage bit of the first data type to obtain the first storage space value.

2. The model compression method according to claim 1, characterized in that: The obtaining of the first stored value and setting the second data type according to the first stored value comprises: querying a first storage value of a second server; A second data type is set according to the first stored value and the first parameter matrix.

3. The model compression method according to claim 1, characterized in that: The compressing the first storage space value based on the second data type to obtain the second storage space value comprises: Obtain a first storage value of the first storage space value and a first storage bit of the first storage value; According to the second storage bit of the second data type, a first storage value of the first storage bit is intercepted to obtain a second storage value; The second storage value is represented by the second storage bit and re-input into the first storage space value to obtain a second storage space value.

4. The model compression method according to claim 1, characterized in that: The constructing a third storage space value according to the first parameter matrix, the first data type and the second data type comprises: Creating an empty matrix according to the matrix elements of the first parameter matrix; Acquire multiple values ​​based on Gaussian noise, and represent the values ​​with second storage bits of a second data type to obtain a third storage value; Inputting the third stored value into the empty matrix to obtain an auxiliary parameter matrix; Shift all the second storage bits of the auxiliary parameter matrix right by K times to obtain a fourth storage value and a fourth storage bit corresponding to the fourth storage value, where K is an arbitrary integer; The fourth storage value and a fourth storage bit corresponding to the fourth storage value are substituted into the auxiliary parameter matrix to obtain a third storage space value, where the third storage space value includes a third data type.

5. The model compression method according to claim 1, characterized in that: The constructing a second model based on the second storage space value and the third storage space value comprises: concatenating the second storage value of the second storage space value with the fourth storage value of the third storage space value to obtain a second model; The second model is uploaded to the blockchain.

6. The model compression method according to claim 1, characterized in that: The constructing the second model based on the second storage space value and the third storage space value further includes: Setting a first weight value for the second storage space value; Setting a second weight value for the third storage space value, wherein the first weight value is greater than the second weight value; The second model is constructed based on the first weight value of the second storage space value and the second weight value of the third storage space value.

7. A model compression system, characterized in that: include: An acquisition module, configured to acquire a first storage space value of a first model, wherein the first storage space value includes a first parameter matrix and a first data type; A setting module, used for acquiring a first stored value, and setting a second data type according to the first stored value; a compression module, configured to compress the first storage space value based on the first data type and the second data type to obtain a second storage space value; A first construction module, configured to construct a third storage space value according to the first parameter matrix and the second data type; A second construction module, configured to construct a second model based on the second storage space value and the third storage space value; Wherein, the acquisition module is also used for: Acquire a storage vector of a plurality of storage data pre-stored in the first model, wherein the storage vector includes a plurality of storage values; Constructing a first parameter matrix according to the stored vectors, wherein each of the stored values ​​corresponds one-to-one to a matrix element of the first parameter matrix; querying a second storage value of the first server, and determining a first data type according to the second storage value and the first parameter matrix; Each storage value of the first parameter matrix is ​​represented by the first storage bit of the first data type to obtain the first storage space value.

8. A computer device, characterized in that: The computer device includes a memory and a processor. The memory stores a computer program that can be run on the processor. When the computer program is executed by the processor, the steps of the model compression method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program can be executed by at least one processor to enable the at least one processor to perform the steps of the model compression method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data compression acquisition and transmission method suitable for advanced measurement system

    CN111064705A