Process-in-memory architecture based on resistive random-access memory and matrix factorization acceleration algorithm
By using the in-memory architecture of resistive switching memory and matrix decomposition acceleration algorithm in the Transformer model, the problem that existing processors are difficult to efficiently handle self-attention calculations is solved, the matrix multiplication is simplified and the calculation efficiency is improved, and the power consumption is reduced. consumption and storage requirements.
Patent Information
- Application Number
- PCT/CN2024/073129
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-10-13
- Filing Date
- 2024-01-18
- Publication Date
- 2024-09-19
AI Technical Summary
It is difficult for existing processors to efficiently handle the self-attention calculation in the Transformer model, especially the unique calculation process of scaling dot product attention and a large number of matrix-matrix multiplication operations, resulting in low computing speed and energy efficiency.
Using an in-memory architecture based on resistive switching memory and matrix decomposition acceleration algorithm, matrix multiplication is converted into vector multiplication and dot product through symmetric matrix decomposition, and the hardware architecture is used to optimize the self-attention calculation process and simplify matrix multiplication operations.
It reduces computing power consumption and latency, reduces the space requirements for storing intermediate results, improves computing efficiency and accuracy, reduces the sparsity of the weight matrix through matrix decomposition, and improves the utilization of in-memory computing.
Smart Images

Figure CN2024073129_19092024_PF_FP_ABST
Abstract
Description
In-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm Technical Field
[0001] The present invention relates to the fields of artificial intelligence algorithms and hardware, and in particular to an in-memory architecture for Transformr acceleration based on resistive random access memory and a matrix decomposition acceleration algorithm. Background Art
[0002] The Transformer has become a popular deep neural network (DNN) model in neural language processing (NLP) applications, demonstrating excellent performance in neural machine translation, entity recognition, and other areas. Transformer-based models, such as the Generative Pretrained Transformer (GPT), the Vision Transformer (ViT), and the Swin-Transformer, have become one of the most significant advances in the field of artificial intelligence. These models achieve higher accuracy than traditional convolutional neural networks (CNNs) and have disrupted CNNs' dominance in various AI tasks. Self-attention is a key mechanism in the Transformer model, performing self-attention calculations on each element in the input sequence and obtaining a self-attention representation for each element. This mechanism captures dependencies between elements in the sequence, enabling long-range dependency modeling, implementing a multi-head attention mechanism, and reducing computational complexity. It is a core element of the Transformer model and, therefore, its computation is one of the core mathematical operations of the Transformer model.
[0003] Unfortunately, the superior accuracy of Transformer-based models comes at the cost of more operations, but existing processors designed for CNNs cannot efficiently handle these operations. Although researchers have successfully applied process-in-memory (PIM) architectures based on resistive random access memory (ReRAM) to accelerate convolutional neural networks (CNNs) and recurrent neural networks (RNNs), the unique computational process of scaled dot-product attention in the Transformer makes it difficult to directly apply these designs. In addition, the Transformer must perform many matrix-matrix multiplication (MatMul) operations, where both matrices are intermediate results from previous layers. The early work requires writing these intermediate results to the computing device, which can pause the computation and reduce speed and energy efficiency.
[0004] Summary of the Invention
[0005] The present invention aims to address the shortcomings of existing technologies by providing an in-memory architecture based on resistive random access memory (RRAM) and a matrix decomposition acceleration algorithm. This invention leverages the properties of symmetric matrices to decompose the matrix, transforming matrix multiplication into vector multiplication and dot product. Furthermore, by introducing a hardware architecture to handle the computational process, the self-attention computation process is further optimized based on the Re-Transformer.
[0006] The object of the present invention is achieved through the following technical solution: an in-memory architecture based on resistive random access memory and a matrix decomposition acceleration algorithm, comprising:
[0007] Pre-training unit: train the three network parameter weight matrices W of the Transformer neural network through the data set Q ,W K ,W V ;
[0008] Decomposition unit: weight matrix W obtained according to the pre-training unit Q and W K Perform matrix decomposition, the decomposition formula is W Q W K T =W qk =A+B, where W qk is a real square matrix, A is a real symmetric matrix, B is an antisymmetric matrix, and A=W qk +W qk T / 2, B=W qk -W qk T / 2; Based on the properties of real symmetric matrices and antisymmetric matrices, the following decomposition is performed: A=P·D·P T , B=U·C·U T , where P is an orthogonal matrix, D is a diagonal matrix, U is a reversible matrix, and C is a block diagonal matrix;
[0009] Preprocessing unit: processes the input matrix X and the matrices P, D, U, and C obtained by the decomposition unit by rows and columns respectively, and inputs them into the calculation unit after staggered arrangement;
[0010] Computing unit: Using resistive random access memory as the computing element, the matrix output by the pre-processing unit is multiplied and added to obtain the product matrix. The formula is Out = P'·D·P' T +U'·C·U' T , where P'=X·P, U'=X·U, Out is the attention score;
[0011] Cache unit: temporarily stores the intermediate results calculated in the calculation unit in the cache unit;
[0012] Self-attention mechanism unit: Using the hybrid softmax calculation array based on the in-memory logic of the resistive memory, the product matrix Out obtained by the calculation unit is normalized to obtain the data softmax [(P'·D·P' T +U'·C·U' T ) / dk 0.5 )], where dk is the dimension of the key-value matrix K, and the obtained data is softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )] with the input matrix X and the weight matrix W V Perform matrix multiplication to obtain the self-attention weight coefficient.
[0013] Furthermore, the initial Transformer neural network randomly initializes three network parameter weight matrices W when performing self-attention calculation Q 、W K 、W V , by multiplying the input matrix X after adding the position information, we can get the query matrix Q, key value matrix K, and value matrix V.
[0014] Furthermore, the self-attention calculation formula of the Transformer neural network is softmax(Q·K T / dk 0.5 )·V, where the attention score Out=Q·K T Expand to Q·K T =(X·W Q )·(X·W K ) T =X·(W Q W K T )X T ;
[0015] Based on W Q W K T The product result W qk For a square matrix, according to the properties of the square matrix, W qk Decomposed into a real symmetric matrix A and an antisymmetric matrix B, and A = W qk +W qk T / 2, B=W qk -W qk T / 2;
[0016] Based on the properties of the real symmetric matrix and the antisymmetric matrix, the decomposition results are obtained by using the orthogonal decomposition of the real symmetric matrix and the Schur decomposition of the antisymmetric matrix: A = P·D·P T , B=U·C·U T , and D and C are in the following form: D=diag(λ1,λ2,…,λ i ), λ i is the eigenvalue of the real symmetric matrix A, i∈{1,2,...,m}, m is the number of rows in the weight matrix;
[0017] Furthermore, after obtaining the orthogonal matrix P, the reversible matrix U, the diagonal matrix D and the block diagonal matrix C, the attention score Out is expressed as: Out = X·(W Q W K T )·X T =X·A·X T +X·B·X T =(X·P)·D·(X·P) T +(X·U)·C·(X·U) T ;
[0018] Let P'=X·P, U'=X·U, the simplified formula is: Out=P'·D·P' T +U'·C·U' T .
[0019] Furthermore, after obtaining the attention score, the hybrid softmax calculation array based on the in-memory logic of the resistive memory is used to obtain the data softmax [(P'·D·P' T +U'·C·U' T ) / dk 0.5 )], and then multiply it by the input matrix X and the weight matrix W V , and the final output self-attention weight coefficient Z is obtained, which is expressed as: Z=softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )]·X·W V .
[0020] Furthermore, by utilizing the relevant properties of symmetric matrices, complex matrix-matrix operations are simplified to matrix-vector multiplication and dot products between vectors.
[0021] Furthermore, the resistive random access memory is used in the Transformer for matrix-vector and softmax operations.
[0022] The beneficial effects of the present invention are as follows: the present invention utilizes some properties of matrices to further optimize the self-attention calculation process on the basis of Re-Transformer, simplifies the original matrix-matrix operation to matrix-vector operation and dot product between vectors, and uses an in-memory calculation array represented by resistive random access memory to calculate the intermediate results. Since this solution optimizes the calculation process of matrix multiplication and utilizes in-memory calculation of resistive random access memory, it saves a lot of writing and storage requirements, which can further reduce power consumption, delay and space required to store intermediate results. In addition, sparse array design optimization method is an effective optimization method that can improve computing efficiency while reducing storage space. Therefore, the present invention utilizes the properties of the matrix to decompose the original part of the weight matrix, thereby reducing the sparsity of the weight matrix, and thereby improving the array utilization and accuracy of the in-memory calculation. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In the accompanying drawings, which are not necessarily drawn to scale, pictures may replace some of the text to clearly and vividly illustrate the relevant examples and solutions. The accompanying drawings are primarily for the purpose of illustrating the specification and claims in a schematic manner, and are not intended to be a precise reference.
[0024] Figure 1 shows the calculation steps of traditional Transformer self-attention.
[0025] Figure 2 shows the computational flow chart of traditional Transformer self-attention.
[0026] Figure 3 shows the computation steps of Re-Transformer self-attention for ReRAM in-memory computation.
[0027] Figure 4 shows the computational flow chart of Re-Transformer self-attention.
[0028] FIG5 shows the core idea of the Eigen-Transformer of the present invention to simplify the Self-Attention calculation by using matrix decomposition.
[0029] Figure 6 shows the calculation method and steps of Eigen-Transformer self-attention.
[0030] FIG7 shows an in-memory acceleration method for matrix multiplication by vector based on resistive random access memory.
[0031] Figure 8 shows the computational flow chart of Eigen-Transformer self-attention.
[0032] Figure 9 shows an explanation of the calculation methods of the three Transformer self-attention involved in the present invention (including a comparison of the required cache space). DETAILED DESCRIPTION
[0033] In order to enable relevant personnel in this field to better understand the technical solution of the present invention, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments. The embodiments of the present invention are further described in detail below with reference to the accompanying drawings and specific embodiments, but are not intended to limit the present invention. For the various steps described herein, if there is no necessity for a contextual relationship between each other, the order in which they are described as examples herein should not be regarded as limiting, and those skilled in the art should know that they can be adjusted in order, as long as the algorithmic logic between them is not destroyed, resulting in the inability to implement the entire process.
[0034] Explanation of relevant technical terms:
[0035] Transformer Neural Network:
[0036] From a macro perspective, Transformer is a seq2seq model based on the attention mechanism. The encoder is responsible for converting the input sequence (x1, ..., x a ) is mapped to a set of continuous sequences z=(z1,...,z a ). For a given z, the decoder generates the output sequence (y1, ..., y b At each step, the model is autoregressive. The Transformer follows this overall architecture. Unlike traditional convolutional neural networks (CNNs) and recurrent neural networks (RNNs), the entire network consists entirely of a self-attention mechanism and a feedforward neural network. Typically, a Transformer neural network consists of two parts: an encoder and a decoder.
[0037] The encoder consists of N identical encoder blocks stacked together, and the decoder is similarly composed of N identical decoder blocks stacked together. The encoder calculates the correlation between input sequences. Each encoder block includes a multi-head attention layer, which calculates global information about the input data. Because self-attention utilizes a parallel computing strategy, processing all input sequence data simultaneously, the model's computational efficiency is very high. The stacking of multiple encoder layers can better explore potential connections between sequence data. The decoder combines the global correlation information between previous sequences and outputs the sequence to be predicted.
[0038] Self-Attention Mechanism:
[0039] The traditional attention mechanism operates between elements of the target set Target and elements of the source set Source. Simply put, the calculation of the attention mechanism's weights requires the participation of the target. That is, in the encoder-decoder model, the calculation of the attention weights requires not only the hidden states of the encoder but also the hidden states of the decoder. The self-attention mechanism, on the other hand, parallelizes the weighted relationship between each vector in the input sequence and all other vectors, representing a global relationship. Therefore, only the corresponding matrix operations need to be performed at the source, without using information from the target. Figure 1 shows the calculation steps of the traditional self-attention mechanism.
[0040] When the initial Transformer neural network performs self-attention calculation, it randomly initializes three network parameter weight matrices W Q 、W K 、W V , by multiplying the input matrix X after adding position information to obtain the query matrix Q, key value matrix K, and value matrix V to assist in the calculation of self-attention: Q = X·W Q K=X·W K V=X·W V W Q ,W K ,W V ∈R mxn Out=Q·K T
[0041] Where m and n are the number of rows and columns of the weight matrix respectively; Out is the attention score; and the superscript T indicates the transpose of the matrix.
[0042] The self-attention weight coefficient Z is calculated by the three matrices Q, K, and V. The calculation formula is as follows: Z = Attention(Q, K, V) = softmax(Q·K T / dk 0.5 )·V
[0043] Among them, dk represents the dimension of the key-value matrix K, and Attention is the self-attention function. In order to prevent the inner product of Q and K from being too large, which leads to the extreme self-attention weight coefficient, the calculation is divided by dk 0.5It acts as a buffer. The Attention function calculates the degree of attention paid to a single position in the input sequence relative to all positions. The higher the correlation between two elements, the greater the corresponding attention weight. The entire calculation process does not prioritize the input vectors, and parallel computation is achieved through matrixing. Figure 2 illustrates the relevant calculation process.
[0044] In "Re-Transformer: ReRAM-based processing-in-memory architecture for transformer acceleration," Yang et al. proposed a ReRAM-based PIM architecture for Transformer acceleration. The core ideas behind this architecture include:
[0045] In the matrix linear transformation, the weight matrix W is K Changes to W K T , other factors remain unchanged, and Q is calculated at the same time; compared to the initial Transformer, this step only calculates Q;
[0046] When calculating the attention score, the formula (Q·W K T )·X T This step requires an additional cache X T ;
[0047] Each attention score is subjected to a hybrid softmax operation that applies the selection and comparison logic of ReRAM;
[0048] The softmax operation results are successively right-multiplied by the input matrix X and the weight matrix W V , and obtain the self-attention weight coefficient Z. The overall calculation steps are shown in Figure 3.
[0049] The specific calculation process is shown in Figure 4, which mainly includes: Q = X·W Q R=Q·W K T Out=R·X T Z=[softmax(R·X T / dk 0.5 )·X]·W V
[0050] Among them, R is the intermediate matrix.
[0051] The present invention provides an in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm for Transformer neural network acceleration, denoted as Eigen-Transformer, which mainly makes innovations in self-attention acceleration algorithm and hardware architecture.
[0052] In terms of the self-attention acceleration algorithm, based on the Re-Transformer, the self-attention calculation of the initial Transformer is further optimized by using matrix decomposition and some properties of symmetric matrices. The core idea is shown in Figure 5 and is mainly derived from:
[0053] Any real square matrix can be decomposed into the sum of a real symmetric matrix and an antisymmetric matrix;
[0054] Any real symmetric matrix must be orthogonal to a diagonal matrix, and the elements on the main diagonal of the diagonal matrix are all the eigenvalues of the real symmetric matrix;
[0055] Any antisymmetric matrix can be transformed into a block diagonal matrix by Schur decomposition;
[0056] Specifically:
[0057] The traditional Transformer's self-attention calculation is softmax(Q·K T / dk 0.5 )·V, where Q·K T Expanded to: Out=Q·K T =(X·W Q )·(X·W K ) T =X·(W Q W K T )X T W Q W K T =W qk =A+B
[0058] Among them, W qk is a real square matrix, A is a real symmetric matrix, B is an antisymmetric matrix, and A=W qk +W qk T / 2, B=W qk -W qk T / 2;
[0059] Based on the properties of real symmetric matrices and antisymmetric matrices, they are decomposed as follows: A=P·D·P T , B=U·C·U T
[0060] Among them, P is an orthogonal matrix, D is a diagonal matrix, U is a reversible matrix, C is a block diagonal matrix, and D and C can be written as follows:
[0061] D=diag(λ1,λ2,…,λ i ), λ i is the eigenvalue of the real symmetric matrix A, i∈{1,2,...,m};
[0062] Based on the decomposition results, the original weight W in the initial Transformer self-attention calculation Q ,W K Substitute the orthogonal matrix P, the reversible matrix U, the diagonal matrix D and the block diagonal matrix C, and the calculation steps are transformed into those shown in FIG6. Specifically, Out=X·(W Q W K T )·X T =X·A·X T +X·B·X T =(X·P)·D·(X·P) T +(X·U)·C·(X·U) T
[0063] Let P' = X·P and U' = X·U. This calculation conforms to the general in-memory computation format—matrix multiplication by input vector. Therefore, the present invention attempts to compute matrix-matrix and matrix-vector multiplications using an in-memory computation array, exemplified by resistive random access memory. Essentially, this approach uses physical quantities (such as voltage and current) to encode input, weight, and output data. By constructing circuits such that the input data, weights, and output data satisfy the mathematical relationship of matrix-vector multiplication, this computation is performed in a highly parallel manner in the analog domain. The relevant computational paradigm is shown in Figure 7.
[0064] Furthermore, the self-attention calculation is simplified to: Out = P'·D·P' T +U'·C·U' T
[0065] Furthermore, using the hybrid softmax operation based on ReRAM in-memory logic proposed in the Re-Transformer work, the following operation results are obtained: Softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )]
[0066] D=diag(λ1,λ2,…λ i ), λ iis the eigenvalue of the real symmetric matrix A, i∈{1,2,...,m};
[0067] Further, the result is multiplied by the input matrix X and the weight matrix W successively V , we can get the final output self-attention weight coefficient Z, which is specifically expressed as: Z=softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )]·X·W V
[0068] According to the above process, draw the corresponding flow chart as shown in Figure 8.
[0069] The self-attention calculation in this invention is mainly focused on P', U', P'·D·P' T and U'·C·U' T superior.
[0070] P'·D·P' T For example, due to the properties of the diagonal matrix D, the calculation result O of the i-th row and j-th column is ij Just use P' i and P' j Perform inner product, P' i and P' j are the i-th and j-th row vectors of the matrix P', i≠j; then multiplying by the diagonal elements in the diagonal matrix D can get the output; in addition, due to the properties of symmetric matrices, we only need to do the upper triangular or lower triangular to get the entire output matrix of this calculation.
[0071] In the same way, U'·C·U' T To calculate , we exploit the properties of antisymmetric matrices and block diagonal matrices, similarly calculating only the upper or lower triangular elements to obtain the entire result, significantly reducing the number of calculations throughout the process. Furthermore, the entire process only requires caching matrices P' and U', as well as the diagonal elements of the diagonal matrix D and the block diagonal matrix C, thus reducing cache space.
[0072] In terms of hardware architecture, this paper attempts to utilize Resistive Random Access Memory (ReRAM) in the Transformer. Based on the optimization of the self-attention acceleration algorithm process, corresponding hardware supporting measures are proposed to improve accelerated computing, which mainly include:
[0073] According to the self-attention acceleration algorithm optimization made by this invention, its calculation process is mainly transformed from the original matrix-matrix multiplication operation to matrix-vector multiplication and dot product between vectors. Therefore, the present invention attempts to use ReRAM-based in-memory logic to calculate related processes, store the elements in the matrix and vector in ReRAM, and use ReRAM's calculation logic to perform operations, which can greatly reduce computing power consumption and cache space.
[0074] Secondly, in the softmax operation, the hybrid softmax proposed based on ReRAM's selection and comparison logic is also used to transform the original softmax operation. The operation process is simplified by using ReRAM's selection and comparison logic structure. The relevant measures are detailed in the Re-Transformer article.
[0075] Based on the above analysis, the in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm provided by the present invention includes the following units:
[0076] Pre-training unit: train the three network parameter weight matrices W of the Transformer neural network through the data set Q ,W K ,W V ;
[0077] Decomposition unit: weight matrix W obtained according to the pre-training unit Q and W K Perform matrix decomposition, the decomposition formula is W Q W K T =W qk =A+B, where W qk is a real square matrix, A is a real symmetric matrix, B is an antisymmetric matrix, and A=W qk +W qk T / 2, B=W qk -W qk T / 2; Based on the properties of real symmetric matrices and antisymmetric matrices, the following decomposition is performed: A=P·D·P T , B=U·C·U T , where P is an orthogonal matrix, D is a diagonal matrix, U is a reversible matrix, and C is a block diagonal matrix;
[0078] Preprocessing unit: processes the input matrix X and the matrices P, D, U, and C obtained by the decomposition unit by rows and columns respectively, and inputs them into the calculation unit after staggered arrangement;
[0079] Computing unit: Using resistive random access memory as the computing element, the matrix output by the pre-processing unit is multiplied and added to obtain the product matrix. The formula is Out = P'·D·P' T +U'·C·U' T , where P'=X·P, U'=X·U, Out is the attention score;
[0080] Cache unit: temporarily stores the intermediate results calculated in the calculation unit in the cache unit for easy application in subsequent calculations;
[0081] Self-attention mechanism unit: Using the hybrid softmax calculation array based on the in-memory logic of the resistive memory, the product matrix Out obtained by the calculation unit is normalized to obtain the data softmax [(P'·D·P' T +U'·C·U' T ) / dk 0.5 )], where dk is the dimension of the key-value matrix K, and the obtained data is softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )] with the input matrix X and the weight matrix W V Perform matrix multiplication to obtain the self-attention weight coefficient, and output the self-attention weight coefficient through the data output module.
[0082] A comparison is made between the calculation methods and preliminary cache spaces of the initial Transformer, Re-Transformer, and the Eigen-Transformer of the present invention, and the corresponding results are shown in FIG9 .
[0083] The softmax operation part of the present invention adopts the hybrid softmax proposed in Re-Transformer - the softmax based on the ReRAM memory logic, so it is not repeated in this invention.
[0084] This paper aims to optimize the self-attention calculation process to reduce the number of calculations and write operations. It then uses the softmax operation based on the selection and comparison logic structure of ReRAM to further reduce overall power consumption.
[0085] In addition, the present invention has been described in the text in its general process and ideas, and its scope includes any and all algorithms and architectures based on which the present invention is based. The operating methods in the claims will be specifically interpreted based on the language used in the claims.
[0086] The above description is intended to be illustrative. A person of ordinary skill in the art can conduct preliminary theoretical research and use some auxiliary tools to perform preliminary simulations after reading the above description. The main core idea of the present invention is to optimize the self-attention calculation by utilizing matrix properties and attempt to calculate the transition matrix used in this solution through ReRAM in-memory logic. Therefore, people in the relevant field can conduct further research and optimization.
Claims
1. An in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm, characterized in that: include: Pre-training unit: Train the three network parameter weight matrices W of the Transformer neural network through the data set Q ,W K ,W V ; Decomposition unit: weight matrix W obtained from the pre-training unit Q and W K Perform matrix decomposition, the decomposition formula is W Q ·W K T =W qk =A+B, where W qk is a real square matrix, A is a real symmetric matrix, B is an antisymmetric matrix, and A=W qk +W qk T / 2, B = W qk -W qk T / 2; Based on the properties of real symmetric matrices and antisymmetric matrices, the following decomposition is performed: A = P·D·P T , B=U·C·U T , where P is an orthogonal matrix, D is a diagonal matrix, U is a reversible matrix, and C is a block diagonal matrix; Preprocessing unit: Process the input matrix X and the matrices P, D, U, and C obtained by the decomposition unit by rows and columns respectively, and input them into the calculation unit after staggered arrangement; Computing unit: Using resistive memory as the computing element, the matrix output by the preprocessing unit is multiplied and added to obtain the product matrix. The formula is Out = P'·D·P' T +U'·C·U' T , where P'=X·P, U'=X·U, Out is the attention score; Cache unit: temporarily stores the intermediate results calculated in the calculation unit in the cache unit; Self-attention mechanism unit: Using the hybrid softmax calculation array based on the in-memory logic of the resistive memory, the product matrix Out obtained by the calculation unit is normalized to obtain the data softmax [(P'·D·P' T +U'·C·U' T ) / dk 0.5 )], where dk is the dimension of the key-value matrix K, and the obtained data is softmax[(P'·D·P' T +U'·C·U' T ) / dk 0.5 )] with the input matrix X and the weight matrix W V Perform matrix multiplication to obtain the self-attention weight coefficient.
2. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 1, characterized in that: When the initial Transformer neural network performs self-attention calculation, the three network parameter weight matrices W are randomly initialized. Q , W K , W V , by multiplying the input matrix X after adding the position information, we can get the query matrix Q, key value matrix K, and value matrix V.
3. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 2, characterized in that: The self-attention calculation formula of the Transformer neural network is softmax(Q·K T / dk 0.5 )·V, where the attention score Out = Q·K T Expand to Q·K T =(X·W Q )·(X·W K ) T =X·(W Q ·W K T )X T ; Based on W Q ·W K T The product result W qk is a square matrix. According to the properties of the square matrix, W qk Decomposed into a real symmetric matrix A and an antisymmetric matrix B, and A = W qk +W qk T / 2, B = W qk -W qk T / 2; Based on the properties of the real symmetric matrix and the antisymmetric matrix, the decomposition result is obtained by using the orthogonal decomposition of the real symmetric matrix and the Schur decomposition of the antisymmetric matrix: A = P·D·P T , B=U·C·U T , and D and C are in the following form: D = diag(λ1,λ2,…,λ i ), λ i is the eigenvalue of the real symmetric matrix A, i∈{1,2,...,m}, m is the number of rows in the weight matrix; 4. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 1, characterized in that: After obtaining the orthogonal matrix P, the reversible matrix U, the diagonal matrix D and the block diagonal matrix C, the attention score Out is expressed as: Out = X·(W Q ·W K T )·X T =X·A·X T +X·B·X T =(X·P)·D·(X·P) T +(X·U)·C·(X·U) T ; Let P'=X·P, U'=X·U, the simplified formula is: Out=P’·D·P’ T +U’·C·U’ T 。 5. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 1, characterized in that: After obtaining the attention score, the hybrid softmax calculation array based on the in-memory logic of the resistive memory is used to obtain the data softmax [(P'·D·P' T +U'·C·U' T ) / dk 0.5 )], and then multiply it by the input matrix X and the weight matrix W V , the final output self-attention weight coefficient Z is obtained, expressed as: Z=softmax[(P'·D·P' T +U·C·U T ) / min 0.5 )]·X·W V 。 6. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 1, characterized in that: By utilizing the relevant properties of symmetric matrices, complex matrix-matrix operations can be simplified to matrix-vector multiplication and dot products between vectors.
7. The in-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm according to claim 1, characterized in that: The resistive memory is used in Transformer for matrix-vector and softmax operations.
Citation Information
Patent Citations
Analog computation matrix multiplication circuit and application thereof in DFT (Discrete Fourier Transform) / IDFT (Inverse Discrete Fourier Transform)
CN114282164A
RRAM in-memory computing system array structure optimization-oriented method
CN115879530A
Neural network accelerator for ReRAM
CN115965067A
In-memory architecture based on resistive random access memory and matrix decomposition acceleration algorithm
CN117371500A
Apparatus and method for matrix multiplication using processing-in-memory
US20220129519A1
Cited By
Acceleration method and accelerator for video generation model using 3D attention mechanism
CN120547415A
Transform model reasoning-based importance perception KV coverage method and system
CN121879685A
Method and system for evaluating energy attenuation of hydrogen-electricity system in extremely cold flight
CN122652364A
