Task execution method and device for large language model, equipment and storage medium

Through sparse representation and target attention task screening, it solves the problem of memory occupation and invalid calculation of large language models when performing attention tasks, improves processing efficiency and maintains model accuracy.

CN118550708APending Publication Date: 2024-08-27BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410789531.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-18
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

When existing large language models perform attention tasks, the processing efficiency is low due to the memory occupation and invalid calculation of the mask area, and the sparse or low-rank attention mechanism has a greater loss in model accuracy.

Method used

A sparse representation is used to represent the mask position of the feature to be processed, and the target attention task is determined from multiple attention tasks to be processed through the judgment unit. Attention calculation is only performed on non-all mask areas, reducing computational overhead and improving efficiency.

Benefits of technology

Without losing accuracy, it reduces memory usage and computing overhead, improves the processing efficiency of large language models, and is suitable for mask shape expression in different scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550708A
    Figure CN118550708A
Patent Text Reader

Abstract

The invention provides a task execution method and device for a large language model, equipment and a storage medium, and relates to the technical field of artificial intelligence, in particular to the technical fields of deep learning, large language models, natural language processing, computer vision and the like. According to the specific implementation scheme, the method comprises the steps of determining a target attention task from multiple attention tasks to be processed by using a judgment unit based on sparse representation corresponding to features to be processed; wherein the target attention task is a task corresponding to a non-complete mask area of the to-be-processed feature; the sparse representation is used for representing the mask position of the to-be-processed feature; the mask positions represent mask endpoint positions in at least two mutually disjoint intervals in a mask matrix corresponding to the to-be-processed features; and executing the target attention task by using the computing unit to obtain attention features.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to technical fields such as deep learning, large language models, natural language processing, and computer vision, and specifically to task execution methods, devices, equipment, and storage media for large language models. Background Art

[0002] Large Language Model (LLM) refers to an advanced artificial intelligence algorithm trained on a large amount of data. A natural language processing system with more than 100 billion parameters can be used in customized AI applications such as content generation, text summarization, chatbots, coding, and prediction of protein structure and biomolecule properties.

[0003] The current large language model mainly uses the Transformer architecture to implement feature processing based on the attention mechanism. Summary of the invention

[0004] The present disclosure provides a task execution method, apparatus, device and storage medium for a large language model.

[0005] According to one aspect of the present disclosure, a task execution method for a large language model is provided, comprising: based on a sparse representation corresponding to a feature to be processed, determining a target attention task from a plurality of attention tasks to be processed using a judgment unit; wherein the target attention task is a task corresponding to a non-entire mask area of ​​the feature to be processed; the sparse representation is used to characterize a mask position of the feature to be processed; the mask position characterizes the mask endpoint positions within at least two mutually non-intersecting intervals in a mask matrix corresponding to the feature to be processed; and executing the target attention task using a computing unit to obtain an attention feature.

[0006] According to another aspect of the present disclosure, a task execution device for a large language model is provided, comprising: a judgment unit and a calculation unit. The judgment unit is used to determine a target attention task from a plurality of attention tasks to be processed based on a sparse representation corresponding to the feature to be processed; wherein the target attention task is a task corresponding to a non-entire mask area of ​​the feature to be processed; the sparse representation is used to characterize the mask position of the feature to be processed; the mask position characterizes the mask endpoint position within at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed. The calculation unit is used to execute the target attention task and obtain the attention feature.

[0007] According to another aspect of the present disclosure, a task execution device for a large language model is provided. The device includes the task execution apparatus for a large language model provided by the present disclosure.

[0008] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided according to the present disclosure.

[0009] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided. The computer instructions are used to cause a computer to execute the method provided according to the present disclosure.

[0010] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method provided according to the present disclosure is implemented.

[0011] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0013] Figure 1 Schematically illustrates an exemplary system architecture of a task execution method and device that can apply a large language model according to an embodiment of the present disclosure;

[0014] Figure 2 A flowchart of a task execution method for a large language model according to an embodiment of the present disclosure is schematically shown;

[0015] Figure 3A to Figure 3D A mask schematic diagram in a causal scenario according to an embodiment of the present disclosure is schematically shown;

[0016] Figure 4A~Figure 4B A mask schematic diagram in a non-causal scenario according to an embodiment of the present disclosure is schematically shown;

[0017] Figure 5 A mask schematic diagram in a complex scene according to an embodiment of the present disclosure is schematically shown;

[0018] Figure 6 A schematic diagram schematically shows how to divide tasks to be processed into blocks according to an embodiment of the present disclosure;

[0019] Figure 7 A schematic diagram schematically shows a method for determining a target task to be processed according to an embodiment of the present disclosure;

[0020] Figure 8A schematic diagram schematically shows a method of performing attention calculation on a target processing task according to an embodiment of the present disclosure;

[0021] Fig. 9 A block diagram schematically shows a task execution device for a large language model according to an embodiment of the present disclosure; and

[0022] Fig.10 A block diagram of an electronic device suitable for implementing a task execution method for a large language model according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0023] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0024] Transformer is the basis of the target large language model and can handle natural language problems in complex scenarios. The calculation process of Transformer relies on the attention mechanism. During the training process of the large language model, different mask matrices are usually referenced according to the training stage and training task, so that when the large language model performs the attention task, the masked feature parts can be selectively ignored, thereby improving the processing performance of the large language model.

[0025] In related examples, the mask shape is generally [B, A, S, S], where B represents the batch size, A represents the number of heads, and S represents the length of the feature sequence. This masking method not only brings about a memory occupancy and memory access overhead of the square of the sequence length to hardware resources, but also results in a large amount of invalid calculations on the masked area when performing attention tasks, affecting the processing efficiency of the model.

[0026] The sparse or low-rank attention mechanism in another example uses a coarse-grained masking method, which can reduce computational overhead but causes a large loss in model accuracy.

[0027] In view of this, in order to reduce the occupancy of video memory by efficient masks and the memory access overhead of invalid calculations, an embodiment of the present disclosure provides a task execution method for a large language model, including: based on a sparse representation corresponding to a feature to be processed, using a judgment unit to determine a target attention task from multiple attention tasks to be processed; wherein the target attention task is a task corresponding to a non-entire mask area of ​​the feature to be processed; the sparse representation is used to characterize the mask position of the feature to be processed; the mask position characterizes the mask endpoint positions within at least two non-intersecting intervals in the mask matrix corresponding to the feature to be processed; and using a computing unit to execute the target attention task to obtain an attention feature.

[0028] Figure 1 An exemplary system architecture to which the method and apparatus for executing a task for a large language model according to an embodiment of the present disclosure can be applied is schematically shown.

[0029] It should be noted that Figure 1 The examples shown are only examples of system architectures to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but do not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios. For example, in another embodiment, the exemplary system architecture to which the task execution method and apparatus for a large language model can be applied may include a terminal device, but the terminal device may implement the task execution method and apparatus for a large language model provided by the embodiments of the present disclosure without interacting with the server.

[0030] like Figure 1 As shown, the system architecture according to this embodiment may include a terminal device 101, a network 102, and a server cluster 103. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server cluster 103. The network 102 may also be used to provide a medium for a communication link within the server cluster 103. The network 102 may include various connection types, such as wired and / or wireless communication links, etc.

[0031] The user can use the terminal device 101 to interact with the server cluster 103 through the network 102 to receive or send messages, etc. For example, the terminal device 101 can send a request for training a deep learning model to the server cluster 103 through the network 102.

[0032] Various communication client applications may be installed on the terminal device 101, such as knowledge reading applications, web browser applications, search applications, instant messaging tools, email clients and / or social platform software (for example only).

[0033] The terminal device 101 may be any electronic device having a display screen and supporting web browsing, including but not limited to a smart phone, a tablet computer, a laptop computer, a desktop computer, and the like.

[0034] The server cluster 103 may be a server that provides various services, such as a background management server that provides support for requests sent by users using the terminal device 101 (only an example).

[0035] The server cluster 103 may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.

[0036] The server cluster 103 includes multiple server nodes 1031, 1032, 1033, and 1034, each of which includes one or more hardware devices. The server cluster 103 or the server node can be used to execute the task execution method for the large model provided by the present disclosure, so as to realize the deployment, reasoning, or training of the large model with lower computing resources and storage resources.

[0037] It can be understood that the above describes the system architecture of the present disclosure, and the following will describe the method of the present disclosure.

[0038] Figure 2 The flowchart of the task execution method for a large language model according to an embodiment of the present disclosure is schematically shown.

[0039] like Figure 2 As shown, the method 200 includes operations S210 to S220.

[0040] In operation S210, a target attention task is determined from a plurality of attention tasks to be processed using a judgment unit based on a sparse representation corresponding to the feature to be processed.

[0041] In operation S220, a target attention task is performed using a computing unit to obtain an attention feature.

[0042] According to an embodiment of the present disclosure, the judgment unit and the computing unit may include at least one of a central processing unit (CPU), a graphics processing unit (GPU), and an artificial intelligence computing unit. The artificial intelligence computing unit may include at least one of a neural network processing unit (NPU), a tensor processing unit (TPU), and a Kunlun core.

[0043] According to an embodiment of the present disclosure, the sparse representation is used to characterize the mask position of the feature to be processed, which can be used as an expression of the mask shape. The mask position characterizes the mask endpoint positions in at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed.

[0044] For example, sparse representation can express a mask of shape [B, A, S, n], where B represents the batch size, A represents the number of heads, S represents the length of the feature sequence, n=dk, k represents the number of non-intersecting intervals into which the feature sequence in the S dimension is divided, and d represents the number of elements in each interval used to identify the endpoint positions of the mask.

[0045] When d=1, it means that there is one element in the interval used to identify the mask endpoint position, which can be the starting endpoint position or the ending endpoint position. When the mask endpoint position is identified by the starting endpoint position, it means that the mask area is from the starting endpoint to the region boundary line. When the mask endpoint position is identified by the ending endpoint position, it means that the mask area is from the region boundary line to the ending endpoint.

[0046] When d=2, it can be indicated that there are 2 elements in the interval used to identify the mask endpoint positions, including both the start endpoint position and the end endpoint position.

[0047] Figure 3A A mask schematic diagram in a causal scenario according to an embodiment of the present disclosure is schematically shown.

[0048] Figure 3B A mask schematic diagram in a causal scenario according to an embodiment of the present disclosure is schematically shown.

[0049] exist Figure 3A and Figure 3B In the figure, the mask matrix can be divided into the lower left area and the upper right area by the diagonal line. Since the upper right area has been masked, only the mask situation of the lower left area can be expressed. In the figure, S1 and E1 respectively represent the mask start endpoint position and mask end endpoint position of the lower left area, and S2 and E2 respectively represent the mask start endpoint position and mask end endpoint position of the lower left area. The shaded area in the figure represents the non-masked area, and the light gray area represents the masked area.

[0050] like Figure 3A As shown, in the mask schematic diagram 300A, in the lower left area, the mask area of ​​the first column starts from the fourth row and ends at the boundary line, so S1=4. The 0th, 7th, 8th, and 9th columns are all non-masked areas, so S1=10, or it can be infinite. In this scenario, since each mask area ends at the boundary line, it can be sparsely represented in the shape of [B, A, S, 2].

[0051] like Figure 3B As shown, in the mask schematic diagram 300B, in the lower left area, the mask area of ​​column 0 starts from row 4 and ends at row 7, so S1 = 4, E1 = 7. In this scenario, since the mask area does not end at the boundary line, it can be sparsely represented in the shape of [B, A, S, 4].

[0052] It should be noted that since the upper right areas of the mask diagram 300A and the mask diagram 300B are both masked, in order to further reduce the memory usage and access overhead caused by the sequence length, the sparse representation in the causal scenario can also be simplified to [B, A, S, 1] (corresponding to Figure 3A ) and [B,A,S,2] (corresponding to Figure 3B ). This simplified sparse representation is only suitable for causal scenarios with simple mask forms.

[0053] According to an embodiment of the present disclosure, the attention task may be a multi-head self-attention task corresponding to a large language model. For example, multiple attention tasks may correspond to modules based on multi-head self-attention mechanism reasoning of multiple processing layers of the large language model.

[0054] According to an embodiment of the present disclosure, the calculation formula based on the attention mechanism is as follows:

[0055] (1)

[0056] Among them, Q, K, and V represent the query matrix, key matrix, and value matrix respectively, and the shapes are all [B, S, A, H]. H represents the header size, and B, S, and A have the same meanings as described above and are not repeated here. M represents the mask matrix.

[0057] When attention is calculated according to the above formula (1), when the calculated intermediate features are When the masked regions in the corresponding mask matrices are added together, the result of the attention mechanism calculation is 0.

[0058] Therefore, the matrix operation for this part is actually invalid, but it generates unnecessary computational overhead. The judgment unit can be used to judge whether the current attention task to be processed is the task corresponding to all masked areas, so that before executing the attention task, the task corresponding to all masked areas can be skipped to reduce the computational overhead during the execution of the attention task.

[0059] According to an embodiment of the present disclosure, the target attention task may be a task corresponding to a non-all masked areas of the feature to be processed. For example, it may include a task corresponding to a part of the masked area and / or a task corresponding to a non-masked area. Then, the calculation unit is used to perform attention calculation only on the tasks corresponding to the non-all masked areas to obtain the attention feature.

[0060] According to an embodiment of the present disclosure, by using a judgment unit to determine, based on a sparse representation corresponding to the feature to be processed, the task corresponding to non-all masked areas of the feature to be processed from multiple attention tasks to be processed, it is achieved that before executing the attention task, the task corresponding to the entire masked area is skipped, and the calculation unit is used to perform attention calculation only on the task corresponding to non-all masked areas to obtain the attention feature, thereby reducing the computational overhead during the execution of the attention task.

[0061] As the number of applicable scenarios for large language models continues to increase, how to accurately express the mask shapes in different scenarios within the linear-level spatial and temporal overhead of the feature sequence length can reduce video memory usage and computing overhead without losing accuracy.

[0062] Therefore, the method provided by the embodiment of the present disclosure also includes the following operation: using a sparse representation unit to perform a sparse representation task to perform sparse representation on the features to be processed based on the scene category corresponding to the task to be processed.

[0063] According to an embodiment of the present disclosure, the scene categories may include causal scenes, non-causal scenes, and complex scenes. Causal scenes, for example, may be scenes of item recommendation for advertisement placement. Non-causal scenes, for example, may be scenes of text recognition. Complex scenes, for example, may be scenes of multimodal task recognition.

[0064] According to an embodiment of the present disclosure, based on the scene category corresponding to the task to be processed, sparse representation of the features to be processed may include the following operations: in response to the scene category being a causal scene, dividing the mask matrix into two non-intersecting first intervals and second intervals along the diagonal of the mask matrix, and all elements in the first interval are masked; and sparsely representing the features to be processed using the mask endpoint positions in the second interval.

[0065] According to an embodiment of the present disclosure, the mask endpoint positions may be the starting mask row and the ending mask row of each column element of the second interval in the mask matrix corresponding to the feature to be processed.

[0066] Figure 3C A mask schematic diagram in a causal scenario according to an embodiment of the present disclosure is schematically shown.

[0067] Figure 3D A mask schematic diagram in a causal scenario according to an embodiment of the present disclosure is schematically shown.

[0068] Figure 3C and Figure 3D The meaning of the diagram in the figure is the same as described above. Figure 3A and Figure 3B The first interval may be the upper right area, and the second interval may be the lower left area.

[0069] like Figure 3C As shown, in the mask schematic diagram 300C, the starting mask row of columns 0 to 9 is the 5th row, the mask end row is the boundary line, the sequence length S is 10, and when the mask end row needs to be represented, the sparse representation can be [B, A, 10, 2]. When the mask end row does not need to be represented, the sparse representation can be [B, A, 10, 1], and the corresponding values ​​can be [[5], [5], [5], [5], [5], [5], [5], [5], [5], [5]].

[0070] like Figure 3D As shown, in the mask diagram 300D, columns 0 to 3 and rows 7 to 9 are all unmasked, the starting mask row of columns 4 to 6 is row 7, the mask termination row is the boundary line, and the sequence length S is 10. When the mask termination row needs to be represented, the sparse representation can be [B, A, 10, 2]. When the mask termination row does not need to be represented, the sparse representation can be [B, A, 10, 1], and the corresponding values ​​can be [

[10] ,

[10] ,

[10] ,

[10] , [7], [7],

[10] ,

[10] ,

[10] ].

[0071] According to an embodiment of the present disclosure, in response to the scene category being a non-causal scene, the mask matrix is ​​divided into two non-intersecting third intervals and fourth intervals along the diagonal of the mask matrix; and the mask endpoint positions within the third interval and the mask endpoint positions within the fourth interval are used to perform sparse representation on the features to be processed.

[0072] According to an embodiment of the present disclosure, the mask endpoint positions may be the starting mask row and the ending mask row of each column element of the third interval and the starting mask row and the ending mask row of each column element of the fourth area in the mask matrix corresponding to the feature to be processed.

[0073] Figure 4A~Figure 4B A mask schematic diagram in a non-causal scenario according to an embodiment of the present disclosure is schematically shown.

[0074] Figure 4A and Figure 4B The meaning of the diagram in the figure is the same as described above. Figure 3A and Figure 3B The third interval may be the upper right area, and the fourth interval may be the lower left area.

[0075] like Figure 4A As shown, in the mask schematic diagram 400A, in the lower left area, columns 0 to 2 are all non-mask areas, the mask end rows of columns 3 to 9 are all boundary lines, and the starting mask rows are rows 3 to 9. In the upper right area, columns 0 to 2 are all non-mask areas, the mask of column 3 has been shown in the lower left area, the starting mask row of column 4 is 3, and the mask end row is 4, so S2=3 and E2=4 on the corresponding column. And so on.

[0076] like Figure 4B As shown, in the mask schematic diagram 400B, in the lower left area, the starting mask line of columns 0 to 3 is 4, and the mask ending line is the boundary line. The starting mask line of columns 4 to 6 is 7, and the mask ending line is the boundary line. Columns 7 to 9 are all non-masked areas. In the upper right area, columns 0 to 3 are non-masked areas. The starting mask line of columns 4 to 6 is the boundary line, and the mask ending line is 4. The starting mask line of columns 7 to 9 is the boundary line, and the mask ending line is 7. Therefore, it can be sparsely represented as [B, A, 10, 2], and the values ​​are: [[0,4], [0,4], [0,4], [0,4], [4,7], [4,7], [4,7], [7,10], [7,10], [7,10]].

[0077] In the above two scenarios, the mask shapes are relatively simple, and the accurate expression of the mask shapes can be achieved by dividing the mask matrix into two regions. Figure 5 The mask diagram for the complex scene shown in the figure requires dividing more non-intersecting intervals to accurately express the mask shape.

[0078] Figure 5 A mask schematic diagram in a complex scene according to an embodiment of the present disclosure is schematically shown.

[0079] like Figure 5 As shown, in the mask schematic diagram 500, every two rows can be used as an interval, the shaded area represents the non-mask area, and the gray area represents the mask area. S1~S5 respectively represent the starting mask row of each column element in each interval; E1~E5 respectively represent the ending mask row of each column element in each interval.

[0080] For example: Column 0 is all non-masked area in k1 interval. In k2 interval, the starting mask line is 2, and the mask end line is 4 (since the mask end line is the boundary line of the interval, the representation of the end line can also be omitted), and the corresponding column S2=2, E2=4. In k3 interval, it is all non-masked area. In k4 interval, the starting mask line is 6, and the mask end line is 8, and the corresponding column S4=6, E4=8. In k5 interval, it is all non-masked area. Therefore, the sparse representation can be [B,A,10,10], and the corresponding values ​​are as follows Figure 5 shown.

[0081] According to the embodiments of the present disclosure, by accurately sparsely representing the mask shapes in different scenarios, it is possible to reduce video memory usage and computational overhead without losing accuracy within the linear spatiotemporal overhead of the feature sequence length.

[0082] Since the parameters involved in the processing of large language models are at the level of hundreds of billions when executing tasks, in order to improve the processing efficiency of the model, the features can be divided into blocks and processed in parallel using distributed multiple GPUs.

[0083] Therefore, the task execution method for a large language model provided by an embodiment of the present disclosure also includes the following operations: using a blocking unit to execute a blocking task, so as to block the parameter matrix corresponding to the features to be processed based on the length of the parameter matrix corresponding to the features to be processed and the number of registers, to obtain a parameter matrix corresponding to each attention task to be processed; the parameter matrix includes: a query matrix, a key matrix, a value matrix and a mask matrix; and using a target storage unit to store the query matrix, key matrix, value matrix and mask matrix corresponding to each attention task to be processed.

[0084] According to an embodiment of the present disclosure, the hyperparameters for performing the block task can be first determined based on the length of the parameter matrix corresponding to the features to be processed and the number of registers, and then, based on the matrix multiplication operation rules, the parameter matrix corresponding to the features to be processed is blocked to obtain the parameter matrix corresponding to each attention task to be processed.

[0085] For example, the query matrix shape can be [2, 8, 1024, 128] which can be divided into a parameter matrix of [2, 8, 64, 128] or [2, 8, 128, 128]. The query matrix shape can be [2, 8, 1024, 256] which can be divided into a parameter matrix of [2, 8, 32, 256] or [2, 8, 64, 256] or [2, 8, 128, 256] or [2, 8, 256,256].

[0086] Figure 6 The diagram schematically shows a schematic diagram of dividing a task to be processed into blocks according to an embodiment of the present disclosure.

[0087] like Figure 6 As shown, the Query matrix, Key matrix, Value matrix and Mask matrix can be divided into 4 blocks, each of which includes 3 elements.

[0088] According to an embodiment of the present disclosure, the parameter matrix corresponding to the feature to be processed is divided into blocks based on the length of the parameter matrix corresponding to the feature to be processed and the number of registers, which can effectively improve the processing efficiency of the large language model.

[0089] According to an embodiment of the present disclosure, based on the attention calculation mechanism, the matrix dimension obtained by multiplying the transpose of the Query matrix and the Key matrix is ​​the same as the dimension of the Mask matrix. Therefore, the block dimension of the Query matrix and the Key matrix determines the block dimension of the Mask matrix.

[0090] Therefore, it is possible to determine whether the attention task to be processed is an invalid task by determining the mask interval corresponding to multiple attention tasks to be processed, so as to reduce the computational overhead occupied by invalid tasks in the process of executing attention tasks.

[0091] According to an embodiment of the present disclosure, based on the sparse representation corresponding to the feature to be processed, a judgment unit is used to determine a target attention task from multiple attention tasks to be processed, including: based on the sparse representation corresponding to the feature to be processed, determining a mask interval corresponding to the multiple attention tasks to be processed; and based on the mask interval, determining the target attention task from the multiple attention tasks to be processed by using the judgment unit.

[0092] According to an embodiment of the present disclosure, the mask interval may represent the area between the mask start endpoint and the mask end endpoint, so as to determine which intermediate calculation result matrices of the attention tasks to be processed are located within the mask interval, thereby determining that the attention tasks to be processed located within the mask interval are invalid tasks before executing the attention tasks.

[0093] Since the block is based on the feature matrix corresponding to the attention task of the same head in the same batch, B and A are omitted here. For example, the block of the Query matrix is ​​[3,128], the block of the Key matrix is ​​[3,128], and since Q * K^T = [3, 3], it can be determined that the block of the Mask matrix is ​​[3, 3].

[0094] Therefore, we can traverse each [3, 3] block to see whether it is in the mask interval to determine whether the corresponding attention task to be processed is an invalid task.

[0095] Figure 7 A schematic diagram of determining a target task to be processed according to an embodiment of the present disclosure is schematically shown.

[0096] like Figure 7As shown, in embodiment 700, the non-shaded area is the mask area, and 701 represents the 12 tokens contained in all the pending attention tasks of a certain head of a certain batch. All areas in the [3, 3] block 7012 corresponding to the pending attention task B are mask areas, and it can be determined that the pending attention task B is an invalid task. Only part of the area in the [3, 3] block 7011 corresponding to the pending attention task A is the mask area, so it can be determined that the pending attention task A is the target attention task.

[0097] According to an embodiment of the present disclosure, by screening invalid tasks based on mask intervals, invalid tasks can be skipped in advance before executing attention tasks to reduce the computational overhead occupied by invalid tasks.

[0098] According to an embodiment of the present disclosure, determining mask intervals corresponding to multiple attention tasks to be processed based on a sparse representation corresponding to the features to be processed may include the following operations: for each attention task to be processed, determining multiple mask endpoint positions in a mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the features to be processed; and determining the mask interval corresponding to each attention task to be processed based on the multiple mask endpoint positions.

[0099] According to an embodiment of the present disclosure, each to-be-processed attention task may be a block-based attention task.

[0100] Since the mask shapes of different application scenarios are different, in order to adapt to the needs of different application scenarios, the mask position can be the starting mask row and the ending mask row of each column element in at least two non-intersecting intervals in the mask matrix corresponding to the feature to be processed.

[0101] According to an embodiment of the present disclosure, determining the mask endpoint positions in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed may include the following operations: determining the starting mask row and the ending mask row of each column element in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed.

[0102] According to an embodiment of the present disclosure, a mask interval corresponding to each attention task to be processed is determined based on multiple mask endpoint positions, including: determining the terminating mask row of each column element as the terminating position of the mask interval; and determining the starting mask row of each column element as the starting position of the mask interval.

[0103] like Figure 7As shown, the shape of the sparse representation can be [B, A, 12, 4], and the corresponding values ​​are: the starting mask behavior of the lower left area is [12, 5, 5, 5, 6, 6, 9, 9, 9, 12, 12, 12], the mask ending behavior of the lower left area is [12, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12], the starting mask behavior of the upper right area is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], and the mask ending behavior of the lower right area is [0, 1, 2, 2, 3, 3, 6, 6, 6, 12, 12, 12].

[0104] According to the embodiment of the present disclosure, for the block corresponding to the task A to be processed, the block is in the lower left interval, which corresponds to the 0th to 2nd columns. The end mask row [12,11,11] of the corresponding column can be used as the end position of the mask interval. The start mask row [12,5,5] of the corresponding column can be used as the start position of the mask interval.

[0105] According to an embodiment of the present disclosure, for the block corresponding to the task B to be processed, the block is in the lower left interval, which corresponds to the 3rd to 5th columns in the interval. The ending mask row [12,11,11] of the corresponding column can be used as the ending position of the mask interval, and the starting mask row [5,6,6] of the corresponding column can be used as the starting position of the mask interval.

[0106] According to an embodiment of the present disclosure, the mask position is a starting mask column and an ending mask column of each row of elements in at least two mutually non-intersecting intervals in a mask matrix corresponding to the feature to be processed.

[0107] According to an embodiment of the present disclosure, determining the mask endpoint positions in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed may include the following operations: determining the starting mask column and the ending mask column of each row element in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed.

[0108] According to an embodiment of the present disclosure, determining the mask interval corresponding to each attention task to be processed based on multiple mask endpoint positions may include the following operations: determining the ending mask column of each row of elements as the ending position of the mask interval; and determining the starting mask column of each row of elements as the starting position of the mask interval.

[0109] The method of determining the mask interval by using the starting mask column and the ending mask column of each row of elements to represent the mask position is the same as the method of determining the mask interval by using the starting mask row and the ending mask row of each column of elements to represent the mask position, and will not be described in detail here.

[0110] According to an embodiment of the present disclosure, since the sparse representation accurately expresses the shape of the mask, the mask interval can be quickly determined based on the maximum (ending mask row / column) and minimum (starting mask row / column) values ​​of the mask rows / columns corresponding to the task block to be processed, thereby reducing the computational overhead during the judgment of invalid tasks.

[0111] According to an embodiment of the present disclosure, based on a mask interval, a target attention task is determined from multiple attention tasks to be processed using a judgment unit, which may include the following operations: in response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, the attention task to be processed is determined to be the target attention task using a judgment unit; wherein the intermediate feature matrix is ​​obtained based on the query matrix and key matrix corresponding to the attention task to be processed.

[0112] According to an embodiment of the present disclosure, the element endpoint position and the mask interval can be intersected to determine whether the attention task to be processed is the target attention task. When the element endpoint position and the mask interval have an intersection, and the element endpoint positions are all within the mask interval, the task to be processed can be determined to be an invalid task. When the element endpoint position and the mask interval have a partial intersection, or no intersection, the task to be processed can be determined to be the target attention task.

[0113] For example: the element endpoint position in the intermediate feature matrix corresponding to a task to be processed is [3,4], and the mask interval is [5,11]. It can be determined that the above two intervals have no intersection, and the attention task to be processed can be determined to be the target attention task.

[0114] According to an embodiment of the present disclosure, the mask interval includes a mask end position and a mask start position. In response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, the judgment unit is used to determine that the attention task to be processed is a target attention task, which may include the following operations: In response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is greater than the mask end position or less than the mask start position, the judgment unit is used to determine that the attention task to be processed is a target attention task.

[0115] According to an embodiment of the present disclosure, the intermediate feature matrix can be obtained as shown in formula (1): .

[0116] like Figure 7 As shown, for the block corresponding to the task A to be processed, the end position of the mask interval corresponding to the block is [12,11,11], and the starting position of the mask is [12,5,5].

[0117] According to the embodiments of the present disclosure, since the blocks corresponding to the task A to be processed are located in the 6th to 8th rows of the 0th to 2nd columns, only the 6th to 8th rows of the 1st to 2nd columns are located in the mask interval, 6 is less than 12, 7 is between 5 and 11, and 8 is between 5 and 11. Therefore, the elements in the intermediate feature matrix corresponding to the task A to be processed are partially located in the mask area and can be determined as the target attention task.

[0118] According to an embodiment of the present disclosure, for the block corresponding to the task B to be processed, the end position of the mask interval corresponding to the block is [12, 11, 11], and the start position is [5, 6, 6].

[0119] According to an embodiment of the present disclosure, since the blocks corresponding to the task B to be processed are located in the 6th to 8th rows of the 3rd to 5th columns, 6 is between 5 and 12, 7 is between 6 and 11, and 8 is between 6 and 11, all the elements in the intermediate feature matrix corresponding to the task B to be processed are located within the mask interval, indicating that the blocks corresponding to the task B to be processed are all located in the mask area and can be determined as invalid tasks.

[0120] According to the embodiments of the present disclosure, by comparing the mask interval within the block with the element endpoint task, the judgment logic is simple and efficient, and invalid tasks can be quickly determined in linear time so as to skip invalid tasks and reduce the computational overhead during the execution of the attention task.

[0121] According to an embodiment of the present disclosure, using a computing unit to perform a target attention task and obtain an attention feature may include the following operations: using a computing unit to read at least one query matrix, at least one key matrix, at least one value matrix and at least one mask matrix corresponding to the target attention task from a target storage unit; and using a target computing unit to perform the target attention task and obtain the attention feature based on the at least one query matrix, at least one key matrix, at least one value matrix and at least one mask matrix.

[0122] Figure 8 A schematic diagram of performing attention calculation on a target processing task according to an embodiment of the present disclosure is schematically shown.

[0123] like Figure 8 As shown, in embodiment 800, when performing a target attention task, the target attention task can be performed using a target computing unit based on at least one query matrix 803, at least one key matrix 802, at least one value matrix 807 and at least one mask matrix 801 to obtain an attention feature 806.

[0124] For example: the first intermediate feature 8041 can be obtained according to the transpose of the query matrix 8031 ​​and the key matrix 8021; the second intermediate feature 8051 can be obtained according to the first intermediate feature 8041 and the mask matrix 8011; the second intermediate feature 8051 is processed by the activation function to obtain the activation feature matrix; the attention feature 8061 is obtained according to the activation feature matrix and the key matrix 8071.

[0125] According to an embodiment of the present disclosure, the activation function may be a normalization function.

[0126] According to an embodiment of the present disclosure, a computing unit is used to perform calculations only on a target attention task, thereby reducing the attention calculation process corresponding to an invalid task and further reducing the computational overhead of executing the attention task.

[0127] Fig. 9 A block diagram of a task execution device for a large language model according to an embodiment of the present disclosure is schematically shown.

[0128] like Fig. 9 As shown, the device 900 may include: a judgment unit 910 and a calculation unit 920.

[0129] The judgment unit 910 is used to determine a target attention task from multiple attention tasks to be processed based on the sparse representation corresponding to the feature to be processed; wherein the target attention task is a task corresponding to a non-entire mask area of ​​the feature to be processed; the sparse representation is used to represent the mask position of the feature to be processed; the mask position represents the mask endpoint position within at least two non-intersecting intervals in the mask matrix corresponding to the feature to be processed.

[0130] The computing unit 920 is used to perform the target attention task and obtain the attention feature.

[0131] According to an embodiment of the present disclosure, the judgment unit includes: a first determination subunit and a second determination subunit. The first determination subunit is used to determine a mask interval corresponding to a plurality of attention tasks to be processed based on a sparse representation corresponding to the feature to be processed. The second determination subunit is used to determine a target attention task from the plurality of attention tasks to be processed using the judgment unit based on the mask interval.

[0132] According to an embodiment of the present disclosure, the first determination subunit is used to: for each attention task to be processed, based on the sparse representation corresponding to the feature to be processed, determine a plurality of mask endpoint positions in a mask matrix corresponding to each attention task to be processed; and determine a mask interval corresponding to each attention task to be processed based on the plurality of mask endpoint positions.

[0133] According to an embodiment of the present disclosure, the mask position is the starting mask row and the ending mask row of each column element in at least two non-intersecting intervals in the mask matrix corresponding to the feature to be processed; the first determination subunit is used to: determine the starting mask row and the ending mask row of each column element in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed.

[0134] According to an embodiment of the present disclosure, the first determining subunit is used to: determine the ending mask row of each column element as the ending position of the mask interval; and determine the starting mask row of each column element as the starting position of the mask interval.

[0135] According to an embodiment of the present disclosure, the mask position is the starting mask column and the ending mask column of each row of elements in at least two non-intersecting intervals in the mask matrix corresponding to the feature to be processed; the first determination subunit is used to: determine the starting mask column and the ending mask column of each row of elements in the mask matrix corresponding to each attention task to be processed based on the sparse representation corresponding to the feature to be processed.

[0136] According to an embodiment of the present disclosure, the first determining subunit is used to: determine the ending mask column of each row of elements as the ending position of the mask interval; and determine the starting mask column of each row of elements as the starting position of the mask interval.

[0137] According to an embodiment of the present disclosure, the second determination subunit is used to: in response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, use the judgment unit to determine that the attention task to be processed is the target attention task; wherein the intermediate feature matrix is ​​obtained based on the query matrix and key matrix corresponding to the attention task to be processed.

[0138] According to an embodiment of the present disclosure, the mask interval includes a mask end position and a mask start position; the second determination subunit is used to: in response to the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed being greater than the mask end position or less than the mask start position, use the judgment unit to determine that the attention task to be processed is the target attention task.

[0139] According to an embodiment of the present disclosure, a computing unit includes: a reading subunit and a computing subunit. The reading subunit is used to read at least one query matrix, at least one key matrix, at least one value matrix and at least one mask matrix corresponding to a target attention task from a target storage unit using the computing unit; and the computing subunit is used to perform a target attention task using a target computing unit according to the at least one query matrix, at least one key matrix, at least one value matrix and at least one mask matrix to obtain an attention feature.

[0140] According to an embodiment of the present disclosure, a computing subunit is used to obtain a first intermediate feature based on the transpose of a query matrix and a key matrix; obtain a second intermediate feature based on the first intermediate feature and a mask matrix; process the second intermediate feature using an activation function to obtain an activation feature matrix; and obtain an attention feature based on the activation feature matrix and the key matrix.

[0141] According to an embodiment of the present disclosure, the above-mentioned device further includes: a blocking unit and a target storage unit.

[0142] A blocking unit is used to perform a blocking task to block the parameter matrix corresponding to the feature to be processed based on the length of the parameter matrix corresponding to the feature to be processed and the number of registers to obtain a parameter matrix corresponding to each attention task to be processed; the parameter matrix includes: a query matrix, a key matrix, a value matrix and a mask matrix.

[0143] A target storage unit is used to store the query matrix, key matrix, value matrix and mask matrix corresponding to each attention task to be processed.

[0144] According to an embodiment of the present disclosure, the above-mentioned device also includes: a sparse representation unit, which is used to perform a sparse representation task to sparsely represent the features to be processed based on the scene category corresponding to the task to be processed.

[0145] According to an embodiment of the present disclosure, the sparse representation unit includes: a first division subunit and a first representation subunit.

[0146] The first division subunit is used for dividing the mask matrix into two mutually non-intersecting first intervals and second intervals by the diagonal of the mask matrix in response to the scene category being a causal scene, and all elements in the first interval are masked. The first representation subunit is used for sparsely representing the feature to be processed by using the mask endpoint position in the second interval.

[0147] According to an embodiment of the present disclosure, the sparse representation unit includes: a second division subunit and a second representation subunit.

[0148] The second division subunit is used for dividing the mask matrix into two mutually non-intersecting third intervals and fourth intervals along the diagonal of the mask matrix in response to the scene category being a non-causal scene.

[0149] The second representation subunit is used to perform sparse representation on the feature to be processed by using the mask endpoint position in the third interval and the mask endpoint position in the fourth interval.

[0150] According to an embodiment of the present disclosure, the present disclosure also provides a task execution device for a large language model, including the above-mentioned apparatus.

[0151] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0152] According to an embodiment of the present disclosure, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described above.

[0153] According to an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method as described above.

[0154] According to an embodiment of the present disclosure, a computer program product includes a computer program, and when the computer program is executed by a processor, the computer program implements the method as described above.

[0155] Fig.10 A schematic block diagram of an example electronic device 1000 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0156] like Fig.10 As shown, the device 1000 includes a computing unit 1001, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1002 or a computer program loaded from a storage unit 808 to a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the device 800 can also be stored. The computing unit 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 804. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0157] A number of components in the device 800 are connected to the I / O interface 1005, including: an input unit 1006, such as a keyboard, a mouse, etc.; an output unit 1007, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 1009, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1009 allows the device 1000 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0158] The computing unit 1001 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as a task execution method for a large language model. For example, in some embodiments, the task execution method for a large language model may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 1008. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1000 via the ROM 1002 and / or the communication unit 1009. When the computer program is loaded into the RAM 1003 and executed by the computing unit 1001, one or more steps of the task execution method for a large language model described above may be performed. Alternatively, in other embodiments, the computing unit 1001 may be configured to execute the task execution method for a large language model in any other appropriate manner (eg, by means of firmware).

[0159] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0160] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0161] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0162] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0163] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0164] A computer system may include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on respective computers and having a client-server relationship to each other. The server may be a cloud server, a server in a distributed system, or a server combined with a blockchain.

[0165] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0166] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A task execution method for a large language model, comprising: Based on the sparse representation corresponding to the feature to be processed, a target attention task is determined from a plurality of attention tasks to be processed using a judgment unit; wherein the target attention task is a task corresponding to a non-entire mask area of ​​the feature to be processed; the sparse representation is used to represent the mask position of the feature to be processed; the mask position represents the mask endpoint position in at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed; and The target attention task is performed using a computing unit to obtain attention features.

2. The method according to claim 1, wherein: The method of determining a target attention task from a plurality of attention tasks to be processed by using a judgment unit based on a sparse representation corresponding to the feature to be processed includes: Determining mask intervals corresponding to the plurality of attention tasks to be processed based on the sparse representation corresponding to the features to be processed; and Based on the mask interval, the judgment unit is used to determine a target attention task from a plurality of attention tasks to be processed.

3. The method according to claim 2, wherein: The determining, based on the sparse representation corresponding to the feature to be processed, the mask intervals corresponding to the plurality of attention tasks to be processed comprises: For each attention task to be processed, determining a plurality of mask endpoint positions in a mask matrix corresponding to each attention task to be processed based on a sparse representation corresponding to the feature to be processed; and According to the multiple mask endpoint positions, a mask interval corresponding to each attention task to be processed is determined.

4. The method according to claim 3, wherein: The mask positions are a starting mask row and an ending mask row of each column element in at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed; The determining, based on the sparse representation corresponding to the feature to be processed, the mask endpoint position in the mask matrix corresponding to each attention task to be processed comprises: Based on the sparse representation corresponding to the feature to be processed, a starting mask row and an ending mask row of each column element in the mask matrix corresponding to each attention task to be processed are determined.

5. The method according to claim 4, wherein: The step of determining a mask interval corresponding to each attention task to be processed according to the plurality of mask endpoint positions includes: Determining the terminating mask row of each column of elements as the terminating position of the mask interval; and The starting mask row of each column of elements is determined as the starting position of the mask interval.

6. The method according to claim 3, wherein: The mask position is a starting mask column and an ending mask column of each row element in at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed; The determining, based on the sparse representation corresponding to the feature to be processed, the mask endpoint position in the mask matrix corresponding to each attention task to be processed comprises: Based on the sparse representation corresponding to the feature to be processed, a starting mask column and an ending mask column of each row element in the mask matrix corresponding to each attention task to be processed are determined.

7. The method according to claim 6, wherein: The step of determining a mask interval corresponding to each attention task to be processed according to the plurality of mask endpoint positions includes: Determine the end mask column of each row of elements as the end position of the mask interval; and The starting mask column of each row of elements is determined as the starting position of the mask interval.

8. The method according to any one of claims 2 to 5, wherein: The step of determining a target attention task from a plurality of attention tasks to be processed by the judgment unit based on the mask interval includes: In response to the fact that the position of the element endpoint in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, using the judgment unit to determine that the attention task to be processed is the target attention task; The intermediate feature matrix is ​​obtained according to the query matrix and the key matrix corresponding to the attention task to be processed.

9. The method according to claim 8, wherein: The mask interval includes a mask end position and a mask start position; In response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, using the judgment unit to determine that the attention task to be processed is the target attention task, comprising: In response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is greater than the mask end position or less than the mask start position, the judgment unit is used to determine that the attention task to be processed is the target attention task.

10. The method according to any one of claims 1 to 9, wherein: The using a computing unit to perform the target attention task to obtain an attention feature includes: reading, using a computing unit, at least one query matrix, at least one key matrix, at least one value matrix, and at least one mask matrix corresponding to the target attention task from a target storage unit; and The target attention task is performed using the target computing unit according to the at least one query matrix, the at least one key matrix, the at least one value matrix and the at least one mask matrix to obtain the attention feature.

11. The method according to claim 10, wherein: The step of performing the target attention task using the target computing unit according to the at least one query matrix, the at least one key matrix, the at least one value matrix and the at least one mask matrix to obtain the attention feature comprises: Obtaining a first intermediate feature according to the transposition of the query matrix and the key matrix; Obtaining a second intermediate feature according to the first intermediate feature and the mask matrix; Processing the second intermediate feature using an activation function to obtain an activation feature matrix; The attention feature is obtained according to the activation feature matrix and the key matrix.

12. The method according to any one of claims 1 to 11, further comprising: Performing a block task using a block unit to block the parameter matrix corresponding to the feature to be processed based on the length of the parameter matrix corresponding to the feature to be processed and the number of registers to obtain a parameter matrix corresponding to each attention task to be processed; The parameter matrix includes: a query matrix, a key matrix, a value matrix and a mask matrix; as well as The query matrix, the key matrix, the value matrix and the mask matrix corresponding to each attention task to be processed are stored in a target storage unit.

13. The method according to any one of claims 1 to 11, further comprising: A sparse representation task is performed using a sparse representation unit to sparsely represent the feature to be processed based on a scene category corresponding to the task to be processed.

14. The method according to claim 13, wherein: The sparsely representing the features to be processed based on the scene category corresponding to the task to be processed includes: In response to the scenario category being a causal scenario, dividing the mask matrix into two mutually non-intersecting first intervals and second intervals along a diagonal of the mask matrix, and all elements in the first interval are masked; and The mask endpoint positions within the second interval are used to perform a sparse representation on the feature to be processed.

15. The method according to claim 13, wherein: The sparsely representing the features to be processed based on the scene category corresponding to the task to be processed includes: In response to the scene category being a non-causal scene, dividing the mask matrix into two mutually non-intersecting third and fourth intervals along a diagonal of the mask matrix; and The feature to be processed is sparsely represented by using the mask endpoint position in the third interval and the mask endpoint position in the fourth interval.

16. A task execution device for a large language model, comprising: A judgment unit, configured to determine a target attention task from a plurality of attention tasks to be processed based on a sparse representation corresponding to the feature to be processed; wherein the target attention task is a task corresponding to a non-entire mask region of the feature to be processed; the sparse representation is used to characterize a mask position of the feature to be processed; the mask position characterizes a mask endpoint position within at least two mutually non-intersecting intervals in a mask matrix corresponding to the feature to be processed; and A computing unit is used to execute the target attention task and obtain attention features.

17. The device according to claim 16, wherein: The judging unit comprises: A first determination subunit is configured to determine, based on a sparse representation corresponding to the features to be processed, mask intervals corresponding to the plurality of attention tasks to be processed; and The second determination subunit is used to determine a target attention task from a plurality of attention tasks to be processed based on the mask interval and using the judgment unit.

18. The device according to claim 16, wherein: The first determining subunit is used to: For each attention task to be processed, determining a plurality of mask endpoint positions in a mask matrix corresponding to each attention task to be processed based on a sparse representation corresponding to the feature to be processed; as well as According to the multiple mask endpoint positions, a mask interval corresponding to each attention task to be processed is determined.

19. The device according to claim 18, wherein: The mask position is a starting mask row and an ending mask row of each column element in at least two mutually non-intersecting intervals in the mask matrix corresponding to the feature to be processed; the first determining subunit is used to: Based on the sparse representation corresponding to the feature to be processed, a starting mask row and an ending mask row of each column element in the mask matrix corresponding to each attention task to be processed are determined.

20. The device according to claim 19, wherein The first determining subunit is used to: Determining the terminating mask row of each column of elements as the terminating position of the mask interval; and The starting mask row of each column of elements is determined as the starting position of the mask interval.

21. The device according to claim 18, wherein The mask position is a starting mask column and an ending mask column of each row element in at least two mutually non-intersecting intervals in a mask matrix corresponding to the feature to be processed; the first determining subunit is used to: Based on the sparse representation corresponding to the feature to be processed, a starting mask column and an ending mask column of each row element in the mask matrix corresponding to each attention task to be processed are determined.

22. The device according to claim 21, wherein The first determining subunit is used to: Determine the end mask column of each row of elements as the end position of the mask interval; and The starting mask column of each row of elements is determined as the starting position of the mask interval.

23. The device according to any one of claims 17 to 20, wherein: The second determining subunit is used to: In response to the fact that the position of the element endpoint in the intermediate feature matrix corresponding to the attention task to be processed is not within the mask interval, using the judgment unit to determine that the attention task to be processed is the target attention task; The intermediate feature matrix is ​​obtained according to the query matrix and the key matrix corresponding to the attention task to be processed.

24. The device according to claim 23, wherein: The mask interval includes a mask end position and a mask start position; the second determining subunit is used to: In response to the fact that the element endpoint position in the intermediate feature matrix corresponding to the attention task to be processed is greater than the mask end position or less than the mask start position, the judgment unit is used to determine that the attention task to be processed is the target attention task.

25. The device according to any one of claims 16 to 24, wherein: The computing unit comprises: a reading subunit, configured to read, using a computing unit, at least one query matrix, at least one key matrix, at least one value matrix, and at least one mask matrix corresponding to the target attention task from a target storage unit; and A computing subunit is used to perform the target attention task using the target computing unit according to the at least one query matrix, the at least one key matrix, the at least one value matrix and the at least one mask matrix to obtain the attention feature.

26. The device according to claim 25, wherein The computing subunit is used for: Obtaining a first intermediate feature according to the transposition of the query matrix and the key matrix; Obtaining a second intermediate feature according to the first intermediate feature and the mask matrix; Processing the second intermediate feature using an activation function to obtain an activation feature matrix; as well as The attention feature is obtained according to the activation feature matrix and the key matrix.

27. The device according to any one of claims 16 to 26, further comprising: A blocking unit, used to perform a blocking task, to block the parameter matrix corresponding to the feature to be processed based on the length of the parameter matrix corresponding to the feature to be processed and the number of registers, to obtain a parameter matrix corresponding to each attention task to be processed; The parameter matrix includes: a query matrix, a key matrix, a value matrix and a mask matrix; as well as A target storage unit is used to store the query matrix, the key matrix, the value matrix and the mask matrix corresponding to each attention task to be processed.

28. The device according to any one of claims 16 to 26, further comprising: A sparse representation unit is used to perform a sparse representation task to sparsely represent the features to be processed based on a scene category corresponding to the task to be processed.

29. The device according to claim 28, wherein The sparse representation unit comprises: a first division subunit, configured to, in response to the scene category being a causal scene, divide the mask matrix into two mutually non-intersecting first intervals and a second interval along a diagonal of the mask matrix, and all elements in the first interval are masked; and The first representation subunit is used to perform sparse representation on the feature to be processed by using the mask endpoint position in the second interval.

30. The device according to claim 28, wherein The sparse representation unit comprises: a second division subunit, configured to divide the mask matrix into two mutually non-intersecting third intervals and fourth intervals along a diagonal of the mask matrix in response to the scene category being a non-causal scene; and The second representation subunit is used to perform sparse representation on the feature to be processed by using the mask endpoint position in the third interval and the mask endpoint position in the fourth interval.

31. A task execution device for a large language model, comprising: The device according to any one of claims 16 to 30.

32. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 15.

33. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-15.

34. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 15.

Citation Information

Cited By

  • Transform-based natural language processing method

    CN120045667A