Model storage method and apparatus
By dividing floating-point parameters and storing the difference by discarding the mantissa, combined with the grouping difference verification of fixed-point parameters, the problem of insufficient storage space on edge devices is solved, and efficient and lossless model storage is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-09
- Publication Date
- 2026-03-10
AI Technical Summary
In existing technologies, the large number of parameters in neural networks leads to excessive storage space load on edge devices, especially the storage space occupied by floating-point and fixed-point numbers.
The floating-point parameters are divided into two parts: only the sign bit, exponent bit, and part of the mantissa bits are stored, and the remaining mantissa bits are discarded. The floating-point parameters are stored by difference, and the fixed-point parameters are stored after being grouped and checked by difference according to the distribution characteristics.
It effectively reduces storage space requirements, avoids parameter distortion after compression, and achieves efficient storage for edge devices.
Smart Images

Figure CN115952226B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data storage, and more particularly to a model storage method and apparatus. Background Technology
[0002] Compared to traditional methods, current models have achieved superior performance on a wide range of tasks, but they also present deployment problems and challenges. For example, the number of parameters in neural networks is usually in the millions or larger, making the storage and use of neural networks on edge devices a significant challenge. Typically, neural network parameters are stored in the form of single-precision floating-point numbers (Full Precise Float 32, abbreviated as fp32), half-precision floating-point numbers (Full Precise Float 16, abbreviated as fp16), or 8-bit fixed-point numbers (int8). However, regardless of the bit width used to store neural network parameters, it places a heavy burden on the storage space of edge devices. Summary of the Invention
[0003] This disclosure provides a model storage method and apparatus to at least solve the problem in the related art that storing models can place a heavy burden on the storage space of edge devices.
[0004] According to a first aspect of the present disclosure, a model storage method is provided, comprising: for a first parameter in the model to be stored as a floating-point number, dividing the first parameter into a first part parameter and a second part parameter, wherein the first part parameter and the second part parameter occupy the same storage space, the first part parameter including the sign bit, exponent bit and part of the mantissa bit of the first parameter, and the second part parameter including the remaining mantissa bit of the first parameter; obtaining the difference between the first parameter and the first part parameter; and storing the difference and the first part parameter to obtain the stored first parameter of the model to be stored.
[0005] Optionally, storing the difference includes storing the difference in a predetermined storage format, wherein the storage space occupied by the predetermined storage format is less than the storage space occupied by the first part of the parameters.
[0006] Optionally, for the second parameter in the model to be stored, which is a fixed-point number of a first representation range, the number of parameters whose parameter values fall within the second representation range is determined, wherein the second representation range is smaller than the first representation range; if the number of parameters exceeds a predetermined proportion of the total number of second parameters, the second parameters whose parameter values fall within the second representation range are stored according to the fixed-point number of the second representation range, to obtain the second parameters after partial storage of the model to be stored; the second parameters whose parameter values do not fall within the second representation range are stored according to the original storage format, to obtain the second parameters after storage of the other parts of the model to be stored.
[0007] Optionally, second parameters whose parameter values fall within the second representation range are stored according to the storage format of fixed-point numbers of the second representation range, to obtain the second parameters of the model to be stored after partial storage. This includes: determining storage groups based on the storage space occupied by the two storage methods of fixed-point numbers of the first and second representation ranges; storing the second parameters whose parameter values fall within the second representation range in sequence according to the storage format of fixed-point numbers of the second representation range, using storage groups as units, to obtain the second parameters of the model to be stored after partial storage; and identifying the storage format corresponding to each storage group.
[0008] Optionally, if the number of parameters does not exceed a predetermined proportion of the total number of second parameters, the second parameters are grouped to obtain multiple first parameter sets; for each first parameter set, the parameters in the first parameter set are converted according to the storage format of fixed-point numbers of the second representation range to obtain a second parameter set; if the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is within a predetermined range, the parameters in the first parameter set are stored according to the storage format of fixed-point numbers of the second representation range to obtain the stored first parameter set of the model to be stored.
[0009] Optionally, if the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is not within a predetermined range, the parameters in the first parameter set are stored in their original storage form to obtain the stored first parameter set of the model to be stored.
[0010] Optionally, after storing the parameters in the first parameter set according to the fixed-point number of the second representation range to obtain the stored first parameter set of the model to be stored, the method further includes: identifying the storage space occupied by the stored first parameter set and the corresponding storage format.
[0011] According to a second aspect of the present disclosure, a model storage device is provided, comprising: a partitioning unit configured to partition a first parameter in a model to be stored as a floating-point number into a first part and a second part of the parameter, wherein the first part and the second part of the parameter occupy the same storage space, the first part of the parameter including a sign bit, an exponent bit, and a portion of the mantissa bits of the first parameter, and the second part of the parameter including the remaining mantissa bits of the first parameter; a difference acquisition unit configured to acquire the difference between the first parameter and the first part of the parameter; and a storage unit configured to store the difference and the first part of the parameter to obtain the stored first parameter of the model to be stored.
[0012] Optionally, the storage unit is further configured to store the difference in a predetermined storage format, wherein the storage space occupied by the predetermined storage format is less than the storage space occupied by the first part of the parameters.
[0013] Optionally, the model storage device further includes: a determining unit configured to, for a second parameter in the model to be stored in the form of a fixed-point number of a first representation range, determine the number of parameters whose parameter values fall within the second representation range, wherein the second representation range is smaller than the first representation range; and a storage unit further configured to, when the number of parameters exceeds a predetermined proportion of the total number of second parameters, store the second parameters whose parameter values fall within the second representation range in the form of a fixed-point number of the second representation range, to obtain the second parameters after partial storage of the model to be stored; and store the second parameters whose parameter values do not fall within the second representation range in the original storage form, to obtain the second parameters after storage of the remaining parts of the model to be stored.
[0014] Optionally, the storage unit is further configured to determine the storage space occupied by the two storage methods based on the fixed-point number of the first representation range and the fixed-point number of the second representation range, and to identify the storage group; taking the storage group as a unit, the second parameters whose parameter values fall within the range of the second representation range are stored in the storage form of the fixed-point number of the second representation range, to obtain the second parameters after partial storage of the model to be stored; and the storage form corresponding to each storage group is identified.
[0015] Optionally, the storage unit is further configured to group the second parameters to obtain multiple first parameter sets if the number of parameters does not exceed a predetermined proportion of the total number of second parameters; for each first parameter set, the parameters in the first parameter set are converted according to the storage format of fixed-point numbers of the second representation range to obtain a second parameter set; if the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is within a predetermined range, the parameters in the first parameter set are stored according to the storage format of fixed-point numbers of the second representation range to obtain the stored first parameter set of the model to be stored.
[0016] Optionally, the storage unit is further configured to store the parameters in the first parameter set in the original storage form when the average difference between the parameters in the first parameter set and the parameters in the corresponding second parameter set is not within a predetermined range, thereby obtaining the stored first parameter set of the model to be stored.
[0017] Optionally, the storage unit is further configured to store the parameters in the first parameter set in a storage format with a fixed number of points according to the second representation range, and after obtaining the stored first parameter set of the model to be stored, to identify the storage space occupied by the stored first parameter set and the corresponding storage format.
[0018] According to a fifth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement a model storage method according to the present disclosure.
[0019] According to a sixth aspect of the present disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by at least one processor, causes at least one processor to perform the model storage method as described above according to the present disclosure.
[0020] According to a seventh aspect of the present disclosure, a computer program product is provided, including computer instructions that, when executed by a processor, implement the model storage method according to the present disclosure.
[0021] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects:
[0022] According to the model storage method and apparatus of this disclosure, for parameters stored in floating-point format, this disclosure divides the parameter into two parts and stores only the part including the sign bit, exponent bit, and part of the mantissa bits. This eliminates the need to store the remaining mantissa bits, reducing the storage space occupied by such parameters. Furthermore, this disclosure also stores the deviation introduced by removing the second part, avoiding distortion caused by recovering the parameter after compression. Therefore, this disclosure solves the problem in related technologies where storing models places a heavy burden on the storage space of edge devices.
[0023] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0024] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0025] Figure 1 This is a schematic diagram illustrating an implementation scenario of the model storage method according to an exemplary embodiment of the present disclosure;
[0026] Figure 2 This is a flowchart illustrating a model storage method according to an exemplary embodiment;
[0027] Figure 3 This is a schematic diagram of the structure of an fp16 according to an exemplary embodiment;
[0028] Figure 4This is a schematic diagram illustrating a method of adding special effects to a video according to an exemplary embodiment;
[0029] Figure 5 This is a block diagram illustrating a model storage device according to an exemplary embodiment;
[0030] Figure 6 This is a block diagram of an electronic device 600 according to an embodiment of the present disclosure. Detailed Implementation
[0031] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0032] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following examples do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0033] It should be noted that the phrase "at least one of several items" in this disclosure refers to three parallel cases: "any one of the several items", "a combination of any number of the several items", and "all of the several items". For example, "including at least one of A and B" includes the following three parallel cases: (1) including A; (2) including B; (3) including A and B. As another example, "performing at least one of step one and step two" indicates the following three parallel cases: (1) performing step one; (2) performing step two; (3) performing both step one and step two.
[0034] This disclosure provides a model storage method that can reduce the heavy load that the storage model places on the storage space of edge devices. The following explanation uses the parameters of the storage form fp16 as an example.
[0035] Figure 1 This is a schematic diagram illustrating an implementation scenario of a model storage method according to exemplary embodiments of the present disclosure, such as... Figure 1The implementation scenario includes server 100, user terminal 110, and user terminal 120. The number of user terminals is not limited to two and includes, but is not limited to, devices such as mobile phones and personal computers. The user terminals can store models. The server can be a single server, a server cluster composed of several servers, or a cloud computing platform or virtualization center.
[0036] Assuming user terminal 110 is an edge device and user terminal 120 is a non-edge device, and the model on user terminal 120 needs to be stored on user terminal 110, then for the first parameter in the model to be stored, which is stored in fp16 format, user terminal 120 divides the first parameter into a first part parameter and a second part parameter. The first part parameter and the second part parameter occupy the same storage space. The first part parameter includes 1 sign bit, 5 exponent bits, and 2 mantissa bits, and the second part parameter includes 8 mantissa bits. The difference between the first parameter and the first part parameter is obtained; the difference and the first part parameter are stored on user terminal 110 to obtain the stored first parameter of the model to be stored. It should be noted that user terminal 110 and user terminal 120 can complete this work independently, or they can be provided with data services by server 100. This disclosure does not limit this. When providing data services through server 100, user terminal 120 uploads the model to be stored to server 100. For the first parameter in the model to be stored, which is stored in fp16 format, server 100 divides the first parameter into a first part parameter and a second part parameter. The first part parameter and the second part parameter occupy the same storage space. The first part parameter includes 1 sign bit, 5 exponent bits, and 2 mantissa bits, and the second part parameter includes 8 mantissa bits. The difference between the first parameter and the first part parameter is obtained. The difference and the first part parameter are stored on user terminal 110 to obtain the stored first parameter of the model to be stored. In this way, the storage format of the first parameter changes from fp16 to fp8.
[0037] The model storage method and apparatus according to exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings.
[0038] Figure 2 This is a flowchart illustrating a model storage method according to an exemplary embodiment, such as... Figure 2 As shown, the model storage method includes the following steps:
[0039] In step S201, for the first parameter in the model to be stored as a floating-point number, the first parameter is divided into a first part parameter and a second part parameter. The first part parameter and the second part parameter occupy the same storage space. The first part parameter includes the sign bit, exponent bit and part of the mantissa bit of the first parameter, and the second part parameter includes the remaining mantissa bit of the first parameter.
[0040] The aforementioned floating-point numbers generally include fp32 and fp16. For example, taking the floating-point number fp16 as an example, the structure of fp16 is as follows: Figure 3 As shown, for parameters stored in fp16 format, the following can be used: Figure 3 The sign bit, exponent bit, and the first two mantissa bits shown are used as the first part of the parameters. Figure 3 The last 8 digits shown are used as the second part of the parameters.
[0041] return Figure 2 In step S202, the difference between the first parameter and the first part of the parameters is obtained. This step can obtain the difference between the first parameter and the first part of the parameters using the `diff` command, although other commands can also be used, and this disclosure does not limit this. It should be noted that the function of the `diff` command is to compare two text files line by line and list their differences.
[0042] return Figure 2 In step S203, the difference and the first part of the parameters are stored to obtain the first parameters of the model to be stored. In this step, only the first part of the parameters and the corresponding difference are stored, and the second part of the parameters is discarded. At this time, the parameters stored in fp16 format are compressed into parameters stored in fp8 format.
[0043] According to an exemplary embodiment of this disclosure, storing the difference may include storing the difference in a predetermined storage format, wherein the storage space occupied by the predetermined storage format is less than the storage space occupied by the first part of the parameters. According to this embodiment, by using a storage method that occupies less storage space than the first part of the parameters to store the difference, excessive increases in the storage space occupied by the first parameters after the model to be stored is avoided.
[0044] For example, the difference can be stored using a fixed-point number int6 or int4. This way, even if the difference is stored, the storage space occupied by the first parameter of the model to be stored will not increase too much. Of course, this disclosure does not limit this.
[0045] To better understand the above embodiments of this disclosure, the parameters stored in fp32 format will be systematically described below. For parameters stored in fp32 format, the compression method in related technologies can be used to compress the parameters in fp32 format to parameters in fp16 format. After obtaining the parameters in fp16 format, the method of this disclosure is then executed to obtain parameters in fp8 format. Alternatively, the method of this disclosure can be directly executed to compress the parameters in fp32 format to obtain parameters in fp16 format. This disclosure does not limit the scope of the method.
[0046] Typically, fp32 is represented by 1 sign bit, 8 exponent bits, and 23 mantissa bits. Its representation range is determined by the 23 mantissa bits and 8 exponent bits. We can first convert the fp32 parameter to fp16 using compression methods. fp16 is represented by 1 sign bit, 5 exponent bits, and 10 mantissa bits. Then, using the basic data type char in computer programming languages, the fp16 parameter can be divided into two parts: one part includes the mantissa, exponent, and sign bits, represented as 2+5+1 (the first part of the parameter mentioned above); the other part includes the remaining mantissa bits, 8 mantissa bits (the second part of the parameter mentioned above). During storage, the part containing the 8 mantissa bits is discarded, and only the part including the mantissa, exponent, and sign bits is stored. Thus, the fp16 parameter is compressed into an fp8 parameter. To avoid significant parameter loss in the compressed fp8 format, the difference between the parameter (including the mantissa, exponent, and sign bits) and the parameter in fp16 format can be obtained using the diff instruction. This difference is stored in an additional memory space as an int6 or int4. Assuming the difference is stored as a 4-bit fixed-point number (int4), the total memory occupied by the parameter in fp32 format is 12 bits, including the memory occupied by the mantissa, exponent, and sign bits, and the memory occupied by the difference. It should be noted that char is used in C or C++ to define character variables, occupying only one byte, with a value range of -128 to +127.
[0047] It should be noted that since the binary representation of a computer cannot precisely describe a number (such as 0.1), floating-point numbers are essentially an approximate representation. For example, for data stored in fp16 format, its storage format in the computer is 10+5+1, that is, the exponent and sign bits are stored in the lower bits. Furthermore, models (such as neural network models) are usually more sensitive to the size of the exponent. Therefore, this disclosure considers that the mantissa part can be discarded to reduce the memory occupied by the parameters.
[0048] Generally, a model's parameters may include not only floating-point parameters but also fixed-point parameters, which also need to be compressed accordingly. Considering that model parameters usually follow a normal distribution, with a large number of parameters around 0 and a small number of parameters taking larger values (i.e., an absolute value around 127 in int8 storage), different models may have a large number of parameters within the range of int6 (-32, 32) or int4 (-8, 8). Based on this, this disclosure provides two methods.
[0049] In the first method, according to an exemplary embodiment of this disclosure, for a second parameter in the model to be stored that is a fixed-point number of a first representation range, the number of parameters whose parameter values fall within the second representation range is determined, wherein the second representation range is smaller than the first representation range; if the number of parameters exceeds a predetermined proportion of the total number of second parameters, the second parameters whose parameter values fall within the second representation range are stored in the fixed-point number of the second representation range to obtain the second parameters after partial storage of the model to be stored; and the second parameters whose parameter values do not fall within the second representation range are stored in the original storage format to obtain the second parameters after storage of the remaining parts of the model to be stored.
[0050] According to this embodiment, some parameters that are stored in the form of fixed-point numbers of the first representation range are stored in the form of fixed-point numbers of the second representation range. As a result, the storage space occupied by the parameters that are stored in the form of fixed-point numbers of the first representation range can store multiple parameters, instead of being limited to one parameter. This is equivalent to reducing the storage space occupied by the parameters. Moreover, the parameters compressed in this embodiment are those that fall within the second representation range, so the compressed parameters are also lossless.
[0051] The aforementioned predetermined ratio can be 95% or other ratios, depending on the user's needs; this disclosure does not impose any limitations. The fixed-point number of the first representation range can be int8, and the fixed-point number of the second representation range can be int6 or int4; this disclosure does not impose any limitations on this. For example, taking the example that the fixed-point number of the first representation range can be int8 and the fixed-point number of the second representation range can be int4, the number of parameters whose values fall within the representation range of int4 in the int8 form is first determined. When the number of parameters exceeds 95% of the total number of second parameters, the parameters whose values fall within the representation range of int4 can be stored in the int4 storage format, while the parameters that do not fall within the representation range of int4 continue to be stored in the int8 storage format.
[0052] According to an exemplary embodiment of this disclosure, second parameters whose value range falls within the second representation range are stored in a fixed-point storage format according to the second representation range, to obtain the second parameters of the model to be stored after partial storage. This includes: determining storage groups based on the storage space occupied by the two storage methods, the first and second representation ranges; storing the second parameters whose value range falls within the second representation range sequentially in a fixed-point storage format according to the second representation range, to obtain the second parameters of the model to be stored after partial storage, using storage groups as units; and identifying the storage format corresponding to each storage group. According to this embodiment, using storage groups as units ensures no loss during the conversion between the two storage methods, that is, ensuring that the storage space occupied by the original storage method is completely used to store the second parameters after the conversion. Simultaneously, identifying the storage format of each storage group ensures that the converted compression method is known during subsequent recovery, facilitating decompression.
[0053] Specifically, since the smallest storage unit format supported by computers is 8 bits, and the storage space for three 8-bit parameters can hold four 6-bit parameters, and the storage space for one 8-bit parameter can hold two 4-bit parameters, for parameters in int6 form, each 24 bits is a storage group, and additional storage space can be used to identify whether each storage group stores the parameter in int8 or int6 form. For parameters in int4 form, each 8 bits is a storage group, and additional storage space can be used to identify the actual location of the int8 parameter; the remaining part defaults to int4 form. This identification method also saves storage space and also identifies whether each storage group stores the parameter in int8 or int4 form. Therefore, the final storage form for int8 parameters is either int8 + int6 or int8 + int4.
[0054] The above method is simple to implement and the parameters are recovered without loss. However, it requires that most of the fixed-point type parameters in the model fall within the representation range of int6 or int4. Otherwise, the excessive storage space occupied by the additional identifier storage group will result in poor compression effect.
[0055] In the second approach, according to an exemplary embodiment of this disclosure, when the number of parameters does not exceed a predetermined proportion of the total number of second parameters, the second parameters are grouped to obtain multiple first parameter sets. For each first parameter set, the parameters in the first parameter set are converted according to a fixed-point storage format within a second representation range to obtain a second parameter set. When the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is within a predetermined range, the parameters in the first parameter set are stored according to a fixed-point storage format within the second representation range to obtain the stored first parameter set of the model to be stored. According to embodiments of this disclosure, by grouping the second parameters and compressing each group separately, each group can be compressed according to its own proportion. Larger parameters can be compressed more, and smaller parameters only need to be compressed less, thereby reducing the distortion caused by parameter compression.
[0056] For example, let's take a first representation range with a fixed-point number of int8 and a second representation range with a fixed-point number of int4. Generally, the main loss when compressing int8 to int4 comes from the uneven distribution of parameters, leading to information loss after mapping to a lower bit space. Based on this, this embodiment groups the parameters in int8 form to obtain multiple parameter sets. The size of each set can be dynamically controlled and set according to user needs; this disclosure does not impose any limitations. After obtaining multiple parameter sets, for each parameter set, an attempt is made to convert it to int4 form. If the average difference between the converted parameter value and the original int8 parameter value in a parameter set is within 1%, then this parameter set can be stored in int4 storage form. It should be noted that the above average difference can also be obtained using the diff instruction; this disclosure does not impose any limitations on this.
[0057] For example, after obtaining multiple parameter sets, for each parameter set, we can try converting it to int4 and int6 forms respectively. If the average difference between the parameter value restored by converting to int4 and the parameter value in the original int8 form is within 1%, it means that this parameter set can be stored in int4 form. If it is not within this 1% range, we further check whether the average difference between the parameter value restored by converting to int6 and the parameter value in the original int8 form is within 1%. If it is within this 1% range, it means that this parameter set can be stored in int6 form.
[0058] The above method itself has losses, but by using group compression and limiting the average difference, the loss of model parameter compression can be effectively reduced.
[0059] According to an exemplary embodiment of this disclosure, when the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is not within a predetermined range, the parameters in the first parameter set are stored in their original storage format to obtain the stored first parameter set of the model to be stored. According to this embodiment, if the compressed parameters exhibit significant distortion after restoration, the corresponding first parameter set continues to use its original storage format without compression, thus avoiding severe distortion caused by compression.
[0060] For example, if the average difference between the parameter values after conversion to int4 and int6 and the original int8 parameter values is not within 1%, it means that this parameter set cannot be stored in int4 and int6, and int8 storage format should continue to be used.
[0061] According to an exemplary embodiment of this disclosure, after storing the parameters in the first parameter set in a fixed-point storage format according to the second representation range to obtain the stored first parameter set of the model to be stored, the method further includes: identifying the storage space occupied by the stored first parameter set and the corresponding storage format. According to this embodiment, identifying the storage format of the stored parameter set ensures that the converted compression method is known during subsequent recovery, so that decompression can be performed accordingly.
[0062] For example, after processing, each parameter set can be identified by additional storage space as a new storage format and the number of bits occupied by that parameter set, so that it can be decompressed according to the actual compression method during subsequent decompression.
[0063] In summary, this disclosure provides a dynamically adaptive model parameter compression method that introduces dynamic grouping and segmentation to ensure compression efficiency while minimizing weight distortion after compression. This method can reduce storage space by up to 25% for floating-point numbers and by at least 25% for fixed-point numbers using a hybrid compression scheme. Furthermore, because errors are compensated for during compression, the model accuracy is almost unaffected after restoring the compressed parameters. Moreover, this disclosure allows for flexible selection of different compression strategies based on the distribution of model parameters and the model's sensitivity to these parameters, achieving optimal compression results without compromising accuracy.
[0064] It should be noted that this disclosure is for the parameters of the trained model. No optimization or assumptions are made about the model itself. The parameters of the model are compressed to reduce its storage space. When the model is actually needed, the compressed and stored model parameters are restored and normal model inference is performed.
[0065] To better understand the above embodiments, specific scenarios will be used for explanation below. For example, consider a scenario where a new video effect is used for the first time. In this scenario, the new video effect is referred to as the target effect. There is generally an effect model for the target effect, which is called the target effect model in this embodiment. Currently, to avoid sending all videos using the target effect to the server and centrally adding the target effect to the corresponding videos through the target effect model on the server, which would overload the server, the target effect model is generally distributed to the terminals corresponding to the videos that need to use the target effect, thereby reducing the server load.
[0066] Specifically, Figure 4 This is an illustration of adding special effects to a video according to an exemplary embodiment, such as... Figure 4 As shown, when a target account records a video on a local terminal using a video application and needs to apply a target effect to the video, the target account first triggers the target effect through the video application. Since the target effect is a new video effect, the local terminal does not have the corresponding target effect model. Therefore, the video application needs to send a request to the server where the target effect model is located to obtain the target effect model. After receiving the request, the server will send the target effect model to the video application. However, the storage space of the local terminal is generally small and it is difficult to hold the target effect model. Therefore, when the video application receives the target effect model, it can use the model storage method disclosed herein to store the target effect model in the local memory. The specific storage method will not be discussed here. After the target effect model is stored in the local terminal's memory, when the target account triggers the target effect, the memory will decompress the stored target effect model. The video application uses the decompressed target effect model to add the target effect to the video. It should be noted that after adding the target effect, you can delete the decompressed target effect model and only keep the compressed target effect model to avoid insufficient storage space on the local terminal.
[0067] Figure 5 This is a block diagram illustrating a model storage device according to an exemplary embodiment. (Refer to...) Figure 5 The device includes a division unit 50, a difference acquisition unit 52, and a storage unit 54.
[0068] The partitioning unit 50 is configured to partition the first parameter, which is stored as a floating-point number in the model to be stored, into a first part and a second part of the parameter. The first part and the second part of the parameter occupy the same storage space. The first part of the parameter includes the sign bit, exponent bit, and part of the mantissa bit of the first parameter, and the second part of the parameter includes the remaining mantissa bit of the first parameter. The difference acquisition unit 52 is configured to acquire the difference between the first parameter and the first part of the parameter. The storage unit 54 is configured to store the difference and the first part of the parameter to obtain the stored first parameter of the model to be stored.
[0069] According to an exemplary embodiment of the present disclosure, the storage unit 54 is further configured to store the difference in a predetermined storage format, wherein the storage space occupied by the predetermined storage format is less than the storage space occupied by the first part of the parameters.
[0070] According to an exemplary embodiment of this disclosure, the model storage device further includes: a determining unit 56, configured to determine, for a second parameter in the model to be stored that has a fixed-point number of storage forms representing a first representation range, the number of parameters whose parameter values fall within the second representation range, wherein the second representation range is smaller than the first representation range; and a storage unit 54, further configured to, when the number of parameters exceeds a predetermined proportion of the total number of second parameters, store the second parameters whose parameter values fall within the second representation range in the form of fixed-point number of storage forms representing the second representation range, to obtain the second parameters after partial storage of the model to be stored; and store the second parameters whose parameter values do not fall within the second representation range in the original storage form, to obtain the second parameters after storage of the remaining parts of the model to be stored.
[0071] According to an exemplary embodiment of this disclosure, the storage unit 54 is further configured to determine a storage group based on the storage space occupied by the two storage methods of fixed-point number of the first representation range and fixed-point number of the second representation range; and to store the second parameters whose parameter values fall within the range of the second representation range in the storage form of fixed-point number of the second representation range in the storage group, thereby obtaining the second parameters after partial storage of the model to be stored; and to identify the storage form corresponding to each storage group.
[0072] According to an exemplary embodiment of this disclosure, the storage unit 54 is further configured to group the second parameters to obtain multiple first parameter sets when the number of parameters does not exceed a predetermined proportion of the total number of second parameters; for each first parameter set, the parameters in the first parameter set are converted according to the storage format of fixed-point numbers of the second representation range to obtain a second parameter set; when the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is within a predetermined range, the parameters in the first parameter set are stored according to the storage format of fixed-point numbers of the second representation range to obtain the stored first parameter set of the model to be stored.
[0073] According to an exemplary embodiment of this disclosure, the storage unit 54 is further configured to store the parameters in the first parameter set in the original storage form when the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is not within a predetermined range, thereby obtaining the stored first parameter set of the model to be stored.
[0074] According to an exemplary embodiment of this disclosure, the storage unit 54 is further configured to store the parameters in the first parameter set in a storage format of fixed-point number according to the second representation range, and after obtaining the stored first parameter set of the model to be stored, identify the storage space occupied by the stored first parameter set and the corresponding storage format.
[0075] According to embodiments of this disclosure, an electronic device may be provided. Figure 6 This is a block diagram of an electronic device 600 according to an embodiment of the present disclosure. The electronic device includes at least one memory 601 and at least one processor 602. The at least one memory stores a set of computer-executable instructions. When the set of computer-executable instructions is executed by the at least one processor, a model storage method according to an embodiment of the present disclosure is executed.
[0076] As an example, electronic device 600 may be a PC, tablet, personal digital assistant, smartphone, or other device capable of executing the aforementioned set of instructions. Here, electronic device 1000 is not necessarily a single electronic device, but may be a collection of any devices or circuits capable of executing the aforementioned instructions (or instruction sets) individually or in combination. Electronic device 600 may also be part of an integrated control system or system manager, or may be configured to interconnect with a portable electronic device locally or remotely (e.g., via wireless transmission) through an interface.
[0077] In electronic device 600, processor 602 may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. By way of example and not limitation, processor 602 may also include analog processors, digital processors, microprocessors, multi-core processors, processor arrays, network processors, etc.
[0078] The processor 602 can execute instructions or code stored in memory, wherein memory 601 can also store data. Instructions and data can also be sent and received via a network through a network interface device, wherein the network interface device can employ any known transmission protocol.
[0079] The memory 601 may be integrated with the processor 602, for example, by placing RAM or flash memory within an integrated circuit microprocessor. Alternatively, the memory 601 may include a separate device, such as an external disk drive, a storage array, or other storage device usable by any database system. The memory 601 and the processor 602 may be operatively coupled, or may communicate with each other, for example, via I / O ports, network connections, etc., enabling the processor 602 to read files stored in the memory 601.
[0080] In addition, the electronic device 600 may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of the electronic device can be interconnected via a bus and / or network.
[0081] According to embodiments of this disclosure, a computer-readable storage medium may also be provided, wherein when instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor causes the processor to perform the model storage method of the embodiments of this disclosure. Examples of computer-readable storage media include: read-only memory (ROM), random access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disc storage, hard disk drive (HDD), solid-state drive (SSD), card storage (such as multimedia cards, secure digital (SD) cards, or ultra-fast digital (XD) cards), magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device, hard disk, solid-state drive, and any other device configured to store a computer program and any associated data, data files, and data structures in a non-transitory manner and to provide the computer program and any associated data, data files, and data structures to a processor or computer so that the processor or computer can execute the computer program. The computer program in the aforementioned computer-readable storage medium can run in an environment deployed in computer devices such as clients, hosts, agent devices, servers, etc. Furthermore, in one example, the computer program and any associated data, data files, and data structures are distributed across a networked computer system, such that the computer program and any associated data, data files, and data structures are stored, accessed, and executed in a distributed manner through one or more processors or computers.
[0082] According to an embodiment of this disclosure, a computer program product is provided, including computer instructions, which, when executed by a processor, implement the model storage method of the embodiment of this disclosure.
[0083] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0084] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A model storage method characterized by comprising: The method comprises the following steps: For a first parameter in a to-be-stored model, the first parameter is stored in the form of a floating-point number, the first parameter is divided into a first partial parameter and a second partial parameter, the first partial parameter and the second partial parameter occupy the same storage space, the first partial parameter comprises a sign bit, an exponent bit and a partial mantissa bit of the first parameter, and the second partial parameter comprises a remaining mantissa bit of the first parameter; A difference value between the first parameter and the first partial parameter is obtained; The difference value and the first partial parameter are stored to obtain a stored first parameter of the to-be-stored model; The method further comprises the following steps: for a second parameter in the to-be-stored model, the second parameter is stored in the form of a fixed-point number in a first representation range, the number of parameters in the second parameter whose parameter value range falls within a second representation range is determined, and the second representation range is smaller than the first representation range; In a case where the number of parameters exceeds a predetermined proportion of a total number of the second parameter, the second parameter whose parameter value range falls within the second representation range is stored in the form of a fixed-point number in the second representation range to obtain a part of the stored second parameter of the to-be-stored model; The second parameter whose parameter value range does not fall within the second representation range is stored in an original storage form to obtain another part of the stored second parameter of the to-be-stored model; The method of storing the second parameter whose parameter value range falls within the second representation range in the form of a fixed-point number in the second representation range to obtain the part of the stored second parameter of the to-be-stored model comprises the following steps: Based on storage spaces occupied by the fixed-point number in the first representation range and the fixed-point number in the second representation range, a storage group is determined; The second parameter whose parameter value range falls within the second representation range is stored in the form of a fixed-point number in the second representation range in a unit of the storage group to obtain the part of the stored second parameter of the to-be-stored model; The storage form corresponding to each storage group is identified.
2. The model storage method of claim 1, wherein, The method of storing the difference value comprises the following steps: The difference value is stored in a predetermined storage form, and the predetermined storage form occupies a smaller storage space than the first partial parameter.
3. The model storage method of claim 1, wherein The method further comprises the following steps: In a case where the number of parameters does not exceed the predetermined proportion of the total number of the second parameter, the second parameter is grouped to obtain a plurality of first parameter sets; For each first parameter set, the parameters in the first parameter set are respectively converted into a second parameter set in the form of a fixed-point number in the second representation range; In a case where an average value of differences between the parameters in the first parameter set and the parameters in the corresponding second parameter set is within a predetermined range, the parameters in the first parameter set are stored in the form of a fixed-point number in the second representation range to obtain a stored first parameter set of the to-be-stored model.
4. The model storage method of claim 3, wherein, The method further comprises the following steps: In a case where the average difference between the parameters in the first parameter set and the corresponding parameters in the second parameter set is not within the predetermined range, the parameters in the first parameter set are stored in the original storage form to obtain a stored first parameter set of the model to be stored.
5. The model storage method of claim 3, wherein After storing the parameters in the first parameter set in the storage form of the fixed-point number of the second representation range to obtain a stored first parameter set of the model to be stored, the method further includes: identifying the storage space occupied by the stored first parameter set and the corresponding storage form.
6. A model storage device characterized by comprising: The method includes: a division unit configured to divide, for a first parameter in a model to be stored and in a storage form of a floating-point number, the first parameter into a first part and a second part, the first part and the second part occupying the same storage space, the first part including a sign bit, an exponent bit, and part of a tail bit of the first parameter, and the second part including the remaining tail bit of the first parameter; a difference acquisition unit configured to acquire a difference between the first parameter and the first part; a storage unit configured to store the difference and the first part to obtain a stored first parameter of the model to be stored. The model storage device further includes a determination unit configured to determine, for a second parameter in the model to be stored and in a storage form of a fixed-point number of a first representation range, a number of parameters whose parameter values fall within a second representation range, wherein the second representation range is smaller than the first representation range. The storage unit is further configured to, in a case where the number of parameters exceeds a predetermined proportion of the total number of the second parameters, store the second parameters whose parameter values fall within the second representation range in the storage form of the fixed-point number of the second representation range to obtain part of the stored second parameters of the model to be stored, and store the second parameters whose parameter values do not fall within the second representation range in the original storage form to obtain other part of the stored second parameters of the model to be stored. The storage unit is further configured to determine storage groups based on the storage space occupied by the fixed-point number of the first representation range and the fixed-point number of the second representation range, and sequentially store, in the storage form of the fixed-point number of the second representation range, the second parameters whose parameter values fall within the second representation range in units of storage groups to obtain part of the stored second parameters of the model to be stored, and identify the storage form corresponding to each storage group.
7. An electronic device, comprising: The method includes: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the model storage method of any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor is caused to perform the model storage method of any one of claims 1 to 5.
Citation Information
Patent Citations
Floating-point-type data lossless compression method for scientific calculation
CN105024702A
Operation processing device
JP1988071726A