A method of data processing and related apparatus
By rationally dividing matrix reading and computation within the processor and optimizing the grouped matrix multiplication module of the MoE model, the problem of low computational efficiency caused by a large number of parameters is solved, thereby improving the overall performance of the MoE model.
Patent Information
- Application Number
- CN202510687019.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-26
- Publication Date
- 2026-11-27
AI Technical Summary
The large number of parameters in the grouped matrix multiplication module of the MoE model leads to low computational efficiency and a long incremental inference stage, which affects the model performance.
By setting up a first cache and a second cache in the processor, the matrix can be rationally divided according to the load, reducing the bandwidth requirements for matrix reads and optimizing matrix multiplication calculations.
It improves the computational and execution efficiency of grouped matrix multiplication and shortens the analysis time of the MoE model.
Smart Images

Figure CN123178759A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data processing method and related apparatus. Background Technology
[0002] There are various types of models in artificial intelligence technology. Mixture of experts (MoE) models, as an important type of artificial intelligence (AI) model, are widely used in fields such as text reasoning. A MoE model consists of multiple individual subnetworks, which are called "experts." Each subnetwork processes a subset of the input data to collectively complete the reasoning process.
[0003] During the MoE model processing, the activation matrices corresponding to multiple tokens are assigned to multiple "experts" in the MoE model for processing. Before the matrices are assigned to multiple "experts" for processing, the routing network needs to flexibly distribute the tokens according to the matching degree between the tokens and the "experts", and then the "experts" group and calculate the matrices corresponding to the tokens.
[0004] In the MoE model, the group matrix multiplication (GMM) module accounts for the majority of the total parameters. The time consumed in the incremental inference stage is directly proportional to the number of parameters. Therefore, improving the parameter tuning efficiency and execution efficiency of the GMM module becomes the key to optimizing the inference performance of the MoE model. Summary of the Invention
[0005] This application provides a data processing method and related apparatus for improving computational efficiency in grouped matrix multiplication.
[0006] In a first aspect, this application provides a data processing method applied to a processor, the processor including a first cache, a second cache, a matrix calculator, a first register, a second register, and a third register, wherein the data processing speed of the first cache is higher than that of the second cache, and the method includes:
[0007] If the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes, the first cache retrieves the first matrix, which is an M*K matrix;
[0008] The first cache retrieves n consecutive columns of the second matrix, which is a K*N matrix;
[0009] The matrix calculator performs multiplication on the first and second submatrices to obtain the third submatrix. The first submatrix is a submatrix of the first matrix, and the first submatrix is an a*b matrix. The second submatrix is a submatrix of the second matrix consisting of n consecutive columns, and the second submatrix is a b*n matrix. The capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes.
[0010] In this embodiment, before performing matrix multiplication between the first and second matrices, the processor first determines the relationship between the capacity of the first cache, the capacity of the second cache, and the size of the first matrix to determine whether the processor is in a low-load state relative to the first matrix. When the processor is in a low-load state, it is not necessary to simultaneously partition the first and second matrices before calculation; only the second matrix needs to be partitioned. This simplifies the calculation required to partition the first matrix, reduces the computational load on the processor, and eliminates the need for multiple reads of the first matrix's contents, reducing the time consumed by matrix reads and improving the computational efficiency of matrix multiplication. This, in turn, improves the parameter tuning efficiency and execution efficiency of the GMM module.
[0011] In one possible implementation of the first aspect, the method further includes:
[0012] When at least one of the following occurs: the capacity of the first cache is less than M*K bytes or the capacity of the second cache is less than M*K bytes, the first cache retrieves consecutive x rows of the first matrix and consecutive y columns of the second matrix, where x and y are both positive integers.
[0013] The matrix calculator performs multiplication on the fourth and fifth submatrices to obtain the sixth submatrix. The fourth submatrix is a submatrix consisting of x consecutive rows of the first matrix, and the fifth submatrix is a submatrix consisting of y consecutive columns of the second matrix. The fourth submatrix is an x*z matrix, and the fifth submatrix is a z*y matrix. The capacity of the first register is greater than x*z bytes, and the capacity of the second register is greater than z*y bytes.
[0014] In this embodiment, when the processor is under high load relative to the size of the first matrix, the first matrix and the second matrix are simultaneously divided. During each calculation, the first cache reads a portion of the rows of the first matrix and a portion of the columns of the second matrix. This allows the limited capacity of the first and second caches to effectively provide temporary storage for the multiplication operations of the first and second matrices. This enables the processor to efficiently read and calculate the first and second matrices whether it is under high or low load relative to the first matrix, avoiding excessively long processor waiting times.
[0015] In one possible implementation of the first aspect, the consecutive x rows of the first matrix are obtained by dividing the M rows of the first matrix into p equal parts, and the consecutive y columns of the second matrix are obtained by dividing the N columns of the second matrix into q equal parts, where p and q are integers greater than 1. The amount of data migration of the first cache that retrieves the consecutive x rows of the first matrix p+1 times and the consecutive y columns of the second matrix q+1 times is less than a preset amount of data.
[0016] In this embodiment, by setting a certain preset data volume, a combination that meets the computational speed requirements can be quickly selected from multiple combinations of partitioning methods for the first and second matrices, significantly improving the rationality of the partitioning methods for the first and second matrices. Since the first cache may retrieve the first and second matrices from inside or outside the processor, bandwidth is limited when retrieving them from outside the processor. By rationally partitioning the first and second matrices, the efficiency of the first cache in retrieving the first and second matrices is improved, thus balancing computational power and efficiency. When retrieving them from inside the processor, the larger matrix size also improves the efficiency of retrieving the first and second matrices, achieving the goal of balancing computational power and efficiency.
[0017] In one possible implementation of the first aspect, the preset data volume includes the amount of data obtained by the first cache from the first matrix in the form of X consecutive rows P+1 times and from the second matrix in the form of Y consecutive columns Q+1 times. The X consecutive rows of the first matrix are obtained by dividing the first matrix into M rows P, and the Y consecutive columns of the second matrix are obtained by dividing the second matrix into N columns Q. P and Q are integers greater than 1, and P is not equal to p and Q is not equal to q.
[0018] In this embodiment, from various ways of partitioning the rows of the first matrix and the columns of the second matrix, the partitioning method with the smallest amount of data acquired by the first cache is selected as the partitioning method of the rows of the first matrix and the columns of the second matrix. This can effectively reduce the amount of data acquired by the first cache when calculating the matrix multiplication of the first matrix and the second matrix, reduce the latency caused by the bandwidth occupied by data flow, and effectively improve the computational efficiency of matrix multiplication between the first matrix and the second matrix.
[0019] In one possible implementation of the first aspect, the method further includes:
[0020] Increment the frequency of occurrence of the first parameter group by one. The first parameter group includes a low load identifier, a first matrix specification of M*K, and a first column specification with a value of n. Alternatively, the first parameter group includes a low load identifier, a first matrix specification, a first column specification, a second column specification of specification b, and a second row specification of specification b.
[0021] In this embodiment of the application, data collection is completed by recording the frequency of occurrence of the first parameter group when the first cache is under low load, which facilitates the verification of the effect of the segmentation method of the first matrix and the second matrix.
[0022] In one possible implementation of the first aspect, the method further includes:
[0023] Increment the frequency of the second parameter group by one. The second parameter group includes a high load identifier, a first matrix specification of M*K, a first row specification with a value of x, and a first column specification with a value of y. Alternatively, the second parameter group includes a high load identifier, a first matrix specification, a first row specification, a first column specification, a second column specification with a specification of z, and a second row specification with a specification of z.
[0024] In one possible implementation of the first aspect, the method further includes:
[0025] When the frequency of the second parameter group is greater than the threshold and the third matrix is an M*K matrix, the first cache obtains the consecutive x rows of the third matrix and the consecutive y columns of the fourth matrix. The fourth matrix is a K*N matrix, and the third matrix and the fourth matrix are multiplied.
[0026] In this embodiment, the matrix segmentation method in the matrix multiplication calculation is determined by comparing whether the matrix format of the left matrix in the matrix multiplication calculation is the same as that of the matrix corresponding to the high-frequency parameter. When the matrix format of the left matrix in the matrix multiplication calculation is the same as that of the matrix corresponding to the high-frequency parameter, the matrix segmentation method is no longer calculated, which can effectively save the time required for calculation in the matrix segmentation process and further improve the computational efficiency of the processor in matrix multiplication.
[0027] In one possible implementation of the first aspect, the first cache retrieves the first matrix by:
[0028] The first cache retrieves the first matrix from the second cache.
[0029] In this embodiment of the application, in a specific implementation scenario, since the matrix needs to be quantized in the inference of the MoE model, the quantization process is carried out in the vector calculator of the processor, and the second cache is the high-speed cache closest to the vector calculator. Based on the low load state of the processor, the first cache can directly obtain the first matrix from the second cache, simplifying the data migration process of the first matrix, reducing the bandwidth occupation, and thus improving the matrix calculation efficiency of the processor.
[0030] In one possible implementation of the first aspect, the first cache retrieves consecutive x rows of the first matrix and consecutive y columns of the second matrix, comprising:
[0031] The first cache retrieves consecutive x rows of the first matrix and consecutive y columns of the second matrix from the third cache, which is contained within the processor.
[0032] In this embodiment of the application, the first matrix and the second matrix obtained by quantization are stored in the third cache. When matrix multiplication is required, the first cache retrieves part of the contents of the first matrix and the second matrix from the third cache multiple times to ensure high-speed matrix multiplication and improve the efficiency of matrix multiplication in the processor.
[0033] Secondly, this application provides a data processing apparatus, comprising:
[0034] The acquisition unit is used to acquire a first matrix when the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes. The first matrix is an M*K matrix.
[0035] The acquisition unit is also used to acquire n consecutive columns of the second matrix, which is a K*N matrix;
[0036] The calculation unit is used to perform multiplication calculations on the first submatrix and the second submatrix to obtain the third submatrix. The first submatrix is a submatrix of the first matrix and is an a*b matrix. The second submatrix is a submatrix of the second matrix consisting of n consecutive columns and is a b*n matrix. The capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes.
[0037] Thirdly, this application provides a data processing apparatus, including a processor and a memory coupled together, the memory storing a program, which, when executed by the processor, implements the method shown in the first aspect or any possible implementation of the first aspect.
[0038] Fourthly, this application provides a computer-readable storage medium including a program that, when executed by a processing unit, performs the method as described in the first aspect or any possible implementation thereof.
[0039] Fifthly, this application provides a computer program product, including a computer program, characterized in that, when executed by a processor, the computer program implements the method shown in the first aspect or any possible implementation of the first aspect. Attached Figure Description
[0040] Figure 1 A schematic diagram of the processor architecture provided in this application;
[0041] Figure 2A flowchart illustrating the data processing method provided in this application;
[0042] Figure 3 A schematic diagram illustrating the data changes provided in this application;
[0043] Figure 4 Another flowchart illustrating the data processing method provided in this application;
[0044] Figure 5 Another schematic diagram illustrating the changes in data provided for this application;
[0045] Figure 6 Another flowchart illustrating the data processing method provided in this application;
[0046] Figure 7 A schematic diagram of the data processing apparatus provided in this application;
[0047] Figure 8 Another schematic diagram of the data processing apparatus provided in this application. Detailed Implementation
[0048] This application provides a data processing method and related apparatus for improving computational efficiency in grouped matrix multiplication.
[0049] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0050] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of units is not necessarily limited to those units, but may include other units not explicitly listed or inherent to those processes, methods, products, or apparatuses. Additionally, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or multiple items. For example, at least one of a, b, or c can be expressed as: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0051] The MoE model is an important AI model. Compared to the feedforward network layer of a conventional model, it replaces the conventional feedforward network layer with multiple sub-networks, each of which is an independent neural network. These sub-networks are called "experts." During model inference, the routing module allocates tokens that require matrix multiplication to the appropriate "experts" for processing. The "experts" then perform grouped calculations on the matrices corresponding to the tokens based on the current load.
[0052] In the MoE model, the GMM module accounts for the majority of the total parameters. The time consumed in the incremental inference stage is directly proportional to the number of parameters. Therefore, improving the parameter tuning efficiency and execution efficiency of the GMM module becomes the key to optimizing the inference performance of the MoE model.
[0053] To address the above issues, this application proposes that the load status of an "expert" can be determined based on the available cache capacity of the "expert" and the size of the matrix corresponding to the token. For example, if the available cache capacity of the "expert" is a first cache and a second cache, with the first and second caches operating independently, and the matrix corresponding to the token is a first matrix, and the capacity of the first matrix is less than the capacity of the first cache and approximately also less than the capacity of the second cache, then the "expert" is considered to be under low load. Under low load, the entire first matrix can be loaded directly into the first cache, and then the second matrix, which will be multiplied by the first matrix, can be loaded in batches to complete the multiplication operation between the first and second matrices. This fully utilizes the available cache of the "expert," eliminating the need to read the first matrix into the cache multiple times, reducing the time consumed by reading the matrix, simplifying matrix grouping under low load, and improving the computational efficiency of matrix multiplication. This, in turn, improves the parameter tuning efficiency and execution efficiency of the GMM module.
[0054] To facilitate understanding, the following will be combined with Figure 1 This application provides a brief overview of the application scenarios for the data processing method. Figure 1 This is a schematic diagram of one processor architecture.
[0055] The data processing device includes a first cache, a second cache, a matrix calculator, a vector calculator, a first register, a second register, and a third register. The first cache is a high-speed cache closest to the matrix calculator, used to temporarily store matrices used in matrix calculations by the matrix calculator. The second cache is a high-speed cache closest to the vector calculator, used to temporarily store matrices used in quantization by the vector calculator. The third cache is a low-speed cache used to temporarily store large amounts of data in the processor. The first register is used to temporarily store the left matrix in matrix multiplication operations by the matrix calculator, the second register is used to temporarily store the right matrix in matrix multiplication operations by the matrix calculator, and the third register is used to temporarily store the results of matrix multiplication operations by the matrix calculator.
[0056] In the inference process of the MoE model, each "expert" corresponds to at least one such expert. Figure 1 The processor shown performs three steps: quantization, expert computation, and dequantization. During the expert computation process, due to the limited capacity of the matrix calculator, the multiplication of the first and second matrices requires repeated readings of both matrices. The solution provided in this application reduces the bandwidth required for reading the first and second matrices by rationally dividing them, thereby reducing the time required for data reading and improving the processor's computational efficiency in matrix multiplication. This, in turn, improves the parameter tuning efficiency and execution efficiency of the GMM module.
[0057] Based on the above Figure 1 The data processing device shown below, in conjunction with Figure 2 The data processing method provided in this application is described.
[0058] S201. If the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes, the first cache retrieves the first matrix.
[0059] The first matrix is an M*K matrix. That is, the processor is considered to be under low load when the capacity of the first cache is greater than or equal to the capacity of the first matrix, and the capacity of the second cache is greater than or equal to the capacity of the first matrix.
[0060] In one possible implementation, the first matrix is a quantized matrix, such as... Figure 1 In the processor shown, the quantization of the matrix is performed in a vector calculator. The vector calculator performs quantization to obtain a first matrix, which is temporarily stored in a second cache. The first cache obtains the first matrix from the second cache.
[0061] In this embodiment of the application, in a specific implementation scenario, since the matrix needs to be quantized in the inference of the MoE model, the quantization process is carried out in the vector calculator of the processor, and the second cache is the high-speed cache closest to the vector calculator. Based on the low load state of the processor, the first cache can directly obtain the first matrix from the second cache, simplifying the data migration process of the first matrix, reducing the bandwidth occupation, and thus improving the matrix calculation efficiency of the processor.
[0062] It should be understood that the solution provided in this application is described here with one "expert" corresponding to one processor as an example. In specific implementation scenarios, each "expert" can correspond to multiple processors. Taking "expert" corresponding to two processors as an example, that is, "expert" corresponds to the first cache 1 and the first cache 2. The first cache 1 and the first cache 2 perform similar operations. The first cache 1 obtains the first matrix of the first M / 2 rows, and the first cache 2 obtains the first matrix of the last M / 2 rows. The description here is only an example. In actual applications, it should be set according to the specific application scenario. There are no restrictions here.
[0063] S202, The first cache retrieves n consecutive columns of the second matrix;
[0064] The second matrix is a K*N matrix. The first and second matrices are multiplied in the processor. The first matrix is the left matrix in the matrix multiplication, and the second matrix is the right matrix in the matrix multiplication.
[0065] Specifically, when the first cache retrieves n consecutive columns of the second matrix, the maximum number of columns of the second matrix that the first cache can hold is determined based on the current remaining space of the first cache, and the value of n is determined accordingly. For example, if the current remaining space of the first cache can hold 4 columns of the second matrix and N is 15, then the first cache needs to retrieve the entire contents of the second matrix in 4 steps. For example, the first time it retrieves columns 1-4 of the second matrix, the second time it retrieves columns 5-8 of the second matrix, the third time it retrieves columns 9-12 of the second matrix, and the fourth time it retrieves columns 13-15 of the second matrix. There is no limit to this.
[0066] S203, the matrix calculator performs multiplication on the first and second submatrices to obtain the third submatrix.
[0067] The first submatrix is a submatrix of the first matrix, the second submatrix is a submatrix of n consecutive columns of the second matrix, the first submatrix is a matrix with a*b capacity, the second submatrix is a matrix with a*c capacity, the first register has a capacity greater than a*b bytes, the second register has a capacity greater than b*n bytes, and the third register has a capacity greater than a*n bytes.
[0068] Specifically, in the processor, the first, second, and third registers are used to temporarily store the left matrix, right matrix, and result of matrix multiplication in the matrix calculator, respectively. Therefore, the capacities of the left matrix, right matrix, and result of matrix multiplication in the matrix calculator should be smaller than the capacities of the first, second, and third registers, respectively. The left matrix used in matrix multiplication is the first submatrix, the right matrix is the second submatrix, and the matrix obtained from matrix multiplication is the third submatrix. Therefore, the capacity of the first submatrix is smaller than the capacity of the first register, the capacity of the second submatrix is smaller than the capacity of the second register, and the capacity of the third submatrix is smaller than the capacity of the third register. That is, the capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes; however, there are no restrictions on this.
[0069] In this embodiment, before performing matrix multiplication between the first and second matrices, the processor first determines the relationship between the capacity of the first cache, the capacity of the second cache, and the size of the first matrix to determine whether the processor is in a low-load state relative to the first matrix. When the processor is in a low-load state, it is not necessary to simultaneously partition the first and second matrices before calculation; only the second matrix needs to be partitioned. This simplifies the calculation required to partition the first matrix, reduces the computational load on the processor, and eliminates the need for multiple reads of the first matrix's contents, reducing the time consumed by matrix reads and improving the computational efficiency of matrix multiplication. This, in turn, improves the parameter tuning efficiency and execution efficiency of the GMM module.
[0070] For ease of understanding Figure 2 In the method shown, the data flow of the first and second matrices in the processor is described below in conjunction with... Figure 3 Please provide an explanation. For example... Figure 3 As shown, the first cache retrieves the first matrix from the second cache, and the first cache retrieves n consecutive columns of the second matrix from the third cache or an external device. Furthermore, the first and second submatrices are moved to the first register and the second register, respectively, so that the matrix calculator can perform multiplication on the first and second submatrices to obtain the third submatrix. The specifications of each matrix are as follows: Figure 3 As shown in the gray box.
[0071] Correspondingly, under high processor load conditions, the data processing method provided in this application is as follows: Figure 4 As shown.
[0072] S401. When at least one of the following occurs: the capacity of the first cache is less than M*K bytes or the capacity of the second cache is less than M*K bytes, the first cache retrieves consecutive x rows of the first matrix and consecutive y columns of the second matrix.
[0073] Where x and y are both positive integers, that is, the processor is considered to be under high load when the capacity of the first cache is less than the capacity of the first matrix, or the capacity of the second cache is less than the capacity of the first matrix, or the capacity of the first cache is less than the capacity of the first matrix and the capacity of the second cache is less than the capacity of the first matrix.
[0074] In one possible implementation, the first cache may obtain consecutive x rows of the first matrix and consecutive y columns of the second matrix from outside the processor, without limitation.
[0075] In one possible implementation, if a third cache exists in the processor, the third cache is a low-speed cache with a data processing speed lower than that of the first cache and the second cache. Since the third cache is located inside the processor, the data transfer speed of the first cache from the third cache to obtain the matrix is greater than the data transfer speed of the first cache from the outside of the processor. Therefore, the first cache can obtain consecutive x rows of the first matrix and consecutive y columns of the second matrix from the third cache.
[0076] In this embodiment of the application, the first matrix and the second matrix obtained by quantization are stored in the third cache. When matrix multiplication is required, the first cache retrieves part of the contents of the first matrix and the second matrix from the third cache multiple times to ensure high-speed matrix multiplication and improve the efficiency of matrix multiplication in the processor.
[0077] Specifically, the consecutive x rows of the first matrix are any one of the p+1 consecutive x rows obtained by dividing the M rows of the first matrix into p equal parts, such as the (x+1)th row to the 2xth row of the first matrix. The consecutive y columns of the second matrix are any one of the q+1 consecutive y columns obtained by dividing the N columns of the second matrix into q equal parts, such as the 1st column to the yth column of the second matrix, without any restrictions.
[0078] It should be understood that in order to ensure that the first cache can successfully retrieve the consecutive x rows of the first matrix and the consecutive y columns of the second matrix, the capacity of the first cache should be greater than x*K+K*y bytes, but no limit is imposed here.
[0079] In one possible implementation, when dividing the M rows of the first matrix into p equal parts and the N columns of the second matrix into q equal parts, p and q can be randomly selected and are not restricted here. Adaptively, to ensure that the division can be achieved, p and q should satisfy p < M and q < N.
[0080] In one possible implementation, when dividing the M rows of the first matrix into p equal parts and the N columns of the second matrix into q equal parts, the amount of data migration required for the first cache to retrieve the complete contents of the first and second matrices needs to be analyzed. For example, when dividing the M rows of the first matrix into p equal parts and the N columns of the second matrix into q equal parts, the first cache needs to retrieve p+1 consecutive x rows of the first matrix and q+1 consecutive y columns of the second matrix to fully retrieve the first and second matrices. That is, the first cache needs to transfer (p+1)*(x*K)+(q+1)*(K*y) bytes of data to fully retrieve the first and second matrices. To reduce the waiting time caused by data transmission, the amount of data transmission required for the first cache to fully retrieve the first and second matrices should be minimized.
[0081] In one possible implementation, the amount of data migration when the first cache retrieves p+1 consecutive x rows of the first matrix and q+1 consecutive y columns of the second matrix is less than a preset data amount. This preset data amount can be a specific value determined based on experience in reading data from the first cache, and is not limited here.
[0082] In this embodiment of the application, by setting a certain preset amount of data, a combination that meets the computational speed requirements can be quickly selected from multiple combinations of partitioning methods of the first matrix and the second matrix, which greatly improves the rationality of partitioning methods of the first matrix and the second matrix, and takes into account both computing power and efficiency.
[0083] In one possible implementation, the preset data volume can also be the amount of data obtained by the first cache from obtaining X consecutive rows of the first matrix P+1 times and from obtaining Y consecutive columns of the second matrix Q+1 times. The X consecutive rows of the first matrix are obtained by dividing the M rows of the first matrix into P equal parts, and the Y consecutive columns of the second matrix are obtained by dividing the N columns of the second matrix into Q equal parts. P and Q are integers greater than 1, and P is not equal to p, and Q is not equal to q. That is, the preset data volume is any partitioning method of the first and second matrices other than dividing the M rows of the first matrix into p equal parts and the N columns of the second matrix into q equal parts. Considering that the data migration amount of obtaining p+1 consecutive rows of the first matrix and q+1 consecutive columns of the second matrix from the first cache is less than the preset data volume, it can also be understood as the partitioning method with the smallest data migration amount among various partitioning methods of the first and second matrices, where the M rows of the first matrix are divided into p equal parts and the N columns of the second matrix are divided into q equal parts.
[0084] In this embodiment, from various ways of partitioning the rows of the first matrix and the columns of the second matrix, the partitioning method with the smallest amount of data acquired by the first cache is selected as the partitioning method of the rows of the first matrix and the columns of the second matrix. This can effectively reduce the amount of data acquired by the first cache when calculating the matrix multiplication of the first matrix and the second matrix, reduce the latency caused by the bandwidth occupied by data flow, and effectively improve the computational efficiency of matrix multiplication between the first matrix and the second matrix.
[0085] S402. The matrix calculator performs multiplication on the fourth and fifth submatrices to obtain the sixth submatrix.
[0086] Among them, the fourth submatrix is a submatrix of x consecutive rows of the first matrix, the fifth matrix is a submatrix of y consecutive columns of the second matrix, the fourth submatrix is an x*z matrix, the fifth submatrix is a z*y matrix, the sixth matrix is an x*y matrix, the capacity of the first register is greater than x*z bytes, the capacity of the second register is greater than z*y bytes, and the capacity of the third register is greater than x*y bytes.
[0087] Specifically, the matrix calculator obtains the sixth submatrix by multiplying the fourth and fifth submatrixes in a similar way to the matrix calculator that calculates the first and second submatrixes, and will not be elaborated here.
[0088] Furthermore, the matrix specifications of the fourth, fifth, and sixth submatrices are set in a similar manner to those of the first, second, and third submatrices, and will not be repeated here.
[0089] In this embodiment, when the processor is under high load relative to the size of the first matrix, the first matrix and the second matrix are simultaneously divided. During each calculation, the first cache reads a portion of the rows of the first matrix and a portion of the columns of the second matrix. This allows the limited capacity of the first and second caches to effectively provide temporary storage for the multiplication operations of the first and second matrices. This enables the processor to efficiently read and calculate the first and second matrices whether it is under high or low load relative to the first matrix, avoiding excessively long processor waiting times.
[0090] For ease of understanding Figure 4 In the method shown, the data flow of the first and second matrices in the processor is described below in conjunction with... Figure 5 Please provide an explanation. For example... Figure 5 As shown, the first cache obtains consecutive x rows of the first matrix and consecutive y columns of the second matrix from the third cache or an external device. Furthermore, the fourth and fifth submatrices are moved to the first and second registers respectively, so that the matrix calculator can perform multiplication on the fourth and fifth submatrices to obtain the sixth submatrix.
[0091] In the above Figure 2 and Figure 4 Based on the method shown, since the processor still needs to consume computing power to divide the first matrix and the second matrix, this application also proposes that after each calculation, the division method of the first matrix and the second matrix and whether the first cache is low-load or high-load relative to the size of the first matrix can be recorded when performing matrix multiplication operation on the first matrix and the second matrix.
[0092] For example, when the first cache is under low load relative to the size of the first matrix, the frequency of occurrence of the first parameter group is incremented by one. The first parameter group includes a low load identifier, a first matrix specification of M*K, and a first column specification with a value of n. Alternatively, the first parameter includes a low load identifier, a first matrix specification, a first column specification, a second column specification of b, and a second row specification of b.
[0093] In this embodiment of the application, data collection is completed by recording the frequency of occurrence of the first parameter group when the first cache is under low load, which facilitates the verification of the effect of the segmentation method of the first matrix and the second matrix.
[0094] For example, when the first cache is under high load relative to the size of the first matrix, the frequency of the second parameter group is incremented by one. The second parameter group includes a high load identifier, a first matrix size of M*K, a first row size with a value of x, and a first column size with a value of y; or, the second parameter group includes a high load identifier, a first matrix size of M*K, a first row size with a value of x, a first column size with a value of y, a second column size with a value of z, and a second row size with a size of z. The first row size is used to divide the rows of the first matrix, the second column size is used to divide the columns of the first matrix, the first column size is used to divide the columns of the second matrix, and the second row size is used to divide the rows of the second matrix.
[0095] Based on the above statistical results, this application further proposes that the matrix can be segmented to have the same specifications as the first matrix based on the aforementioned data collection results. For example, when the frequency of the second parameter group is greater than the second threshold and the third matrix is an M*K matrix, the first cache can directly obtain the consecutive x rows of the third matrix and the consecutive y columns of the fourth matrix. Since the results calculated by the "expert" need to be weighted during the calculation of the MoE model, the second matrix (i.e., the right matrix) is this weight. Therefore, each time a matrix operation is performed by the same "expert," the specifications of the fourth matrix are the same as those of the second matrix. That is, the fourth matrix is a K*N matrix. Furthermore, during the multiplication operation between the third and fourth matrices, the matrix specifications when performing calculations in the matrix calculator are the same as those of the fourth and fifth sub-matrices, which will not be elaborated here.
[0096] In this case, the time required for calculation during matrix partitioning can be effectively saved, further improving the computational efficiency of matrix multiplication operations in the processor.
[0097] The aforementioned Figure 2 and Figure 4 When the method shown is applied to the inference scenario of the MoE model, the inference process of the MoE model is as follows: Figure 6As shown, after program initialization begins, the matrix specifications that the "expert" needs to process are first determined. Based on the specifications of the left matrix that the "expert" needs to process, it is determined whether this matrix specification corresponds to a high-frequency parameter set. If a high-frequency parameter set exists, the left matrix that the "expert" needs to process is preprocessed, and the left and / or right matrices are segmented and matrix multiplied based on the parameters in the high-frequency parameter set. Then, inverse quantization is performed to determine if the matrix has been traversed through each "expert" in the "expert list". If so, the result is output; otherwise, the "expert" is replaced and a similar process to that described above is executed. The high-frequency parameter set includes the segmentation methods for the left and right matrices.
[0098] Based on the above method, an example was provided in the control group of the MoE model. The first MoE model was the MoE model that did not use the method provided in this application, and the second MoE model was the MoE model that used the data processing method provided in this application. As shown in Table 1, when the sample size is 128 and the input sequence length is 2k, under the condition of 8 "experts", the solution provided by this invention can shorten the model analysis time by 10.1%.
[0099] Table 1. Schematic diagram of GMM operator time consumption in MoE model.
[0100] Expert Specifications: (5120, 2688) GMM operator execution time (μs) First MoE Model 723.6300 Second MoE model 651.267
[0101] Based on the above method, another experiment was conducted in the control group of the MoE model. The experimental results are shown in Table 2. The first MoE model is the MoE model that does not use the method provided in this application, and the second MoE model is the MoE model that uses the data processing method provided in this application. As shown in Table 2, with 8 "experts" and each "expert" associated with two processors, the solution provided by this invention can shorten the model analysis time by 9.8%.
[0102] Table 2. Schematic diagram of GMM operator time consumption in MoE model.
[0103] Expert Specifications: (5120, 1344) GMM operator execution time (μs) First MoE Model 759.3900 Second MoE model 683.1500
[0104] The data processing method proposed in this application has been described above. The data processing apparatus provided in this application will now be described in conjunction with the accompanying drawings:
[0105] Figure 7 A schematic diagram of the structure of the data processing apparatus provided in this application.
[0106] The data processing device 700 includes:
[0107] The acquisition unit 710 is used to acquire a first matrix when the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes. The first matrix is an M*K matrix.
[0108] The acquisition unit 710 is also used to acquire n consecutive columns of the second matrix, which is a K*N matrix;
[0109] The calculation unit 720 is used to perform multiplication calculations on the first submatrix and the second submatrix to obtain the third submatrix. The first submatrix is a submatrix of the first matrix and is an a*b matrix. The second submatrix is a submatrix of the second matrix consisting of n consecutive columns and is a b*n matrix. The capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes.
[0110] Optionally, the acquisition unit 710 is also used for:
[0111] When at least one of the following occurs: the capacity of the first cache is less than M*K bytes or the capacity of the second cache is less than M*K bytes, obtain x consecutive rows of the first matrix and y consecutive columns of the second matrix, where x and y are both positive integers.
[0112] The calculation unit 720 is also used to perform multiplication calculations on the fourth submatrix and the fifth submatrix to obtain the sixth submatrix. The fourth submatrix is a submatrix of consecutive x rows of the first matrix, and the fifth submatrix is a submatrix of consecutive y columns of the second matrix. The fourth submatrix is an x*z matrix, and the fifth submatrix is a z*y matrix. The capacity of the first register is greater than x*z bytes, and the capacity of the second register is greater than z*y bytes.
[0113] Optionally, the consecutive x rows of the first matrix are obtained by dividing the M rows of the first matrix into p equal parts, and the consecutive y columns of the second matrix are obtained by dividing the N columns of the second matrix into q equal parts, where p and q are integers greater than 1. The amount of data migration for the first cache to retrieve the consecutive x rows of the first matrix p+1 times and the consecutive y columns of the second matrix q+1 times is less than the preset data amount.
[0114] Optionally, the preset data volume includes the amount of data obtained by the first cache from the first matrix in the form of X consecutive rows P+1 times and from the second matrix in the form of Y consecutive columns Q+1 times. The X consecutive rows of the first matrix are obtained by dividing the first matrix into M rows P equally, and the Y consecutive columns of the second matrix are obtained by dividing the second matrix into N columns Q equally. P and Q are integers greater than 1 and P is not equal to p and Q is not equal to q.
[0115] Optionally, the device 70 further includes a statistics unit 730 for incrementing the frequency of occurrence of the first parameter group by one. The first parameter group includes a low load identifier, a first matrix specification of M*K, and a first column specification with a value of n. Alternatively, the first parameter group includes a low load identifier, a first matrix specification, a first column specification, a second column specification of b, and a second row specification of b.
[0116] Optionally, the device 700 also includes a statistical unit 730 for:
[0117] Increment the frequency of the second parameter group by one. The second parameter group includes a high load identifier, a first matrix specification of M*K, a first row specification with a value of x, and a first column specification with a value of y. Alternatively, the second parameter group includes a high load identifier, a first matrix specification, a first row specification, a first column specification, a second column specification with a specification of z, and a second row specification with a specification of z.
[0118] Optionally, the acquisition unit 710 is also used to acquire consecutive x rows of the third matrix and consecutive y columns of the fourth matrix when the frequency of occurrence of the second parameter group is greater than the threshold and the third matrix is an M*K matrix, and to perform multiplication operation between the third matrix and the fourth matrix.
[0119] Please see Figure 8 , Figure 8 This is a schematic diagram of the data processing apparatus provided in an embodiment of this application.
[0120] like Figure 8 As shown, the data processing device 800 includes a bus 803, a memory 804, a processor 805, and a communication interface 806. The processor 805, the memory 804, and the communication interface 806 communicate with each other via the bus 803. The data processing device 800 can be a server or a terminal device. It should be understood that the present invention does not limit the number of processors and memories in the data processing device 800.
[0121] The 803 bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 8 The bus is represented by only one line, but this does not mean that there is only one bus or one type of bus. Bus 803 may include a path for transmitting information between various components of the data processing device 800.
[0122] The processor 805 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0123] The memory 804 may include volatile memory, such as random access memory (RAM). The processor 805 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0124] The memory 804 stores executable program code, and the processor 805 executes the executable program code to implement the acquisition unit 801 (as described above). Figure 7 The acquisition unit 710 and the calculation unit 802 (mentioned above) Figure 7 The computing unit 720 in the memory performs its functions to implement the data processing method. That is, the memory 804 stores instructions for the cloud service platform to execute the data processing method provided in this embodiment.
[0125] The communication interface 806 uses transceiver units such as, but not limited to, network interface cards and transceivers to enable communication between the data processing device 800 and other devices or communication networks.
[0126] The data processing device 800 is used to execute the operations performed by each device in the processor in the foregoing embodiments, so as to implement the data processing method provided in the embodiments of this application.
[0127] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0128] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0129] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0130] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0131] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A data processing method, characterized in that, Applied to a processor, the processor including a first cache, a second cache, a matrix calculator, a first register, a second register, and a third register, wherein the data processing speed of the first cache is higher than that of the second cache, the method includes: If the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes, the first cache retrieves the first matrix, which is an M*K matrix; The first cache retrieves n consecutive columns of the second matrix, where the second matrix is a K*N matrix; The matrix calculator performs multiplication on the first submatrix and the second submatrix to obtain the third submatrix. The first submatrix is a submatrix of the first matrix and is an a*b matrix. The second submatrix is a submatrix of the second matrix consisting of n consecutive columns and is a b*n matrix. The capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes.
2. The method according to claim 1, characterized in that, The method further includes: When at least one of the following occurs: the capacity of the first cache is less than M*K bytes or the capacity of the second cache is less than M*K bytes, the first cache obtains x consecutive rows of the first matrix and y consecutive columns of the second matrix, where x and y are both positive integers. The matrix calculator performs multiplication on the fourth and fifth submatrices to obtain the sixth submatrice. The fourth submatrice is a submatrice consisting of x consecutive rows of the first matrix, and the fifth submatrice is a submatric consisting of y consecutive columns of the second matrix. The fourth submatrice is an x*z matrix, and the fifth submatrice is a z*y matrix. The capacity of the first register is greater than x*z bytes, and the capacity of the second register is greater than z*y bytes.
3. The method according to claim 2, characterized in that, The consecutive x rows of the first matrix are obtained by dividing the M rows of the first matrix into p equal parts, and the consecutive y columns of the second matrix are obtained by dividing the N columns of the second matrix into q equal parts, where p and q are integers greater than 1. The amount of data migration of the first cache that retrieves the consecutive x rows of the first matrix p+1 times and the consecutive y columns of the second matrix q+1 times is less than a preset amount of data.
4. The method according to claim 3, characterized in that, The preset data volume includes the amount of data obtained by the first cache from the first matrix in X consecutive rows P+1 times and from the second matrix in Y consecutive columns Q+1 times. The X consecutive rows of the first matrix are obtained by dividing the first matrix into M rows P. The Y consecutive columns of the second matrix are obtained by dividing the second matrix into N columns Q. P and Q are integers greater than 1, and P is not equal to p and Q is not equal to q.
5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: Increment the frequency of occurrence of the first parameter group by one. The first parameter group includes a low load identifier, a first matrix specification of M*K, and a first column specification with a value of n. Alternatively, the first parameter group includes the low load identifier, the first matrix specification, the first column specification, a second column specification of b, and a second row specification of b.
6. The method according to any one of claims 2 to 4, characterized in that, The method further includes: Increment the frequency of occurrence of the second parameter group by one. The second parameter group includes a high load identifier, a first matrix specification of M*K, a first row specification with a value of x, and a first column specification with a value of y. Alternatively, the second parameter group includes the high load identifier, the first matrix specification, the first row specification, the first column specification, a second column specification with a specification of z, and a second row specification with a specification of z.
7. The method according to claim 5 or 6, characterized in that, The method further includes: When the frequency of occurrence of the second parameter group is greater than the threshold and the third matrix is an M*K matrix, the first cache obtains the consecutive x rows of the third matrix and the consecutive y columns of the fourth matrix, the fourth matrix is a K*N matrix, and the third matrix and the fourth matrix are multiplied.
8. The method according to any one of claims 1 to 7, characterized in that, The first cache retrieves the first matrix by: The first cache retrieves the first matrix from the second cache.
9. The method according to any one of claims 2 to 7, characterized in that, The first cache retrieves consecutive x rows of the first matrix and consecutive y columns of the second matrix, including: The first cache obtains consecutive x rows of the first matrix and consecutive y columns of the second matrix from the third cache, the third cache being contained in the processor.
10. A data processing apparatus, characterized in that, include: The acquisition unit is used to acquire the first matrix when the capacity of the first cache is greater than or equal to M*K bytes and the capacity of the second cache is greater than or equal to M*K bytes, wherein the first matrix is an M*K matrix; The acquisition unit is further configured to acquire n consecutive columns of the second matrix, wherein the second matrix is a K*N matrix; The calculation unit is used to perform multiplication calculations on the first submatrix and the second submatrix to obtain the third submatrix. The first submatrix is a submatrix of the first matrix and is an a*b matrix. The second submatrix is a submatrix of the second matrix consisting of n consecutive columns and is a b*n matrix. The capacity of the first register is greater than a*b bytes, the capacity of the second register is greater than b*n bytes, and the capacity of the third register is greater than a*n bytes.
11. A data processing apparatus, characterized in that, The method includes a processor coupled to a memory storing a program, wherein the program instructions stored in the memory are executed by the processor to implement the method of any one of claims 1 to 9.
12. A computer-readable storage medium comprising a program, which, when executed by a processing unit, performs the method as described in any one of claims 1 to 9.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 9.
