A long sequence modeling method, device, equipment, medium and product

By optimizing the training of the AI ​​model and reducing its memory consumption in long-sequence tasks, it solves the problem of huge memory consumption of existing AI models when processing long-sequence tasks, and improves the model's processing power and computing resource utilization efficiency.

CN118261268BActive Publication Date: 2024-10-11HUBEI LUOJIA ZHIYAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410397604.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-03
Publication Date
2024-10-11
Estimated Expiration
2044-04-03

AI Technical Summary

Technical Problem

Existing AI models consume huge amounts of memory when processing long sequence tasks, which limits their application in related fields.

Method used

By preprocessing the initial long sequence data, using the pre-configured model to be trained and initialization conditions, performing model training according to the preset training rules, optimizing model parameters, and reducing the computational complexity of the self-attention mechanism from O(n2) to O (n), linearized computation and storage requirements.

Benefits of technology

Significantly improves the model's ability to process long sequences and reduces computing resource (video memory) consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118261268B_ABST
    Figure CN118261268B_ABST
Patent Text Reader

Abstract

The present disclosure provides a long sequence modeling method, device, equipment, medium and product. The long sequence modeling method includes: preprocessing the acquired initial long sequence data to obtain sample data; using the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, performing model training according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks. The long sequence modeling method provided by the embodiment of the present disclosure can improve the model's ability to process long sequences while reducing the consumption of computing resources (video memory).
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, and in particular to a long sequence modeling method, a long sequence modeling device, an electronic device, a non-transitory computer-readable storage medium, and a computer program product. Background Art

[0002] With the continuous advancement of artificial intelligence (AI) technology, the application scenarios of AI models are becoming more and more extensive (for example, natural language understanding, time series prediction, speech recognition, etc.), and the complexity of the tasks processed is also increasing.

[0003] However, the AI ​​models in current related technologies have the problem of huge video memory consumption when processing long sequence tasks, which limits the application of AI models in fields related to long sequences.

[0004] Therefore, how to provide a modeling method suitable for long sequence tasks so that the AI ​​model created by this method can reduce video memory consumption when processing long sequence tasks has become an urgent problem that needs to be solved. Summary of the invention

[0005] The present invention provides a long sequence modeling method to solve the defect of the AI ​​model in the prior art that the video memory consumption is huge when processing long sequence tasks.

[0006] The present disclosure provides a long sequence modeling method, comprising:

[0007] Preprocess the acquired initial long sequence data to obtain sample data;

[0008] Utilizing the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, model training is performed according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0009] The present disclosure also provides a long sequence modeling device, comprising:

[0010] The data preprocessing module is configured to: preprocess the acquired initial long sequence data to obtain sample data;

[0011] The model training module is configured to: utilize the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, perform model training according to preset training rules, and obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0012] The present disclosure also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the long sequence modeling method described above is implemented.

[0013] The present disclosure also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the long sequence modeling methods described above.

[0014] The present disclosure also provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the long sequence modeling methods described above.

[0015] As described above, by using the long sequence modeling method provided by the embodiment of the present disclosure, the relevant model can be optimized and trained, so as to obtain optimized model parameters; and then when the long sequence model is applied in the inference stage, the complexity of the model attention mechanism calculation can be reduced from O(n 2 ) to O(n) — that is, ‘linearizing’ the relationship between the computational and storage requirements of the AI ​​model’s self-attention mechanism and the length of the task sequence — thereby greatly improving the model’s ability to process long sequences while reducing the consumption of computing resources (graphics memory). BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the present disclosure or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0017] Figure 1 It is one of the flowcharts of the long sequence modeling method provided by the present disclosure;

[0018] Figure 2 This is the second flow chart of the long sequence modeling method provided by the present disclosure;

[0019] Figure 3 This is the third flow chart of the long sequence modeling method provided by the present disclosure;

[0020] Figure 4 is a schematic diagram of the structure of a long sequence modeling device provided by the present disclosure;

[0021] Figure 5 It is a schematic diagram of the structure of an electronic device provided by the present disclosure. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the technical solutions in the present disclosure will be clearly and completely described below in conjunction with the drawings in the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0023] Summary of the invention concept:

[0024] After research, the inventors of the present disclosure discovered that the cause of the aforementioned prior art problems is that when the existing AI model processes long sequence tasks, the computational and storage requirements of its self-attention mechanism grow nonlinearly (for example, quadratically) with the length of the task sequence; therefore, it leads to huge consumption of video memory, thereby limiting the application of AI models in fields related to long sequences.

[0025] Based on this finding, the inventors conducted further searches and found that the processing method in the related art is to adapt to the limitations of the model by truncating the sequence length, but this method may damage the integrity of the sequence and the coherence of the contextual information.

[0026] To this end, the inventors considered "linearizing the relationship between the computation and storage requirements of the self-attention mechanism of the AI ​​model and the length of the task sequence without limiting the sequence length" as the direction and focus of the invention. In view of this, the long sequence modeling scheme disclosed in the present invention is proposed.

[0027] Example:

[0028] The long sequence modeling solution disclosed in the present invention is described below in conjunction with the accompanying drawings.

[0029] Figure 1 is a flow chart of a long sequence modeling method provided by an exemplary embodiment of the present disclosure. This embodiment can be applied to electronic devices (e.g., servers or cloud computing platforms), such as Figure 1 As shown, the long sequence modeling method includes the following steps:

[0030] S110, preprocessing the acquired initial long sequence data to obtain sample data.

[0031] The present disclosure does not limit the data type of the "initial long sequence data", which may include but is not limited to natural language text, voice data, meteorological data, etc.

[0032] The specific implementation of the preprocessing will be described below and will not be repeated here.

[0033] Optionally, the execution subject (eg, server) of step S110 may communicate with the data terminal providing the initial long sequence data in a variety of available ways to obtain the data, for example, in a wired or wireless manner.

[0034] S120, using the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, perform model training according to preset training rules to obtain a long sequence model. Wherein, the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0035] As an optional example, the model to be optimized may select a conventional long sequence task model.

[0036] As described above, by using the long sequence modeling method provided by the embodiment of the present disclosure, the relevant model can be optimized and trained, so as to obtain optimized model parameters; and then when the long sequence model is applied in the inference stage, the complexity of the model attention mechanism calculation can be reduced from O(n 2 ) to O(n) — that is, ‘linearizing’ the relationship between the computational and storage requirements of the AI ​​model’s self-attention mechanism and the length of the task sequence — thereby greatly improving the model’s ability to process long sequences while reducing the consumption of computing resources (graphics memory).

[0037] As an optional implementation, Figure 1 Based on the examples, refer to Figure 2 , step S110 can be implemented in the following manner:

[0038] Step S1101, match the type of the initial long sequence data and determine the segmentation rule. Step S1102, segment the initial long sequence data based on the segmentation rule to obtain multiple sample elements. Step S1103, number the multiple sample elements to form a set of sample element sequences as the sample data.

[0039] Among them, when the current sample element is used as the sample input of the model, the next sample element directly adjacent to the current sample element is used as the sample true value according to the number, which is used to compare with the model output.

[0040] In step S1101, as an optional example, for example, if the type of the initial long sequence data is natural language text, then the "semantic segmentation rule" can be used as the segmentation rule. For another example, if the type of the initial long sequence data is speech data, then the relevant rules of "speech recognition" data preprocessing can be used as the segmentation rule.

[0041] In step S1103, as an optional example, the principle for numbering the plurality of sample elements is: numbering each sample element in sequence according to its original position in the "initial long sequence data".

[0042] For example, for the exemplary "initial long sequence data" "I want to be on the Spring Festival Gala", it can be divided into four words: "I", "want", "go", and "Spring Festival Gala"; according to the above numbering principle, "I" can be numbered 1, "want" can be numbered 2, "go" can be numbered 3, and "Spring Festival Gala" can be numbered 4.

[0043] As an optional implementation, Figure 1 , 2 Based on the embodiment, the pre-configured initialization conditions at least include: a pre-configured set of randomly initialized basis vectors B, a matrix W t , and a set of initial base state matrices and

[0044] Among them, the basis vector B, the initial basis state matrix and The number of vectors N is determined by the length of the initial long sequence, and the vector dimension d is determined by the dimension of the initial long sequence; the matrix W t Used to store query state, the initial state is empty; initial base state matrix The state vector after linear transformation of the dynamic cache key state; the initial base state matrix Used for dynamic cache value state after linear transformation of state vector; initial base state matrix and The matrix elements are initialized to 0.

[0045] It should be noted that the initialized basis vector B is a set of trainable basis vectors. During the training process, the basis vector B is used to transform and compress the states of the query, key, and value in the attention mechanism. By only fine-tuning the basis vector B, the original self-attention can be approximated. 2 ) complexity is reduced to O(n) complexity, greatly improving the model's ability to process long sequences while reducing the consumption of computing resources (especially video memory).

[0046] In addition, the randomly initialized basis vector B will be continuously optimized and adjusted during the training process, so the basis vector B at the end of the final model training is what we need.

[0047] As an optional implementation, Figure 1 , 2 Based on the embodiment, the pre-configured model to be trained includes: a pre-configured hidden state h corresponding to the input data t , initial query state weight matrix W q, initial key state weight matrix W k And the initial value state weight matrix W v .

[0048] As an optional implementation, Figure 1 , 2 Based on the embodiment, the model training is performed according to the preset training rules, including:

[0049] Step 1: According to the serial number of the sample element, determine the current sample element input into the model to be trained in the sample data.

[0050] As an optional example, assume that a set of sample elements currently being trained includes c1 to c5; wherein the subscript number of element c is its corresponding number.

[0051] Specifically, if the sample element of the previous training is c1, then the current sample elements can be determined to be c1 and c2 (in the previous training, after executing steps 1 to 5, the sample element c2 is fitted); if the sample elements of the previous training are c1 and c2, then the current sample elements can be determined to be c1, c2, c3; if the sample elements of the previous training are c1, c2, c3, then the current sample elements can be determined to be c1, c2, c3, c4; and so on. In other words, as the number of iterations increases, the number of sample elements in each iteration training also gradually increases, that is, the sample elements fitted in the previous training are added to the sample element sequence of this training as the current sample elements.

[0052] Step 2: According to the serial number of the sample element, determine the true value distribution of the sample element corresponding to the current sample element in the sample data.

[0053] Referring to the example of step 1, if the current sample elements are c1, c2, c3, the corresponding sample element true value distribution can be expressed as [0, 0, 0, 1, 0], which is used to determine the sample element true value from the sample data [c1, c2, c3, c4, c5]. In this distribution, the number 1 indicates valid and 0 indicates invalid. The number 1 in the distribution [0, 0, 0, 1, 0] corresponds to the sample element c4, which is used to perform cross entropy calculation with the sample element estimated distribution fitted based on the current sample elements c1, c2, c3.

[0054] Step 3: Input the current sample element into the model to be trained to obtain the estimated distribution of the sample element output by the model to be trained and the corresponding matrix W t .

[0055] As an optional example, in step 3, the data processing logic of the model to be trained may include the following steps 31 to 36:

[0056] Step 31: According to the current sample element, determine the query state, key state and value state corresponding to the current sample element.

[0057] Optionally, refer to Figure 3 , assuming the current sample element is c t , the query state q corresponding to the current sample element can be determined by the following calculation formula t , key state k t and the value state v t :

[0058]

[0059]

[0060]

[0061] Among them, h t Indicates that the current sample element is c t The corresponding hidden state; W q Indicates that the current sample element is c t The corresponding initial query state weight matrix; W k Indicates that the current sample element is c t The corresponding initial bond state weight matrix; W v Indicates that the current sample element is c t The corresponding initial value state weight matrix; represents a 1×d-dimensional real vector space;

[0062] Step 32: Determine the intermediate state w using the query state corresponding to the current sample element and the basis vector B t , and stored in the matrix W t .

[0063] Optionally, based on step 31, the intermediate state w can be determined by the following calculation formula: t :

[0064]

[0065]

[0066] Among them, W t-1 Indicates the intermediate state corresponding to the sample element before the current sample element; Represents an N×1-dimensional real vector space.

[0067] Step 33: Using the intermediate state w t, linearly transform the key state and value state corresponding to the current sample element, obtain the transformation results of the key state and the transformation results of the value state respectively, and update and store the transformation results of the key state into the base state matrix Update the transformation result of the value state and store it in the base state matrix

[0068] Specifically, step 33 can be performed using the following calculation formula:

[0069]

[0070]

[0071] w t =[w t1 , w t2 ,...,w tN ] T

[0072] k t =[k t1 , k t2 , …, k td ]

[0073]

[0074] in, A base state matrix representing the transformation result of the key state corresponding to the current sample element; A base state matrix representing the transformation result of the value state corresponding to the current sample element; A base state matrix representing a transformation result of a key state corresponding to a previous sample element adjacent to a current sample element is stored; represents a base state matrix storing the transformation result of the value state corresponding to the previous sample element adjacent to the current sample element; kt represents the key state; represents the real vector space of N×d dimensions; the symbol Represents the vector outer product.

[0075] It should be noted that the initial base state matrix It is only the initial state, which will be dynamically updated as the model training progresses. It can be understood that the above base state matrix is the initial base state matrix Gradually updated. Correspondingly, the above base state matrix is the initial base state matrix Gradually updated.

[0076] Step 34: Using the updated base state matrix Replace the base state matrix stored in video memory Using the updated base state matrix Replace the base state matrix stored in video memory

[0077] It can be understood that by executing step 34, huge video memory pressure in long sequence modeling can be avoided.

[0078] Step 35: Using the updated base state matrix and the base state matrix Determine the self-attention output value.

[0079] Optionally, refer to Figure 3 , step 35 can be implemented by the following calculation formula:

[0080]

[0081] in, Represents the self-attention output value; q t Indicates the query state corresponding to the current sample element; d indicates the vector dimension; represents a 1×d-dimensional real vector space; A base state matrix representing the transformation result of the key state corresponding to the current sample element; Represents the base state matrix that stores the transformation result of the value state corresponding to the current sample element.

[0082] Step 36: Determine the estimated distribution of the sample elements based on the self-attention output value.

[0083] Among them, it is assumed that the current sample element is c1~c t ; Then the estimated distribution of sample elements can be expressed as at least including c t+1 A series of elements distributed within it.

[0084] Step 4: Calculate the cross entropy loss between the estimated distribution of the sample elements and the true value distribution of the sample elements, taking the cross entropy loss as zero and the matrix W t Orthogonal constraint is used as the optimization goal, the estimated distribution of the sample elements is optimized by adjusting the basis vector B and the relevant parameters of the model to be trained, and steps 3 to 4 are iterated to save the corresponding basis vector B and the relevant parameters of the model to be trained at the end of the optimization;

[0085] Step 5: Iterate steps 1 to 4 until all the sample data are trained.

[0086] Optionally, the matrix W t The orthogonality constraint can be expressed as the following calculation form:

[0087]

[0088] Where I represents the identity matrix.

[0089] It should be noted that the regularization constraints selected in the embodiments of the present disclosure can ensure that the final basis state can effectively approximate the original self-attention.

[0090] As an optional example, in step 4, the parameters related to the model to be trained may include the initial query state weight matrix W q , the initial bond state weight matrix W k , initial value state weight matrix W v .

[0091] As described above, by using the long sequence modeling method provided by the embodiment of the present disclosure, the relevant model can be optimized and trained, so as to obtain optimized model parameters; and then when the long sequence model is applied in the inference stage, the complexity of the model attention mechanism calculation can be reduced from O(n 2 ) to O(n) — that is, ‘linearizing’ the relationship between the computational and storage requirements of the AI ​​model’s self-attention mechanism and the length of the task sequence — thereby greatly improving the model’s ability to process long sequences while reducing the consumption of computing resources (graphics memory).

[0092] The long sequence modeling device provided by the present disclosure is described below. The long sequence modeling device described below and the long sequence modeling method described above can be referenced to each other.

[0093] Figure 4 Schematic diagram of the structure of a long sequence modeling device provided by an exemplary embodiment of the present disclosure. Figure 4 As shown, the long sequence modeling device includes: a data preprocessing module 410, configured to: preprocess the acquired initial long sequence data to obtain sample data; a model training module 420, configured to: use the sample data, a preconfigured model to be trained and a preconfigured initialization condition, perform model training according to preset training rules, and obtain a long sequence model; wherein the preconfigured model to be trained includes a model to be optimized for processing long sequence tasks.

[0094] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the long sequence modeling method, which includes: preprocessing the acquired initial long sequence data to obtain sample data; using the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, performing model training according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0095] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0096] On the other hand, the present disclosure also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the long sequence modeling method provided by the above methods, which includes: preprocessing the acquired initial long sequence data to obtain sample data; using the sample data, a pre-configured model to be trained and a pre-configured initialization condition, performing model training according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0097] On the other hand, the present disclosure also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the long sequence modeling method provided by the above-mentioned methods, the method comprising: preprocessing the acquired initial long sequence data to obtain sample data; using the sample data, a pre-configured model to be trained and pre-configured initialization conditions, performing model training according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks.

[0098] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0099] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0100] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present disclosure.

Claims

1. A long sequence modeling method, It is characterized in that include: Preprocess the acquired initial long sequence data to obtain sample data; Using the sample data, the pre-configured model to be trained and the pre-configured initialization conditions, model training is performed according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks; The preprocessing of the acquired initial long sequence data to obtain sample data includes: Matching the type of the initial long sequence data and determining a segmentation rule; Based on the segmentation rule, the initial long sequence data is segmented to obtain a plurality of sample elements; Numbering the multiple sample elements to form a set of sample element sequences as the sample data; When the current sample element is used as the sample input of the model, the next sample element directly adjacent to the current sample element is used as the sample true value according to the number, which is used to compare with the model output; The pre-configured initialization conditions include at least: a pre-configured set of randomly initialized basis vectors B , a matrix , and a set of initial base state matrices and ;in, Basis Vectors B , the initial base state matrix and The number of vectors N Determined by the length of the initial long sequence, the vector dimension d Determined by the dimension of the initial long sequence; matrix Used to store query status, the initial status is empty; Initial base state matrix The state vector after linear transformation of dynamic cache key state; Initial base state matrix The state vector after linear transformation of the dynamic cache value state; Initial base state matrix and The matrix elements of are initialized to 0; The performing of model training according to preset training rules includes: Step 1: According to the serial number of the sample element, determine the current sample element input into the model to be trained in the sample data; Step 2: According to the number of the sample element, determine the true value distribution of the sample element corresponding to the current sample element in the sample data; Step 3: Input the current sample element into the model to be trained to obtain the estimated distribution of the sample element output by the model to be trained and the corresponding matrix ; Step 4: Calculate the cross entropy loss between the estimated distribution of the sample elements and the true value distribution of the sample elements, taking the cross entropy loss as zero and the matrix Orthogonality constraint is used as the optimization goal, by adjusting the basis vector B The estimated distribution of the sample elements is optimized with the relevant parameters of the model to be trained, and steps 3 to 4 are iterated to save the corresponding basis vectors at the end of the optimization. B Parameters related to the model to be trained; Step 5, iterate step 1 to step 4 until all the sample data are trained; Wherein, in step 3, the data processing logic of the model to be trained includes: According to the current sample element, determining a query state, a key state, and a value state corresponding to the current sample element; Using the query state corresponding to the current sample element and the basis vector B , determine the intermediate state , and store it in the matrix ; Using the intermediate state , linearly transform the key state and value state corresponding to the current sample element, obtain the transformation results of the key state and the transformation results of the value state respectively, and update and store the transformation results of the key state into the base state matrix , update and store the transformation result of the value state into the base state matrix ; Using the updated base state matrix Replace the base state matrix stored in video memory , using the updated base state matrix Replace the base state matrix stored in video memory ; Using the updated base state matrix and the base state matrix , determine the self-attention output value; Determine the estimated distribution of the sample elements according to the self-attention output value.

2. The long sequence modeling method according to claim 1, It is characterized in that The pre-configured model to be trained includes: a pre-configured hidden state corresponding to the input data, an initial query state weight matrix, an initial key state weight matrix, and an initial value state weight matrix.

3. A long sequence modeling device, It is characterized in that include: The data preprocessing module is configured to: preprocess the acquired initial long sequence data to obtain sample data; The model training module is configured to: utilize the sample data, the pre-configured model to be trained and the pre-configured initialization conditions to perform model training according to preset training rules to obtain a long sequence model; wherein the pre-configured model to be trained includes a model to be optimized for processing long sequence tasks; Wherein, the data preprocessing module is further configured as follows: Matching the type of the initial long sequence data and determining a segmentation rule; Based on the segmentation rule, the initial long sequence data is segmented to obtain a plurality of sample elements; Numbering the multiple sample elements to form a set of sample element sequences as the sample data; When the current sample element is used as the sample input of the model, the next sample element directly adjacent to the current sample element is used as the sample true value according to the number, which is used to compare with the model output; The pre-configured initialization conditions include at least: a pre-configured set of randomly initialized basis vectors B , a matrix , and a set of initial base state matrices and ;in, Basis Vectors B , the initial base state matrix and The number of vectors N Determined by the length of the initial long sequence, the vector dimension d Determined by the dimension of the initial long sequence; matrix Used to store query status, the initial status is empty; Initial base state matrix The state vector after linear transformation of dynamic cache key state; Initial base state matrix The state vector after linear transformation of the dynamic cache value state; Initial base state matrix and The matrix elements of are initialized to 0; Wherein, the model training module is further configured as follows: Step 1: According to the serial number of the sample element, determine the current sample element input into the model to be trained in the sample data; Step 2: According to the number of the sample element, determine the true value distribution of the sample element corresponding to the current sample element in the sample data; Step 3: Input the current sample element into the model to be trained to obtain the estimated distribution of the sample element output by the model to be trained and the corresponding matrix ; Step 4: Calculate the cross entropy loss between the estimated distribution of the sample elements and the true value distribution of the sample elements, taking the cross entropy loss as zero and the matrix Orthogonality constraint is used as the optimization goal, by adjusting the basis vector B The estimated distribution of the sample elements is optimized with the relevant parameters of the model to be trained, and steps 3 to 4 are iterated to save the corresponding basis vectors at the end of the optimization. B Parameters related to the model to be trained; Step 5, iterate step 1 to step 4 until all the sample data are trained; Wherein, in step 3, the data processing logic of the model to be trained includes: According to the current sample element, determining a query state, a key state, and a value state corresponding to the current sample element; Using the query state corresponding to the current sample element and the basis vector B , determine the intermediate state , and store it in the matrix ; Using the intermediate state , linearly transform the key state and value state corresponding to the current sample element, obtain the transformation results of the key state and the transformation results of the value state respectively, and update and store the transformation results of the key state into the base state matrix , update and store the transformation result of the value state into the base state matrix ; Using the updated base state matrix Replace the base state matrix stored in video memory , using the updated base state matrix Replace the base state matrix stored in video memory ; Using the updated base state matrix and the base state matrix , determine the self-attention output value; Determine the estimated distribution of the sample elements according to the self-attention output value.

4. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, it implements the long sequence modeling method as described in any one of claims 1 to 2.

5. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, it implements the long sequence modeling method as described in any one of claims 1 to 2.

6. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, it implements the long sequence modeling method as described in any one of claims 1 to 2.