Mixed precision weight processing method, device, equipment and computer program product
Through grouping and inverse quantization parameter optimization, the mixed-precision weight operation of large language models reduces the number of memory accesses, improves computational efficiency and model inference speed, and solves the problem of low operational efficiency of large language models under mixed precision.
Patent Information
- Application Number
- CN202410801312.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-06-19
AI Technical Summary
Large language models require multiple memory access operations when performing mixed-precision weight operations, resulting in low computing efficiency and slow inference speed. Especially in multiplication operations, the amount of data is huge, which affects the deployment cost and inference quality of the model.
By obtaining the activation matrix and weight matrix, grouping to obtain weight blocks, and determining the inverse quantization parameters of each block, multiplication operations are performed based on these parameters to reduce the number of memory access operations and improve calculation efficiency.
It effectively improves the efficiency and quality of mixed-precision weight operations, reduces the inference speed and deployment cost of large language models, and improves the practicality of the model.
Smart Images

Figure CN118378005B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a mixed precision weight processing method, device, equipment and computer program product. Background Art
[0002] As the technology of large language models continues to mature, the application scope of large language models is becoming more and more extensive. In order to reduce the deployment cost of large language models, large language models often need to be deployed through quantization operations. For quantized large language models, they often correspond to a huge number of model weights with different precisions, such as: integer type int, 2-bit precision model weights, integer type int, 4-bit precision model weights, etc. When performing reasoning operations based on large language models, it often includes operations between model weights of mixed precision, especially multiplication operations. Due to the huge amount of data in the operation operation, multiple memory access operations are required, which will not only greatly reduce the operation efficiency, but also affect the reasoning speed of the large language model. Summary of the invention
[0003] The embodiments of the present invention provide a mixed-precision weight processing method, apparatus, device and computer program product, which can improve the computational efficiency of mixed-precision weights and thereby ensure the reasoning quality and efficiency of a large language model.
[0004] In a first aspect, an embodiment of the present invention provides a method for processing mixed precision weights, including:
[0005] Obtaining an activation matrix and a weight matrix corresponding to the large language model, wherein the activation matrix includes a plurality of activation values, and the weight matrix includes: a plurality of unquantized model weights and a plurality of quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights;
[0006] Grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix;
[0007] Determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same;
[0008] Based on the inverse quantization parameter, the activation matrix and the multiple weight blocks are multiplied to obtain a processing result.
[0009] In a second aspect, an embodiment of the present invention provides a mixed precision weight processing device, including:
[0010] An acquisition module, configured to acquire an activation matrix and a weight matrix corresponding to a large language model, wherein the activation matrix includes a plurality of activation values, and the weight matrix includes: a plurality of unquantized model weights and a plurality of quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights;
[0011] A processing module, used for grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix;
[0012] A determination module, used to determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same;
[0013] The processing module is further used to perform a multiplication operation on the activation matrix and the multiple weight blocks based on the inverse quantization parameter to obtain a processing result.
[0014] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the mixed precision weight processing method in the above-mentioned first aspect.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer storage medium for storing a computer program, wherein the computer program enables a computer to implement the method for processing mixed precision weights in the first aspect when executed.
[0016] In a fifth aspect, an embodiment of the present invention provides a computer program product, comprising: a computer-readable storage medium storing computer instructions, which, when executed by one or more processors, causes the one or more processors to execute the steps in the mixed precision weight processing method shown in the first aspect above.
[0017] The mixed precision weight processing method, device, equipment and computer program product provided by the embodiments of the present invention obtain an activation matrix and a weight matrix corresponding to a large language model, group the weight matrix, obtain a plurality of weight blocks corresponding to the weight matrix, and then determine the inverse quantization parameter corresponding to each weight block, and perform multiplication operation on the activation matrix and the plurality of weight blocks based on the inverse quantization parameter, so as to obtain the operation processing result stably. Specifically, since the inverse quantization parameters corresponding to the weight values in the same weight block are the same, when performing the processing operation on the weight values in each weight block, only one reading operation is required for the inverse quantization parameter, and the inverse quantization parameter can be directly used for multiple processing operations between the plurality of weight values and the activation value in the weight block, thereby reducing the number of memory access operations and the resources required for the memory access operations. In this way, sufficient resource information can be used to perform calculation operations on the activation matrix and the weight matrix, thereby effectively improving the quality and efficiency of the processing between the activation matrix and the weight matrix, and further improving the practicality of the method. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A schematic diagram of a scenario of a mixed precision weight processing method provided by an embodiment of the present invention;
[0020] Figure 2 A flow chart of a method for processing mixed precision weights provided by an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of storing quantized model weights provided by an embodiment of the present invention;
[0022] Figure 4 A schematic flow chart of another mixed precision weight processing method provided by an embodiment of the present invention;
[0023] Figure 5 A schematic diagram of a flow chart of performing multiplication operations on multiple activation parameter blocks and multiple weight blocks based on the inverse quantization parameter to obtain multiple block operation results provided by an embodiment of the present invention;
[0024] Figure 6A schematic flow chart of performing multiplication operations on multiple activation parameter blocks and multiple weight blocks based on the inverse quantization parameter to obtain multiple block operation results provided by an application embodiment of the present invention;
[0025] Figure 7 A schematic diagram of a rearranged weight matrix provided in an application embodiment of the present invention;
[0026] Figure 8 A schematic diagram of the structure of a mixed precision weight processing device provided by an embodiment of the present invention;
[0027] Fig. 9 For Figure 8 A schematic diagram of the structure of an electronic device corresponding to the mixed precision weight processing device provided in an embodiment is shown. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "an", and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two, but does not exclude the situation of including at least one.
[0030] It should be understood that the term "and / or" used in this article is only a way to describe the association relationship of associated devices, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated devices before and after are in an "or" relationship.
[0031] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0032] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a product or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such a product or system. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the product or system including the elements.
[0033] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0034] In order to facilitate understanding of the specific implementation process and implementation effect of the mixed precision weight processing method, device, equipment and computer program product in this embodiment, the relevant technology is briefly described below:
[0035] Large Language Model (LLM) is a deep learning model trained on massive text data. It can not only generate natural language text, but also deeply understand the meaning of text and handle various natural language tasks, such as text feature extraction, question answering, translation, etc.
[0036] As the technology of large language models continues to mature, large language models are being used more and more widely. Since large language models have a large number of weight parameters, the parameter precision of the weight parameters can include integer and floating point types. At this time, if the large language model is directly deployed, the large number of weight parameters not only increases the deployment cost of the large language model, but also increases the deployment requirements for graphics cards and video memory. Therefore, in order to reduce the deployment cost of large language models, the weights of large language models can be quantized, and then the large language models after quantization can be deployed.
[0037] For a quantized large language model, it often corresponds to a huge number of model weights of different precisions, such as: integer type int, 2-bit precision model weights, integer type int, 4-bit precision model weights, etc. When performing reasoning operations based on a large language model, it often includes operations between model weights of mixed precision, especially multiplication operations. Since the amount of data in the operation is huge, multiple memory access operations are required, which will not only greatly reduce the operation efficiency, but also affect the reasoning speed of the large language model.
[0038] In order to solve the above technical problems, the embodiments of the present invention provide a mixed precision weight processing method, device, equipment and computer program product, wherein, with reference to the attached Figure 1As shown, the execution subject of the mixed precision weight processing method is a mixed precision weight processing device 200, and the mixed precision weight processing device 200 is communicatively connected to the client 100. When the mixed precision weight processing device 200 is implemented as a server in the cloud, the mixed precision weight processing method can be executed in the cloud, and several computing nodes (cloud servers) can be deployed in the cloud, and each computing node has computing, storage and other processing resources. In the cloud, multiple computing nodes can be organized to provide a certain service. Of course, a computing node can also provide one or more services. The way to provide the service in the cloud can be to provide a service interface to the outside, and the user calls the service interface to use the corresponding service. The service interface includes a software development kit (Software Development Kit, referred to as SDK), an application programming interface (Application Programming Interface, referred to as API), and the like.
[0039] The client 100 is used for users to apply so as to realize the processing operation of mixed precision weights. In specific implementation, the client 100 can be a mobile phone, a personal computer PC, a tablet computer, a setting application, a wearable device, etc. In addition, the basic structure of the client 100 may include: at least one processor. The number of processors depends on the configuration and type of the client 100. The client 100 may also include a memory, which may be volatile, such as: random access memory (Random Access Memory, referred to as RAM), or non-volatile, such as: read-only memory (Read-Only Memory, referred to as ROM), flash memory, etc., or may include both types at the same time. The memory usually stores an operating system (Operating System, referred to as OS), one or more applications, and may also store program data, etc. In addition to the processing unit and the memory, the client 100 also includes some basic configurations, such as: a network card chip, an IO bus, a display component, and some peripheral devices, etc. Optionally, some peripheral devices may include, for example: a keyboard, a mouse, an input pen, a printer, etc. Other peripheral devices are well known in the art and will not be described in detail here.
[0040] The mixed precision weight processing device 200 refers to a device that can provide mixed precision weight processing operations in a network virtual environment, and generally refers to a device that uses the network to perform information planning and mixed precision weight processing operations. In physical implementation, the mixed precision weight processing device 200 can be any device that can provide computing services, respond to mixed precision weight processing requests, and perform mixed precision weight processing operations, for example: it can be a cluster server, a conventional server, a cloud server, a cloud host, a virtual center, etc. The structure of the mixed precision weight processing device 200 mainly includes a processor, a hard disk, a memory, a system bus, etc., which is similar to a general computer architecture.
[0041] In the above embodiment, the client 100 is connected to the mixed precision weight processing device 200 through a network, and the network connection can be a wireless or wired network connection. If the client 100 can be connected to the mixed precision weight processing device 200 through a communication connection, the network standard of the mobile network can be any one of 2G (GSM), 2.5G (GPRS), 3G (WCDMA, TD-SCDMA, CDMA2000, UTMS), 4G (LTE), 4G+ (LTE+), WiMax, 5G, 6G, etc.
[0042] The client 100 is used to obtain the processing requirements of mixed precision weights in the application scenario of the large language model. In some instances, the processing requirements can be obtained through human-computer interaction operations. At this time, the client 100 can display a human-computer interaction interface, and the user can enter the execution operation in the human-computer interaction interface. It can be understood that different processing requirements can be obtained in different application scenarios, such as: text information feature extraction requirements, information search requirements, etc. In order to accurately implement the processing operation of mixed precision weights, the processing requirements of mixed precision weights can be sent to the processing device 200 of mixed precision weights.
[0043] The processing device 200 of mixed precision weights is used to obtain the processing requirements of mixed precision weights through the client 100, and then obtain the activation matrix and the weight matrix corresponding to the large language model based on the processing requirements of the mixed precision weights, wherein the activation matrix may include multiple activation values, and the weight matrix may include multiple unquantized model weights and multiple quantized model weights of different precisions, and the precision of the above-mentioned unquantized model weights is higher than the precision of the quantized model weights.
[0044] After obtaining the activation matrix and the weight matrix, in order to improve the efficiency of processing the activation matrix and the weight matrix, the weight matrix can be grouped to obtain multiple weight blocks corresponding to the weight matrix, wherein the precision corresponding to different weight blocks can be the same or different, for example: multiple weight blocks may include: weight block 1, weight block 2, weight block 3, the precision of the weight value in weight block 1 is int2, the precision of the weight value in weight block 2 is int4, and the precision of the weight value in weight block 3 is fp16. It can be understood that the weight values included in the above-mentioned weight block 1 and weight block 2 are quantized model weights after quantization operations, and the weight values included in the above-mentioned weight block 3 are unquantized model weights that have not undergone quantization operations. Alternatively, multiple weight blocks may include: weight block 1, weight block 2, and weight block 3, the precision of the weight values in weight block 1 is int2, the precision of the weight values in weight block 2 is int2, and the precision of the weight values in weight block 3 is int4, wherein the precision of the weight values corresponding to weight block 1 and weight block 2 is the same, and the weight values included in weight block 1, weight block 2, and weight block 3 are quantized model weights after quantization operation.
[0045] After obtaining multiple weight blocks, the multiple weight blocks can be analyzed and processed to determine the inverse quantization parameters corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same, and the inverse quantization parameters corresponding to the weight block can be obtained by analyzing and calculating the original model weights and the quantized model weights in the weight block, respectively. In some instances, the inverse quantization parameters may include scaling factors and offsets. After obtaining the inverse quantization parameters, the activation matrix, and multiple weight blocks, the activation matrix and the multiple weight blocks can be multiplied based on the inverse quantization parameters, so that the operation results can be stably obtained.
[0046] In this embodiment, since the inverse quantization parameters corresponding to the weight values in the same weight block are the same, when processing the weight values in each weight block, it is only necessary to read the inverse quantization parameters once, and the inverse quantization parameters can be directly used to perform multiple processing operations between the multiple weight values and activation values in the weight block. This effectively improves the efficiency of processing between the activation matrix and the weight matrix, and further improves the practicality of the method.
[0047] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the case where there is no conflict between the embodiments, the following embodiments and the features in the embodiments can be combined with each other. In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0048] Figure 2 A flow chart of a mixed precision weight processing method provided by an embodiment of the present invention; see attached Figure 2 As shown, this embodiment provides a mixed precision weight processing method, the execution subject of the method is a mixed precision weight processing device, the mixed precision weight processing device can be implemented as software, or a combination of software and hardware. When the mixed precision weight processing device is implemented as hardware, it can be various electronic devices with mixed precision weight processing operations, including but not limited to personal computers, servers, etc. When the mixed precision weight processing device is implemented as software, it can be installed in the electronic devices listed above. Specifically, the mixed precision weight processing method may include:
[0049] Step S201: Obtain an activation matrix and a weight matrix corresponding to the large language model, wherein the activation matrix includes multiple activation values, and the weight matrix includes: multiple unquantized model weights and multiple quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights.
[0050] Step S202: grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix.
[0051] Step S203: Determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same.
[0052] Step S204: performing a multiplication operation on the activation matrix and the plurality of weight blocks based on the inverse quantization parameter to obtain a processing result.
[0053] The specific implementation process and effects of each of the above steps are described in detail below:
[0054] Step S201: Obtain an activation matrix and a weight matrix corresponding to the large language model, wherein the activation matrix includes multiple activation values, and the weight matrix includes: multiple unquantized model weights and multiple quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights.
[0055] Among them, when the user uses a large language model to perform reasoning operations, the reasoning operations include multiplication operations, addition operations, and subtraction operations between a weight matrix (including multiple model weights of a large language model) and an activation matrix (including multiple activation values used to activate the large language model for operation operations). In order to improve the quality and efficiency of reasoning operations, especially the quality and efficiency of multiplication operations between matrices, this embodiment proposes an implementation method for improving the processing efficiency of mixed precision weights by minimizing the number of memory access operations. Specifically, the activation matrix to be processed can be obtained first. Specifically, the activation matrix can include multiple activation values, and the above-mentioned activation values can include at least one of the following: a default activation value or an input activation value for inputting into the first model network layer in the large language model, an output value for inputting into the next network model layer after the previous network model layer performs reasoning, and the like.
[0056] In order to accurately implement the mixed precision weight processing operation, in addition to obtaining the activation matrix, it is also necessary to obtain the weight matrix corresponding to the large language model, which may include: multiple unquantized model weights and multiple quantized model weights of different precisions. The quantized model weights of different precisions may refer to quantized model weights represented by different bits, such as: integer int 2bit precision model weights, integer int 4bit precision model weights, integer int 8bit precision model weights, etc. The above-mentioned unquantized model weights often refer to model weights that are more important for the large language model. Since they have not been quantized, the precision of the unquantized model weights is usually higher than the precision of the quantized model weights. For example, the precision of the unquantized model weights can be floating point FP16bit.
[0057] Specifically, with respect to the weight matrix, this embodiment does not limit the method for obtaining the weight matrix. In some instances, the weight matrix can be obtained by analyzing and processing the weights of a large language model. At this time, obtaining the weight matrix corresponding to the large language model may include: obtaining multiple original weights corresponding to the large language model; determining weights that need to be quantized and weights that do not need to be quantized among the multiple original weights; then quantizing the weights that need to be quantized to obtain quantized model weights; determining the weights that do not need to be quantized as unquantized model weights; and determining the weight matrix based on the unquantized model weights and the quantized model weights. This effectively ensures the accuracy and reliability of obtaining the weight matrix.
[0058] Among them, whether the original weight needs to be quantized can be judged based on the importance of the original weight. At this time, determining the weights that need to be quantized and the weights that do not need to be quantized among multiple original weights can include: obtaining the importance corresponding to each of the multiple original weights. Specifically, the importance corresponding to each of the multiple original weights can be obtained by analyzing and processing the original weights based on preset rules or preset algorithms. After obtaining the importance corresponding to each of the multiple original weights, the importance can be analyzed and compared with the preset threshold. When the importance is greater than or equal to the preset threshold, the original weight corresponding to the importance is determined as a weight that does not need to be quantized; when the importance is less than the preset threshold, the original weight corresponding to the importance is determined as a weight that needs to be quantized.
[0059] In other instances, the weight matrix can be obtained not only by analyzing and processing the model weights of the large language model, but also by a preset device. In this case, obtaining the weight matrix corresponding to the large language model may include: obtaining a preset device that is communicatively connected to a mixed precision weight processing device, wherein the preset device may store the weight matrix corresponding to the large language model; and then the weight matrix corresponding to the large language model may be actively or passively obtained through the preset device, thereby also ensuring the accuracy and reliability of obtaining the weight matrix.
[0060] In some other examples, before obtaining the activation matrix and the weight matrix corresponding to the large language model, the present embodiment provides a technical solution for compressing and storing the quantized model weights, which can improve the efficiency of reading the quantized model weights. At this time, the method in the present embodiment may also include: obtaining the quantized model weights corresponding to the large language model; determining the lower limit of the read bit width for reading the quantized model weights; and compressing and storing the quantized model weights based on the lower limit of the read bit width.
[0061] For the model weights of a large language model, the number of model weights of the large language model is huge, and the number of quantized model weights is also large. When using the large language model for inference operations, it is necessary to read and process each quantized model weight, which can easily reduce the time required for inference operations on the large language model. Therefore, in order to reduce the situation where the model operation speed or model inference speed is reduced due to too many memory access operations on the model weights, the quantized model weights of the large language model can be compressed and stored. Specifically, the quantized model weights corresponding to the large language model can be obtained first, and then the lower limit of the read bit width for reading the quantized model weights can be determined. In some instances, the lower limit of the read bit width can be a preset parameter or a default parameter.
[0062] After obtaining the read bit width lower limit, since the accuracy of the read bit width lower limit is often higher than the accuracy of the quantized model weights, the quantized model weights can be compressed and stored based on the read bit width lower limit. After compressing and storing the quantized model weights based on the read bit width lower limit, this embodiment also provides a technical solution for accessing the compressed and stored quantized model weights. At this time, the method in this embodiment may include: obtaining a weight access request; reading the compressed and stored quantized model weights based on the weight access request and the read bit width lower limit, and obtaining multiple quantized model weights corresponding to the access request.
[0063] Specifically, when a user has an access demand for the quantized model weights, the processing device can obtain a weight access request. The weight access request can be obtained through human-computer interaction or a trigger task of a preset device. After obtaining the weight access request, the compressed and stored quantized model weights can be read based on the weight access request and the read bit width lower limit. Since the quantized model weights are compressed and stored, multiple quantized model weights can be read in one read operation, thereby obtaining multiple quantized model weights corresponding to the access request.
[0064] For example, see Attachment Figure 3 As shown, when the lower limit of the read bit width is 32 bits, the quantized model weights can be stored based on a 32-bit integer type. At this time, if the precision of the quantized model weights is a 4-bit integer type, 8 4-bit quantized model weights can be compressed into a group and written to the memory. In this way, when a group of data is read uniformly, 8 quantized model weights can be obtained through a single read operation. Similarly, if the precision of the quantized model weights is a 2-bit integer type, 16 2-bit quantized model weights can be compressed into a group and written to the memory. In this way, when a group of data is read uniformly, 16 quantized model weights can be read through a single read operation. This effectively reduces the number of memory accesses in the quantized model, while increasing the memory access efficiency of the quantized model weights, further improving the flexibility and reliability of the application of this method.
[0065] Step S202: grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix.
[0066] Since a weight matrix includes multiple model weight values, and the multiple model weight values have different corresponding precisions, if the multiple model weight values and multiple activation values are calculated directly, the huge amount of calculation will not only increase the difficulty of calculation, but also easily increase the error rate of calculation. Therefore, in order to improve the processing quality and efficiency between mixed precision weights, after obtaining the weight matrix, the weight matrix can be grouped to obtain multiple weight blocks corresponding to the weight matrix, where the precision corresponding to different weight blocks can be the same or different, for example: the precision corresponding to weight block 1 is int 2bit, the precision corresponding to weight block 2 is int 4bit, the precision corresponding to weight block 3 is int8bit, and so on.
[0067] In some instances, the grouping operation can be implemented based on the accuracy of each weight value in the weight matrix. In this case, grouping the weight matrix to obtain multiple weight blocks corresponding to the weight matrix may include: obtaining the accuracy corresponding to each weight value in the weight matrix; grouping the weight matrix based on the accuracy corresponding to each weight value in the weight matrix to obtain multiple weight blocks corresponding to the weight matrix, the accuracy of the weight values in different weight blocks is different, thereby effectively achieving the accurate reliability of obtaining multiple weight blocks.
[0068] In other instances, the grouping operation can be implemented not only based on the accuracy of each weight value in the weight matrix, but also through the importance of each weight value in the weight matrix. At this time, grouping the weight matrix in this embodiment to obtain multiple weight blocks corresponding to the weight matrix can include: obtaining the importance of each quantized model weight and each unquantized model weight in the weight matrix; rearranging the quantized model weights and unquantized model weights in the weight matrix based on the importance to obtain a rearranged weight matrix; grouping the rearranged weight matrix to obtain multiple weight blocks corresponding to the weight matrix.
[0069] Specifically, after obtaining the weight matrix, the weight matrix can be analyzed and processed to obtain the importance of each quantized model weight and each unquantized model weight in the weight matrix, wherein the importance of each quantized model weight and each unquantized model weight in the weight matrix can be determined by analyzing and processing according to preset rules or preset scenario algorithms. In some instances, the importance is positively correlated with the accuracy of the model weight, that is, the higher the accuracy of the model weight, the higher the importance of the model weight, and the more important the model weight; the lower the accuracy of the model weight, the lower the importance of the model weight, and the less important the model weight.
[0070] After obtaining the importance of each quantized model weight and each unquantized model weight, the quantized model weights and unquantized model weights in the weight matrix can be rearranged based on the importance, so as to obtain a rearranged weight matrix. Among them, since the importance of the unquantized model weights is often higher than that of the quantized model weights, when the model weights in the rearranged weight matrix are sorted in order from low to high importance, the quantized model weights are often located at the front end of the rearranged weight matrix, and the unquantized model weights are often located at the back end of the rearranged weight matrix. It should be noted that when there are multiple model weights with the same importance, the order of the multiple model weights can be randomly arranged.
[0071] After obtaining the rearranged weight matrix, the rearranged weight matrix can be grouped to obtain multiple weight blocks corresponding to the weight matrix. For the weight blocks, the importance corresponding to different weight blocks can be the same or different. Since the importance is related to the accuracy of the weight values in the weight matrix, the accuracy corresponding to different weight blocks is also the same or different. For any two quantized model weights in the same weight block, the importance of any two quantized model weights can be the same or different, that is, the accuracy of any two quantized model weights in the same weight block can be the same or different, which effectively realizes the grouping operation of the weight matrix.
[0072] Step S203: Determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same.
[0073] After obtaining multiple weight blocks corresponding to the weight matrix, in order to accurately analyze and process the activation matrix and the weight matrix, the inverse quantization parameters corresponding to each weight block can be determined, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same, and the inverse quantization parameters may include scaling factors and offsets for analyzing and processing the weight values in the weight block. In some instances, the inverse quantization parameters may be obtained through human-computer interaction operations. In this case, determining the inverse quantization parameters corresponding to each weight block may include: displaying a human-computer interaction interface; obtaining an execution operation input by a user in the human-computer interaction interface; and determining the inverse quantization parameters corresponding to each weight block based on the execution operation.
[0074] In other instances, the inverse quantization parameters can be obtained not only through human-computer interaction, but also by accessing a preset memory. At this time, determining the inverse quantization parameters corresponding to each weight block may include: obtaining identification information corresponding to each weight block; accessing the global memory based on the identification information to obtain the inverse quantization parameters corresponding to each weight block, the inverse quantization parameters including a scaling factor and an offset.
[0075] Among them, for the weight blocks, since different weight blocks include different model weights, different weight blocks may correspond to different inverse quantization parameters for realizing inference operations, and the inverse quantization parameters corresponding to different weight blocks may be stored in the global memory. At this time, in order to accurately analyze and process the activation matrix and the weight matrix, the identification information corresponding to each weight block may be obtained first, and then the global memory may be accessed based on the identification information, so as to obtain the inverse quantization parameters corresponding to each weight block, thereby effectively ensuring the accurate and reliable determination of the inverse quantization parameters.
[0076] It should be noted that each weight block may include multiple quantized model weights of different precisions, and the above-mentioned multiple quantized model weights all need to perform corresponding inference operations based on inverse quantization parameters. Since the inverse quantization parameters corresponding to multiple quantized model weights in a weight block are the same, when performing inference operations on multiple quantized model weights in the same weight block, only one access operation to the global memory is required to obtain the inverse quantization parameters required for inference operations on multiple quantized model weights in a weight block, so as to perform corresponding inference operations based on the inverse quantization parameters, thereby further improving the efficiency of processing between the activation matrix and the weight matrix.
[0077] Step S204: performing a multiplication operation on the activation matrix and the plurality of weight blocks based on the inverse quantization parameter to obtain a processing result.
[0078] After obtaining the inverse quantization parameters, the activation matrix and the multiple weight blocks can be multiplied based on the inverse quantization parameters to obtain the operation processing result. In some instances, the multiplication operation can be implemented by a pre-trained machine learning model. In this case, the activation matrix and the multiple weight blocks are multiplied based on the inverse quantization parameters to obtain the operation processing result, which can include: obtaining the pre-trained machine learning model; inputting the inverse quantization parameters, the activation matrix and the multiple weight blocks into the machine learning model for multiplication, and obtaining the operation processing result output by the machine learning model.
[0079] In other instances, in order to further improve the efficiency of analyzing and processing mixed precision weights, the multiplication operation can not only be implemented through a pre-trained machine learning model, but also the activation matrix can be grouped first, and then the grouped activation matrix is multiplied with multiple weight blocks. At this time, the activation matrix is multiplied with multiple weight blocks based on the inverse quantization parameter, and the operation processing results obtained may include: grouping the activation matrix to obtain multiple activation parameter blocks; multiplying multiple activation parameter blocks with multiple weight blocks based on the inverse quantization parameter to obtain multiple block operation results; based on the multiple block operation results, determining the operation processing results corresponding to the activation matrix and the weight matrix.
[0080] In order to improve the efficiency of the multiplication operation, after obtaining the activation matrix, the activation matrix can be grouped to obtain multiple activation parameter blocks. Specifically, the specific implementation method and implementation effect of grouping the activation matrix are similar to the specific implementation method and implementation effect of "grouping the weight matrix" in the above embodiment. Please refer to the above statements for details, which will not be repeated here.
[0081] After obtaining multiple activation parameter blocks, the multiple activation parameter blocks and the multiple weight blocks can be multiplied based on the inverse quantization parameters to obtain multiple block operation results. In some instances, the multiplication operation can be implemented by a pre-trained machine learning model or a neural network model. At this time, multiplying the multiple activation parameter blocks and the multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results can include: obtaining a pre-trained machine learning model or a neural network model for implementing multiplication operations; inputting the inverse quantization parameters, the multiple activation parameters and the multiple weight blocks into the machine learning model or the neural network model for multiplication, so as to obtain multiple block operation results output by the machine learning model or the neural network model.
[0082] In addition, for multiple block operation results, since each block operation result is used to constitute a part of the operation processing result obtained by performing a multiplication operation between the activation matrix and the weight matrix, after obtaining multiple block operation results, the operation processing results corresponding to the activation matrix and the weight matrix can be determined based on the multiple block operation results. Specifically, the position information corresponding to each of the multiple block operation results can be determined first. The position information corresponding to each block operation result can be determined by the first position of the activation parameter block in the activation matrix and the second position of the weight block in the weight matrix. Then, the multiple block operation results can be spliced and combined based on the position information corresponding to each of the multiple block operation results, so as to obtain the operation processing results corresponding to the activation matrix and the weight matrix. In this way, the mixed precision weights can be processed efficiently, further improving the practicality of the method.
[0083] In addition, in order to facilitate the calculation operations on each activation parameter block and multiple weight blocks, after obtaining multiple activation parameter blocks, the present embodiment also provides a technical solution for storing the activation parameter blocks. At this time, the method in the present embodiment may also include: obtaining the shared memory corresponding to each weight block used to calculate with the activation parameter block, and the shared memories corresponding to different weight blocks are independent of each other; storing the activation parameter block in the corresponding shared memory.
[0084] Among them, when performing calculation operations on the activation parameter block and each weight block, the same activation parameter block needs to perform multiple calculation operations, for example: activation parameter block a needs to be calculated and processed with each model weight in weight block 1 respectively; activation parameter block b needs to be calculated and processed with each model weight in weight block 2 respectively, and so on. At this time, in order to improve the efficiency of the calculation and processing operation, after obtaining multiple activation parameter blocks, multiple activation parameter blocks can be stored in a shared memory. Specifically, for each weight block in the weight matrix, each weight block can correspond to its own corresponding shared memory, and the shared memories corresponding to different weight blocks can be independent of each other. The above-mentioned shared memory is used to store each activation parameter block.
[0085] In order to improve the efficiency of analyzing and processing mixed precision weights, the shared memory corresponding to each weight block used to operate on the activation parameter block can be obtained first. The shared memories corresponding to the above different weight blocks are independent of each other. Then, the activation parameter block can be stored in the corresponding shared memory. When performing operations on the activation parameter block and each weight value in the weight block, the activation parameter block that needs to be operated on with each weight value in the weight block can be obtained by accessing the shared memory once, thereby avoiding multiple acquisition operations on the activation parameter block and further improving the efficiency of operations on the activation parameter block and the weight block.
[0086] The mixed precision weight processing method provided in this embodiment obtains an activation matrix and a weight matrix corresponding to a large language model, groups the weight matrix, obtains a plurality of weight blocks corresponding to the weight matrix, and then determines the inverse quantization parameter corresponding to each weight block, and multiplies the activation matrix by the plurality of weight blocks based on the inverse quantization parameter, so that the operation processing result can be obtained stably. Specifically, since the inverse quantization parameters corresponding to the weight values in the same weight block are the same, when performing processing operations on the weight values in each weight block, only one reading operation is required for the inverse quantization parameter, and the inverse quantization parameter can be directly used for multiple processing operations between the plurality of weight values and the activation value in the weight block, thereby reducing the number of memory access operations and the resources required for the memory access operations. In this way, sufficient resource information can be used to perform calculation operations on the activation matrix and the weight matrix, thereby effectively improving the quality and efficiency of processing between the activation matrix and the weight matrix, and further improving the practicality of the method.
[0087] Figure 4 A flowchart of another mixed precision weight processing method provided by an embodiment of the present invention is provided; based on the above embodiment, refer to the attached Figure 4 As shown, in order to further improve the efficiency of processing the mixed precision weights, before determining the inverse quantization parameters corresponding to each weight block, the inverse quantization parameters may be stored in the global memory. Specifically, the method in this embodiment may further include:
[0088] Step S401: Obtain inverse quantization parameters corresponding to each weight block.
[0089] After obtaining the weight blocks, the weight blocks can be analyzed and processed to obtain the inverse quantization parameters corresponding to each weight block. In some instances, the inverse quantization parameters can be obtained through human-computer interaction operations. At this time, obtaining the inverse quantization parameters corresponding to each weight block can include: displaying the human-computer interaction interface; obtaining the execution operation input by the user in the human-computer interaction interface, which execution operation can be a configuration operation of the inverse quantization parameter, a calculation operation of the inverse quantization parameter, etc.; determining the inverse quantization parameters corresponding to each weight block based on the execution operation, thereby effectively ensuring the accuracy and reliability of obtaining the inverse quantization parameters.
[0090] In other instances, the inverse quantization parameters can be obtained not only through human-computer interaction, but also by analyzing and processing the quantized model weights and the original model weights. At this time, obtaining the inverse quantization parameters corresponding to each weight block can include: obtaining any two quantized model weights in the weight block and the original model weights corresponding to the two quantized model weights; based on the two quantized model weights and the corresponding original model weights, determining the inverse quantization parameters corresponding to the weight block.
[0091] Among them, since the original model weight can be determined by analyzing and processing the inverse quantization parameter and the quantized model parameter, for example, when the inverse quantization parameter includes the scaling factor scale and the offset zeros, the original model weight is W, and the quantized model weight is W_q, the following relationship between the inverse quantization parameter, the original model weight and the quantized model parameter can be obtained: W=scale*(W_q-zeros). Based on the above formula, when the original model weight W and the quantized model weight W_q are known values, the inverse quantization parameter can be calculated by any two quantized model weights and the original model weights corresponding to the two quantized model weights.
[0092] Specifically, in order to accurately determine the inverse quantization parameters corresponding to the weight block, any two quantized model weights in the weight block and the original model weights corresponding to the two quantized model weights can be obtained. In some instances, the quantized model weights and the original model weights can be obtained through human-computer interaction or preset devices. After obtaining any two quantized model weights in the weight block and the original model weights corresponding to the two quantized model weights, the two quantized model weights and the corresponding original model weights can be analyzed and processed, so that the inverse quantization parameters corresponding to the weight block can be accurately determined.
[0093] For example, in any weight block, the original model weight W1 and the original model weight W2 are included. The quantized model weight corresponding to the original model weight W1 is W_q1, and the quantized model weight corresponding to the original model weight W2 is W_q2. The following formula can be obtained through the above parameters:
[0094] W1=scale*(W_q1-zeros) (Formula 1)
[0095] W2=scale*(W_q2-zeros) (Formula 2)
[0096] Through the above two formulas, the inverse quantization parameter corresponding to the weight block can be accurately determined. The inverse quantization parameter includes the scaling factor scale and the offset zeros, which effectively ensures the accuracy and reliability of the analysis and processing of the inverse quantization parameter.
[0097] Step S402: based on the identification information corresponding to each weight block, the inverse quantization parameter corresponding to each weight block is stored in the global memory.
[0098] After obtaining the inverse quantization parameters corresponding to each weight block, in order to facilitate the corresponding processing operations on each weight block based on the inverse quantization parameters corresponding to each weight block, the inverse quantization parameters corresponding to each weight block can be stored in the global memory. In this way, when there is a calculation requirement for the weight value in the weight block, the inverse quantization parameters corresponding to all the weight values in the weight block can be obtained through a one-time access operation to the global memory, and corresponding processing operations can be performed on the weight values in the weight block based on the inverse quantization parameters, further improving the efficiency of processing the mixed precision weights.
[0099] In this embodiment, by obtaining the inverse quantization parameters corresponding to each weight block, and then storing the inverse quantization parameters corresponding to each weight block in the global memory based on the identification information corresponding to each weight block, it is effectively facilitated to perform corresponding processing operations on each weight block based on the inverse quantization parameters corresponding to each weight block, which is beneficial to improving the efficiency of processing mixed precision weights.
[0100] Figure 5 A schematic diagram of a flow chart of performing multiplication operations on multiple activation parameter blocks and multiple weight blocks based on inverse quantization parameters to obtain multiple block operation results is provided in an embodiment of the present invention; on the basis of the above embodiment, refer to the attached Figure 5As shown, this embodiment provides a technical solution for implementing a multiplication operation between an activation parameter block and a weight block based on a channel mapping relationship corresponding to each weight block. At this time, performing multiplication operations on multiple activation parameter blocks and multiple weight blocks based on an inverse quantization parameter, and obtaining multiple block operation results may include:
[0101] Step S501: Obtain channel mapping relationships corresponding to a plurality of weight blocks, where the channel mapping relationships are used to identify channel change information of each quantized model weight in the weight block after the rearrangement operation.
[0102] For the weight block, since it includes the quantized model weights after the rearrangement operation, the position channel of the quantized model weights in the weight block may change. For example: the quantized weight values in the weight block include [weight value 1, weight value 2, weight value 3, weight value 4, weight value 5]. The above quantized weight values are the order of weight values after the rearrangement operation. Before the rearrangement operation, the order of the above quantized weight values can be [weight value 4, weight value 5, weight value 1, weight value 3, weight value 2].
[0103] By comparison, it can be seen that the order of the quantized weight values before the rearrangement operation is different from the order after the rearrangement operation (including completely different or partially different). In order to accurately realize the operation between the weight block and the activation matrix, the channel mapping relationship corresponding to each of the multiple weight blocks can be obtained. The channel mapping relationship can represent the channel change information of each quantized model weight in the weight block after the rearrangement operation. For example, before the rearrangement operation, the weight block a is [weight value 4, weight value 5, weight value 1, weight value 3, weight value 2]. After the rearrangement operation, the weight block a` is [weight value 1, weight value 2, weight value 3, weight value 4, weight value 5]. By analyzing and processing the two weight blocks, it can be obtained that the channel mapping relationship corresponding to the weight block a` can be [3,5,4,1,2]. The above-mentioned "3" located at the first position is used to identify that the original channel position of the quantized model weight currently located at the first channel is the 3rd channel, and the above-mentioned "5" located at the second position is used to identify that the original channel position of the quantized model weight currently located at the second channel is the 5th channel, and so on.
[0104] In addition, the present embodiment does not limit the specific method for obtaining the channel mapping relationship corresponding to each of the multiple weight blocks. In some instances, the channel mapping relationship may be information that is pre-calculated and stored in a preset area. In this case, the channel mapping relationship corresponding to each weight block can be obtained by accessing the preset area. Specifically, obtaining the channel mapping relationship corresponding to each of the multiple weight blocks may include: obtaining the block identifier of each weight block, wherein the block identifier can be determined by the position of the first block element or the last block element in the weight block in the weight matrix; and then accessing the preset area based on the block identifier to obtain the channel mapping relationship corresponding to the current weight block.
[0105] In other instances, the channel mapping relationship can not only be obtained by accessing a preset area, but can also be determined by analyzing and processing the original channel order and the rearranged channel order. At this time, obtaining the channel mapping relationship corresponding to each of the multiple weight blocks can include: obtaining the original channel order of the quantized model weights in the multiple weight blocks; determining the rearranged channel order of the quantized model weights after rearrangement; based on the original channel order and the rearranged channel order, determining the channel mapping relationship corresponding to each of the multiple weight blocks.
[0106] Specifically, after obtaining multiple weight blocks, the weight blocks and weight matrices can be analyzed and processed, so as to obtain the original channel order of the quantized model weights in the multiple weight blocks. In some instances, the original channel order of the quantized model weights can be represented by the position of the quantized model weights in the weight matrix before the rearrangement operation, or by the position of the quantized model weights in the weight block before the rearrangement operation. In order to accurately determine the channel mapping relationship corresponding to each weight block, it is necessary not only to obtain the original channel order of the quantized model weights in multiple weight blocks, but also to determine the rearranged channel order of the quantized model weights after the rearrangement. In some instances, the rearranged channel order can be represented by the position of the quantized model weights in the weight matrix after the rearrangement operation, or by the position of the quantized model weights in the weight block after the rearrangement operation.
[0107] After obtaining the original channel order and the rearranged channel order, the original channel order and the rearranged channel order corresponding to each weight block can be analyzed and processed, so that the channel mapping relationship corresponding to each of the multiple weight blocks can be stably determined.
[0108] It should be noted that the execution order between the steps of "obtaining the original channel order of the quantized model weights in multiple weight blocks" and "determining the rearranged channel order of the quantized model weights after rearrangement" in the above embodiment is not limited to the execution order specified in the above embodiment. For example, the step of "obtaining the original channel order of the quantized model weights in multiple weight blocks" can be executed after the step of "determining the rearranged channel order of the quantized model weights after rearrangement", or the step of "obtaining the original channel order of the quantized model weights in multiple weight blocks" can be executed simultaneously with the step of "determining the rearranged channel order of the quantized model weights after rearrangement". Those skilled in the art can adjust the order between the above two steps according to the specific application scenarios or application requirements, which will not be repeated here.
[0109] Step S502: adjusting the activation values in the activation parameter blocks to be multiplied based on the channel mapping relationships corresponding to the multiple weight blocks, to obtain multiple adjustment parameter blocks.
[0110] When performing calculation operations on weight blocks and activation parameter blocks, the channel positions of each weight value in the weight blocks change. At this time, if calculation operations are performed directly on the weight blocks and activation parameter blocks, inference calculation errors will occur. Therefore, in order to accurately perform calculation operations on weight blocks and activation parameter blocks, after obtaining the channel mapping relationships corresponding to multiple weight blocks, the activation values in the activation parameter blocks that need to be multiplied can be adjusted based on the channel mapping relationships corresponding to the multiple weight blocks, so that the order of the activation values in the activation parameter blocks corresponds to the order of the quantized model weights in the weight blocks, so that multiple adjustment parameter blocks can be obtained.
[0111] In some instances, the adjustment operation of the activation value can be implemented through a pre-trained machine learning model. At this time, the activation value in the activation parameter block that needs to be multiplied is adjusted based on the channel mapping relationship corresponding to each of the multiple weight blocks. Obtaining multiple adjustment parameter blocks may include: obtaining a pre-trained machine learning model; inputting the channel mapping relationship and activation parameter block corresponding to each of the multiple weight blocks into the machine learning model for adjustment, and obtaining multiple adjustment parameter blocks output by the machine learning model.
[0112] In other instances, the adjustment operation can be implemented not only through a machine learning model, but also by rearranging the activation parameter blocks. In this case, the activation values in the activation parameter blocks that need to be multiplied are adjusted based on the channel mapping relationships corresponding to the multiple weight blocks. Obtaining multiple adjustment parameter blocks may include: obtaining the original channel order corresponding to each activation value in the activation parameter block; rearranging the activation values in the activation parameter block based on the channel mapping relationship and the original channel order to obtain the adjustment parameter block.
[0113] Specifically, in order to adjust the activation values in the activation parameter block based on the channel mapping relationship corresponding to each of the multiple weight blocks, the original channel order corresponding to each activation value in the activation parameter block can be obtained first, and the original channel order can be determined by the position of each activation value in the activation matrix, or by the position of each activation value in the activation parameter block. After obtaining the original channels corresponding to each activation in the activation parameter block, the activation values in the activation parameter block can be rearranged based on the channel mapping relationship and the original channel order, that is, the rearranged channel order for rearranging the activation values in the activation parameter block is first determined by the channel mapping relationship and the original channel order, and then the activation values in the activation parameter block can be rearranged according to the rearranged channel order to obtain an adjusted parameter block, wherein the adjustment parameter block includes multiple activation values that have been rearranged, and the order of the activation values in the activation parameter block corresponds to the quantized model weights in the weight block, which effectively ensures the accuracy and reliability of the inference operation between the weight block and the activation parameter block.
[0114] Step S503: performing multiplication operations on multiple adjustment parameter blocks and multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results.
[0115] After obtaining the adjustment parameter blocks and weight blocks, multiplication operations can be performed separately on multiple adjustment parameter blocks and multiple weights based on the inverse quantization parameters. In some instances, the multiplication operations can be obtained through a pre-trained machine learning model. At this time, multiplication operations are performed on multiple adjustment parameter blocks and multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results, which may include: obtaining a machine learning model for multiplying multiple adjustment parameter blocks and multiple weight blocks; inputting the inverse quantization parameters, multiple adjustment parameter blocks and multiple weight blocks into the machine learning model for operation processing, so as to obtain multiple block operation results output by the machine learning model.
[0116] In other instances, the multiplication operation can not only be implemented through the machine learning model, but also the quantized model weights can be first dequantized, and then the multiplication operation can be performed on the parameters after the dequantization operation. Specifically, in this embodiment, multiple adjustment parameter blocks and multiple weight blocks are multiplied based on the dequantization parameters to obtain multiple block operation results, which may include: dequantizing the quantized model weights in the corresponding weight blocks based on the dequantization parameters to obtain multiple dequantized model weights; determining multiple dequantization parameter blocks based on multiple dequantized model weights and multiple unquantized model weights in the corresponding weight blocks; multiplying multiple dequantization parameter blocks and multiple adjustment parameter blocks to obtain multiple block operation results.
[0117] Among them, after obtaining the inverse quantization parameters, the quantized model weights in the corresponding weight block can be inversely quantized based on the inverse quantization parameters, so that the inverse quantized model weights can be obtained. For example, taking the inverse quantization parameters including the scaling factor and the offset as an example, after obtaining the scaling factor and the offset, the quantized model weights in the corresponding weight block can be inversely quantized based on the scaling factor and the offset. Specifically, when the scaling factor is scale, the offset is zeros, and the quantized model weight is W_q, the inverse quantization operation can be implemented by the formula "(W_q-zeros)*scale", so that multiple inverse quantized model weights can be obtained, and the weight accuracy of the inverse quantized model weights can be the same as the accuracy of the unquantized model weights that have not undergone the quantization operation.
[0118] Since the calculation operations between the activation matrix and the weight matrix include not only the calculation operations between the dequantized model weights and the activation matrix, but also the calculation operations between the unquantized model weights and the activation matrix, in order to accurately realize the accurate processing operations of the mixed precision weights, after obtaining multiple dequantized model weights, multiple dequantized parameter blocks can be generated based on the multiple dequantized model weights and the corresponding multiple unquantized model weights in the weight blocks, and then the multiple dequantized parameter blocks and the multiple adjustment parameter blocks can be multiplied, so that the multiple block calculation results can be accurately obtained.
[0119] In some instances, when performing multiplication operations on multiple inverse quantization parameter blocks and multiple adjustment parameter blocks to obtain multiple block operation results, in order to further improve the quality and efficiency of the multiplication operation, the parameters in the inverse quantization parameter block and the parameters in the adjustment parameter block can be first subjected to precision conversion operations, and then operation operations are performed based on the inverse quantization parameter blocks and the adjustment parameter blocks after the precision conversion operations. At this time, performing multiplication operations on multiple inverse quantization parameter blocks and multiple adjustment parameter blocks to obtain multiple block operation results can include: converting weight values in each inverse quantization parameter block into weight values of half-precision floating point numbers (half2); converting activation values in each adjustment parameter block into activation values of half-precision floating point numbers (half2); and then performing multiplication operations on the weight values of the half-precision floating point numbers and the activation values of the half-precision floating point numbers, thereby quickly and accurately obtaining multiple block operation results, further improving the efficiency of the use of the method.
[0120] In this embodiment, by obtaining the channel mapping relationship corresponding to each of the multiple weight blocks, the activation value in the activation parameter block that needs to be multiplied is adjusted based on the channel mapping relationship corresponding to the multiple weight blocks, to obtain multiple adjustment parameter blocks, and then the multiple adjustment parameter blocks are multiplied with the multiple weight blocks based on the inverse quantization parameters, so that multiple block operation results can be stably obtained, and then the processing results of the mixed precision weights can be generated based on the multiple block operation results, further ensuring the efficiency of the analysis and processing of the mixed precision weights.
[0121] For specific applications, refer to the attached Figure 6 As shown, taking the inverse quantization parameter including the scaling factor scale and the offset zeros as an example, this application embodiment provides a mixed precision weight multiplication operation acceleration method, which can effectively improve the reasoning speed of the large language model. After testing and comparison, the reasoning speed of the large language model can be made more than 3 times the speed of reasoning with the model weight of fp16bit. Specifically, the method may include:
[0122] Step 1: Get the weight matrix W_p.
[0123] Among them, the weight matrix W_p refers to a K*N dimensional matrix composed of model weights in a large language model. In order to accurately obtain the weight matrix W_p, all model weights of the large language model can be obtained first, and then the unimportant weights that need to be quantized and the important weights that do not need to be quantized in all model weights can be determined. Specifically, whether the model weights are important can be determined according to preset rules or preset algorithms. After obtaining the unimportant weights, the unimportant weights can be quantized to obtain the quantized weights, and then the weight matrix W_p is determined based on the quantized weights and the important weights corresponding to the large language model.
[0124] For a large language model, more important model weights require more bits of precision to represent them, and less important model weights can be represented by fewer bits of precision. The obtained weight matrix W_p often includes weights of mixed precision. For example, the quantized weights may include model weights with int 2-bit precision, int 4-bit precision, int 8-bit precision, and so on. Important weights may be model weights with fp16-bit precision, fp32-bit precision, and so on.
[0125] For example, in order to increase the memory access efficiency of the weight matrix, when the quantized model weights are int 4-bit precision model weights, the int 32-bit data type can be used for storage, that is, 8 quantized model weights can be read at a time; when the quantized model weights are int 2-bit precision model weights, 64 quantized model weights can be read in one read operation, which can significantly improve the ratio of calculation times / memory access times, and thus make full use of the computing power of the graphics card.
[0126] After obtaining the quantized weights and the important weights corresponding to the large language model, the quantized weights and the important weights corresponding to the large language model can be sorted according to the importance of the weights, so that the weight matrix after the rearrangement operation can be obtained, such as Figure 7 As shown, when the weight matrix includes model weights with int 4-bit precision and model weights with fp 16-bit precision, since the accuracy of the model weights with int 4-bit precision is lower than that of the model weights with fp 16-bit precision, the model weights with int 4-bit precision can be placed at the front of the matrix and the model weights with fp 16-bit precision can be placed at the back of the matrix, which facilitates the multiplication operation on the activation matrix.
[0127] Furthermore, after obtaining the weight matrix after the rearrangement operation, in order to further improve the quality and efficiency of the multiplication operation, the quantized weights in the weight matrix can be grouped or blocked, and the important weights in the weight matrix can be grouped separately, so that multiple weight blocks can be obtained, such as Figure 7 As shown, by grouping the weight matrix, the weight blocks can be obtained , weight block …weighted blocks ,Among them, the weight precisions corresponding to different weight blocks can be the same or different.
[0128] Since the model weights in the weight block have undergone a rearrangement operation, in order to accurately perform multiplication operations on the weight matrix W_p and the activation matrix X, the channel mapping relationship used to identify the channel change information of each quantized model weight in the weight block after the rearrangement operation can be determined, which can be represented by perm. For the fp16bit precision model weights in the weight matrix, the position of the fp16bit precision model weights can be marked by fp_indices.
[0129] Step 2: Get the activation matrix X.
[0130] The activation matrix X may be a matrix of M*K dimensions input by the user to the large language model, or, for any network model layer in the large language model, the activation matrix X of the network model layer may be the output result of the previous network model layer. For example, the current network model layer is the attention layer, and the previous layer of the attention layer is the normalization layer. Therefore, for the attention layer, the result of the normalization layer's operation is the activation matrix X of the attention layer.
[0131] When performing multiplication operations on the activation matrix X and the weight matrix W_p, in order to minimize the number of memory accesses to the activation values in the activation matrix, the activation values in the activation matrix X can be loaded into the shared memory through the corresponding thread. At this time, the shared memory can store m*k input values in the correct order, so that multiple inference operations can be performed on the obtained activation matrix X through one access operation, which is beneficial to improve the efficiency of the multiplication operation.
[0132] Specifically, there are different shared memories corresponding to different weight blocks, that is, when the number of weight blocks is multiple, the number of shared memories is multiple. After obtaining the activation matrix X that needs to be multiplied for each weight block, the activation matrix X corresponding to each weight block can be stored in the shared memory corresponding to the weight block. This reduces the repeated reading of the activation matrix X, that is, the activation matrix X that needs to be operated multiple times can be obtained by accessing the shared memory once, which is conducive to improving the efficiency of the multiplication operation.
[0133] When performing a multiplication operation, a block strategy can be used to implement the multiplication operation. For example, the activation matrix X can be divided into activation parameter blocks of (m_group, BLOCK_K_SIZE), where m_group is a pre-configured vertical dimension parameter for the activation matrix X, which is generally 8, and BLOCK_K_SIZE is a pre-configured horizontal dimension parameter for limiting the size of the activation parameter block. In some instances, BLOCK_K_SIZE can be 128. In this case, the activation matrix X can be divided into multiple 8*128 activation parameter blocks. Similarly, by dividing the weight matrix W_p, multiple weight blocks can be obtained, where the weight blocks can be small blocks of (BLOCK_K_SIZ, 4), so that calculation operations can be performed on each activation parameter block and each weight block. Specifically, when performing a multiplication operation, multiple threads tread can be established for the multiplication tasks between each block, and then each thread tread is assigned the task that needs to be multiplied, which can further improve the efficiency of the multiplication operation.
[0134] Step 3: Calculate the scaling factor and offset corresponding to each weight block.
[0135] Among them, the scaling factor scale and the offset zeros are quantization hyperparameters used to perform dequantization operations on the weight blocks. The above scaling factor scale and offset zeros can be determined by the following formula "w=scale*(W_q-zeros)". The above w is the original model weight, and W_q is the quantized model weight. The scaling factor scale and offset zeros corresponding to the weight block can be determined by the two original model weights and the quantized model weight in the same weight block.
[0136] Step 4: Store the scaling factors and offsets corresponding to each weight block in global memory.
[0137] Among them, there are different shared memories corresponding to different weight blocks, that is, when the number of weight blocks is multiple, the number of shared memories is multiple. After obtaining the scaling coefficients and offsets corresponding to each weight block, the scaling coefficients and offsets corresponding to each weight block can be stored in the shared memory corresponding to the weight block. In this way, the scaling coefficients and offsets that require multiple calculation operations can be obtained by accessing the shared memory once, which is beneficial to improving the efficiency of multiplication operations.
[0138] Step 5: Based on the channel mapping relationship corresponding to each of the multiple weight blocks, the activation value in the activation parameter block that needs to be multiplied is adjusted to obtain multiple adjustment parameter blocks.
[0139] After obtaining the channel mapping relationship perm / fp_indices, the order of activation values in the activation parameter block can be adjusted based on the order of perm / fp_indices so that the order of activation values x in the activation parameter block corresponds to the order of W_q, so that multiple adjustment parameter blocks can be stably obtained.
[0140] Step 6: Use the scaling factor and the offset to perform a dequantization operation on the quantized model weights in the corresponding weight block to obtain multiple dequantized model weights.
[0141] Among them, when the scaling factor is scale, the offset is zeros, and the quantized model weight is W_q, the scaling factor scale and offset zeros that have been read in can be read in or reused first, and then the formula "(W_q-zero)*scale" can be used to perform dequantization operations on the quantized model weights in the corresponding weight block to obtain multiple dequantized model weights, which can be marked as block_wq.
[0142] Step 7: Perform multiplication operations on multiple inverse quantization model weights and multiple adjustment parameter blocks to obtain multiple block operation results.
[0143] After the above steps, X with fp16 precision and W with fp16 precision can be obtained. In order to improve the calculation efficiency, the dequantization model weight and the adjustment parameter block are converted into the data type of half-precision floating point number half_2, and then the dequantization model weight of the half-precision floating point number and the adjustment parameter block of the half-precision floating point number are multiplied, so that multiple block operation results can be obtained.
[0144] Step 8: Add multiple block operation results to the corresponding positions of the output results to obtain the final operation processing result of the matrix multiplication operation.
[0145] The technical solution provided by the present application embodiment can efficiently and quickly perform multiplication operations on the activation matrix and the weight matrix. Specifically, when performing multiplication operations, the repeated memory access operations on the offset and scaling coefficient of the same weight block are reduced, that is, the scale and zero of multiple model weights in the same weight block only need to be read once, and multiple multiplication operations can be implemented, which effectively improves the efficiency of the multiplication operation; in addition, when performing multiplication operations on mixed-precision model weights, it is not necessary to rebuild the fp16 precision model weights, which greatly enhances the calculation speed of the multiplication operation; and, by designing a method of merging and storing low-precision weights or compressed storage, the calculation memory access ratio can be effectively improved through high-bit-width read operations, which is beneficial to improving the utilization rate of the graphics card computing power, and further ensuring the quality and efficiency of the multiplication operations on the mixed-precision weights.
[0146] Figure 8 A structural diagram of a mixed precision weight processing device provided by an embodiment of the present invention; see attached Figure 8 As shown, this embodiment provides a mixed precision weight processing device, which is used to perform the above Figure 2 The processing method of the mixed precision weight shown in the figure, specifically, the processing device may include:
[0147] An acquisition module 11 is used to acquire an activation matrix and a weight matrix corresponding to the large language model, wherein the activation matrix includes multiple activation values, and the weight matrix includes: multiple unquantized model weights and multiple quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights;
[0148] The processing module 12 is used to group the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix;
[0149] A determination module 13 is used to determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same;
[0150] The processing module 12 is further used to perform a multiplication operation on the activation matrix and the plurality of weight blocks based on the inverse quantization parameter to obtain an operation processing result.
[0151] In some instances, when the processing module 12 groups the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix, the processing module 12 is used to: obtain the importance of each quantized model weight and each unquantized model weight in the weight matrix; rearrange the quantized model weights and the unquantized model weights in the weight matrix based on the importance to obtain a rearranged weight matrix; and group the rearranged weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix.
[0152] In some instances, when the determination module 13 determines the inverse quantization parameters corresponding to each weight block, the determination module 13 is used to execute: obtaining identification information corresponding to each weight block; accessing the global memory based on the identification information to obtain the inverse quantization parameters corresponding to each weight block, the inverse quantization parameters including a scaling factor and an offset.
[0153] In some examples, before determining the inverse quantization parameters corresponding to each weight block, the acquisition module 11 and the processing module 12 in this embodiment are used to perform:
[0154] An acquisition module 11 is used to acquire the inverse quantization parameters corresponding to each weight block;
[0155] The processing module 12 is used to store the inverse quantization parameters corresponding to each weight block in the global memory based on the identification information corresponding to each weight block.
[0156] In some instances, when the acquisition module 11 acquires the inverse quantization parameters corresponding to each weight block, the acquisition module 11 is used to execute: acquiring any two quantized model weights in the weight block and the original model weights corresponding to the two quantized model weights; determining the inverse quantization parameters corresponding to the weight block based on the two quantized model weights and the corresponding original model weights.
[0157] In some instances, when the processing module 12 performs multiplication operations on the activation matrix and multiple weight blocks based on the inverse quantization parameters to obtain the operation processing results, the processing module 12 is used to execute: grouping the activation matrix to obtain multiple activation parameter blocks; multiplying the multiple activation parameter blocks and multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results; and determining the operation processing results corresponding to the activation matrix and the weight matrix based on the multiple block operation results.
[0158] In some examples, after obtaining multiple activation parameter blocks, the acquisition module 11 and the processing module 12 in this embodiment are used to perform the following steps:
[0159] An acquisition module 11 is used to acquire the shared memory corresponding to each weight block used for computing with the activation parameter block, and the shared memories corresponding to different weight blocks are independent of each other;
[0160] The processing module 12 is used to store the activation parameter block in the corresponding shared memory.
[0161] In some instances, when the processing module 12 performs multiplication operations on multiple activation parameter blocks and multiple weight blocks based on inverse quantization parameters to obtain multiple block operation results, the processing module 12 is used to execute: obtaining channel mapping relationships corresponding to each of the multiple weight blocks, the channel mapping relationships being used to identify channel change information of each quantized model weight in the weight block after the rearrangement operation; adjusting activation values in the activation parameter blocks to be multiplied based on the channel mapping relationships corresponding to each of the multiple weight blocks to obtain multiple adjustment parameter blocks; and performing multiplication operations on multiple adjustment parameter blocks and multiple weight blocks based on inverse quantization parameters to obtain multiple block operation results.
[0162] In some instances, when the processing module 12 obtains the channel mapping relationship corresponding to each of the multiple weight blocks, the processing module 12 is used to execute: obtaining the original channel order of the quantized model weights in the multiple weight blocks; determining the rearranged channel order of the quantized model weights after rearrangement; based on the original channel order and the rearranged channel order, determining the channel mapping relationship corresponding to each of the multiple weight blocks.
[0163] In some instances, when the processing module 12 adjusts the activation values in the activation parameter block that needs to be multiplied based on the channel mapping relationship corresponding to each of the multiple weight blocks to obtain multiple adjustment parameter blocks, the processing module 12 is used to execute: obtaining the original channel order corresponding to each activation value in the activation parameter block; rearranging the activation values in the activation parameter block based on the channel mapping relationship and the original channel order to obtain the adjustment parameter block.
[0164] In some instances, when the processing module 12 performs multiplication operations on multiple adjustment parameter blocks and multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results, the processing module 12 is used to execute: performing inverse quantization operations on the quantized model weights in the corresponding weight blocks based on the inverse quantization parameters to obtain multiple inverse quantization model weights; determining multiple inverse quantization parameter blocks based on the multiple inverse quantization model weights and the multiple unquantized model weights in the corresponding weight blocks; and performing multiplication operations on multiple inverse quantization parameter blocks and multiple adjustment parameter blocks to obtain multiple block operation results.
[0165] In some examples, before obtaining the activation matrix and the weight matrix corresponding to the large language model, the obtaining module 11, the processing module 12 and the determining module 13 in this embodiment are used to perform the following steps:
[0166] An acquisition module 11 is used to acquire a quantized model weight corresponding to a large language model;
[0167] A determination module 13 is used to determine a lower limit of a read bit width for reading the quantized model weights;
[0168] The processing module 12 is used to compress and store the quantized model weights based on the read bit width lower limit.
[0169] In some examples, after compressing and storing the quantized model weights based on the read bit width lower limit, the acquisition module 11 and the processing module 12 in this embodiment are used to perform the following steps:
[0170] An acquisition module 11 is used to acquire a weight access request;
[0171] The processing module 12 is used to read the compressed and stored quantized model weights based on the weight access request and the read bit width lower limit to obtain multiple quantized model weights corresponding to the access request.
[0172] Figure 8 The device shown can perform Figure 1-Figure 7 For the method of the embodiment shown in the figure, the part not described in detail in this embodiment can be referred to Figure 1-Figure 7 The implementation process and technical effects of this technical solution refer to Figure 1-Figure 7 The description in the illustrated embodiment will not be repeated here.
[0173] In one possible design, Figure 8 The structure of the mixed precision weight processing device shown in the figure can be implemented as an electronic device, which can be a controller, a personal computer, a server, or other devices. Fig. 9 As shown, the electronic device may include: a first processor 21 and a first memory 22. The first memory 22 is used to store the corresponding electronic device to execute the above Figure 1-Figure 7 The program of the mixed precision weight processing method provided in the illustrated embodiment, the first processor 21 is configured to execute the program stored in the first memory 22.
[0174] The program includes one or more computer instructions, wherein the one or more computer instructions can implement the following steps when executed by the first processor 21: obtaining an activation matrix and a weight matrix corresponding to a large language model, wherein the activation matrix includes multiple activation values, and the weight matrix includes: multiple unquantized model weights and multiple quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights; grouping the weight matrix to obtain multiple weight blocks corresponding to the weight matrix; determining the inverse quantization parameters corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same; performing multiplication operations on the activation matrix and the multiple weight blocks based on the inverse quantization parameters to obtain operation processing results.
[0175] Furthermore, the first processor 21 is also used to execute the aforementioned Figure 1-Figure 7 All or part of the steps in the illustrated embodiments.
[0176] The structure of the electronic device may further include a first communication interface 23 for the electronic device to communicate with other devices or a communication network.
[0177] In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by electronic devices, which includes instructions for executing the above Figure 1-Figure 7 The procedures involved in the method for processing mixed precision weights in the illustrated embodiment.
[0178] In addition, an embodiment of the present invention provides a computer program product, including: a computer-readable storage medium storing computer instructions, when the computer instructions are executed by one or more processors, causing the one or more processors to execute the above Figure 1-Figure 7 The steps in the method for processing mixed precision weights in the method embodiment are shown.
[0179] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0180] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0181] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution can essentially or in other words be embodied in the form of a computer product, and the present invention can be implemented in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0182] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable device to generate a machine, so that the instructions executed by the processor of the computer or other programmable device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0183] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable device to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide the functions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in the blocks or multiple blocks. In a typical configuration, the computing device includes one or more processors (CPU), input / output interfaces, network interfaces and memory. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0184] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0185] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A mixed precision weight processing method, It is characterized in that include: In response to a demand for extracting text features, an activation matrix and a weight matrix corresponding to a large language model are obtained, wherein the activation matrix includes a plurality of activation values, and the weight matrix includes: a plurality of unquantized model weights and a plurality of quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights, and the plurality of activation values include an input activation value for inputting into a first model network layer in the large language model; Grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix; Determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same; Based on the inverse quantization parameter, the activation matrix and the multiple weight blocks are multiplied to obtain a processing result.
2. The method according to claim 1, It is characterized in that The weight matrix is grouped to obtain a plurality of weight blocks corresponding to the weight matrix, including: Obtaining the importance of each quantized model weight and each unquantized model weight in the weight matrix; Rearranging the quantized model weights and the unquantized model weights in the weight matrix based on the importance to obtain a rearranged weight matrix; The rearranged weight matrix is grouped to obtain a plurality of weight blocks corresponding to the weight matrix.
3. The method according to claim 1, It is characterized in that Determine the inverse quantization parameters corresponding to each weight block, including: Obtaining identification information corresponding to each weight block; The global memory is accessed based on the identification information to obtain inverse quantization parameters corresponding to each weight block, wherein the inverse quantization parameters include a scaling factor and an offset.
4. The method according to claim 3, It is characterized in that Before determining the inverse quantization parameters corresponding to each weight block, the method further includes: Obtain the inverse quantization parameters corresponding to each weight block; Based on the identification information corresponding to each weight block, the inverse quantization parameter corresponding to each weight block is stored in the global memory.
5. The method according to claim 4, It is characterized in that Get the inverse quantization parameters corresponding to each weight block, including: Obtain any two quantized model weights in the weight block and the original model weights corresponding to the two quantized model weights; Based on the two quantized model weights and the corresponding original model weights, a dequantization parameter corresponding to the weight block is determined.
6. The method according to claim 1, It is characterized in that The method further comprises: performing a multiplication operation on the activation matrix and the plurality of weight blocks based on the inverse quantization parameter to obtain an operation processing result, comprising: Grouping the activation matrix to obtain multiple activation parameter blocks; Performing multiplication operations on the multiple activation parameter blocks and the multiple weight blocks based on the inverse quantization parameters to obtain multiple block operation results; Based on the multiple block operation results, the operation processing results corresponding to the activation matrix and the weight matrix are determined.
7. The method according to claim 6, It is characterized in that After obtaining the plurality of activation parameter blocks, the method further comprises: Acquire a shared memory corresponding to each weight block for performing operations with the activation parameter block, wherein the shared memories corresponding to different weight blocks are independent of each other; The activation parameter block is stored in the corresponding shared memory.
8. The method according to claim 6, It is characterized in that Based on the inverse quantization parameter, a plurality of activation parameter blocks and the plurality of weight blocks are multiplied to obtain a plurality of block operation results, including: Obtaining a channel mapping relationship corresponding to each of the plurality of weight blocks, wherein the channel mapping relationship is used to identify channel change information of each quantized model weight in the weight block after the rearrangement operation; Based on the channel mapping relationship corresponding to each of the multiple weight blocks, the activation value in the activation parameter block to be multiplied is adjusted to obtain multiple adjustment parameter blocks; Based on the inverse quantization parameter, a multiplication operation is performed on the multiple adjustment parameter blocks and the multiple weight blocks to obtain multiple block operation results.
9. The method according to claim 8, It is characterized in that Get the channel mapping relationship corresponding to multiple weight blocks, including: Get the original channel order of the quantized model weights in multiple weight blocks; Determining a rearranged channel order of the quantized model weights after rearrangement; Based on the original channel order and the rearranged channel order, a channel mapping relationship corresponding to each of the plurality of weight blocks is determined.
10. The method according to claim 8, It is characterized in that Based on the channel mapping relationship corresponding to each of the multiple weight blocks, the activation value in the activation parameter block to be multiplied is adjusted to obtain multiple adjustment parameter blocks, including: Obtaining the original channel order corresponding to each activation value in the activation parameter block; The activation values in the activation parameter block are rearranged based on the channel mapping relationship and the original channel order to obtain an adjustment parameter block.
11. The method according to claim 8, It is characterized in that The method further comprises: performing a multiplication operation on the plurality of adjustment parameter blocks and the plurality of weight blocks based on the inverse quantization parameter to obtain a plurality of block operation results, including: Performing a dequantization operation on the quantized model weights in the corresponding weight block based on the dequantization parameter to obtain a plurality of dequantized model weights; Determining a plurality of inverse quantization parameter blocks based on the plurality of inverse quantization model weights and a plurality of unquantized model weights in the corresponding weight blocks; A multiplication operation is performed on the multiple inverse quantization parameter blocks and the multiple adjustment parameter blocks to obtain multiple block operation results.
12. The method according to any one of claims 1 to 11, It is characterized in that Before obtaining the activation matrix and the weight matrix corresponding to the large language model, the method further includes: Obtaining a quantized model weight corresponding to the large language model; Determining a lower limit of a read bit width for reading the quantized model weights; The quantized model weights are compressed and stored based on the read bit width lower limit.
13. The method according to claim 12, It is characterized in that After compressing and storing the quantized model weights based on the read bit width lower limit, the method further includes: Get weighted access request; The compressed and stored quantized model weights are read based on the weight access request and the read bit width lower limit to obtain a plurality of quantized model weights corresponding to the access request.
14. A mixed precision weight processing device, It is characterized in that include: An acquisition module, configured to acquire an activation matrix and a weight matrix corresponding to a large language model in response to a demand for extracting text features, wherein the activation matrix includes a plurality of activation values, and the weight matrix includes: a plurality of unquantized model weights and a plurality of quantized model weights of different precisions, wherein the precision of the unquantized model weights is higher than the precision of the quantized model weights, and the plurality of activation values include an input activation value for inputting into a first model network layer in the large language model; A processing module, used for grouping the weight matrix to obtain a plurality of weight blocks corresponding to the weight matrix; A determination module, used to determine the inverse quantization parameter corresponding to each weight block, wherein the inverse quantization parameters corresponding to multiple quantized model weights in the same weight block are the same; The processing module is further used to perform a multiplication operation on the activation matrix and the multiple weight blocks based on the inverse quantization parameter to obtain a processing result.
15. An electronic device, It is characterized in that include: A memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method of any one of claims 1 to 13.
16. A computer storage medium, It is characterized in that Used to store a computer program, which enables a computer to implement the method of any one of claims 1 to 13 when executed.
17. A computer program product, It is characterized in that include: A computer program, when executed by a processor of an electronic device, causes the processor to execute the steps of any one of the methods of claims 1 to 13.
