Compression method, device, computer equipment, storage medium and program product of artificial intelligence model

By segmented processing and encoding the weight parameters of the artificial intelligence model, combined with Zerobitmap and arithmetic coding technology, the problem of difficulty in loading weight parameters at one time is solved, and the effect of reducing data volume and improving computing power is achieved.

CN119382717BActive Publication Date: 2025-04-22深圳市欧冶半导体有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411983160.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-22
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

It is difficult for existing chips to load all the weight parameters of the artificial intelligence model into on-chip storage at one time, resulting in increased data interactions on-chip and off-chip, limiting the chip's computing power.

Method used

By segmented processing and encoding the weight parameters of the artificial intelligence model, the combination of Zerobitmap encoding and arithmetic encoding can reduce the amount of data of the weight parameters, so that they can be loaded into on-chip storage at one time.

Benefits of technology

It effectively reduces the amount of data of weight parameters in the artificial intelligence model, reduces data interaction, improves the chip's computing power, and enables the weight parameters to be loaded into on-chip storage at one time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119382717B_ABST
    Figure CN119382717B_ABST
Patent Text Reader

Abstract

The present application relates to a compression method, device, computer equipment, storage medium and program product for an artificial intelligence model. The method comprises: segmenting the weight parameter sequence of the artificial intelligence model to obtain a plurality of data segments of equal length; for each data segment of equal length, encoding each weight parameter in the data segment to obtain first encoded data of the first bit width and second encoded data of the second bit width; sequentially assigning a corresponding probability model to each binary character in the bitmap data; performing arithmetic encoding on the binary characters based on the probability model until the arithmetic encoding of all bitmap data is completed to obtain third encoded data of all bitmap data; using the second encoded data and the third encoded data as the weight parameter compression result of the artificial intelligence model. The use of this method can effectively reduce the amount of data of the weight parameters in the artificial intelligence model, and ensure that the weight parameters can be loaded into the on-chip storage at one time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, computer equipment, storage medium and program product for compressing an artificial intelligence model. Background Art

[0002] With the rapid development of artificial intelligence technology, the recognition accuracy of artificial intelligence models is constantly increasing, and the number of parameters of artificial intelligence models is also increasing. Due to the limitation of on-chip storage resources, it is difficult for existing chips to load all the weight parameters of artificial intelligence models into on-chip storage at one time. The usual practice is to use layered and block calculations to solve the problem of insufficient on-chip storage resources, but this will increase the data interaction between on-chip and off-chip, and memory access is often the main bottleneck limiting the computing power of chips. Therefore, how to reduce the amount of data of weight parameters in artificial intelligence models so that the weight parameters can be loaded into on-chip storage at one time is the key to improving chip computing power. Summary of the invention

[0003] Based on this, it is necessary to provide a compression method, device, computer equipment, storage medium and program product for an artificial intelligence model to address the above-mentioned technical problems, which can effectively reduce the amount of data of the weight parameters in the artificial intelligence model and ensure that the weight parameters can be loaded into the on-chip storage at one time.

[0004] In a first aspect, the present application provides a method for compressing an artificial intelligence model, the method comprising:

[0005] The weight parameter sequence of the artificial intelligence model is processed in segments to obtain multiple data segments of equal length;

[0006] For each data segment of equal length, each weight parameter in the data segment is encoded to obtain first encoded data of a first bit width and second encoded data of a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter;

[0007] sequentially assigning corresponding probability models to each binary character in the bitmap data;

[0008] Performing arithmetic coding on the binary characters based on the probability model until the arithmetic coding of all the bitmap data is completed, thereby obtaining third coded data of all the bitmap data;

[0009] The second encoded data and the third encoded data are used as weight parameter compression results of the artificial intelligence model.

[0010] In one embodiment, the method further comprises:

[0011] Pruning the initial artificial intelligence model to obtain a processed artificial intelligence model;

[0012] The weight parameters of the artificial intelligence model are quantized to obtain a weight parameter sequence of the artificial intelligence model.

[0013] In one embodiment, encoding each weight parameter in the data segment to obtain first encoded data with a first bit width and second encoded data with a second bit width comprises:

[0014] Using Zerobitmap encoding, each weight parameter in the data segment is encoded into a first bit width encoded weight parameter and a second bit width encoded weight parameter;

[0015] Combining the encoded weight parameters of the first bit width to obtain first encoded data;

[0016] The encoded weight parameters of the second bit width are combined to obtain second encoded data.

[0017] In one embodiment, assigning a corresponding probability model to each binary character in the bitmap data in turn includes:

[0018] Inputting binary characters in the bitmap data into a context model;

[0019] For each binary character in the bitmap data, assigning a corresponding probability model to the current binary character through the context model;

[0020] The performing arithmetic coding on the binary character based on the probability model until the arithmetic coding of all the bitmap data is completed to obtain the third coded data of all the bitmap data comprises:

[0021] Inputting the current binary character and the corresponding probability model into an arithmetic coding model;

[0022] The arithmetic coding model is used to perform arithmetic coding on the current binary character according to the probability model until the arithmetic coding of all the bitmap data is completed, thereby obtaining third coded data of all the bitmap data.

[0023] In one embodiment, the arithmetic coding model is used to perform arithmetic coding on the current binary character according to the probability model until the arithmetic coding of all the bitmap data is completed, and the third coded data of all the bitmap data is obtained, including:

[0024] By using the arithmetic coding model, arithmetic coding is performed on the current binary character according to the coding interval corresponding to the probability model to obtain a current coding result;

[0025] A probability model is updated based on the current encoding result so that data of the probability model assigned to the next binary character is updated, and the next binary character is arithmetically encoded based on the updated probability model until the arithmetic encoding of all the bitmap data is completed to obtain third encoded data of all the bitmap data.

[0026] In one embodiment, the method further comprises:

[0027] Storing the weight parameter compression result of the artificial intelligence model in the memory;

[0028] In case of receiving a task processing request, reading the weight parameter compression result from the memory;

[0029] Performing arithmetic decoding on the third coded data in the weight parameter compression result to obtain the bitmap data;

[0030] Decoding the bitmap data and the second encoded data to obtain a weight parameter sequence of the artificial intelligence model;

[0031] Task processing is performed based on the artificial intelligence model with the weight parameter sequence.

[0032] In a second aspect, the present application further provides a compression device for an artificial intelligence model, the device comprising:

[0033] A segmentation module is used to segment the weight parameter sequence of the artificial intelligence model to obtain multiple data segments of equal length;

[0034] A first encoding module is used to encode each weight parameter in the data segment for each data segment of equal length to obtain first encoded data of a first bit width and second encoded data of a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter;

[0035] An allocation module, used for sequentially allocating corresponding probability models to each binary character in the bitmap data;

[0036] The second encoding module is used to perform arithmetic encoding on the binary characters based on the probability model until the arithmetic encoding of all the bitmap data is completed, thereby obtaining third encoded data of all the bitmap data; and use the second encoded data and the third encoded data as the weight parameter compression result of the artificial intelligence model.

[0037] In one embodiment, the device further comprises:

[0038] A pruning module is used to prune the initial artificial intelligence model to obtain a processed artificial intelligence model;

[0039] The quantization module is used to quantize the weight parameters of the artificial intelligence model to obtain a weight parameter sequence of the artificial intelligence model.

[0040] In one of the embodiments, the first encoding module is further used to encode each weight parameter in the data segment into a first bit width encoded weight parameter and a second bit width encoded weight parameter by using Zerobitmap encoding; the first bit width encoded weight parameters are combined to obtain first encoded data; and the second bit width encoded weight parameters are combined to obtain second encoded data.

[0041] In one embodiment, the allocation module is further used to input the binary characters in the bitmap data into the context model; for each binary character in the bitmap data, allocate a corresponding probability model to the current binary character through the context model;

[0042] The second encoding module is also used to input the current binary character and the corresponding probability model into the arithmetic coding model; through the arithmetic coding model, the current binary character is arithmetically encoded according to the probability model until the arithmetic encoding of all the bitmap data is completed, and the third encoded data of all the bitmap data is obtained.

[0043] In one of the embodiments, the second encoding module is also used to perform arithmetically encoding on the current binary character through the arithmetic coding model according to the coding interval corresponding to the probability model to obtain a current encoding result; update the probability model based on the current encoding result so that the probability model assigned to the next binary character is updated, and perform arithmetically encoding on the next binary character based on the updated probability model until the arithmetic encoding of all the bitmap data is completed to obtain third encoded data of all the bitmap data.

[0044] In one embodiment, the device further comprises:

[0045] A storage module, used to store the weight parameter compression result of the artificial intelligence model in a memory;

[0046] A reading module, configured to read the weight parameter compression result from the memory when receiving a task processing request;

[0047] A first decoding module, configured to perform arithmetic decoding on the third coded data in the weight parameter compression result to obtain the bitmap data;

[0048] A second decoding module, used for decoding the bitmap data and the second encoded data to obtain a weight parameter sequence of the artificial intelligence model;

[0049] A task processing module is used to perform task processing based on the artificial intelligence model with the weight parameter sequence.

[0050] In a third aspect, the present application also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the compression method of the artificial intelligence model when executing the computer program.

[0051] In a fourth aspect, the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the compression method of the artificial intelligence model are implemented.

[0052] In a fifth aspect, the present application also provides a computer program product, which includes a computer program that implements the steps of the compression method of the artificial intelligence model when executed by a processor.

[0053] The compression method, device, computer equipment, storage medium and computer program product of the above-mentioned artificial intelligence model segment the weight parameter sequence of the artificial intelligence model to obtain multiple data segments of equal length; for each data segment of equal length, encode each weight parameter in the data segment to obtain first encoded data with a first bit width and second encoded data with a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is less than the second bit width, and the second bit width is equal to the bit width of the weight parameter. Through this encoding, the data volume of the weight parameter can be effectively reduced; in addition, a corresponding probability model is assigned to each binary character in the bitmap data in turn; based on the probability model, the binary characters are arithmetically encoded until the arithmetic encoding of all bitmap data is completed, and the third encoded data of all bitmap data is obtained, so that the data volume of the weight parameter can be further compressed. Therefore, encoding by two different encoding methods can greatly reduce the data volume of the weight parameter, so that after the second encoded data and the third encoded data are used as the compression results of the weight parameters of the artificial intelligence model, the weight parameters of the artificial intelligence model can be loaded into the on-chip storage at one time, which is beneficial to improving the computing power of the chip. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1A diagram of an application environment of a compression method for an artificial intelligence model in one embodiment;

[0055] Figure 2 A schematic diagram of a flow chart of a method for compressing an artificial intelligence model in one embodiment;

[0056] Figure 3 It is a schematic diagram of data changes before and after Zerobitmap encoding in one embodiment;

[0057] Figure 4 A schematic diagram of a flow chart of compression and decompression of an artificial intelligence model in another embodiment;

[0058] Figure 5 is a structural block diagram of a compression device for an artificial intelligence model in one embodiment;

[0059] Figure 6 It is a structural block diagram of a compression device of an artificial intelligence model in another embodiment;

[0060] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0061] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application 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 application and are not used to limit the present application.

[0062] It should be noted that in the following description, the terms "first, second and third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first, second and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0063] The compression method of the artificial intelligence model provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The compression method of the above-mentioned artificial intelligence model can be executed by the terminal 102 or the server 104, or by the server 104 and the terminal 102. Taking the execution of the terminal 102 of this method as an example: the terminal 102 performs segmentation processing on the weight parameter sequence of the artificial intelligence model to obtain a plurality of data segments of equal length; for each data segment of equal length, each weight parameter in the data segment is encoded to obtain the first encoded data of the first bit width and the second encoded data of the second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is less than the second bit width, and the second bit width is equal to the bit width of the weight parameter; the corresponding probability model is assigned to each binary character in the bitmap data in turn; the binary characters are arithmetically encoded based on the probability model until the arithmetic encoding of all bitmap data is completed, and the third encoded data of all bitmap data is obtained; the second encoded data and the third encoded data are used as the weight parameter compression result of the artificial intelligence model. Therefore, when a task processing request is received, the weight parameter compression result of the artificial intelligence model can be decoded and the parameters can be dequantized, so that the artificial intelligence model can be used to perform task processing operations.

[0064] Among them, the terminal 102 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, an Internet of Things device and a portable wearable device. The Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner and a smart car device, etc.

[0065] Server 104 can be an independent physical server or a service node in a blockchain system. A peer-to-peer network is formed between the service nodes in the blockchain system. The peer-to-peer protocol is an application layer protocol running on the Transmission Control Protocol (TCP). In addition, server 104 can also be a server cluster composed of multiple physical servers, and can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (CDNs), and big data and artificial intelligence platforms.

[0066] In one embodiment, Figure 2 As shown, a compression method for an artificial intelligence model is provided, which can be Figure 1 The method is performed by a server or a terminal in the embodiment, or by a server and a terminal in collaboration. Figure 1The following steps are used as an example to illustrate the terminal execution in:

[0067] S202, segmenting the weight parameter sequence of the artificial intelligence model to obtain multiple data segments of equal length.

[0068] Among them, the artificial intelligence model can be a neural network model for processing images, videos, voices or texts, such as an image recognition model, a video classification model, a voice recognition model or a text translation model, so that tasks such as image recognition, video classification, voice recognition or text translation can be performed; in addition, it can also be a generative model, such as a Transformer model for text-generated images or text-generated videos, so that tasks such as text-generated images or text-generated videos can be performed.

[0069] The weight parameter sequence may be a parameter sequence composed of weight parameters of each network layer in the artificial intelligence model. The weight parameters in the weight parameter sequence may be arranged in the order of the network layers, or may be arranged by the terminal according to the execution logic.

[0070] The data segment may be a subsequence obtained by segmenting the weight parameter sequence, and each data segment includes a plurality of weight parameters of equal quantity.

[0071] In one embodiment, the terminal may first determine the segment length, and then segment the weight parameter sequence of the artificial intelligence model according to the segment length to obtain multiple data segments of equal length.

[0072] In one embodiment, the artificial intelligence model may be a model obtained after pruning the initial artificial intelligence model, or may be an initial artificial intelligence model that does not require pruning; it should be noted that the initial artificial intelligence model may be a trained neural network model that can be used to process images, videos, voices or texts. When the artificial intelligence model may be a model obtained after pruning the initial artificial intelligence model, before S202, the terminal may first prune the initial artificial intelligence model to obtain a processed artificial intelligence model; and quantize the weight parameters of the artificial intelligence model to obtain a weight parameter sequence of the artificial intelligence model.

[0073] Among them, pruning is a model optimization technology that simplifies the model structure by removing some unimportant neurons in the initial artificial intelligence model. Pruning can be performed according to the network layer or channel, or it can be performed weight by weight or neuron, thereby reducing the complexity of the model while minimizing the impact on model performance.

[0074] In one embodiment, after pruning, the terminal may also perform sparse processing on the artificial intelligence model obtained after pruning to obtain a processed artificial intelligence model.

[0075] Among them, sparsification is to set some weight parameters in the model to zero or approximately zero, thereby significantly reducing the storage requirements and calculation amount of the model. Among them, the weight parameters that need to be sparsified can be unimportant weight parameters.

[0076] S204, for each data segment of equal length, encode each weight parameter in the data segment to obtain first encoded data of the first bit width and second encoded data of the second bit width.

[0077] The first coded data is bitmap data in the form of a binary string, and the bit width of the first coded data is the first bit width. The first bit width is smaller than the second bit width, that is, the first bit width of the first coded data is smaller than the second bit width of the second coded data.

[0078] The second encoded data may be multi-base encoded data, specifically, encoded data of a second bit width, the second bit width being equal to the bit width of the weight parameter, that is, the base number of the second encoded data is the same as the base number of the weight parameter of the artificial intelligence model. The above base number may be referred to as the bit width.

[0079] In one embodiment, the terminal adopts Zerobitmap encoding to encode each weight parameter in the data segment into a first bit width encoded weight parameter and a second bit width encoded weight parameter; the first bit width encoded weight parameters are combined to obtain first encoded data; the second bit width encoded weight parameters are combined to obtain second encoded data.

[0080] Among them, Zerobitmap encoding can be a bitmap encoding used for lossless compression.

[0081] For example, assuming that the bit width of each weight parameter in the data segment is 8 bits, the bit length of the data segment is 64 bits. Figure 3 As shown in the figure, the weight parameters of the data segment are {1, 0, 0, 2, 2, 0, 0, 1}. These weight parameters are encoded by Zerobitmap encoding to obtain bitmap data {0, 1,1, 0, 0, 1, 1, 0} with a bit width of 1 bit and encoded data {1, 2, 2, 1} with a bit width of 8 bits for each weight parameter. Therefore, the encoded bit length is 48 bits. Among them, 1 bit "1" indicates that the data at this position is 0, 1 bit "0" indicates that the data at this position is not 0, and the 8-bit value corresponds to the non-0 weight parameter in the data segment.

[0082] S206, assigning corresponding probability models to each binary character in the bitmap data in turn.

[0083] In one embodiment, the terminal inputs the binary characters in the bitmap data into the context model; for each binary character in the bitmap data, the context model is used to assign a corresponding probability model to the current binary character.

[0084] The bitmap data is a binary string, and the maximum probability symbol (MPS) at different binary character positions in the binary string may be different, and the probabilities may also be different. The context model determines the value of MPS and the value of the minimum probability symbol (LPS) according to the sparsity of the binary string. For example, if the sparsity is greater than 0.5, MPS is set to 0 and LPS is set to 1, otherwise vice versa.

[0085] If MPS is 0, the initial interval of MPS Approximately equal to the sparsity rate * 256, the initial interval of LPS is approximately equal to 1-sparseness rate, otherwise it is the opposite. Can be obtained by looking up the table.

[0086] Assume that MPS comes first and LPS comes later, and the probability of LPS is , then the probability of MPS is , so the cumulative probability of LPS is , the cumulative probability of MPS is = 0.

[0087] Regarding the update of the interval size, if the current encoding is LPS: ; If the current encoding is MPS: .

[0088] Regarding the update of the interval starting point, if the current code is LPS: ; If the current encoding is MPS: .

[0089] S208, performing arithmetic coding on the binary characters based on the probability model until the arithmetic coding of all the bitmap data is completed to obtain third coded data of all the bitmap data.

[0090] In one embodiment, the terminal inputs the current binary character and the corresponding probability model into the arithmetic coding model; through the arithmetic coding model, the current binary character is arithmetically encoded according to the probability model until the arithmetic coding of all bitmap data is completed to obtain the third encoded data of all bitmap data.

[0091] Specifically, the terminal uses an arithmetic coding model to perform arithmetical coding on the current binary character according to the coding interval corresponding to the probability model to obtain the current coding result; the probability model is updated based on the current coding result to update the data of the probability model assigned to the next binary character, and the next binary character is arithmetically encoded based on the updated probability model until the arithmetic coding of all bitmap data is completed to obtain the third encoded data of all bitmap data.

[0092] S210, using the second encoded data and the third encoded data as weight parameter compression results of the artificial intelligence model.

[0093] In one embodiment, after completing the encoding of the bitmap data of all data segments, the terminal uses the obtained second encoded data and third encoded data as the weight parameter compression result of the artificial intelligence model.

[0094] In one embodiment, the terminal may store the weight parameter compression result of the artificial intelligence model in the memory; upon receiving a task processing request, read the weight parameter compression result from the memory; arithmetically decode the third encoded data in the weight parameter compression result to obtain bitmap data; decode the bitmap data and the second encoded data to obtain the weight parameter sequence of the artificial intelligence model; and perform task processing based on the artificial intelligence model with the weight parameter sequence.

[0095] In order to understand the solution of this application more clearly, you can combine Figure 4 The details are as follows:

[0096] (i) Pruning and / or sparsifying the initial AI model;

[0097] (2) quantifying the weight parameters in the processed AI model;

[0098] (iii) using a hybrid coding method to encode the quantized weight parameters;

[0099] The hybrid coding method may be a combination of Zerobitmap coding and CABAC coding.

[0100] The quantized weight parameters can be divided into data segments of the same length, and the weight parameters in each data segment are encoded using Zerobitmap encoding. In addition, the bitmap data obtained by Zerobitmap encoding is further CABAC encoded.

[0101] Among them, if the sparseness rate of the bitmap data is greater than 0.5, MPS is set to 0 and LPS is set to 1, otherwise vice versa.

[0102] If MPS is 0, the initial interval of MPS Approximately equal to the sparsity rate * 256, the initial interval of LPS Approximately equal to 1-sparseness rate, otherwise vice versa.

[0103] Assume that MPS comes first and LPS comes later, and the probability of LPS is , then the probability of MPS is , so the cumulative probability of LPS is , the cumulative probability of MPS is = 0.

[0104] Regarding the update of the interval size, if the current encoding is LPS: ; If the current encoding is MPS: .

[0105] Regarding the update of the interval starting point, if the current code is LPS: ; If the current encoding is MPS: .

[0106] (iv) compressing the weight parameters of the artificial intelligence model and storing the result in the memory DDR;

[0107] (V) upon receiving a task request, decoding the weight parameter compression result by hybrid decoding;

[0108] The above-mentioned task request may be a task request for image recognition.

[0109] Hybrid decoding can be a combination of CABAC decoding and Zerobitmap decoding. When decoding, the weight parameter compression result can be first subjected to CABAC decoding, which is the opposite of the CABAC encoding process; secondly, the obtained bitmap data can be subjected to Zerobitmap decoding, which can be the opposite of the Zerobitmap encoding process.

[0110] (6) After completing the Zerobitmap decoding, the obtained results are dequantized to obtain the weight parameters of the artificial intelligence model, and then the artificial intelligence model is used to perform task processing, such as image recognition tasks.

[0111] In the above embodiment, the hybrid coding technology of Zerobitmap+CABAC is used for the weight parameters of the artificial intelligence model, which can effectively improve the compression performance; for example, the sparsity rate is 70%, and the direct coding bitmap requires N bits. Further CABAC coding requires about 0.88*N bits, which is calculated as follows: The effect of CABAC coding is close to the information entropy H, , enter the formula to calculate: . Where N is the total length of the data.

[0112] In the above embodiment, the weight parameter sequence of the artificial intelligence model is segmented to obtain multiple data segments of equal length; for each data segment of equal length, each weight parameter in the data segment is encoded to obtain first encoded data with a first bit width and second encoded data with a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter. Through this encoding, the data volume of the weight parameter can be effectively reduced; in addition, a corresponding probability model is assigned to each binary character in the bitmap data in turn; based on the probability model, the binary characters are arithmetically encoded until the arithmetic encoding of all bitmap data is completed, and the third encoded data of all bitmap data is obtained, so that the data volume of the weight parameter can be further compressed. Therefore, encoding by two different encoding methods can greatly reduce the data volume of the weight parameter, so that after the second encoded data and the third encoded data are used as the compression results of the weight parameters of the artificial intelligence model, the weight parameters of the artificial intelligence model can be loaded into the on-chip storage at one time, which is beneficial to improving the computing power of the chip.

[0113] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0114] Based on the same inventive concept, the embodiment of the present application also provides a compression device for an artificial intelligence model for implementing the compression method of the artificial intelligence model involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the compression device for one or more artificial intelligence models provided below can be found in the above limitations on the compression method for the artificial intelligence model, and will not be repeated here.

[0115] In one embodiment, Figure 5 As shown, a compression device for an artificial intelligence model is provided, comprising: a segmentation module 502, a first encoding module 504, an allocation module 506 and a second encoding module 508, wherein:

[0116] Segmentation module 502, used for segmenting the weight parameter sequence of the artificial intelligence model to obtain multiple data segments of equal length;

[0117] A first encoding module 504 is used to encode each weight parameter in each data segment of equal length to obtain first encoded data of a first bit width and second encoded data of a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter;

[0118] An allocation module 506, for sequentially allocating corresponding probability models to each binary character in the bitmap data;

[0119] The second encoding module 508 is used to perform arithmetic encoding on binary characters based on the probability model until the arithmetic encoding of all bitmap data is completed to obtain third encoded data of all bitmap data; the second encoded data and the third encoded data are used as the weight parameter compression result of the artificial intelligence model.

[0120] In one embodiment, if Figure 6 As shown, the device also includes:

[0121] A pruning module 510 is used to prune the initial artificial intelligence model to obtain a processed artificial intelligence model;

[0122] The quantization module 512 is used to quantize the weight parameters of the artificial intelligence model to obtain a weight parameter sequence of the artificial intelligence model.

[0123] In one embodiment, the first encoding module 504 is also used to adopt Zerobitmap encoding to encode each weight parameter in the data segment into a first bit width encoded weight parameter and a second bit width encoded weight parameter; combine the first bit width encoded weight parameters to obtain first encoded data; and combine the second bit width encoded weight parameters to obtain second encoded data.

[0124] In one embodiment, the assignment module 506 is further used to input the binary characters in the bitmap data into the context model; for each binary character in the bitmap data, assign a corresponding probability model to the current binary character through the context model;

[0125] The second encoding module 508 is also used to input the current binary character and the corresponding probability model into the arithmetic coding model; through the arithmetic coding model, the current binary character is arithmetically encoded according to the probability model until the arithmetic encoding of all bitmap data is completed to obtain the third encoded data of all bitmap data.

[0126] In one embodiment, the second encoding module 508 is also used to perform arithmetically encoding on the current binary character through the arithmetic coding model according to the coding interval corresponding to the probability model to obtain the current encoding result; update the probability model based on the current encoding result so that the probability model assigned to the next binary character is updated, and perform arithmetically encoding on the next binary character based on the updated probability model until the arithmetic encoding of all bitmap data is completed to obtain the third encoded data of all bitmap data.

[0127] In one embodiment, if Figure 6 As shown, the device also includes:

[0128] The storage module 514 is used to store the weight parameter compression result of the artificial intelligence model in the memory;

[0129] A reading module 516, configured to read the weight parameter compression result from the memory when receiving a task processing request;

[0130] A first decoding module 518, configured to perform arithmetic decoding on the third coded data in the weight parameter compression result to obtain bitmap data;

[0131] A second decoding module 520, for decoding the bitmap data and the second coded data to obtain a weight parameter sequence of the artificial intelligence model;

[0132] The task processing module 522 is used to perform task processing based on an artificial intelligence model with a weight parameter sequence.

[0133] In the above embodiment, the weight parameter sequence of the artificial intelligence model is segmented to obtain multiple data segments of equal length; for each data segment of equal length, each weight parameter in the data segment is encoded to obtain first encoded data with a first bit width and second encoded data with a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter. Through this encoding, the data volume of the weight parameter can be effectively reduced; in addition, a corresponding probability model is assigned to each binary character in the bitmap data in turn; based on the probability model, the binary characters are arithmetically encoded until the arithmetic encoding of all bitmap data is completed, and the third encoded data of all bitmap data is obtained, so that the data volume of the weight parameter can be further compressed. Therefore, encoding by two different encoding methods can greatly reduce the data volume of the weight parameter, so that after the second encoded data and the third encoded data are used as the compression results of the weight parameters of the artificial intelligence model, the weight parameters of the artificial intelligence model can be loaded into the on-chip storage at one time, which is beneficial to improving the computing power of the chip.

[0134] Each module in the compression device of the above artificial intelligence model can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0135] In one embodiment, a computer device is provided, which may be a server, including a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store model data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a compression method of an artificial intelligence model is implemented.

[0136] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC, Near Field Communication) or other technologies. When the computer program is executed by the processor, a compression method of an artificial intelligence model is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0137] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0138] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above-mentioned artificial intelligence model compression method when executing the computer program.

[0139] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the compression method of the above-mentioned artificial intelligence model are implemented.

[0140] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the steps of the above-mentioned artificial intelligence model compression method.

[0141] It should be noted that the user information and data involved in this application, including but not limited to user device information, user personal information, etc., and the data including but not limited to data used for analysis, stored data, displayed data, etc., are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0142] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM, Read-Only Memory), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM, Magnetoresistive Random Access Memory), ferroelectric random access memory (FRAM, Ferroelectric Random Access Memory), phase change memory (PCM, Phase Change Memory), graphene memory, etc. Volatile memory can include random access memory (RAM, Random Access Memory) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0143] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0144] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for compressing an artificial intelligence model, characterized in that: The method comprises: Segmenting a weight parameter sequence of an artificial intelligence model to obtain a plurality of data segments of equal length; the artificial intelligence model is a neural network model for processing images, videos, voices or texts; For each data segment of equal length, each weight parameter in the data segment is encoded to obtain first encoded data of a first bit width and second encoded data of a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter; sequentially assigning corresponding probability models to each binary character in the bitmap data; Performing arithmetic coding on the binary characters based on the probability model until the arithmetic coding of all the bitmap data is completed, thereby obtaining third coded data of all the bitmap data; The second encoded data and the third encoded data are used as weight parameter compression results of the artificial intelligence model.

2. The method according to claim 1, characterized in that The method further comprises: Pruning the initial artificial intelligence model to obtain a processed artificial intelligence model; The weight parameters of the artificial intelligence model are quantized to obtain a weight parameter sequence of the artificial intelligence model.

3. The method according to claim 1, characterized in that The encoding of each weight parameter in the data segment to obtain first encoded data of a first bit width and second encoded data of a second bit width comprises: Using Zerobitmap encoding, each weight parameter in the data segment is encoded into a first bit width encoded weight parameter and a second bit width encoded weight parameter; Combining the encoded weight parameters of the first bit width to obtain first encoded data; The encoded weight parameters of the second bit width are combined to obtain second encoded data.

4. The method according to claim 1, characterized in that: The step of sequentially assigning corresponding probability models to each binary character in the bitmap data comprises: Inputting binary characters in the bitmap data into a context model; For each binary character in the bitmap data, assign a corresponding probability model to the current binary character through the context model; The performing arithmetic coding on the binary character based on the probability model until the arithmetic coding of all the bitmap data is completed to obtain the third coded data of all the bitmap data comprises: Inputting the current binary character and the corresponding probability model into an arithmetic coding model; The arithmetic coding model is used to perform arithmetic coding on the current binary character according to the probability model until the arithmetic coding of all the bitmap data is completed, thereby obtaining third coded data of all the bitmap data.

5. The method according to claim 4, characterized in that The arithmetic coding model is used to perform arithmetic coding on the current binary character according to the probability model until the arithmetic coding of all the bitmap data is completed, and the third coded data of all the bitmap data is obtained, including: By using the arithmetic coding model, arithmetic coding is performed on the current binary character according to the coding interval corresponding to the probability model to obtain a current coding result; A probability model is updated based on the current encoding result so that data of the probability model assigned to the next binary character is updated, and the next binary character is arithmetically encoded based on the updated probability model until the arithmetic encoding of all the bitmap data is completed to obtain third encoded data of all the bitmap data.

6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Storing the weight parameter compression result of the artificial intelligence model in the memory; In case of receiving a task processing request, reading the weight parameter compression result from the memory; Performing arithmetic decoding on the third coded data in the weight parameter compression result to obtain the bitmap data; Decoding the bitmap data and the second encoded data to obtain a weight parameter sequence of the artificial intelligence model; Task processing is performed based on the artificial intelligence model with the weight parameter sequence.

7. A compression device for an artificial intelligence model, characterized in that: The device comprises: A segmentation module, used for segmenting the weight parameter sequence of the artificial intelligence model to obtain multiple data segments of equal length; the artificial intelligence model is a neural network model for processing images, videos, voices or texts; A first encoding module is used to encode each weight parameter in the data segment for each data segment of equal length to obtain first encoded data of a first bit width and second encoded data of a second bit width; the first encoded data is bitmap data in the form of a binary string, the first bit width is smaller than the second bit width, and the second bit width is equal to the bit width of the weight parameter; An allocation module, used for sequentially allocating corresponding probability models to each binary character in the bitmap data; The second encoding module is used to perform arithmetic encoding on the binary characters based on the probability model until the arithmetic encoding of all the bitmap data is completed, thereby obtaining third encoded data of all the bitmap data; and use the second encoded data and the third encoded data as the weight parameter compression result of the artificial intelligence model.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Data processing method, accelerator, computer equipment and readable storage medium

    CN118261217A

  • Encoding parameters with unit sum

    US20110075724A1