Neural circuit attention mechanism simulation method based on linear time delay
By decomposing and optimizing the matrix multiplication in the self-attention model, rewriting and integrating it into the neural circuit, the problem of incompatibility between the attention mechanism and traditional spiking neurons is solved, and efficient neural circuit attention mechanism simulation is achieved. Improved the stability and applicability of the model.
Patent Information
- Application Number
- CN202410641230.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
AI Technical Summary
In the existing technology, the attention mechanism is incompatible with the firing mechanism of traditional spiking neurons, which affects the generalization and versatility of the intelligent model, making it difficult to efficiently migrate the self-attention model to neuromorphic hardware.
By decomposing the matrix multiplication in the self-attention model, using hidden state values to optimize product calculations, rewriting the matrix multiplication, and integrating the rewriting and correction operation processes in the neural circuit, a linear delay neural circuit attention mechanism is achieved simulation.
It realizes the migration of complex large-scale attention networks to low-power neural circuits, ensures numerical equivalence and uniformity of impulse firing, reduces the inference delay of the spatiotemporal attention mechanism, and improves the stability and applicability of the model.
Smart Images

Figure CN118607602A
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning, and in particular to a method for simulating a linear-delay neural circuit attention mechanism. Background Art
[0002] In today's information age, the rapid development of artificial intelligence and machine learning technologies has made it possible to process large-scale data and solve complex tasks. In this context, the attention mechanism, as a method to simulate human information processing, has attracted widespread attention and research. The attention mechanism can effectively improve the performance and efficiency of neural networks by simulating the human attention allocation process. It enables the neural network to automatically select and focus on important information related to the current task when processing input data, thereby improving the accuracy and robustness of the model. In recent years, the Transformer model, as a deep learning model based on the self-attention mechanism, has achieved leading performance in natural language processing, machine translation, and speech recognition. By introducing the self-attention mechanism, the Transformer can simultaneously consider all position information in the input sequence, thereby capturing global correlation. This mechanism enables the Transformer model to better handle long-distance dependencies and contextual information, greatly improving the model's expressiveness.
[0003] Neural circuits simulate the working principle of biological nervous systems. They are composed of a large number of neurons and their synapses, use pulses as signal carriers, and have good biological interpretability as well as low power consumption characteristics such as high quantization, high sparsity, event-driven, and parallelization. However, traditional neural circuit design does not take the attention mechanism into consideration, and shows performance shortcomings when dealing with large-scale data and complex tasks. Therefore, introducing the attention mechanism into neural circuit design has certain application value. On the one hand, by automatically selecting and focusing on important information related to the current task, the attention mechanism can improve the computational efficiency and accuracy of neural circuits; on the other hand, the sparsity and binary characteristics of pulses in neural circuits can help reduce the energy consumption of information processing systems.
[0004] At present, there has been some progress in the combination of attention mechanism and neural circuit design. However, since the variable multiplication in the attention mechanism is not compatible with the firing mechanism of traditional pulse neurons, these works all require synaptic weight training based on specific task samples, which destroys the generalization and versatility of intelligent models. Summary of the invention
[0005] The present application aims to solve one of the technical problems in the related art at least to some extent.
[0006] To this end, the first objective of this application is to propose a linear-delay neural circuit attention mechanism simulation method so as to migrate the self-attention model to neuromorphic hardware in a high-precision and low-energy manner.
[0007] The second purpose of this application is to propose a linear delay neural circuit attention mechanism simulation device.
[0008] The third objective of the present application is to provide an electronic device.
[0009] A fourth objective of the present application is to provide a computer-readable storage medium.
[0010] A fifth object of the present application is to provide a computer program product.
[0011] To achieve the above-mentioned purpose, the first embodiment of the present application proposes a method for simulating a linear-delay neural circuit attention mechanism, including:
[0012] Decomposing the matrix multiplication in the self-attention model and rewriting the matrix multiplication using hidden state values for product calculation optimization;
[0013] According to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated, and the instantaneous product is corrected according to the constructed global estimator;
[0014] The rewriting operation process and the correction operation process involved in the above steps are integrated into the neural circuit.
[0015] Optionally, decomposing the matrix multiplication in the self-attention model and optimizing the product calculation using hidden state values to rewrite the matrix multiplication includes:
[0016] For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit that introduces the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfies That is, the floating-point input value is equal to the mean value of the pulse input at all time steps, and the expression of the decomposed matrix multiplication is:
[0017]
[0018] Among them, A and B represent two matrices given in matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train;
[0019] The matrix multiplication is rewritten by optimizing the product calculation using the hidden state value as follows:
[0020]
[0021] in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
[0022]
[0023]
[0024] Optionally, the calculating the instantaneous product obtained at each time step according to the rewritten matrix multiplication, and correcting the instantaneous product according to the global estimator, comprises:
[0025] Assume that the input matrix is uniform and satisfies A t ≈A,B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated, and the expression is:
[0026]
[0027] Among them, P t is the instantaneous product obtained at time step t;
[0028] Constructing a real-time global estimator Ψ t , the expression is:
[0029]
[0030] According to the goal of making the current output level consistent with the mean value of the output of all current time steps, the instantaneous product P t Modified to The expression is:
[0031]
[0032] in, Represents the matrix P t The accumulated hidden state value of is expressed as:
[0033]
[0034] After correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
[0035] To achieve the above-mentioned purpose, the second embodiment of the present application proposes a linear delay neural circuit attention mechanism simulation device, including:
[0036] A rewriting module, for decomposing the matrix multiplication in the self-attention model, and rewriting the matrix multiplication by optimizing the product calculation using the hidden state value;
[0037] A correction module, used for calculating the instantaneous product obtained at each time step according to the rewritten matrix multiplication, and correcting the instantaneous product according to the constructed global estimator;
[0038] The migration module is used to integrate the rewriting operation process and the correction operation process involved in the above steps into the neural circuit.
[0039] Optionally, the rewriting module is used to:
[0040] For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit that introduces the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfies That is, the floating-point input value is equal to the mean value of the pulse input at all time steps, and the expression of the decomposed matrix multiplication is:
[0041]
[0042] Among them, A and B represent two matrices given in matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train;
[0043] The matrix multiplication is rewritten by optimizing the product calculation using the hidden state value as follows:
[0044]
[0045] in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
[0046]
[0047] Optionally, the correction module is used to:
[0048] Assume that the input matrix is uniform and satisfies A t ≈A,B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated, and the expression is:
[0049]
[0050] Among them, P t is the instantaneous product obtained at time step t;
[0051] Constructing a real-time global estimator Ψ t , the expression is:
[0052]
[0053] According to the goal of making the current output level consistent with the mean value of the output of all current time steps, the instantaneous product P t Modified to The expression is:
[0054]
[0055] in, Represents the matrix P t The accumulated hidden state value of is expressed as:
[0056]
[0057] After correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
[0058] To achieve the above-mentioned purpose, the third aspect of the present application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0059] The memory stores computer-executable instructions;
[0060] The processor executes the computer-executable instructions stored in the memory to implement the method as described in any one of the first aspects above.
[0061] To achieve the above-mentioned purpose, the fourth aspect embodiment of the present application proposes a computer-readable storage medium, in which computer execution instructions are stored. When the computer execution instructions are executed by a processor, they are used to implement the method as described in any one of the above-mentioned first aspects.
[0062] To achieve the above-mentioned purpose, the fifth aspect of the present application proposes a computer program product, including a computer program, which, when executed by a processor, implements the method as described in any one of the above-mentioned first aspects.
[0063] The technical solution provided by the embodiments of the present application brings at least the following beneficial effects:
[0064] The equivalent modeling of the attention mechanism is completed in the neural circuit, which helps to directly migrate complex large-scale attention networks to low-power neural circuits; the splitting and correction processing of the multiplication between variables in the attention mechanism takes into account the uniformity of pulse emission while ensuring numerical equivalence, providing a guarantee for the stable representation of the neural circuit; by extracting the accumulated hidden state values of the variables to optimize the multiplication operation in a recursive form, the inference delay of the spatiotemporal attention mechanism is effectively compressed from the quadratic complexity to the linear complexity; and the simulation scheme of the attention mechanism can be reused and extended to other modules involving multiplication operations between variables, further providing possibilities for the neural circuit implementation of mainstream intelligent models.
[0065] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0067] Figure 1 It is a flow chart of a method for simulating a linear-delay neural circuit attention mechanism according to an embodiment of the present application;
[0068] Figure 2 is a schematic diagram of product splitting and correction according to an embodiment of the present application;
[0069] Figure 3 It is a schematic diagram of a variable multiplication module using a simulation method in an attention mechanism application architecture according to an embodiment of the present application;
[0070] Figure 4 is a flow chart of calculation of Query-Key product according to an embodiment of the present application;
[0071] Figure 5is a schematic diagram of Query-Key product under continuous value input and pulse input according to an embodiment of the present application;
[0072] Figure 6 is a schematic diagram of the Query-Key product before and after correction under pulse input according to an embodiment of the present application;
[0073] Figure 7 It is the test result on a common data set after being integrated into an intelligent model according to the embodiment of the present application;
[0074] Figure 8 It is a block diagram of a linear delay neural circuit attention mechanism simulation device according to an embodiment of the present application;
[0075] Fig. 9 It is a block diagram of an electronic device. DETAILED DESCRIPTION
[0076] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0077] The following describes a method and device for simulating a linear delay neural circuit attention mechanism according to an embodiment of the present application with reference to the accompanying drawings.
[0078] Figure 1 is a flow chart of a method for simulating a linear delay neural circuit attention mechanism according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0079] Step 101, decompose the matrix multiplication in the self-attention model, and use the hidden state value to optimize the product calculation to rewrite the matrix multiplication.
[0080] As a possible implementation method, the present application first decomposes the core part of the attention operation module, the matrix multiplication. For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit introducing the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfies That is, the floating-point input value is equal to the mean of the pulse input over all time steps.
[0081] Then, the expression of the decomposed matrix multiplication is:
[0082]
[0083]
[0084] Among them, A and B represent two matrices given in matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train.
[0085] It can be understood that in the above multiplication formula, there are a total of T 2 In order to reduce the number of product calculations to linear complexity, this application uses the hidden state value in the neural network as an optimization factor for intermediate calculations to reduce the complexity of direct matrix multiplication.
[0086] In one embodiment of the present application, the product calculation is optimized using hidden state values to rewrite the matrix multiplication, which is expressed as:
[0087]
[0088] in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
[0089]
[0090] Therefore, after extracting the hidden state value, the number of product terms in the original formula is compressed to O(T).
[0091] Step 102, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated, and the instantaneous product is corrected according to the constructed global estimator.
[0092] Assume that the input matrix is uniform and satisfies A t ≈A,B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is:
[0093]
[0094] Among them, P t is the instantaneous product obtained at time step t.
[0095] It should be noted that in the neural circuit, this instantaneous product will be accumulated on the membrane potential step by step. Since the pulse neurons in the neural circuit currently use hardware-friendly fixed thresholds, this accumulation method will make the linearly growing membrane potential unable to be effectively released in the later stage of the time window. For this reason, this application introduces a real-time global estimator Ψ t , use the global estimator to correct the current output result to avoid the linear growth of membrane potential resulting in a large amount of accumulation that cannot be released.
[0096] Specifically, the global estimator Ψ t The expression is:
[0097]
[0098] As long as the current output is t The magnitude is consistent, that is, uniformity can be guaranteed. At the same time, in order to ensure that the mean value of the output of all current time steps is consistent with Ψ t The values are consistent, and the instantaneous product P t Modified to The expression is:
[0099]
[0100] in, Represents the matrix P t The accumulated hidden state value of is expressed as:
[0101]
[0102] It is understandable that if Figure 2 As shown, after correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
[0103] Step 103, integrating the rewriting operation process and the correction operation process involved in the above steps into the neural circuit.
[0104] Finally, in one embodiment of the present application, the above basic operations are integrated into the neural circuit to realize the migration of the attention mechanism in each operation module.
[0105] It is understandable that integrating the above-mentioned optimized computing process (including the decomposed multiplication operation and correction process) into a specially designed neural circuit means that it is necessary to design a hardware architecture that can efficiently perform these customized computing tasks, which may involve customized integrated circuits (ASIC), FPGA or other programmable logic devices, which will not be described in detail in this application.
[0106] It should be noted that in the Transformer architecture, in addition to the Query-Key-Value product part in the self-attention module involving multiplication between variables, some other nonlinear modules, such as LayerNorm and Softmax, also involve multiplication between variables, and the above basic operations can also be applied to these modules.
[0107] In one possible embodiment, a schematic diagram of a variable multiplication module using a simulation method in an attention mechanism application architecture is shown in FIG. Figure 3 shown.
[0108] In one embodiment of the present application, Figure 4 As shown, with QK in the self-attention module T Taking matrix product as an example, the simulation implementation scheme of the neural circuit attention mechanism of this application is explained. For ease of representation, matrix M is used instead of K T .
[0109] Step 1: Encode the floating point input X into a pulse input {X t |t=0,1,…T}, and satisfies X t Each element in is either 0 or 1.
[0110] Step 2: At each time step, calculate the matrix Q t 、M t .in:
[0111] Q t =X t W Q ,M t =(X t W K ) T
[0112] Step 3: At each time step, calculate Q t 、M t The accumulated hidden state value of . Among them:
[0113]
[0114]
[0115] Step 4: At each time step, calculate P t and its accumulated hidden state value
[0116]
[0117]
[0118] Step 5: At each time step, modify P t , that is, calculation
[0119]
[0120] Step 6: Output to the next node of the neural circuit and repeat steps 2-5 until t=T.
[0121] It can be understood that according to the scheme implemented in the above-mentioned embodiments, the present application realizes equivalent modeling through multiplication decomposition, and implicitly simplifies the square operation into a linear operation by using the accumulated value. In order to enable the output value to be effectively released in the subsequent neural circuit, the present application further estimates and corrects the output to alleviate the membrane potential hoarding problem caused to the post-neuron. Although the present application simulates and models the attention mechanism, it can be applied to all special operation units involving multiplication between variables, including various units in the mainstream intelligent model Transformer based on attention, thereby expanding the scope of application and application value of this method.
[0122] in addition, Figure 5 The results of the query-key product operation completed according to the implementation plan are shown. From the comparison of the heat map, it can be seen that although certain information quantization and truncation are caused in the pulse process, the correlation distribution trend of the simulation results is basically consistent with the actual continuous value calculation results. This also shows that the simulation method of this application is numerically equivalent.
[0123] Figure 6 The output results of each time step in the process of completing the Query-Key product operation according to the implementation plan are shown. It can be seen that without correction, the input received by subsequent neurons will increase linearly, resulting in membrane potential accumulation. After correction, although the initial input is still small, it will be adjusted immediately in the subsequent time steps, and the overall change is relatively uniform.
[0124] Furthermore, this method is integrated into the existing pre-trained artificial intelligence large model. Taking the pre-trained ViT-B / 32 as an example, the continuous value input is encoded as a pulse signal, and the modules involving multiplication between variables, namely the matrix correlation operation, Softmax operation and LayerNorm module in the multi-head self-attention module, are rewritten according to the simulation method of this application. Tests are conducted on common image datasets, with the time step T = 32. The classification accuracy of the converted model on CIFAR-10 and CIFAR-100 is as follows: Figure 7 shown.
[0125] It can be seen that without correction, the accuracy loss is more serious, but after correction, the accuracy loss is almost negligible because the hoarding potential is controlled, which further verifies the effectiveness and scalability of this method.
[0126] Figure 8 1 is a block diagram of a linear delay neural circuit attention mechanism simulation device 10 according to an embodiment of the present application, including:
[0127] A rewriting module 100 is used to decompose the matrix multiplication in the self-attention model and optimize the product calculation using the hidden state value to rewrite the matrix multiplication;
[0128] A correction module 200, for calculating the instantaneous product obtained at each time step according to the rewritten matrix multiplication, and correcting the instantaneous product according to the constructed global estimator;
[0129] The migration module 300 is used to integrate the rewriting operation process and the correction operation process involved in the above steps into the neural circuit.
[0130] Optionally, the rewriting module 100 is used to:
[0131] For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit that introduces the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfies That is, the floating-point input value is equal to the mean value of the pulse input at all time steps, and the expression of the decomposed matrix multiplication is:
[0132]
[0133] Among them, A and B represent two matrices given in matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train;
[0134] The product calculation optimization using hidden state values can be rewritten as matrix multiplication, expressed as:
[0135]
[0136] in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
[0137]
[0138]
[0139] Optionally, the correction module 200 is used to:
[0140] Assume that the input matrix is uniform and satisfies A t ≈A,B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated, and the expression is:
[0141]
[0142] Among them, P t is the instantaneous product obtained at time step t;
[0143] Constructing a real-time global estimator Ψ t , the expression is:
[0144]
[0145] According to the goal of making the current output level consistent with the mean value of the output of all current time steps, the instantaneous product P t Modified to The expression is:
[0146]
[0147] in, Represents the matrix P t The accumulated hidden state value of is expressed as:
[0148]
[0149] After correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
[0150] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0151] Fig. 9A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, 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 application described and / or required herein.
[0152] like Fig. 9 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0153] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0154] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 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 701 performs the various methods and processes described above, such as the voice instruction response method. For example, in some embodiments, the voice instruction response method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the voice instruction response method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the voice instruction response method in any other appropriate manner (e.g., by means of firmware).
[0155] 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), load 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.
[0156] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can 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, implements the functions / operations specified in the flow chart and / or block diagram. The program code can 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.
[0157] In the context of the present application, 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 equipment, 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.
[0158] 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).
[0159] The systems and techniques described herein can be implemented in a computing system that includes backend 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 frontend 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 backend components, middleware components, or frontend components. The components of the system can 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), the Internet, and a blockchain network.
[0160] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server 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.
[0161] 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 application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution of this application can be achieved, and this document is not limited here.
[0162] The above specific implementations do not constitute a limitation on the protection scope of this application. 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 modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A method for simulating a neural circuit attention mechanism with linear delay, characterized in that: include: Decomposing the matrix multiplication in the self-attention model and rewriting it by optimizing the product calculation using hidden state values; Calculate the instantaneous product obtained at each time step according to the rewritten matrix multiplication, and correct the instantaneous product according to the constructed global estimator; The rewriting operation process and the correction operation process involved in the above steps are integrated into the neural circuit.
2. The method according to claim 1, characterized in that The decomposing of the matrix multiplication in the self-attention model and optimizing the product calculation using the hidden state value to rewrite the matrix multiplication include: For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit that introduces the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfy That is, the floating-point input value is equal to the mean of the pulse input at all time steps, and the expression of the decomposed matrix multiplication is: Among them, A and B represent the two matrices given in the matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train; The matrix multiplication is rewritten by optimizing the product calculation using the hidden state value as follows: in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
3. The method according to claim 2, characterized in that The instantaneous product obtained by calculating the matrix multiplication at each time step according to the rewritten matrix multiplication and correcting the instantaneous product according to the global estimator comprises: Assume that the input matrix is uniform and satisfies A t ≈A, B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated as: Among them, P t is the instantaneous product obtained at time step t; Constructing a real-time global estimator Ψ t , the expression is: According to the goal of making the current output magnitude consistent with the mean value of the output of all current time steps, the instantaneous product P t Modified to The expression is: in, Represents the matrix P t The accumulated hidden state value is expressed as: After correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
4. A linear delay neural circuit attention mechanism simulation device, characterized in that: include: A rewriting module, configured to decompose the matrix multiplication in the self-attention model and rewrite the matrix multiplication by optimizing the product calculation using hidden state values; A correction module, configured to calculate the instantaneous product obtained at each time step according to the rewritten matrix multiplication, and correct the instantaneous product according to the constructed global estimator; The migration module is used to integrate the rewriting operation process and the correction operation process involved in the above steps into the neural circuit.
5. The device according to claim 4, characterized in that The rewriting module is used to: For the matrix multiplication of the form P = A × B in the self-attention model, in the neural circuit that introduces the time dimension, the pulse matrix is input in sequence at each time step to form a pulse sequence {A t |t=1,2,…,T}, and satisfy That is, the floating-point input value is equal to the mean of the pulse input at all time steps, and the expression of the decomposed matrix multiplication is: Among them, A and B represent the two matrices given in the matrix multiplication P, A t represents the matrix at time step t, B t With A t Similarly, T represents the length of the pulse train; The matrix multiplication is rewritten by optimizing the product calculation using the hidden state value as follows: in, Represents the matrix A in the current product term t The accumulated hidden state value of Represents the matrix B t The accumulated hidden state value of and It can be obtained recursively through the calculation results of the previous step, and the expression is:
6. The device according to claim 5, characterized in that The correction module is used to: Assume that the input matrix is uniform and satisfies A t ≈A, B t ≈B, according to the rewritten matrix multiplication, the instantaneous product obtained at each time step is calculated as: Among them, P t is the instantaneous product obtained at time step t; Constructing a real-time global estimator Ψ t , the expression is: According to the goal of making the current output magnitude consistent with the mean value of the output of all current time steps, the instantaneous product P t Modified to The expression is: in, Represents the matrix P t The accumulated hidden state value is expressed as: After correction, all time steps The mean is That is, the values are consistent, and the modified instantaneous product output That is, the magnitude is consistent.
7. An electronic device, characterized in that: include: a processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 3.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 3 when executed by a processor.
9. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 3 when executed by a processor.
