Method, computing device and storage medium for generating binary mask tensor

By generating binary mask tensors in parallel and introducing correction coefficients, the problem of long generation process in the existing technology is solved, the efficiency is improved, the amount of calculation is reduced, and efficient binary mask tensor generation is achieved.

CN117591076BActive Publication Date: 2024-10-01北京壁仞科技开发有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing schemes for generating binary mask tensors are time-consuming and inefficient because random number generation is serial.

Method used

By determining the elements of each row in the binary mask tensor in parallel, using random seeds and probability to generate the binary mask tensor, introducing a correction coefficient to adjust the random number generation mechanism, and reducing the amount of calculation and improving the generation efficiency by generating the initial mask tensor.

Benefits of technology

It improves the generation efficiency of binary mask tensors, reduces the possibility of weak randomness, reduces the amount of calculation during the generation process, and achieves more efficient binary mask tensor generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117591076B_ABST
    Figure CN117591076B_ABST
Patent Text Reader

Abstract

Embodiments of the present invention relate to a method, a computing device, and a storage medium for generating a binary mask tensor. The method includes: receiving a first instruction indicating the probability of a binary mask tensor to be generated; determining a random seed for each row of the binary mask tensor to be generated in a first dimension; and determining the value of an element of the binary mask tensor to be generated in a second dimension based at least on the probability and the random seed, so as to generate the binary mask tensor. According to the method for generating a binary mask tensor provided by the present invention, the elements of each row in the binary mask tensor can be determined in parallel, thereby improving the generation efficiency of the binary mask tensor.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention generally relate to the field of large model training, and more specifically to a method, computing device, and storage medium for generating a binary mask tensor. Background Art

[0002] When training AI models (such as large language models like GPT), in order to avoid over-fitting during model training, you can use the dropout method to generate random binary mask tensors to mask the outputs of neurons in the model network layer, so that some neurons can be randomly discarded during the iterative process of model training.

[0003] In the existing scheme for generating binary mask tensors, a random number generation function is usually used to serially generate random numbers corresponding to each element in the initial tensor, and then a binary mask tensor is generated based on the dropout probability and the initial tensor, so as to obtain the binary mask tensor required for implementing the dropout method. However, in the above scheme, since the random numbers are generated serially, the generation process of the binary mask tensor is time-consuming and inefficient.

[0004] In summary, existing schemes for generating binary mask tensors are time-consuming and inefficient. Summary of the invention

[0005] In response to the above problems, the present invention provides a method, a computing device and a storage medium for generating a binary mask tensor, so that the elements of each row in the binary mask tensor can be determined in parallel, thereby improving the generation efficiency of the binary mask tensor.

[0006] According to a first aspect of the present invention, a method for generating a binary mask tensor is provided, comprising: receiving a first instruction indicating the probability of a binary mask tensor to be generated; determining a random seed for each row of the binary mask tensor to be generated in a first dimension; and determining the values ​​of elements of the binary mask tensor to be generated in a second dimension based at least on the probability and the random seed, so as to generate a binary mask tensor.

[0007] In some embodiments, the method for generating a binary mask tensor further comprises: determining a correction coefficient based on a first dimension of the binary mask tensor to be generated. In these embodiments, determining the value of an element of the binary mask tensor to be generated in a second dimension based on at least the probability and the random seed comprises: determining the value of an element of the binary mask tensor to be generated in the second dimension based on at least the probability, the random seed and the correction coefficient.

[0008] In some embodiments, determining the correction coefficient based on the first dimension of the binary mask tensor to be generated includes: in response to the first dimension of the binary mask tensor to be generated being greater than a predetermined correction threshold, determining the correction coefficient based on a uniform distribution function; and in response to the first dimension of the binary mask tensor to be generated being less than or equal to the predetermined correction threshold, determining the correction coefficient to be 1.

[0009] In some embodiments, the method for generating a binary mask tensor also includes: in response to receiving a first instruction, generating an initial mask tensor based on the first instruction, wherein the initial values ​​of all elements in the initial mask tensor are the same; determining positions of elements that need to be updated in the initial mask tensor based on the values ​​of the elements of the determined binary mask tensor to be generated in the second dimension; in response to determining the positions of elements that need to be updated in the initial mask tensor, updating the initial values ​​of the corresponding elements to generate a binary mask tensor.

[0010] In some embodiments, generating an initial mask tensor based on a first instruction includes: in response to the first instruction indicating that the probability of a binary mask tensor to be generated is greater than 0 and less than 0.5, generating a first initial mask tensor, and the initial value of all elements in the first initial mask tensor is 1; and in response to the first instruction indicating that the probability of a binary mask tensor to be generated is less than 1 and greater than 0.5, generating a second initial mask tensor, and the initial value of all elements in the second initial mask tensor is 0.

[0011] In some embodiments, determining the values ​​of elements in the second dimension of the binary mask tensor to be generated based at least on the probability and the random seed includes: in response to a first instruction indicating that the probability of the binary mask tensor to be generated is 0.5, iteratively determining the values ​​of the elements in the second dimension of the binary mask tensor to be generated based on a pseudo-random binary sequence algorithm.

[0012] In some embodiments, iteratively determining the value of an element in the second dimension of a binary mask tensor to be generated based on a pseudo-random binary sequence algorithm includes: determining the value of a current element of the binary mask tensor to be generated based on the last binary character of a current output obtained based on the pseudo-random binary sequence algorithm.

[0013] In some embodiments, the random seed determined for each row in the first dimension of the binary mask tensor to be generated is different.

[0014] According to a second aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the method of the first aspect of the present invention.

[0015] According to a third aspect of the present invention, there is provided a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method of the first aspect of the present invention.

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

[0017] The above and other features, advantages and aspects of the embodiments of the present invention will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements.

[0018] Figure 1 The principle of generating a binary mask tensor with a Bernoulli distribution is exemplarily shown.

[0019] Figure 2 A schematic diagram of a computing device for generating a binary mask tensor according to an embodiment of the present invention is shown.

[0020] Figure 3 A flowchart of a method for generating a binary mask tensor according to an embodiment of the present invention is shown.

[0021] Figure 4 A flowchart of a method for generating a binary mask tensor according to an embodiment of the present invention is shown.

[0022] Figure 5 A flowchart of a method for generating a binary mask tensor according to an embodiment of the present invention is shown.

[0023] Figure 6 A flowchart of an example method for generating a binary mask tensor according to an embodiment of the present invention is shown.

[0024] Figure 7 A block diagram of a computing device suitable for implementing embodiments of the present invention is schematically shown. DETAILED DESCRIPTION

[0025] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention 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 invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0026] As used herein, the term "including" and its variations mean open inclusion, i.e., "including but not limited to". Unless otherwise stated, the term "or" means "and / or". The term "based on" means "based at least in part on". The terms "an example embodiment" and "an embodiment" mean "at least one example embodiment". The term "another embodiment" means "at least one additional embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0027] As mentioned above, when training AI models (such as large language models like GPT), in order to avoid overfitting during model training, the dropout method can be used to generate random binary mask tensors to mask the neuron outputs in the model network layer, so that some neurons can be randomly discarded during the iterative process of model training.

[0028] Generally, the implementation of the dropout method includes: generating an initial tensor composed of random numbers; generating a binary mask tensor based on the generated initial tensor; and determining the output result based on at least the binary mask tensor. For example, an initial tensor with the same dimension as the neuron output is generated via a random number generation function (such as the rand function); setting a threshold according to a drop probability (for example, 0.2); re-determining the value corresponding to each element in the initial tensor based on the set threshold to obtain the corresponding binary mask tensor, for example, the value corresponding to the element greater than the threshold can be determined as 1, and the value corresponding to the element less than or equal to the threshold can be determined as 0; and the binary mask tensor is multiplied by the neuron output to obtain the final output result.

[0029] Figure 1 The principle of generating a binary mask tensor with a Bernoulli distribution is exemplarily shown.

[0030] First, use a function such as uniform to obtain uniformly distributed random numbers to generate a uniformly distributed tensor (i.e., the initial tensor). For example, Figure 1 As shown, the uniform function is used to obtain 9 random floating point numbers between 0 and 1, and a 3×3 uniformly distributed tensor is generated based on the 9 random floating point numbers obtained. r , where each random floating point number corresponds to an element in the uniformly distributed tensor. Typically, the size of the generated tensor is consistent with the size of the latent space variable to be masked.

[0031] Then, a binary mask tensor is generated based on the generated uniform distribution tensor. For example, it can be based on the probability provided by the user. p , which associates each element in the uniform distribution tensor with a probability provided by the user pThe comparison is performed, and the value of the corresponding element in the binary mask tensor to be generated is determined based on the comparison result. Figure 1 As shown, the probability provided by the user p The value of is 0.2. If the value of the random floating-point number corresponding to the element in the uniform distribution tensor is less than 0.2, the corresponding element in the binary mask tensor to be generated is set to 0; conversely, if the value of the random floating-point number corresponding to the element in the uniform distribution tensor is greater than or equal to 0.2, the corresponding element in the binary mask tensor to be generated is set to 1. For example, if the value of the random floating-point number corresponding to the element in the uniform distribution tensor is 0.66, the value of the element in the binary mask tensor corresponding to it is 1; if the value of the random floating-point number corresponding to the element in the uniform distribution tensor is 0.16, the value of the element in the binary mask tensor corresponding to it is 0. In this way, a binary mask tensor with a Bernoulli distribution (i.e., a 0-1 distribution) can be generated. It should be understood that the size of the binary mask tensor generated according to the uniform distribution tensor is the same as the size of the uniform distribution tensor.

[0032] Furthermore, the generated binary mask tensor can be scaled to compensate for the neuron outputs that are blocked by the mask. p Scales a binary masked tensor.

[0033] However, in the scheme for generating a binary mask tensor as shown above, a random number generation function serially generates a random number corresponding to each element in the initial tensor, which makes the generation process of the binary mask tensor time-consuming and inefficient.

[0034] In order to at least partially solve one or more of the above problems and other potential problems, an exemplary embodiment of the present invention proposes a scheme for generating a binary mask tensor. In the scheme, by receiving a first instruction indicating the probability of a binary mask tensor to be generated; determining a random seed for each row of the binary mask tensor to be generated in the first dimension; and determining the value of the element of the binary mask tensor to be generated in the second dimension based at least on the probability and the random seed, so that the elements of each row in the binary mask tensor can be determined in parallel, thereby speeding up the generation of the binary mask tensor and improving the generation efficiency of the binary mask tensor.

[0035] The following will be combined Figures 2 to 6 A scheme for generating a binary mask tensor according to an embodiment of the present invention is described in detail.

[0036] Figure 2 FIG. 2 shows a schematic diagram of a computing device 200 for generating a binary mask tensor according to an embodiment of the present invention. Figure 2As shown, the computing device 200 may include: a probability instruction receiving module 210, a random seed determination module 220, and a mask tensor determination module 230. It should be understood that the computing device 200 may also include additional modules not shown and / or the modules shown may be omitted, and the scope of the present invention is not limited in this respect.

[0037] Regarding the probability instruction receiving module 210, it can be used to receive an instruction indicating the probability of a binary mask tensor. According to an embodiment of the present invention, the probability instruction receiving module 210 is configured to: receive a first instruction indicating the probability of a binary mask tensor to be generated.

[0038] Regarding the random seed determination module 220, it can be used to generate a random seed so as to subsequently generate a random number based on the generated random seed. According to an embodiment of the present invention, the random seed determination module 220 is configured to: determine a random seed for each row in the first dimension of the binary mask tensor to be generated. For example, the random seed determination module 220 can determine the random seed based on a uniform distribution function or user input.

[0039] Regarding the mask tensor element determination module 230, it can be used to determine the value corresponding to each element in the mask tensor. According to an embodiment of the present invention, the mask tensor determination module 230 is configured to: determine the value of the element of the binary mask tensor to be generated in the second dimension based on at least the probability and the random seed, so as to generate the binary mask tensor.

[0040] like Figure 2 As shown, the computing device 200 may also optionally include: a correction coefficient determination module 240 , an initial mask tensor generation module 250 , and a mask tensor update module 260 .

[0041] Regarding the correction coefficient determination module 240, it can be used to determine the correction coefficient to adjust the random number generation mechanism, thereby reducing the possibility of reduced randomness of the generated random numbers. According to an embodiment of the present invention, the correction coefficient determination module 240 is configured to: determine the correction coefficient based on the first dimension of the binary mask tensor to be generated. For example, the correction coefficient determination module 240 can be configured to: in response to the first dimension of the binary mask tensor to be generated being greater than a predetermined correction threshold, determine the correction coefficient based on a uniform distribution function; and in response to the first dimension of the binary mask tensor to be generated being less than or equal to the predetermined correction threshold, determine the correction coefficient to be 1.

[0042] Regarding the initial mask tensor generation module 250, it can be used to generate an initial mask tensor so as to obtain a binary mask tensor based on at least the initial mask tensor. According to an embodiment of the present invention, the initial mask tensor generation module 250 is configured to: generate an initial mask tensor based on a first instruction, wherein the initial values ​​of all elements in the initial mask tensor are the same. For example, the initial mask tensor generation module 250 can be configured to generate an all-0 tensor or an all-1 tensor.

[0043] Regarding the binary mask tensor generation module 260, it can be used to update the initial mask tensor to generate a binary mask tensor. According to an embodiment of the present invention, the binary mask tensor generation module 260 is configured to: determine the position of the element that needs to be updated in the initial mask tensor based on the value of the element in the second dimension of the determined binary mask tensor to be generated; in response to determining the position of the element that needs to be updated in the initial mask tensor, update the initial value of the corresponding element to generate a binary mask tensor.

[0044] Figure 3 1 shows a flow chart of a method 300 for generating a binary mask tensor according to an embodiment of the present invention. The method 300 may be performed as follows: Figure 7 The method 300 is executed at the electronic device 700. It should be understood that the method 300 may further include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0045] At step 302 , a first instruction indicating a probability of a binary mask tensor to be generated is received by computing device 200 .

[0046] The probability of generating a binary mask tensor (which can be represented by " p ”), which is the dropout probability, which can indicate the probability that a neuron is randomly discarded during the iteration of model training. Usually, the probability of the binary mask tensor to be generated is p The value range of is between 0 and 1, for example, 0.1, 0.2, 0.5, 0.8, etc. The probability of the binary mask tensor to be generated p The value of may be related to the model data type, task, etc. being trained. According to an embodiment of the present invention, the probability of the binary mask tensor to be generated is p Can be determined by the user to make the probability of the generated binary mask tensor controllable.

[0047] In step 304 , the computing device 200 determines a random seed for each row in the first dimension of the binary mask tensor to be generated.

[0048] Regarding the first dimension, it refers to the height dimension of the tensor.

[0049] The random seed refers to the initial value used to generate a random number sequence. Usually, the generation of random numbers starts based on a certain initial value.

[0050] According to the inventive concept of the present invention, in order to determine the elements of each row in the binary mask tensor in parallel, a random seed can be determined for each row of the binary mask tensor to be generated in the first dimension. That is, a plurality of random seeds are determined, each of which corresponds to a corresponding row in the binary mask tensor to be generated, for the generation of random numbers for the row. According to an embodiment of the present invention, the random seeds determined for each row in the first dimension of the binary mask tensor to be generated are different, so that the disorder of the generated random numbers is increased. In some embodiments, there may be a specific relationship between different random seeds generated for different rows, such as a sequential relationship, a multiple relationship, and the like. For example, in one example, the random seed corresponding to the first row of the binary mask tensor to be generated is 1, the random seed corresponding to the second row of the binary mask tensor to be generated is 100, and the random seed corresponding to the first row of the binary mask tensor to be generated is 10000. In some other embodiments, there is no relationship between different random seeds generated for different rows. For example, in another example, the random seed corresponding to the first row of the binary mask tensor to be generated is 10, the random seed corresponding to the second row of the binary mask tensor to be generated is 3, and the random seed corresponding to the first row of the binary mask tensor to be generated is 420.

[0051] According to an embodiment of the present invention, the random seed can be determined in any appropriate manner, for example, determining the random seed based on a value input by a user, determining the random seed based on a value generated by a random function (for example, a uniform distribution function), or determining the random seed based on the current system time, and the present invention is not limited to this.

[0052] In step 306 , the computing device 200 determines the values ​​of the elements of the binary mask tensor to be generated in the second dimension based on at least the probability and the random seed, so as to generate the binary mask tensor.

[0053] Regarding the second dimension, it refers to the width dimension of the tensor.

[0054] According to an embodiment of the present invention, for each row in the first dimension of the binary mask tensor to be generated, based on the random seed corresponding to each row determined at step 304, a random number generator may be used to generate a random number in the range [0, d-1] based on the random seed and having a size of A vector of random integers without replacement, where d represents the number of columns of the binary mask tensor to be generated in the second dimension, that is, the number of elements included in each row of the binary mask tensor to be generated. pis the probability of the binary mask tensor to be generated indicated by the first instruction received at step 302, “ " is the rounding symbol. For example, if d = 5511 and p = 0.2, a random integer vector without replacement in the range [0, 5510] and of size (1, 1102) can be generated by a random number generator based on a random seed.

[0055] According to an embodiment of the present invention, the value of the element of the binary mask tensor in the second dimension can then be determined based on the generated random integer vector without replacement. Specifically, the value of the element corresponding to the vector in the binary mask tensor can be determined to be a first value (such as 0 or 1) based on the random integer vector without replacement. For example, in one example, the generated random integer vector without replacement is v 1=[1] and the first value is 0, then the value of the second element of the binary mask tensor in the second dimension can be determined to be 0; in another example, if the generated random integer vector without replacement is v 2=[] and the first value is 1, it can be determined that the values ​​of all elements of the binary mask tensor in the second dimension are not 1. Thus, the values ​​of all elements of each row of the binary mask tensor in the second dimension can be determined to obtain the binary mask tensor to be generated.

[0056] From the above, it can be seen that the method for generating a binary mask tensor provided by the present invention can determine the values ​​of the elements of the binary mask tensor in the second dimension in parallel for each row of the binary mask tensor to be generated in the first dimension, so as to generate a binary mask tensor. In other words, the generation of binary mask tensors can be achieved in batches, thereby improving the generation efficiency of binary mask tensors.

[0057] However, when the number of rows of the binary mask tensor to be generated in the first dimension is large, it is easy to cause the randomness of the generated binary mask tensor to weaken. In order to reduce the possibility of the randomness of the generated binary mask tensor to weaken, according to the inventive concept of the present invention, the random number generation mechanism can also be adjusted by introducing a correction coefficient, thereby reducing the possibility of the randomness of the generated random number to be reduced.

[0058] Figure 4 4 is a flowchart of a method 400 for generating a binary mask tensor according to an embodiment of the present invention. The method 400 may be performed as follows: Figure 7 The method 400 is executed at the electronic device 700. It should be understood that the method 400 may further include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0059] At step 402 , a first instruction indicating a probability of a binary mask tensor to be generated is received by computing device 200 .

[0060] Regarding step 402, please refer to the above Figure 3 The description of step 302 is not repeated here.

[0061] In step 404 , the computing device 200 determines a random seed for each row in the first dimension of the binary mask tensor to be generated.

[0062] For step 404, please refer to the above Figure 3 The description of step 304 is not repeated here.

[0063] In step 406 , the computing device 200 determines a correction coefficient based on the first dimension of the binary mask tensor to be generated.

[0064] Regarding the correction coefficient, it can be determined based on a random uniform distribution function. According to an embodiment of the present invention, the correction coefficient (which can be represented by "γ") can be determined by the following formula (1):

[0065] (1)

[0066] Wherein, a is a uniform distribution parameter, and its value range is between 0 and 1. According to an embodiment of the present invention, the uniform distribution parameter a here can be determined by a user, for example.

[0067] As described above, when the number of rows of the binary mask to be generated in the first dimension is large, that is, the parallel dimension used to generate the binary mask tensor is large, it is easy to cause the randomness of the generated binary mask tensor to weaken; and when the parallel dimension is small, the possibility of the randomness of the generated binary mask tensor weakening is correspondingly small. Therefore, according to some other embodiments of the present invention, it is also possible to determine whether it is necessary to introduce a correction coefficient in the process of generating the binary mask tensor based on the number of rows of the binary mask tensor to be generated in the first dimension.

[0068] Specifically, in some embodiments of the present invention, determining the correction coefficient based on the first dimension of the binary mask tensor to be generated may include: in response to the first dimension of the binary mask tensor to be generated being greater than a predetermined correction threshold, determining the correction coefficient based on a uniform distribution function; and in response to the first dimension of the binary mask tensor to be generated being less than or equal to the predetermined correction threshold, determining the correction coefficient to be 1.

[0069] Regarding the predetermined correction threshold (which can be represented by "N"), it can be pre-set by the user, which is equivalent to indicating the row number threshold of the binary mask tensor to be generated in the first dimension. For example, in one example, the predetermined correction threshold N = 2000 can be set. In this case, when the first dimension of the binary mask tensor to be generated is greater than the predetermined correction threshold N = 2000, the correction coefficient γ can be determined by the above formula (1). For example, based on the user's input, the value of the uniform distribution parameter a is determined to be 0.95, on this basis, the correction coefficient can be calculated ; When the first dimension of the binary mask tensor to be generated is less than or equal to the predetermined correction threshold N = 2000, the correction coefficient γ = 1 is determined.

[0070] In step 408 , the computing device 200 determines the values ​​of the elements of the binary mask tensor to be generated in the second dimension based on at least the probability, the random seed, and the correction coefficient.

[0071] According to an embodiment of the present invention, for each row of the binary mask tensor to be generated in the first dimension, based on the random seed corresponding to each row determined at step 404, a random number generator may be used to generate a random number in the range of [0, d-1] based on the random seed and the size of A vector of random integers without replacement, where d represents the number of columns of the binary mask tensor to be generated in the second dimension, that is, the number of elements included in each row of the binary mask tensor to be generated. p is the probability of the binary mask tensor to be generated indicated by the first instruction received at step 402, γ is the correction coefficient determined at step 406, “ " is a rounding symbol. For example, in one example, d =5511, p = 0.2 and , a random number generator can be used to generate a random number in the range [0, 5510] based on a random seed and of size A vector of random integers without replacement.

[0072] Similarly, as shown above, the value of the element of the binary mask tensor in the second dimension can then be determined based on the generated random integer vector without replacement. For details, please refer to the description in the previous article, which will not be repeated here.

[0073] As can be seen from the above, the method for generating a binary mask tensor provided by the present invention introduces a correction coefficient to adjust the mechanism of generating random numbers in the binary mask tensor generation process, so that the possibility of reducing the randomness of the generated random numbers can be reduced. In particular, when the number of rows of the binary mask to be generated in the first dimension is large, the randomness of the generated binary mask tensor can be enhanced by introducing the correction coefficient.

[0074] However, in the process of practicing the dropout method, it is necessary to regenerate the binary mask tensor for each training of the neural network layer, which requires a lot of computation. Especially when performing tasks related to long texts, the computational cost of generating the binary mask tensor is linearly related to the length of the text, or even quadratically related to the length of the text, resulting in a huge computational overhead to implement the dropout method.

[0075] In order to at least solve the above-mentioned problems, according to the inventive concept of the present invention, an initial mask tensor can also be generated so that the values ​​corresponding to some elements in the initial mask tensor are the same as the values ​​corresponding to the corresponding elements in the binary mask tensor to be generated, thereby reducing the amount of calculation in the binary mask tensor generation process. Specifically, the method for generating a binary mask tensor according to an embodiment of the present invention may also include: in response to receiving a first instruction, generating an initial mask tensor based on the first instruction, wherein the initial values ​​of all elements in the initial mask tensor are the same; determining the position of the elements that need to be updated in the initial mask tensor based on the determined values ​​of the elements of the binary mask tensor to be generated in the second dimension; and in response to determining the position of the elements that need to be updated in the initial mask tensor, updating the initial values ​​of the corresponding elements to generate a binary mask tensor. The following will be combined with Figure 5 Detailed description.

[0076] Figure 5 1 shows a flow chart of a method 500 for generating a binary mask tensor according to an embodiment of the present invention. The method 500 may be performed as follows: Figure 7 The method 500 is executed at the electronic device 700. It should be understood that the method 500 may further include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0077] At step 502 , a first instruction indicating a probability of a binary mask tensor to be generated is received by computing device 200 .

[0078] Regarding step 502, please refer to the above Figure 3 The description of step 302 is not repeated here.

[0079] In step 504 , an initial mask tensor is generated by the computing device 200 based on the first instruction, wherein initial values ​​of all elements in the initial mask tensor are the same.

[0080] Regarding the initial mask tensor, it can be a tensor of all 0s or a tensor of all 1s. According to an embodiment of the present invention, the size of the initial mask tensor is the same as the size of the binary mask tensor to be generated.

[0081] It should be understood that when the probability of the binary mask tensor to be generated p The closer it is to 0, the smaller the probability that the neuron will be randomly discarded during the iteration of model training, so the number of elements with a value of 1 in the generated binary mask is greater; accordingly, when the probability of the binary mask tensor to be generated is p The closer to 1, the greater the probability that the neuron is randomly discarded during the iteration of model training, so the number of elements with a value of 0 in the generated binary mask is greater. On this basis, according to an embodiment of the present invention, an initial mask tensor of all 0s or all 1s can be generated based on the instruction in the first instruction to generate an initial mask tensor based on the first instruction.

[0082] For example, generating an initial mask tensor based on a first instruction according to an embodiment of the present invention may include: in response to the first instruction indicating that the probability of the binary mask tensor to be generated is greater than 0 and less than 0.5, generating a first initial mask tensor, and the initial value of all elements in the first initial mask tensor is 1; and in response to the first instruction indicating that the probability of the binary mask tensor to be generated is less than 1 and greater than 0.5, generating a second initial mask tensor, and the initial value of all elements in the second initial mask tensor is 0.

[0083] In step 506 , the computing device 200 determines a random seed for each row in the first dimension of the binary mask tensor to be generated.

[0084] For step 506, please refer to the above Figure 3 The description of step 304 is not repeated here.

[0085] In step 508 , the computing device 200 determines a correction coefficient based on the first dimension of the binary mask tensor to be generated.

[0086] Regarding step 508, please refer to the above Figure 4 The description of step 406 is not repeated here.

[0087] In step 510 , the computing device 200 determines the values ​​of the elements of the binary mask tensor to be generated in the second dimension based on at least the probability, the random seed, and the correction coefficient.

[0088] Regarding step 510, please refer to the above Figure 4 The description of step 408 is not repeated here.

[0089] In step 512 , the computing device 200 determines the positions of the elements that need to be updated in the initial mask tensor based on the values ​​of the elements in the second dimension of the binary mask tensor to be generated.

[0090] As described above, at step 510, a non-replacement random integer vector may be generated to determine that the value of the element corresponding to the vector in the binary mask tensor is a first value (such as 0 or 1). That is, when the first value is different from the value of the element in the initial mask tensor, for example, the first value is 0, and the initial mask tensor is an all-1 tensor (that is, the values ​​of the elements in the initial mask tensor are all 1), the element indicated by the generated non-replacement random integer vector is the position of the element with a value of 0 in the binary mask tensor to be generated, that is, the position of the element in the initial mask tensor whose value needs to be converted from 1 to 0. Thus, the position of the element that needs to be updated in the initial mask tensor can be determined.

[0091] In step 514, the computing device 200 updates the initial values ​​of the corresponding elements in the initial mask tensor to generate a binary mask tensor.

[0092] Regarding updating the initial values ​​of the corresponding elements in the initial mask tensor, it can be to update the values ​​of the elements that need to be updated in the all-0 tensor from 0 to 1, or to update the values ​​of the elements that need to be updated in the all-1 tensor from 1 to 0.

[0093] From the above, it can be seen that by generating an initial mask tensor, it is only necessary to update the values ​​of less than half of the elements in the initial mask tensor to obtain a binary mask tensor, thereby reducing the amount of calculation for generating the binary mask tensor by at least half.

[0094] On this basis, considering the probability of binary mask tensor has countermeasures, that is, based on probability p Determine whether the value of the element in the second dimension of the binary mask tensor to be generated is 0 or 1 based on the probability p It is equivalent to determining that the value of the element in the second dimension of the binary mask tensor to be generated is 1, and this feature can be further utilized to further reduce the amount of calculation for generating the binary mask tensor.

[0095] For example, according to one embodiment of the present invention, if the received first instruction indicates the probability of a binary mask tensor to be generated p = 0.2, then an initial mask tensor of all 1s is generated; then according to the aforementioned method, for each row in the first dimension of the binary mask tensor to be generated, the element with a value of 0 in the row is determined, and the value of the element is updated from 1 to 0. According to another embodiment of the present invention, if the received first instruction indicates the probability of the binary mask tensor to be generated p=0.8, then an initial mask tensor of all 0s is generated; then according to the above method, for each row in the first dimension of the binary mask tensor to be generated, the element with a value of 1 in the row is determined, and the value of the element is updated from 0 to 1. Obviously, based on probability p = 0.2 determines whether the value of the element in the second dimension of the binary mask tensor to be generated is 0 or based on the probability p = 0.8 determines that the value of the element in the second dimension of the binary mask tensor to be generated is 1, that is, it can be based on the probability p = 0.2 generates a binary mask tensor, which determines the probability p = 0.8, thereby achieving the effect of reducing the amount of computation required to generate the binary mask tensor.

[0096] The probability of generating a binary mask tensor p = 0.5, whether generating an initial mask tensor of all 0 tensors or all 1 tensors, it is necessary to update the values ​​of half of the elements to generate a binary mask tensor. Therefore, in some embodiments, an all 0 tensor or an all 1 tensor can be generated, and according to the following Figure 5 A method 500 for generating a binary mask tensor is shown to generate a binary mask tensor.

[0097] However, in order to further reduce the amount of calculation required for generating the binary mask tensor and improve the generation efficiency of the binary mask tensor, according to some embodiments of the present invention, the probability of the binary mask tensor to be generated is p =0.5. Alternatively, the values ​​of the elements of the to-be-generated binary mask tensor in the second dimension may be iteratively determined based on a pseudo-random binary sequence algorithm, so that the binary mask tensor can be generated more efficiently.

[0098] Specifically, according to an embodiment of the present invention, determining the value of an element of the binary mask tensor to be generated in the second dimension based at least on probability and a random seed may include: determining the value of a current element of the binary mask tensor to be generated based on the last binary character of the current output obtained based on a pseudo-random binary sequence algorithm, so as to iteratively determine the value of the element of the binary mask tensor to be generated in the second dimension.

[0099] Regarding the pseudo-random binary sequence algorithm, it can be a 𝐾-order pseudo-random binary sequence algorithm (PRBS K ). According to an embodiment of the present invention, the value of the current element of the binary mask tensor to be generated on the second dimension can be obtained by K The output number is determined by the last binary digit.

[0100] For example, with a 31-order pseudo-random binary sequence algorithm (PRBS 31 ) as an example, the pseudo code of the algorithm can be seen as follows:

[0101]

[0102] That is, when using the 𝐾th order pseudo-random binary sequence algorithm PRBS K For each row in the binary mask tensor to be generated, determine the value of its element in the second dimension, which can be: According to the following formulas (2) and (3), use PRBS K Iterate and take the last binary character of the current output as the value of the corresponding element of the binary mask tensor;

[0103] x i , y = PRBS K ( x i-1 ) (2)

[0104] mask[ j , i ] = y (3)

[0105] For example, for the first row in the binary mask tensor to be generated, for the second element, based on the PRBS K If the last binary character of the current output is 1, the value of the second element is 1, and then the value of the current output is calculated through the PRBS. K Determine the third element of the binary mask tensor for this row. For example, for the second element, based on the PRBS K The current output is 5, which determines the PRBS K (5) = 11, and the last bit of the binary representation of 11 (i.e. 1011) is 1, thus determining that the value of the third element is 1.

[0106] In this case, according to an embodiment of the present invention, the value of the random seed determined for each row in the first dimension of the binary mask tensor to be generated may be in the range [0, 2 k -1], where the value of k is consistent with the 𝐾th order pseudo-random binary sequence algorithm PRBS used later K The value of K is the same.

[0107] From the above, we can see that by the probability of the binary mask tensor to be generated p = 0.5, using the 𝐾th order pseudo-random binary sequence algorithm PRBS KTo generate a binary mask tensor, it is possible to generate a binary mask tensor more efficiently.

[0108] Figure 6 FIG. 6 is a flowchart of an example method 600 for generating a binary mask tensor according to an embodiment of the present invention. The method 600 may be performed as follows: Figure 7 The method 600 is executed at the electronic device 700. It should be understood that the method 600 may further include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.

[0109] At step 602, a first instruction indicating the probability of a binary mask to be generated is received by the computing system 200. Regarding step 602, see the above description of Figure 3 Description of step 302.

[0110] At step 604, the computing system 200 determines the probability of the binary mask to be generated. p Does 0 < p < 0.5 satisfy?

[0111] In response to determining the probability of the binary mask to be generated at step 604 p If 0 < p < 0.5 is satisfied, in step 606 , the computing system 200 generates a full-zero tensor as an initial mask tensor.

[0112] In response to determining the probability of the binary mask to be generated at step 604 p If 0 < p < 0.5 is not satisfied, at step 608, the computing system 200 determines the probability of the binary mask to be generated. p Is it equal to 5?

[0113] In response to determining the probability of the binary mask to be generated at step 608 p is not equal to 5, at step 610 , the computing system 200 generates a full-1 tensor as an initial mask tensor.

[0114] In step 612, the random seed is determined by the computing system 200. For step 612, see the above description of Figure 3 Description of step 304.

[0115] At step 614, the correction factor is determined by the computing system 200. For step 612, see the above description of Figure 4 Description of step 406.

[0116] At step 616, the computing system 200 generates a binary mask based on the probability of p, the random seed determined in step 612, the correction coefficient determined in step 614, and the initial mask tensor generated in step 606 or step 610, to generate a binary mask tensor. For step 616, see the above Figure 5 Description of step 510 and step 512 in FIG.

[0117] In response to determining the probability of the binary mask to be generated at step 608 p If it is equal to 5, the process proceeds to step 618, where the computing system 200 determines the random seed. The range of values ​​of the random seed is related to the order of the pseudo-random binary sequence algorithm to be used.

[0118] At step 620, the computing system 200 generates a binary mask based on the probability of p The random seed determined in step 618 is used to generate a binary mask tensor via a pseudo-random binary sequence algorithm. The detailed steps can be found in the description above and will not be repeated here.

[0119] In summary, the scheme for generating a binary mask tensor according to an embodiment of the present invention can determine the elements of each row in the binary mask tensor in parallel, thereby improving the generation efficiency of the binary mask tensor. And a correction coefficient is introduced to adjust the mechanism for generating random numbers in the binary mask tensor generation process, so that the possibility of reducing the randomness of the generated random numbers can be reduced. At the same time, the scheme for generating a binary mask tensor according to an embodiment of the present invention can reduce the amount of calculation in the binary mask tensor generation process, making the generation of the binary mask tensor more efficient.

[0120] Figure 7 The block diagram of a computing device 700 suitable for implementing the scheme for generating a binary mask tensor according to an embodiment of the present invention is schematically shown. The device 700 may be a device for implementing the execution Figure 3 The method 300 shown, Figure 4 The method 400 shown, Figure 5 The method 500 and Figure 6 The method 600 is shown in the apparatus. Figure 7 As shown, the device 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 702 or computer program instructions loaded from a storage unit 708 to 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 CPU 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.

[0121] Multiple components in the device 700 are connected to the I / O interface 705, including: an input unit 706, an output unit 707, and a storage unit 708. The processing unit 701 performs the various methods and processes described above, such as performing methods 300, 400, 500, or 600. For example, in some embodiments, the methods 300, 400, 500, or 600 may be implemented as a computer software program, which is stored in a machine-readable medium, such as the storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the CPU 701, one or more operations in the methods 300, 400, 500, or 600 described above may be performed. Alternatively, in other embodiments, the CPU 701 may be configured to execute one or more actions of the method 300 , the method 400 , the method 500 , and / or the method 600 in any other appropriate manner (eg, by means of firmware).

[0122] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0123] The computer program instructions for performing the operation of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present invention.

[0124] These computer-readable program instructions can be provided to a processor in a voice interaction device, a general-purpose computer, a special-purpose computer, or a processing unit of other programmable data processing devices, thereby producing a machine, so that when these instructions are executed by the processing unit of a computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other device to work in a specific manner.

[0125] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

[0126] The above are only optional embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for generating a binary mask tensor suitable for AI model training, characterized in that: The AI ​​model includes a neural network layer, and the method includes: receiving a first instruction indicating a probability of a binary mask tensor to be generated; In response to receiving the first instruction, generating an initial mask tensor based on the first instruction, wherein initial values ​​of all elements in the initial mask tensor are the same; For each row of the binary mask tensor to be generated in the first dimension, determining a random seed; Determine, in parallel, values ​​of elements of the to-be-generated binary mask tensor in the second dimension based at least on the probability and the random seed; Determining positions of elements that need to be updated in the initial mask tensor based on the determined values ​​of the elements of the to-be-generated binary mask tensor in the second dimension; and In response to determining the positions of the elements in the initial mask tensor that need to be updated, updating the initial values ​​of the corresponding elements to generate binary mask tensors in batches, The first dimension is the height dimension of the binary mask tensor, and the second dimension is the width dimension of the binary mask tensor.

2. The method according to claim 1, characterized in that Also includes: Determining a correction coefficient based on a first dimension of the binary mask tensor to be generated; Determining the value of the element of the binary mask tensor to be generated in the second dimension based at least on the probability and the random seed includes: determining the value of the element of the binary mask tensor to be generated in the second dimension based at least on the probability, the random seed and the correction coefficient.

3. The method according to claim 2, characterized in that Determining the correction coefficient based on the first dimension of the binary mask tensor to be generated includes: In response to a first dimension of the binary mask tensor to be generated being greater than a predetermined correction threshold, determining the correction coefficient based on a uniform distribution function; and In response to the first dimension of the binary mask tensor to be generated being less than or equal to the predetermined correction threshold, the correction coefficient is determined to be 1.

4. The method according to claim 1, characterized in that: Generating an initial mask tensor based on the first instruction includes: In response to the first instruction indicating that the probability of the binary mask tensor to be generated is greater than 0 and less than 0.5, generating a first initial mask tensor, wherein the initial value of all elements in the first initial mask tensor is 1; and In response to the first instruction indicating that the probability of the binary mask tensor to be generated is less than 1 and greater than 0.5, a second initial mask tensor is generated, and the initial values ​​of all elements in the second initial mask tensor are 0.

5. The method according to claim 1, characterized in that Determining, based at least on the probability and the random seed, a value of an element of the to-be-generated binary mask tensor in the second dimension comprises: In response to the first instruction indicating that the probability of the binary mask tensor to be generated is 0.5, iteratively determining values ​​of elements of the binary mask tensor to be generated in the second dimension based on a pseudo-random binary sequence algorithm.

6. The method according to claim 5, characterized in that Iteratively determining the value of the element of the to-be-generated binary mask tensor in the second dimension based on a pseudo-random binary sequence algorithm includes: According to the last binary character of the current output obtained based on the pseudo-random binary sequence algorithm, the value of the current element of the binary mask tensor to be generated is determined.

7. The method according to claim 1, characterized in that The random seed determined for each row of the to-be-generated binary mask tensor in the first dimension is different.

8. A computing device, characterized in that include: at least one processor; as well as a memory communicatively coupled to the at least one processor; 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 7.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to make a computer execute the method according to any one of claims 1 to 7.