Sequence processing method and device

By dividing sequence vectors into sub-sequences for parallel processing, and using multiple computer processing units to perform parallel attention calculations, the problem of high computational complexity of the self-attention mechanism in long sequence processing is solved, processing efficiency is improved and video memory utilization is optimized.

CN118312328BActive Publication Date: 2024-10-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410732729.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-06
Publication Date
2024-10-18
Estimated Expiration
2044-06-06

AI Technical Summary

Technical Problem

When the computer processing unit processes a long sequence, the time complexity of self-attention mechanism calculation is high, which affects the processing efficiency.

Method used

By dividing the sequence vector to be processed into multiple sub-sequence vectors and using multiple computer processing units to perform parallel attention calculations, the time complexity and memory usage of the self-attention mechanism are reduced, and processing efficiency is improved.

Benefits of technology

It effectively reduces the time complexity and memory usage when the computer processing unit processes long sequences, improves the processing efficiency of long sequences, and further optimizes memory utilization through gradient checkpoints and self-attention multiplexing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118312328B_ABST
    Figure CN118312328B_ABST
Patent Text Reader

Abstract

The present disclosure proposes a sequence processing method and device, which relates to the field of computers. The sequence processing method includes: dividing the sequence vector to be processed into multiple subsequence vectors of the same number according to the number of multiple computer processing units; multiple computer processing units perform the following processing on multiple subsequence vectors in parallel: the i-th computer processing unit obtains the i-th subsequence vector of the sequence vector at the attention layer, where i is a positive integer; the i-th computer processing unit determines the i-th query vector corresponding to the i-th subsequence vector at the attention layer; the i-th computer processing unit performs attention calculation based on the i-th query vector at the attention layer to obtain the i-th group of attention calculation results output by the attention layer. Thereby, the time complexity of the self-attention mechanism calculation when the computer processing unit processes long sequences is reduced, and the processing efficiency of the computer processing unit for long sequences is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computers, and in particular to a sequence processing method and a sequence processing device. Background Art

[0002] With the rapid development of artificial intelligence technology and computing power, the accelerated processing of long sequence data is becoming increasingly important in some specific fields, such as long text summarization, multi-round conversations, audio and video generation, etc.

[0003] Figure 1 FIG. 1 is a schematic diagram showing a related art serial parallel acceleration processing technology. Figure 1 In the sequence parallel processing process shown in the figure, the parallel degree of the transformer model (referred to as the model) is 2, for example. The original input sequence is equally divided into two subsequences, and the two subsequences are input to two computer processing units (referred to as processing units). Each computer processing unit independently calculates the hidden layer (such as regularization, residual connection, and random inactivation). When calculating the attention layer and the forward feedback network, the subsequences are aggregated into the original sequence for calculation. After the output is calculated, the subsequences are still re-divided for processing.

[0004] Assume that the length of the original sequence is SL, the number of attention heads is nh, the dimension of each attention head is d, and the dimension of the hidden layer is H = nh × d. The attention calculation process requires an inner product operation on each query vector (denoted as Query) and key vector (denoted as Key). The time complexity of the attention calculation is O(SL 2 ×H), the time complexity of the remaining calculations is O(SL×H 2 ). When SL>H, the time complexity of the attention layer will be higher than the time complexity of the calculation of other layers.

[0005] Since the time complexity of the self-attention mechanism calculation is proportional to the square of the sequence length, the longer the sequence length, the higher the time complexity of the self-attention mechanism calculation of the computer processing unit. This makes the time complexity of the self-attention mechanism calculation very high when the computer processing unit processes long sequences, affecting the processing efficiency of the computer processing unit for long sequences. And the forward feedback network layer Summary of the invention

[0006] One of the technical problems to be solved by the embodiments of the present disclosure is that the time complexity of the self-attention mechanism calculation when the computer processing unit processes long sequences is high, which affects the processing efficiency of the computer processing unit for the long sequences.

[0007] The disclosed embodiment divides the sequence vector to be processed into multiple sub-sequence vectors of the same number according to the number of multiple computer processing units, and then reduces the time complexity of the self-attention mechanism calculation when the computer processing unit processes a long sequence through query vector block division and parallel attention calculation of multiple computer processing units based on the multi-block query vectors, thereby improving the processing efficiency of the computer processing unit for the long sequence.

[0008] Some embodiments of the present disclosure propose a sequence processing method, including: dividing a sequence vector to be processed into a plurality of sub-sequence vectors of the same number according to the number of multiple computer processing units; the multiple computer processing units perform the following processing on the multiple sub-sequence vectors in parallel: the i-th computer processing unit obtains the i-th sub-sequence vector of the sequence vector at the attention layer, where i is a positive integer; the i-th computer processing unit determines the i-th query vector corresponding to the i-th sub-sequence vector at the attention layer; the i-th computer processing unit performs attention calculation at the attention layer based on the i-th query vector to obtain the i-th group of attention calculation results output by the attention layer.

[0009] In some embodiments, the sequence processing method also includes: the i-th computer processing unit aggregates multiple sub-sequence vectors at the attention layer to obtain a sequence vector; the i-th computer processing unit determines the key vector and value vector corresponding to the sequence vector at the attention layer; wherein the i-th computer processing unit performs attention calculation based on the i-th query vector at the attention layer, and the i-th group of attention calculation results output by the attention layer includes: the i-th computer processing unit performs attention calculation based on the i-th query vector, the key vector and value vector corresponding to the sequence vector at the attention layer, and obtains the i-th group of attention calculation results output by the attention layer.

[0010] In some embodiments, the sequence processing method also includes: when a causal model is being processed, a first computer processing unit that processes the first half of the sub-sequence vector obtains a query vector corresponding to the sub-sequence vector processed by the second computer processing unit from a second computer processing unit that processes the second half of the sub-sequence vector, and helps the second computer processing unit perform partial attention calculations based on the obtained query vector.

[0011] In some embodiments, the first computer processing unit assisting the second computer processing unit in performing partial attention calculation includes: when P is odd and i < [P / 2]', or when P is even and i ≤ [P / 2]': the i-th computer processing unit of the first computer processing unit obtains the (P - i)-th query vector from the (P - i)-th computer processing unit of the second computer processing unit, and assists the (P - i)-th computer processing unit in performing partial attention calculation based on the (P - i)-th query vector, where i ∈ [1, …, P], P represents the number of multiple computer processing units, and [ ]' represents rounding up.

[0012] In some embodiments, the i-th computer processing unit performing attention calculation based on the i-th query vector in the attention layer includes: the i-th computer processing unit determines the j-th key vector corresponding to the j-th subsequence vector in the attention layer, where 0 < j ≤ i, and performs attention calculation based on the i-th query vector and each j-th key vector to obtain the i-th set of attention calculation results output by the attention layer; the i-th computer processing unit assisting the (P - i)-th computer processing unit in performing partial attention calculation based on the (P - i)-th query vector includes: the i-th computer processing unit assists the (P - i)-th computer processing unit in performing [P / 2]' - i attention calculations.

[0013] In some embodiments, the i-th computer processing unit assisting the (P - i)-th computer processing unit in performing [P / 2]' - i attention calculations based on the (P - i)-th query vector includes: the i-th computer processing unit assists the (P - i)-th computer processing unit in performing attention calculation between the (P - i)-th query vector and the ([P / 2]' - i)-th key vector to the 1st key vector.

[0014] In some embodiments, the sequence processing method further includes: while the i-th computer processing unit and the (P - i)-th computer processing unit are performing attention calculation, they asynchronously and parallelly communicate the (P - i)-th query vector and the attention calculation results of the assistance calculation.

[0015] In some embodiments, each computer processing unit maintains parallel computing streams and communication streams, and the i-th computer processing unit and the Pi-th computer processing unit asynchronously and parallelly communicate the Pi-th query vector and the attention calculation result of the assisted calculation while performing attention calculation, including: while the computing stream of the i-th computer processing unit performs attention calculation based on the i-th query vector, the communication stream of the i-th computer processing unit communicates with the communication stream of the Pi-th computer processing unit, so that the i-th computer processing unit obtains the Pi-th query vector from the Pi-th computer processing unit; each time the computing stream of the i-th computer processing unit helps the Pi-th computer processing unit calculate an attention calculation result, while helping to calculate the next attention calculation result, the communication stream of the i-th computer processing unit communicates with the communication stream of the Pi-th computer processing unit, so that the Pi-th computer processing unit obtains the previous attention calculation result of the assisted calculation from the i-th computer processing unit.

[0016] In some embodiments, the sequence processing method further includes: a plurality of computer processing units performing parallel processing of a plurality of sub-sequence vectors in layers other than the attention layer, wherein the other layers include a feedforward network layer.

[0017] In some embodiments, the sequence processing method further includes: saving the forward output of the attention layer to the video memory by setting a gradient checkpoint in the attention layer; and calculating the forward output and gradient of other layers except the attention layer using the saved forward output of the attention layer.

[0018] In some embodiments, the sequence vector includes: an audio sequence vector, a video sequence vector, or a text sequence vector.

[0019] In some embodiments, the computer processing unit includes a graphics processing unit.

[0020] Some embodiments of the present disclosure provide a sequence processing device, comprising: a plurality of computer processing units configured to collaboratively execute a sequence processing method.

[0021] In some embodiments, the sequence processing device further includes: a video memory for storing data generated during the execution of the sequence processing method.

[0022] Some embodiments of the present disclosure provide a computer-readable storage medium having a computer program stored thereon, which implements the steps of the sequence processing method when the computer program is executed by a computer processing unit.

[0023] Some embodiments of the present disclosure provide a computer program product, including a computer program, which implements the steps of the sequence processing method when executed by a computer processing unit. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The following is a brief introduction to the drawings required for use in the embodiments or related technical descriptions. The present disclosure can be more clearly understood according to the following detailed description with reference to the drawings.

[0025] Obviously, the drawings described below are only some embodiments of the present disclosure, and a person skilled in the art can obtain other drawings based on these drawings without creative work.

[0026] Figure 1 A schematic diagram of a related serial parallel acceleration processing technology is shown.

[0027] Figure 2 A schematic diagram showing the main architecture of the transformer model.

[0028] Figure 3 A schematic diagram showing a sequence processing method based on sequence parallelism according to some embodiments of the present disclosure.

[0029] Figure 4 A schematic diagram showing attention reuse and activation value recalculation based on gradient checkpoints according to some embodiments of the present disclosure.

[0030] Figure 5 Schematic diagram of the sequentially parallel attention mechanism for a causal model with unbalanced computational load.

[0031] Figure 6 A schematic diagram showing a sequential parallel attention mechanism for a causal model with computational load balancing according to some embodiments of the present disclosure.

[0032] Figure 7 A schematic diagram showing a computing load balancing method that introduces data pre-fetching and overlapping communication according to some embodiments of the present disclosure.

[0033] Figure 8 A schematic diagram showing the structure of a sequence processing device according to some embodiments of the present disclosure. DETAILED DESCRIPTION

[0034] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0035] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.

[0036] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.

[0037] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.

[0038] In addition, the term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present disclosure generally indicates that the associated objects before and after are in an "or" relationship.

[0039] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.

[0040] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0041] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.

[0042] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.

[0043] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0044] In addition, in order to avoid obscuring the present disclosure due to unnecessary details, only the processing steps and / or device structures closely related to at least the scheme according to the present disclosure are shown in the drawings, and other details that are not closely related to the present disclosure are omitted. It should also be noted that similar reference numerals and letters in the drawings indicate similar items, and therefore once an item is defined in one drawing, it does not need to be discussed again for subsequent drawings.

[0045] Some terms involved in the embodiments of the present disclosure are described below.

[0046] LLM (Large Language Model): is an artificial intelligence model designed to understand and generate human language. They are trained on large amounts of text data and can perform a wide range of tasks, including text summarization, translation, sentiment analysis, etc. LLMs are characterized by their large size and contain billions of parameters.

[0047] Computer processing units (referred to as processing units) include, for example, graphics processing units (GPUs), central processing units (CPUs), etc. Among them, GPUs are programmable computer processing units that can be used for graphics operations and outputs. Due to their computational parallelism, they can be applied to the training of deep learning models or other models, and they have better performance in computational parallelism.

[0048] Transformer is a deep learning model for natural language processing and sequence-to-sequence tasks. It can be used as a semantic feature extraction module for large language models and is easy to learn long-distance correlation semantic features. Multiple layers of Transformer can be set in large language models.

[0049] Gather, also known as All gather, is a collective operation that collects the local data of each process into a global data structure.

[0050] Scatter is a collective operation that scatters a global data structure into the local data of each process.

[0051] SoftMax is a mathematical function used for normalization to convert a set of numerical values ​​into a probability distribution. It maps the input vector to a probability distribution so that all probability values ​​are between 0 and 1 and the sum is 1.

[0052] Normalization is a feature scaling technique used to modify the input data of a layer in a neural network. It calculates the mean and standard deviation of all features of each sample and uses these statistics to normalize each feature, ensuring that the input distribution of each layer remains consistent. This helps speed up the training process and improve model performance. Layer normalization is mainly to solve the problem of internal covariate shift and make model training more stable and faster.

[0053] Regularization is a technique used to prevent model overfitting. It constrains the complexity of the model by adding an additional term (such as L1 or L2 penalty term) to the loss function. This prevents the model from overfitting on the training data, thereby improving the model's generalization ability on unseen data. Common regularization techniques include L1 regularization, L2 regularization, Dropout (random inactivation) and early stopping. Dropout randomly sets the output of some neurons to zero, which prevents the neural network from over-relying on certain specific neurons and enhances the generalization ability of the network.

[0054] Residual connection is a technology that solves the problem of gradient vanishing and accelerates convergence. It accumulates the input of one layer of the neural network to the output of one layer, allowing information from the lower layer to be directly transmitted to the higher layer, avoiding model degradation.

[0055] Embedding: In the field of natural language processing, Embedding is often used to map words or phrases to fixed-length vector representations in the vector space.

[0056] Token: A word unit is the smallest semantic unit. In a large language model, it refers to the smallest unit of text. Usually, a token can be a word, a punctuation mark, a number, a symbol, etc., depending on the specific model and task. For example, in English, a common tokenization method is to split the text according to spaces and punctuation marks to generate word-level tokens. In Chinese, a word segmentation tool can be used to split the text into word-level tokens.

[0057] Compute Unified Device Architecture (CUDA) is a general-purpose parallel computing architecture. CUDA Stream is used to manage and schedule parallel computing tasks. It provides a way to divide computing tasks into multiple parallel streams so that multiple tasks can be executed simultaneously on the GPU, thereby improving computing performance.

[0058] With the rapid development of artificial intelligence technology and computing power, long sequence training is becoming increasingly important in some specific fields, such as long text summarization, multi-round dialogue, audio and video generation, etc. On the one hand, through long sequence model training, the model can better capture longer contextual information, so as to better understand the semantics and structure of the entire sequence. This is very important for processing complex natural language tasks and speech recognition tasks. On the other hand, by training long sequence models, richer feature representations can be extracted, which can be used for transfer learning of other tasks, thereby improving the performance of the model on different tasks.

[0059] Currently, most training acceleration and video memory reduction technologies focus on data parallelism, tensor parallelism, and pipeline parallelism. Among them, data parallelism is used to solve the problem of large batch data. The input batch data is split and processed in parallel. When the batch data is large, it can improve the training speed and reduce the use of video memory. Tensor parallelism and pipeline parallelism are used to solve the problem of large model scale. The model is split and processed in parallel according to certain rules. When the model scale is large, it can improve the training speed and reduce the use of video memory. The above three methods cannot solve the acceleration needs of long sequence models when the length of a single data sample is very large.

[0060] Sequence parallelism improves the efficiency of training and reasoning by dividing a sequence data into multiple subsequences and assigning these subsequences to different computing devices for parallel processing. Each device is responsible for processing a subsequence and synchronizing the hidden state at the time step to capture the temporal dependency. Sequence parallelism can reduce the overall computing time and memory consumption, but it requires dealing with boundary issues and adapting the model structure.

[0061] A large language model is, for example, a multi-layer transformer structure. Figure 2 The figure shows the main structure of the transformer model (model for short), which mainly includes two important structures: attention layer and feedforward network layer. The attention layer is, for example, a self-attention layer and a multi-head attention layer. The feedforward network layer can also be called a feedforward network. There are regularization layers and dropout layers between the attention layer and the feedforward network layer to prevent overfitting. Among them, the residual represents the residual connection, which is used to realize cross-layer connection.

[0062] The self-attention layer first transforms the input vector linearly to obtain three vectors: Q (query vector), K (key vector), and V (value vector). The inner product of the matrix multiplication of Q and K is calculated to obtain the similarity score between each sequence element and other elements. To maintain numerical stability, the result is scaled by a scaling factor of (d k ) 1 / 2 , where d k Represents the dimension size of the key vector K. Finally, the similarity score is normalized by the SoftMax function to obtain the attention weight, and the attention weight is weighted and summed with the vector V to obtain the final attention output (Output). In addition, T represents transposition. The calculation method of the self-attention layer is as follows:

[0063] Output = SoftMax(QK T / (d k ) 1 / 2 )V.

[0064] The multi-head attention layer captures different features by setting multiple self-attentions, and finally concatenates the outputs of multiple self-attentions into a vector.

[0065] The role of the feedforward network layer is to introduce nonlinear transformations to enhance the model's ability to model input features, which is achieved through multiple fully connected layers (linear layers) and nonlinear activation functions.

[0066] Assume that the length of the original sequence is SL, the number of attention heads is nh, the dimension of each attention head is d, and the dimension of the hidden layer is H = nh × d. The attention calculation process requires an inner product operation on each query vector (denoted as Query) and key vector (denoted as Key), and the time complexity is O(SL 2 ×H), the time complexity of the remaining calculations is O(SL×H 2 ), when SL>H, the time complexity of the attention layer will be higher than the time complexity of the calculation of other layers.

[0067] See also Figure 1 The sequence parallel technology uses the attention layer to process a sequence with a length of SL, which is the length of the entire sequence. Since the time complexity of the self-attention mechanism calculation is proportional to the square of the sequence length, the time complexity of the self-attention mechanism calculation is very high when processing long sequences.

[0068] See also Figure 1 The serial parallel technology requires two aggregation operations and two dispersion operations in a single transformer structure. When the degree of parallelism is 2, a total of four forward communications and four reverse communications are involved. The greater the degree of parallelism, the greater the number of communications between computer processing units, and the higher the communication load. This will introduce unbearable training delays in large models containing dozens of transformer layers.

[0069] During model training, forward propagation calculates the output results through training data and weight parameters; back propagation calculates the gradient of the loss function to each parameter through the derivative chain rule, and updates the parameters according to the gradient. In the back propagation of some model training, all intermediate results need to be saved. In the back propagation of other model training, the use of gradient checkpoint technology can release the forward output of some intermediate nodes in the back propagation, and only save the forward output of some intermediate nodes, thereby reducing the memory usage. When the gradient of a node needs to be calculated, the required gradient can be obtained by recalculating the forward output of the previously discarded node. The gradient checkpoint technology currently adds gradient checkpoints between transformer structures, which requires recalculating the results of the entire self-attention layer each time. The time complexity of the calculation of the self-attention layer is quadratic to the length of the sequence. In long sequence scenarios, this part of the overhead is relatively large and cannot be ignored.

[0070] In response to the problems existing in the related sequence parallel technology pointed out above, corresponding solutions are proposed one by one below.

[0071] The disclosed embodiment proposes an efficient sequence parallel technology, which can be used for training long sequence large language models, etc., to avoid redundant storage and improve the utilization of video memory. The technical solution includes the following technical points, for example.

[0072] Sequence-parallel attention layer and forward feedback network layer: The query vector Q is divided into blocks and processed in parallel at the sequence level. The key vector K and value vector V are reused through communication, and only one aggregation operation is required. The attention score of the block can be obtained by calculating the attention of the block Q vector and the aggregated K and V vectors. The block attention score can be passed to the forward feedback network layer in sequence parallel for calculation.

[0073] Self-attention reuse and recomputation: In long sequence scenarios, the computational overhead of the attention layer is higher than that of other modules. Therefore, by storing the output tensor of the self-attention layer, we can effectively balance the trade-off between video memory and training efficiency. Setting the gradient checkpoint after the output of the attention layer can greatly reduce the use of video memory, smooth the video memory peak, and ensure efficient recomputation efficiency.

[0074] End-to-end computing load balancing: In view of the special lower triangle attention calculation mechanism of the causal large language model, end-to-end communication and communication and computing overlap technology are used to balance the computing load of different nodes, which greatly reduces the computing overhead of high-load nodes and improves the resource utilization of low-load nodes.

[0075] The disclosed embodiment takes the main structure of Transformer as an example to introduce a proposed sequence processing method based on sequence parallelism, which can be used for accelerated training and video memory optimization of long sequence and large language models.

[0076] Figure 3 A schematic diagram of a sequence processing method based on sequence parallelism in some embodiments of the present disclosure is shown. Figure 3 Only two computer processing units for parallel processing are shown as examples. It is understandable that there may be more computer processing units for parallel processing, and the model may be a transformer model, for example. For the convenience of description, the following embodiments use GPU to represent a computer processing unit (referred to as a processing unit).

[0077] According to the number of multiple computer processing units, the sequence vector to be processed is divided into multiple sub-sequence vectors of the same number; multiple computer processing units process multiple sub-sequence vectors in parallel. Wherein, the sequence vector includes, but is not limited to, long sequence vectors such as audio sequence vectors, video sequence vectors, or text sequence vectors. For example, in application scenarios such as article summaries, machine translation, and question-answering systems, the sequence vector to be processed is, for example, a long text sequence vector; in application scenarios such as audio / video generation, the sequence vector to be processed is, for example, an audio sequence vector or a video sequence vector.

[0078] Combine the following Figure 3 Describe the sequence-parallel attention mechanism.

[0079] Multiple computer processing units perform attention calculations in parallel on multiple sub-sequence vectors obtained by dividing a sequence vector at the attention layer, and each computer processing unit processes a corresponding sub-sequence vector.

[0080] Taking any ith computer processing unit as an example, i is a positive integer, the ith computer processing unit obtains the ith subsequence vector of the sequence vector at the attention layer; the ith computer processing unit determines the ith query vector corresponding to the ith subsequence vector at the attention layer; the ith computer processing unit performs attention calculation based on the ith query vector at the attention layer, and obtains the ith group of attention calculation results output by the attention layer. Thus, the query vector is divided into blocks and parallelized at the sequence level, which reduces the time complexity and video memory occupancy of the self-attention mechanism calculation when the computer processing unit processes long sequences, and improves the processing efficiency of the computer processing unit for long sequences.

[0081] The i-th computer processing unit aggregates multiple subsequence vectors in the attention layer to obtain a sequence vector; the i-th computer processing unit determines the key vector and value vector corresponding to the sequence vector in the attention layer; the i-th computer processing unit performs attention calculation based on the i-th query vector, the key vector and value vector corresponding to the sequence vector in the attention layer, and obtains the i-th group of attention calculation results output by the attention layer. Thus, the attention score of the block can be obtained by performing attention calculation based on the block Q vector and the aggregated K and V vectors. The block attention score can be transmitted to the forward feedback network layer in sequence and parallel for calculation, reducing the time complexity and video memory occupancy of the computer processing unit calculation, and reducing the number of communications between computer processing units.

[0082] Assume that the vector of the model input sequence is represented by X, and the sequence parallelism is P, that is, there are P computer processing units (such as GPUs) participating in parallel computing. If it is in the model training scenario, there are P training devices (such as GPUs) participating in the training. i represents the i-th subsequence vector, i∈[1,…,P]. As mentioned above, the calculation formula of the attention mechanism is: Output=SoftMax(QK T / (d k ) 1 / 2 )V, the explanation of each symbol is as mentioned above, and will not be repeated here. According to the divisible block calculation characteristics of matrix multiplication, the calculation formula can be expressed as follows:

[0083] Output = [SoftMax(Q1K T / (d k ) 1 / 2 )V,

[0084] SoftMax(Q2K T / (d k ) 1 / 2 )V,…,

[0085] SoftMax(Q P K T / (d k ) 1 / 2 )V].

[0086] This formula shows that the calculation of the attention layer can transform the Q vector into a parallel sequence dimension. Each GPU independently calculates the vector Q i , then Q i The attention score is calculated with the complete K and V vectors. That is, for GPUi, first the input subsequence x i Perform a linear transformation to obtain the query vector Q i In order to obtain complete K and V vectors and reduce the amount of communication between computer processing units, for each subsequence xi Aggregation is performed to obtain a complete sequence vector X, and each GPU independently performs linear transformation on the sequence vector X to obtain complete K and V vectors. Each GPUi can calculate SoftMax (Q i K T / (d k ) 1 / 2 )V, the computational cost and storage cost of the attention mechanism of a single GPU are reduced to 1 / P. That is, the computational cost and storage cost of the attention mechanism of a single GPU are SL 2 , now SL 2 / P.

[0087] Combine the following Figure 3 Describes a sequentially parallel feedforward network.

[0088] Multiple computer processing units perform parallel processing of multiple subsequence vectors in other layers except the attention layer, and the other layers include the forward feedback network layer and the regularization layer, residual connection, Dropout, normalization layer, etc. Thus, the calculation and video memory occupation of the forward feedback network are reduced, and the communication between computer processing units in the forward feedback network is reduced.

[0089] In addition to the self-attention mechanism, other computational steps when processing sequence data, such as regularization layers, residual connections, Dropout, activation layers, linear layers, normalization layers, etc., have no dependencies in the sequence dimension, so they can be independently calculated and distributed among multiple GPUs. This means that each GPU can independently process different parts of the sequence without relying on the calculation results of other GPUs. The components of the feedforward network can all be parallelized in the sequence dimension, and the output results of the feedforward network can be used as the input of the next transformer, which can also be parallelized in the sequence dimension. Therefore, if the feedforward network is calculated in sequence parallel based on two GPUs, the calculation and video memory usage of the feedforward network can be reduced by half, and the two communications between computer processing units in the feedforward network can be reduced.

[0090] Combine the following Figure 4 Describes the setup of gradient checkpoints, as well as attention reuse and activation recalculation based on gradient checkpoints. Figure 4 A schematic diagram of attention reuse and activation value recalculation based on gradient checkpoints in some embodiments of the present disclosure is shown, wherein the dots represent gradient checkpoints, the arrows between the forward propagation branch and the backward propagation branch represent activation value recalculation, and the model is, for example, a transformer model.

[0091] During the training process of large models, in addition to the model parameters and input data that need to be stored in the video memory, the intermediate activation values during the training process also need to be stored in the video memory, and this part often occupies a very large amount of video memory space. As mentioned above, some gradient checkpointing techniques add gradient checkpoints at the end of each layer of the transformer, that is, save the forward output of the forward feedback network in the video memory and discard the intermediate activation values of other layers. In the training of large models with long sequences, the computational cost of the attention layer will be much greater than that of the forward feedback network. Therefore, by reusing the forward output of the self-attention layer and discarding other intermediate activation values, the video memory can be reduced while reducing the overhead of recomputation.

[0092] As Figure 4 shown, in the embodiments of the present disclosure, gradient checkpoints are set in the attention layer; during forward propagation, the forward output (such as activation values, etc.) of the attention layer is saved to the video memory through the gradient checkpoints set in the attention layer, so as to reuse the forward output of the attention layer and discard the forward output of other layers; during backpropagation, when the forward output of other layers is needed, the forward output of the attention layer is reused as the starting point, and the saved forward output of the attention layer is used to recalculate the forward output of other layers, and then the gradients of other layers are recalculated based on the forward output of other layers. Using the saved forward output of the attention layer, the gradient of the attention layer can be calculated. The calculation of the gradient can refer to related technologies and will not be elaborated here.

[0093] Recalling again Figure 3 the relevant description, according to the attention mechanism of sequence parallelism, each GPU needs to calculate the attention scores of the query vectors of the blocks and the complete K and V vectors. However, in a causal large language model (abbreviated as a causal model), each input token only focuses on the information of the tokens in the previous positions when calculating the attention scores, and does not need to calculate the entire attention scores. Therefore, using the attention mechanism of sequence parallelism in a causal model will cause a large amount of idle time for multiple GPUs. Figure 5 FIG. shows a schematic diagram of the sequence parallel attention mechanism of a causal model with unbalanced computational load. Figure 5 FIG. shows a computational topology diagram of the attention scores with, for example, 9 GPUs. Using the symbol i ∈ [1, …, 9] to represent the i-th GPU, Q i represents the query vector of the i-th GPU, that is, the i-th query vector corresponding to the i-th subsequence vector. In a causal large model, the i-th GPU only needs to calculate Q i K j T , where 0 < j ≤ i. Therefore, the higher the serial number of the GPU, the higher the computational cost required. Figure 5 For the sake of simplicity and highlighting the key points, using Q i K j to simplify and represent the inner product Q of the twoi K j T , Q is not explicitly shown i K j T The transposed symbol T in the calculation is the same as in other embodiments, but it should be understood that in the self-attention mechanism, the label Q i K j Representative Q i K j T Operation. Figure 5 As shown, GPU9 needs to calculate Q9K1 to Q9K9, GPU1 only needs to calculate Q1K1. The data dimension that GPU9 needs to calculate is 9 times that of GPU1, and GPU1 has to calculate Q1K1 after calculating Q1K1. T There will be 8 time steps of idle time after that.

[0094] In order to solve the above-mentioned GPU idle problem, this embodiment distributes the total computing load to different GPU nodes through computing load balancing between GPUs, reduces the computing of high-load nodes, and improves the resource utilization of idle nodes.

[0095] Figure 6 A schematic diagram of a sequential parallel attention mechanism for a causal model with computational load balancing in some embodiments of the present disclosure is shown. Figure 6 Describe the technical solution of sequential parallel attention mechanism for causal models with computational load balancing.

[0096] In the case of processing a causal model, the first computer processing unit processing the first half of the subsequence vector has idle time relative to the second computer processing unit processing the second half of the subsequence vector. The first computer processing unit can obtain the query vector corresponding to the subsequence vector processed by the second computer processing unit from the second computer processing unit, and help the second computer processing unit perform partial attention calculation based on the obtained query vector. This reduces the calculation of high-load nodes and improves the resource utilization of idle nodes.

[0097] The computer processing unit pair for calculating load balancing (the first computer processing unit and the second computer processing unit) can be determined, for example, by the following method. When P is odd and i < [P / 2]', or when P is even and i ≤ [P / 2]': The i-th computer processing unit as the first computer processing unit obtains the (P - i)-th query vector from the (P - i)-th computer processing unit as the second computer processing unit, and based on the (P - i)-th query vector, helps the (P - i)-th computer processing unit perform partial attention calculation, where i ∈ [1, …, P], P represents the number of multiple computer processing units, and [ ]' represents rounding up. Thus, the computer processing unit with the most idle time and the computer processing unit with the highest computing load form a computer processing unit pair for calculating load balancing, the computer processing unit with the second most idle time and the computer processing unit with the second highest computing load form a computer processing unit pair for calculating load balancing, and so on, further improving the overall computing load balancing.

[0098] After determining the computer processing unit pair for calculating load balancing, the number of attention calculations that the computer processing unit with more idle time helps the computer processing unit with higher computing load perform can be determined by the following method. The i-th computer processing unit determines the j-th key vector corresponding to the j-th subsequence vector in the attention layer, where 0 < j ≤ i, performs attention calculation based on the i-th query vector and each j-th key vector, and obtains the i-th group of attention calculation results output by the attention layer; the i-th computer processing unit helps the (P - i)-th computer processing unit perform [P / 2]' - i attention calculations based on the (P - i)-th query vector. Thus, the number of attention calculations performed by each computer processing unit is basically the same or very close, further improving the overall computing load balancing.

[0099] After determining the number of attention calculations for helping with the calculation, the following method can be used to determine which attention calculation to help with. The i-th computer processing unit helps the (P - i)-th computer processing unit perform attention calculation of the (P - i)-th query vector with the ([P / 2]' - i)-th key vector to the 1st key vector. Thus, the computer processing unit for helping with the calculation can reuse the key vectors that have been determined during local attention calculation to the greatest extent, and the number of key vectors to be determined is the least, reducing the calculation amount.

[0100] As Figure 6As shown, after GPU1 calculates the attention score of Q1 of its own subsequence, it can obtain Q9 from GPU9 through point-to-point communication, and then calculate Q9K1, Q9K2, Q9K3, and Q9K4 in sequence. Similarly, after GPU2 calculates the attention score of Q2 of its own subsequence, it can obtain Q8 from GPU8 through point-to-point communication, and then calculate Q8K1, Q8K2, and Q8K3 in sequence. After GPU3 calculates the attention score of Q3 of its own subsequence, it can obtain Q7 from GPU7 through point-to-point communication, and then calculate Q7K1 and Q7K2 in sequence. After GPU 4 calculates the attention score of Q4 of its own subsequence, it can obtain Q6 from GPU6 through point-to-point communication, and then calculate Q4K1 in sequence. At this time, GPU1 to GPU9 only need to calculate the attention scores of 5 blocks, which nearly doubles the computing efficiency compared to the initial sequence parallel strategy. Assuming that the sequence length is SL, the time complexity of the attention calculation is SL 2 / P down to SL 2 / 2P. The above computational load balancing method needs to introduce point-to-point communication, and the communication overhead can be hidden by means of data pre-fetching, overlapping communication, etc. or a combination thereof. Figure 7 A schematic diagram showing a computing load balancing method that introduces data pre-fetching and overlapping communication according to some embodiments of the present disclosure.

[0101] The data pre-fetching method includes: the computer processing unit that assists the calculation obtains the corresponding query vector from the computer processing unit being assisted in advance while performing the local attention calculation; the computer processing unit being assisted obtains the attention calculation results of the assisting calculation from the computer processing unit that assists the calculation in advance while performing the local attention calculation. That is, while the i-th computer processing unit performs the attention calculation based on the i-th query vector, the i-th computer processing unit obtains the Pi-th query vector from the Pi-th computer processing unit; each time the i-th computer processing unit assists the Pi-th computer processing unit in calculating an attention calculation result, while assisting in calculating the next attention calculation result, the Pi-th computer processing unit obtains the previous attention calculation result of the assisting calculation from the i-th computer processing unit. Thus, the communication overhead is hidden.

[0102] The overlapping communication method includes: the computer processing unit assisting the calculation and the computer processing unit being assisted perform asynchronous and parallel communication of the query vector and the attention calculation result of the assisting calculation while performing the attention calculation. That is, the i-th computer processing unit and the Pi-th computer processing unit perform asynchronous and parallel communication of the Pi-th query vector and the attention calculation result of the assisting calculation while performing the attention calculation. Thus, the communication overhead is hidden.

[0103] Each computer processing unit maintains two parallel streams, named as a computing stream and a communication stream, so as to jointly execute a data pre-fetching method and an overlapping communication method, and further hide the communication overhead. While the computing stream of the i-th computer processing unit performs attention calculation based on the i-th query vector, the communication stream of the i-th computer processing unit communicates with the communication stream of the Pi-th computer processing unit, so that the i-th computer processing unit obtains the Pi-th query vector from the Pi-th computer processing unit; the computing stream of the i-th computer processing unit helps the Pi-th computer processing unit calculate an attention calculation result each time, and while helping to calculate the next attention calculation result, the communication stream of the i-th computer processing unit communicates with the communication stream of the Pi-th computer processing unit, so that the Pi-th computer processing unit obtains the previous attention calculation result that it helped calculate from the i-th computer processing unit.

[0104] by Figure 7 For example, GPU1 pre-acquires the query vector Q9 from GPU9 while completing the calculation of Q1K1. In the subsequent time step, GPU9 and GPU1 synchronously calculate the attention scores of the blocks, and GPU9 pre-acquires the attention scores calculated with the help of GPU1 from GPU1 in turn. Since the local attention calculations of GPU1 and GPU9 are independent of the data to be pre-fetched, the attention calculation can be performed by one stream (computation stream) and the point-to-point communication can be performed by another stream (communication stream), thereby completing asynchronous parallel communication and calculation and hiding the communication overhead. These two streams can be two CUDA streams, for example. That is, each GPU maintains two CUDA streams, one for calculation and one for communication.

[0105] For any GPUi, the calculation of the attention mechanism for introducing data pre-fetching and overlapping communication includes the following steps. In order to facilitate the control of the calculation order between GPUs, this embodiment is described by using a reverse calculation method, that is, for any GPUi, Q is calculated first. i K i , and finally calculate Q i K1. Understandably, the forward order calculation method can also be used, that is, Q is calculated first for any GPUi i K1, finally calculate Q i K i .

[0106] (1) If GPUi is a GPU in the first half, that is, when P is an odd number and i<[P / 2]', or when P is an even number and i≤[P / 2]', GPUi may perform the following steps.

[0107] (1-1) GPUi’s computational flow independently computes Q i K i, while the communication stream prefetches Q from GPU (P-i). P-i , a total of one time step is required. For example, as Figure 7 shown (P = 9, i = 1), GPU1 independently calculates Q1K 1 , and prefetches Q9 from GPU9 at the same time.

[0108] (1-2) GPUi independently calculates Q i K i to Q i K1 for local attention calculation, which requires i time steps in total. As Figure 7 shown (P = 9, i = 1), GPU1 has calculated Q1K1, and this process requires 1 time step.

[0109] (1-3) GPUi uses idle time to help GPU (P-i) independently calculate Q P-i K [P / 2]’-i to Q P-i K1, which requires [P / 2]'-i time steps in total. The total calculation time requires [P / 2]' time steps. As Figure 7 shown (P = 9, i = 1), GPU1 helps GPU9 independently calculate Q9K4 to Q9K1, and this process requires 4 time steps. Adding the 1 time step for local attention calculation, the total number of time steps is 5.

[0110] (2) If GPUi is the GPU in the second half, that is, when P is odd and [P / 2]' ≤ i ≤ P, or when P is even and [P / 2]' < i ≤ P, GPUi can perform the following steps.

[0111] (2-1) GPUi independently calculates Q i K i to Q i K i-[P / 2], of the process, which requires [P / 2],+1 time steps in total, where [ ] represents rounding down. As Figure 7 shown (P = 9, i = 9), GPU9 independently calculates Q9K9 to Q9K5, which requires 5 time steps in total.

[0112] (2-2) When calculating to Q i K 2i-P , GPU (P+1-i) has already calculated the score of its own attention and then helps GPUi calculate Q i K i-[P / 2],-1 . As Figure 7 shown (P = 9, i = 9), when GPU9 calculates Q9K8, GPU1 has already calculated the score of its own attention and helps GPU9 calculate Q9K4.

[0113] (2-3) In calculating Q i K 2i-P Afterwards, GPUi pre-acquires Q from GPU(P+1-i) through the communication flow i K i-[P / 2],-1 . At each subsequent time step, an attention score can be pre-fetched from GPU (P+1-i), which requires i-[P / 2],-1 time steps in total. Since pre-fetching starts from (P-i+3), the communication flow completes pre-fetching at the [P / 2]'+1 time step. Figure 7 As shown in (P=9, i=9), GPU9 starts prefetching data from GPU1 at the third time step. The prefetching requires a total of four time steps, so the total end time is the sixth time step.

[0114] The disclosed embodiment uses a sequence parallel solution to accelerate the training / inference of large models with long sequences and reduce the memory usage of large models with long sequences. The time complexity of sequence parallel computing and the amount of communication between computer processing units are reduced through the sequence parallel attention mechanism and the forward feedback network, thereby improving the processing efficiency of computer processing units for long sequences. Then, the memory usage is further reduced through self-attention reuse and recalculation to balance the memory peak. Finally, for the causal large language model, the computational load is reduced through an end-to-end computational load balancing method, the utilization rate of idle processing units is improved, and the overall processing efficiency of multiple processing units is improved.

[0115] Figure 8 Schematic diagram of the structure of the sequence processing device of some embodiments of the present disclosure is shown. Figure 8 As shown, the sequence processing device 800 of this embodiment includes: a plurality of computer processing units 810, which are configured to collaboratively execute the sequence processing methods of various embodiments, such as Figure 3-7 The sequence processing method described in the embodiment will not be described in detail here. The computer processing unit 810 includes, for example, a graphics processing unit, a central processing unit, and the like.

[0116] The sequence processing device 800 further includes: a video memory 820 for storing data generated during the execution of the sequence processing method, such as output tensors of the attention layer, model parameters, and input data, etc. There may also be multiple video memories 820.

[0117] The computer processing unit 810 and the video memory 820 may be connected, for example, via a bus 830. The bus 830 may use any of a variety of bus structures. For example, the bus structure includes, but is not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, and a Peripheral Component Interconnect (PCI) bus.

[0118] Some embodiments of the present disclosure provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a computer processing unit, the steps of the sequence processing method of each embodiment are implemented.

[0119] Some embodiments of the present disclosure provide a computer program product, including a computer program, which implements the steps of the sequence processing method of each embodiment when executed by a computer processing unit.

[0120] In the technical solution disclosed in this disclosure, the collection, collection, update, analysis, processing, use, transmission, storage and other aspects of user personal information involved are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.

[0121] It should be understood by those skilled in the art that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present disclosure may take the form of a computer program product implemented on one or more (non-transient) computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, cloud storage, etc.) containing computer program code. A computer program product should be understood as a software product that implements its solution mainly through a computer program.

[0122] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a computer processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the computer processing unit of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0123] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0124] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0125] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.

Claims

1. A sequence processing method, characterized in that: Including: Dividing the sequence vector to be processed into multiple subsequence vectors of the same number according to the number of multiple computer processing units; The multiple computer processing units perform the following processing on the multiple subsequence vectors in parallel: The i-th computer processing unit obtains the i-th subsequence vector of the sequence vector in the attention layer, where i is a positive integer; The i-th computer processing unit determines the i-th query vector corresponding to the i-th subsequence vector in the attention layer; The i-th computer processing unit performs attention calculation based on the i-th query vector in the attention layer to obtain the i-th group of attention calculation results output by the attention layer. In the case of processing a causal model, the first computer processing unit that processes the first half of the subsequence vectors obtains the query vector corresponding to the subsequence vector processed by the second computer processing unit that processes the second half of the subsequence vectors, and helps the second computer processing unit perform partial attention calculation based on the obtained query vector.

2. The sequence processing method according to claim 1, characterized in that: It further includes: The i-th computer processing unit aggregates the multiple subsequence vectors into a sequence vector in the attention layer; The i-th computer processing unit determines the key vector and value vector corresponding to the sequence vector in the attention layer; Among them, the i-th computer processing unit performs attention calculation based on the i-th query vector in the attention layer to obtain the i-th group of attention calculation results output by the attention layer, including: the i-th computer processing unit performs attention calculation based on the i-th query vector, the key vector and value vector corresponding to the sequence vector in the attention layer to obtain the i-th group of attention calculation results output by the attention layer.

3. The sequence processing method according to claim 1, characterized in that: The first computer processing unit helps the second computer processing unit perform partial attention calculation, including: When P is odd and i < [P / 2]', or when P is even and i ≤ [P / 2]': the i-th computer processing unit, as the first computer processing unit, obtains the (P - i)-th query vector from the (P - i)-th computer processing unit, as the second computer processing unit, and helps the (P - i)-th computer processing unit perform partial attention calculation based on the (P - i)-th query vector, where i ∈ [1,..., P], P represents the number of multiple computer processing units, and [ ]' represents rounding up.

4. The sequence processing method according to claim 3, characterized in that: Among them: The i-th computer processing unit performs attention calculation based on the i-th query vector in the attention layer, including: the i-th computer processing unit determines the j-th key vector corresponding to the j-th subsequence vector in the attention layer, where 0 < j ≤ i, and performs attention calculation based on the i-th query vector and each j-th key vector to obtain the i-th group of attention calculation results output by the attention layer; The i-th computer processing unit helps the (P - i)-th computer processing unit perform partial attention calculation based on the (P - i)-th query vector, including: the i-th computer processing unit helps the (P - i)-th computer processing unit perform [P / 2]' - i attention calculations based on the (P - i)-th query vector.

5. The sequence processing method according to claim 4, characterized in that: Among them: The i-th computer processing unit helps the (P - i)-th computer processing unit perform [P / 2]' - i attention calculations based on the (P - i)-th query vector, including: The i-th computer processing unit helps the Pi-th computer processing unit to perform attention calculations on the Pi-th query vector and the [P / 2]'-i-th key vector to the 1st key vector.

6. The sequence processing method according to any one of claims 1 to 5, characterized in that: Also includes: While performing attention calculation, the i-th computer processing unit and the Pi-th computer processing unit asynchronously and in parallel communicate the Pi-th query vector and the attention calculation results of the assisting calculation.

7. The sequence processing method according to claim 6, characterized in that: Each computer processing unit maintains parallel computation and communication flows. The i-th computer processing unit and the Pi-th computer processing unit asynchronously and in parallel communicate the Pi-th query vector and the attention calculation result of the assisting calculation while performing the attention calculation, including: While the computation flow of the i-th computer processing unit performs attention computation based on the i-th query vector, the communication flow of the i-th computer processing unit communicates with the communication flow of the Pi-th computer processing unit, so that the i-th computer processing unit obtains the Pi-th query vector from the Pi-th computer processing unit; The computing flow of the i-th computer processing unit helps the Pi-th computer processing unit calculate an attention calculation result each time. While helping to calculate the next attention calculation result, the communication flow of the i-th computer processing unit communicates with the communication flow of the Pi-th computer processing unit so that the Pi-th computer processing unit obtains the previous attention calculation result that it helped calculate from the i-th computer processing unit.

8. The sequence processing method according to any one of claims 1 to 5, characterized in that: Also includes: Multiple computer processing units perform parallel processing of multiple sub-sequence vectors in layers other than the attention layer, wherein the other layers include a feedforward network layer.

9. The sequence processing method according to any one of claims 1 to 5, characterized in that: Also includes: The forward output of the attention layer is saved to the video memory by setting the gradient checkpoint at the attention layer; Using the saved forward output of the attention layer, calculate the forward output and gradient of other layers except the attention layer.

10. The sequence processing method according to any one of claims 1 to 5, characterized in that: The sequence vector includes: an audio sequence vector, a video sequence vector, or a text sequence vector.

11. The sequence processing method according to any one of claims 1 to 5, characterized in that: The computer processing unit includes a graphics processing unit.

12. A sequence processing device, characterized in that: include: A plurality of computer processing units are configured to collaboratively execute the sequence processing method according to any one of claims 1 to 11.

13. The sequence processing device according to claim 12, characterized in that: Also includes: Video memory is used to store data generated during the execution of the sequence processing method.

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

15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a computer processing unit, the steps of the sequence processing method described in any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • Parallel processing method and device based on sequence model

    CN116128021A