Method and device for calculating residual network layer in generative model, equipment and medium

By reading and transmitting the tensor mean and variance in the residual network layer of the image or video generation model, and performing element-by-element normalization and convolution operations, the problem of slow calculation speed of the residual network layer is solved and the storage is realized. The number of unit accesses is reduced and the calculation rate is increased.

CN118690800APending Publication Date: 2024-09-24SHANGHAI SUIYUAN TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410839243.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

The calculation speed of the residual network layer in existing image or video generation models is slow, which is mainly limited by the high access to the storage unit, resulting in a reduction in the calculation rate of the calculation unit.

Method used

By reading the current input tensor, tensor mean and tensor variance in the storage unit, and performing element-by-element normalization and convolution operations in the calculation unit, after obtaining the convolution output result, the mean and variance operations are performed , reduce the access to the storage unit and increase the calculation rate of the computing unit.

Benefits of technology

It effectively reduces the amount of access to the storage unit, increases the calculation rate of the computing unit, and improves the training and inference speed of the generated model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690800A
    Figure CN118690800A
Patent Text Reader

Abstract

The embodiment of the invention discloses a calculation method and device for a residual network layer in a generative model, equipment and a medium. The method comprises the following steps: reading a current input tensor, a required current tensor mean value and a current tensor variance of a current residual network layer in a storage unit; performing element-by-element normalization processing, element-by-element operation and convolution operation on the current input tensor in the calculation unit to obtain a current convolution output result; performing mean value and variance operation on the current convolution output result in a calculation unit to obtain a next tensor mean value and a next tensor variance required in a next residual network layer; and writing the current convolution output result, the next tensor mean value and the next tensor variance into a storage unit, repeatedly performing calculation to obtain a last convolution output result of the last residual network layer, and performing information generation. By calculating the mean value and the variance required by the next residual network layer in the current residual network layer, the access amount to the storage unit can be reduced, and the calculation rate of the calculation unit is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a calculation method, device, equipment and medium for a residual network layer in a generative model. Background Art

[0002] Image or video generation is an important area of ​​generative artificial intelligence (AIGC). In current image or video generation models, multiple residual network layers (ResNet Block) are usually cascaded. The structure of each ResNet Block is usually a normalization layer (Normalization), an element-wise operation layer (Element-wise) and a convolutional layer (Conv).

[0003] With the development of computer technology, current AI computing chips are equipped with extremely high computing power, which can be used to accelerate convolution calculations. Therefore, the performance of ResNet Block is mainly limited by memory bandwidth. Since the current structure of ResNet Block has a high access volume to storage units, the training or reasoning speed of the generated model is slow, which reduces the computing rate of the computing unit. Summary of the invention

[0004] The present invention provides a calculation method, device, equipment and medium for a residual network layer in a generative model to reduce the amount of access to a storage unit and accelerate the calculation rate of the calculation unit.

[0005] According to one aspect of the present invention, a method for calculating a residual network layer in a generative model is provided, the method comprising:

[0006] Read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the storage unit;

[0007] The current input tensor, the current tensor mean, and the current tensor variance of the current residual network layer are transmitted to the computing unit;

[0008] In the computing unit, the current input tensor of the current residual network layer is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain a current convolution output result of the current residual network layer;

[0009] In the calculation unit, the current convolution output result of the current residual network layer is subjected to mean and variance operations to obtain the next tensor mean and the next tensor variance required in the next residual network layer;

[0010] The current convolution output result, the next tensor mean and the next tensor variance are written into a storage unit, and the calculation is repeated until the last convolution output result of the last residual network layer in the generative model is obtained, and information is generated according to the last convolution output result.

[0011] According to another aspect of the present invention, a computing device for a residual network layer in a generative model is provided, the device comprising:

[0012] A tensor information acquisition module, used for reading in a storage unit the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer;

[0013] A tensor information transmission module is used to transmit the current input tensor, the current tensor mean and the current tensor variance of the current residual network layer to the computing unit;

[0014] A convolution output result determination module, configured to perform element-by-element normalization, element-by-element operation, and convolution operation on the current input tensor of the current residual network layer in a computing unit to obtain a current convolution output result of the current residual network layer;

[0015] A mean-variance operation module, used for performing mean and variance operations on the current convolution output result of the current residual network layer in the calculation unit to obtain the next tensor mean and the next tensor variance required in the next residual network layer;

[0016] An information generation module is used to write the current convolution output result, the next tensor mean and the next tensor variance into a storage unit, and repeatedly calculate until the last convolution output result of the last residual network layer in the generation model is obtained, and information is generated according to the last convolution output result.

[0017] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0018] at least one processor; and

[0019] a memory communicatively connected to the at least one processor; wherein,

[0020] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the calculation method of the residual network layer in the generation model described in any embodiment of the present invention.

[0021] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the calculation method of the residual network layer in the generation model described in any embodiment of the present invention when executed.

[0022] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method for calculating the residual network layer in the generative model described in any embodiment of the present invention.

[0023] The technical solution of the embodiment of the present invention is to read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the storage unit; transmit the current input tensor of the current residual network layer, the current tensor mean and the current tensor variance to the computing unit; perform element-by-element normalization, element-by-element operation and convolution operation on the current input tensor of the current residual network layer in the computing unit to obtain the current convolution output result of the current residual network layer; perform mean and square operation on the current convolution output result of the current residual network layer in the computing unit. The method comprises the following steps: performing difference operation to obtain the next tensor mean and the next tensor variance required in the next residual network layer; writing the current convolution output result, the next tensor mean and the next tensor variance into a storage unit, and repeating the calculation until the last convolution output result of the last residual network layer in the generative model is obtained, and generating information according to the last convolution output result, thereby solving the problem that the storage unit needs to be accessed multiple times when calculating the residual network layer in the generative model. By calculating the mean and variance required for the next residual network layer in the current residual network layer, the access amount to the storage unit can be reduced, thereby accelerating the calculation rate of the calculation unit.

[0024] 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

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0026] Figure 1 is a flowchart of a method for calculating a residual network layer in a generative model provided in Embodiment 1 of the present invention;

[0027] Figure 2It is a structural diagram of a Resnet Block according to an example of the prior art;

[0028] Figure 3 A structure of a Resnet Block provided according to Embodiment 1 of the present invention;

[0029] Figure 4 is a flowchart of a method for calculating a residual network layer in a generative model provided in Embodiment 2 of the present invention;

[0030] Figure 5 is a schematic diagram of a hardware system structure composed of multiple computing units provided according to Embodiment 2 of the present invention;

[0031] Figure 6 This is a schematic diagram of a tensor variance and mean calculation process provided by Embodiment 2 of the present invention;

[0032] Figure 7 is a numerical stability display schematic diagram provided according to the second embodiment of the present invention;

[0033] Figure 8 is a schematic diagram of a cultural graph model structure provided according to the second embodiment of the present invention;

[0034] Fig. 9 is a schematic diagram of a structure of an image-generated video model provided according to Embodiment 2 of the present invention;

[0035] Fig.10 2 is a schematic diagram of the structure of a computing device for a residual network layer in a generative model provided in Embodiment 3 of the present invention;

[0036] Fig.11 It is a structural schematic diagram of an electronic device for implementing a calculation method of a residual network layer in a generation model of an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0038] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0039] Embodiment 1

[0040] Figure 1 It is a flowchart of a calculation method of a residual network layer in a generative model provided according to Embodiment 1 of the present invention. This embodiment can be applied to the case where, when a generative model is used to generate images or videos, the generation rate is improved by reducing the storage access amount. The method can be executed by a calculation device of a residual network layer in a generative model. The calculation device of the residual network layer in the generative model can be implemented in the form of hardware and / or software. The calculation device of the residual network layer in the generative model can be configured in an electronic device such as a computer or a smart terminal.

[0041] In order to facilitate the understanding of the technical solutions of the embodiments of the present invention, Figure 2 This is a structural diagram of a Resnet Block based on an example of the prior art. Figure 3 1 is a structural diagram of a Resnet Block provided according to the first embodiment of the present invention. Figure 2 As shown in FIG. 1 , the prior art requires 4 reads and 3 writes to process the input tensor. Figure 3 In the Resnet Block structure provided by the embodiment of the present invention shown, only one read and one write are required for the input tensor. The storage access amount is reduced from O(7×TCHW) to O(2×TCHW), which reduces the storage access amount of the Resnet Block calculation by about 2 / 3 and improves the computing power utilization of the computing unit. Wherein, TCHW is the tensor shape, T represents the number of video frames, and T is 1 for image data; C is the number of channels, and H and W are height and width, respectively.

[0042] Specifically, the calculation method of the residual network layer in the generative model provided in the embodiment of the present invention is as follows: Figure 1 The method comprises:

[0043] Step 110: read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the generation model in the storage unit.

[0044] Among them, the storage unit can be a memory and / or an on-chip cache. Exemplarily, the current input tensor, the current tensor mean, and the current tensor variance can all be stored in the memory. In order to further improve the operation rate, the current tensor mean and the current tensor variance can be stored in the on-chip cache, and the current input tensor is stored in the memory. The on-chip cache can be a memory with a faster access speed such as a static random access memory (SRAM).

[0045] The generation model can be an image or video generation model. For example, the method exemplified in the present invention can be applied to generation models such as text-generated images, picture-generated images, text-generated videos, or picture-generated videos. Among them, text-generated images refer to images that match the prompt words (prompt) input by the user. Picture-generated images refer to image editing applications that modify the content in the input image according to the user input image and the user input prompt words. Text-generated videos refer to videos that match the prompt words generated according to the user input prompt. Picture-generated videos refer to videos generated according to the user input image.

[0046] In practical applications, the method provided by the embodiment of the present invention can be used to replace the calculation method of the residual network layer in the original generation model. Figure 3 The residual network layer shown is replaced by Figure 2 The residual network layer shown performs convolution calculations.

[0047] The current input tensor may be the input of the current residual network layer. Specifically, the current input tensor may be the convolution output result of the previous residual network layer. The current tensor mean and the current tensor variance may be the mean and variance calculated based on the current input tensor. Figure 2 In the structure shown in FIG. 1 , the current tensor mean and the current tensor variance are calculated in the current residual network layer. The embodiment of the present invention improves the residual network layer structure. Figure 3 In the structure shown, the current tensor mean and current tensor variance are calculated in the previous residual network layer. That is, after the previous residual network layer obtains the convolution output result, it calculates the mean and variance to obtain the current tensor mean and current tensor variance required by the current residual network layer.

[0048] Step 120: transmit the current input tensor, the current tensor mean, and the current tensor variance of the current residual network layer to the computing unit.

[0049] Step 130: In the computing unit, perform element-by-element normalization, element-by-element operation, and convolution operation on the current input tensor of the current residual network layer to obtain the current convolution output result of the current residual network layer.

[0050] like Figure 3 As shown, the calculation of the current input tensor can be element-by-element normalization, element-by-element operation, and convolution operation in sequence. In the embodiment of the present invention, since the current tensor mean and current tensor variance required by the current residual network layer have been obtained before the current residual network layer starts to calculate, element-by-element normalization, element-by-element operation, and convolution operation can be directly performed when the current input tensor is obtained.

[0051] Among them, the element-wise normalization processing (Element-wise Normalization) may include but is not limited to: according to the definition of Normalization layer such as group normalization (Group Norm), instance normalization (Instant Norm), layer normalization (Layer Norm), root mean square normalization (RMS Norm), etc., normalization operation is performed on each element of the current input tensor. Element-wise operations (Element-wise ops) may include but are not limited to: according to the definition of Resnet Block, corresponding activation function operations are performed on each element of the current input tensor, such as SiLU function, ReLU function, GeLU function, Dropout function, etc. Convolution operation (Convolution) may include but is not limited to: according to the definition of Resnet Block, convolution operation is performed on the current input tensor, such as two-dimensional convolution operation (2D conv) and three-dimensional convolution operation (3D conv).

[0052] Step 140: Perform mean and variance operations on the current convolution output result of the current residual network layer in the calculation unit to obtain the next tensor mean and next tensor variance required in the next residual network layer.

[0053] There are many ways to perform mean and variance operations on the current convolution output result. For example, the conventional mean variance operation formula can be directly used to perform mean and variance operations on the current convolution output result. Alternatively, the mean and variance can be calculated and accumulated each time the convolution layer outputs an element in the current convolution output result. The mean and variance operations are performed on the current convolution output result in the current residual network layer, and the results obtained are the next tensor mean and next tensor variance required in the next residual network layer.

[0054] Step 150, write the current convolution output result, the next tensor mean and the next tensor variance into the storage unit, and repeat the calculation until the last convolution output result of the last residual network layer in the generative model is obtained, and generate information according to the last convolution output result.

[0055] Among them, the current convolution output result can be used as the input tensor of the next residual network layer. The next tensor mean and the next tensor variance are the data basis for the next residual network layer to perform element-by-element normalization processing.

[0056] That is, in an embodiment of the present invention, the Normalization layer is split into a mean-variance unit operator and an element-by-element normalization processing operator. Cross-Resnet Block operator fusion is performed in the generative model. The mean-variance unit operator of the current residual network layer is fused with the convolution operator of the previous residual network layer. Based on this, the amount of access of the computing unit to the storage unit can be reduced to improve the computing efficiency of the computing unit.

[0057] The technical solution of this embodiment is to read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the storage unit; transmit the current input tensor of the current residual network layer, the current tensor mean and the current tensor variance to the calculation unit; perform element-by-element normalization, element-by-element operation and convolution operation on the current input tensor of the current residual network layer in the calculation unit to obtain the current convolution output result of the current residual network layer; perform mean and variance on the current convolution output result of the current residual network layer in the calculation unit. The method performs operations to obtain the next tensor mean and the next tensor variance required in the next residual network layer; writes the current convolution output result, the next tensor mean and the next tensor variance into the storage unit, and repeats the calculation until the last convolution output result of the last residual network layer in the generative model is obtained, and generates information according to the last convolution output result, thereby solving the problem that the storage unit needs to be accessed multiple times when calculating the residual network layer in the generative model. By calculating the mean and variance required for the next residual network layer in the current residual network layer, the access to the storage unit can be reduced, thereby accelerating the calculation rate of the calculation unit.

[0058] Embodiment 2

[0059] Figure 4 It is a flowchart of a calculation method of the residual network layer in a generative model provided according to the second embodiment of the present invention. This embodiment is a further refinement of the above technical solution. The technical solution in this embodiment can be combined with various optional solutions in one or more of the above embodiments.

[0060] Specifically, the current input tensor of the current residual network layer is subjected to element-by-element normalization, element-by-element operation, and convolution operation in the computing unit to obtain the current convolution output result of the current residual network layer, including: obtaining the current tensor block in the current input tensor of the current residual network layer through each computing sub-unit; in each computing sub-unit, the corresponding current tensor block is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain the current convolution output sub-result corresponding to each current tensor block of the current residual network layer.

[0061] Optionally, the current convolution output result of the current residual network layer is subjected to mean and variance operations in the computing unit to obtain the next tensor mean and next tensor variance required in the next residual network layer, including: performing mean and variance operations on the current convolution output sub-result of the current residual network layer in each computing sub-unit to obtain the block mean and block variance corresponding to each current tensor block; and fusing each block mean and each block variance between tensor blocks in the computing unit to obtain the next tensor mean and next tensor variance required in the next residual network layer.

[0062] like Figure 4 As shown, the method includes:

[0063] Step 410: read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the generation model in the storage unit.

[0064] In an optional implementation of an embodiment of the present invention, the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer are read in a storage unit, including: reading the current input tensor of the current residual network layer in the generation model in the chip memory; reading the current tensor mean and the current tensor variance required by the current residual network layer in the on-chip cache.

[0065] Among them, the common on-chip cache capacity can usually reach hundreds of KB to tens of MB. Although the on-chip cache cannot accommodate the entire tensor, it can accommodate the mean and variance. Taking Group Norm as an example, g is the number of groups, and g is usually 32. The capacity requirement of Group Norm for SRAM is g×2×BPE. BPE means that each element is represented by several bytes (Byte Per Element). For example, BPE=1 for FP8 (8-byte floating point number), BPE=2 for FP16, and BPE=4 for FP32. Therefore, the SRAM required by Group Norm is usually less than 1KB. Using on-chip cache to cache the mean and variance of tensors can further improve the storage access rate and improve computing efficiency.

[0066] In an optional implementation of an embodiment of the present invention, reading the current input tensor of the current residual network layer in the generation model in the storage unit includes: reading each current tensor block of the current input tensor of the current residual network layer in the generation model in the storage unit.

[0067] In order to speed up the operation of the computing unit, the computing unit can perform parallel operations through multiple computing sub-units. In order to meet the parallel operation of the computing sub-units, the current input tensor can be split to obtain multiple current tensor small blocks. In practical applications, the splitting time may be different. For example, when the tensor is read in the storage unit, it can be read in small blocks. Alternatively, the current input tensor can be read into the computing unit first, and each computing sub-unit then reads the small block for operation. The method of reading the current tensor small blocks of the current input tensor of the current residual network layer in the generation model in the storage unit has a higher operation rate.

[0068] Step 420: transmit the current input tensor, the current tensor mean, and the current tensor variance of the current residual network layer to the computing unit.

[0069] In an optional implementation of an embodiment of the present invention, the current input tensor, current tensor mean and current tensor variance of the current residual network layer are transmitted to the computing unit, including: transmitting each current tensor block of the current input tensor of the current residual network layer to the corresponding computing sub-unit; transmitting the current tensor mean and current tensor variance of the current residual network layer to each computing sub-unit.

[0070] Step 430: Obtain a current tensor block in the current input tensor of the current residual network layer through each computing subunit.

[0071] Figure 5 FIG. 1 is a schematic diagram of a hardware system structure composed of multiple computing units according to Embodiment 2 of the present invention. Figure 5 As shown, each computing subunit can obtain the current tensor block required for calculation. Each computing subunit can calculate in parallel.

[0072] Step 440: In each computing subunit, the corresponding current tensor block is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain the current convolution output sub-result corresponding to each current tensor block of the current residual network layer.

[0073] like Figure 5 As shown, each computing subunit can perform element-by-element normalization, element-by-element operation, and convolution operation. The convolution result obtained by each computing subunit is a part of the current convolution output result. The current convolution output sub-results of each computing subunit are spliced ​​to obtain the current convolution output result.

[0074] It should be noted that in the prior art, the Normalization layer cannot divide the input tensor into blocks for calculation. The definition of the Normalization layer is In the formula, x represents an element of the input tensor of the Normalization layer, y represents an element of the output tensor of the Normalization layer, E[x] and Var[x] represent the mean and variance of the entire input tensor of the Normalization layer, respectively. Therefore, the Normalization layer needs to read in the entire input tensor first to complete the statistics of the mean and variance; then read in the entire input tensor again to normalize each element.

[0075] In the embodiment of the present invention, the Normalization layer is split into a mean-variance operator and an element-by-element normalization operator. Based on this, the input tensor can be split into small blocks for element-by-element normalization, element-by-element operations, and convolution operations.

[0076] Step 450: In each computing subunit, mean and variance operations are performed on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block.

[0077] For the input tensor operated in blocks, the corresponding current convolution output sub-result can be obtained. Therefore, the block mean and block variance corresponding to each current tensor block can be determined according to the current convolution output sub-result. When determining the block mean and block variance corresponding to each current tensor block, the conventional mean variance formula can be used for calculation, or the element-by-element accumulation method can be used for calculation.

[0078] Specifically, in an optional implementation of an embodiment of the present invention, in each computing subunit, mean and variance operations are performed on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block, including: in each computing subunit, a mean and variance recursive algorithm is used to perform mean and variance accumulation operations on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block.

[0079] Among them, the mean and variance accumulation operations, that is, the convolution layer outputs each element x i , you can calculate x i 2 , and accumulate to ∑x i and ∑x i 2 , calculate the mean variance Where N is the number of elements. In the embodiment of the present invention, in order to improve numerical stability, the Welford's online algorithm can be used to accumulate each element. The specific accumulation algorithm can be the mean value using Cumulative calculation, n is the number of elements that have been accumulated during the mean variance calculation. Cumulative calculation. In the formula, M 2,n It means n times the variance of n elements, M can be calculated recursively 2,0 =0,M 2,n =M 2,n-1 +(x n -μ n-1 )(x n -μ n ).

[0080] Step 460: In the calculation unit, the means and variances of each block are fused between the small tensor blocks to obtain the next tensor mean and the next tensor variance required in the next residual network layer.

[0081] Figure 6 FIG. 1 is a schematic diagram of a tensor variance and mean calculation process according to Embodiment 2 of the present invention. Figure 6 As shown in the figure, the current input tensor can be split into multiple current tensor tiles (Tiles), and each current tensor tile can be subjected to element-by-element normalization, element-by-element operation, convolution operation, and mean and variance operation to obtain the block mean and block variance corresponding to each current tensor tile. After obtaining the block mean and block variance, the mean and variance need to be fused to obtain the next tensor mean and next tensor variance required in the next residual network layer.

[0082] The fusion of the mean and variance can be achieved by merging the block means and block variances of the two small blocks of the current tensor until a mean and variance are obtained, which are used as the mean and variance of the next tensor respectively. The merging can be achieved by using a mean and variance parallel algorithm.

[0083] Specifically, in an optional implementation of an embodiment of the present invention, in a computing unit, the means and variances of each block are fused between small tensor blocks to obtain the next tensor mean and next tensor variance required in the next residual network layer, including: using a mean and variance parallel algorithm in the computing unit to pair the means of each block, and aggregate them step by step according to a binary tree to obtain the next tensor mean required in the next residual network layer; using a mean and variance parallel algorithm in the computing unit to pair the variances of each block, and aggregate them step by step according to a binary tree to obtain the next tensor variance required in the next residual network layer.

[0084] like Figure 6As shown in , the mean and variance of each block can be paired and aggregated level by level according to the binary tree. The mean and variance parallel algorithm can use Chan's parallel algorithm. Specifically, the mean fusion can be used Calculate. In the formula, n AB =n A +n B , A and B represent different tensor blocks that need to be fused, n A is the number of elements in the tensor block A, μ A is the mean of the tensor block A. Variance fusion is adopted Calculate. In the formula, δ=μ B -μ A , M 2,A =n A σ A 2 ,M 2,B =n B σ B 2 , σ A 2 and σ B 2 are the variances of tensor chunks A and B, respectively.

[0085] The inventors tested the mean-variance recursive operation performance in practice and found that the mean-variance operation method provided by the embodiment of the present invention has better numerical stability. Figure 7 1 is a schematic diagram showing numerical stability according to the second embodiment of the present invention. Figure 7 As shown, in the test length of 640K of the Gaussian distribution randomly generated array, the variance is fixed to 1. When the mean of the randomly generated array changes from 1 to 1E6 (scientific notation), the mean and variance estimates of the conventional mean-variance calculation method both show a relative error amplification phenomenon; while the relative error of the mean-variance recursive calculation in the embodiment of the present invention is always within 1E-5 (one in 100,000).

[0086] Step 470, write the current convolution output result, the next tensor mean and the next tensor variance into the storage unit, and repeat the calculation until the last convolution output result of the last residual network layer in the generative model is obtained, and generate information according to the last convolution output result.

[0087] To further improve the computational efficiency, the mean and variance can be accumulated in an on-chip cache. Specifically, in an optional implementation of an embodiment of the present invention, writing the current convolution output result, the next tensor mean, and the next tensor variance into a storage unit includes: writing the current convolution output result into a chip memory; and writing the next tensor mean and the next tensor variance into an on-chip cache.

[0088] The technical solution of the embodiment of the present invention is to read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the storage unit; transmit the current input tensor of the current residual network layer, the current tensor mean and the current tensor variance to the calculation unit; obtain the current tensor block in the current input tensor of the current residual network layer through each calculation subunit; perform element-by-element normalization, element-by-element operation and convolution operation on the corresponding current tensor block in each calculation subunit to obtain the current convolution output sub-result corresponding to each current tensor block of the current residual network layer; perform mean and variance operation on the current convolution output sub-result of the current residual network layer in each calculation subunit to obtain the block mean and block variance corresponding to each current tensor block; fuse the block means and block variances between tensor blocks in the calculation unit to obtain the required The mean and variance of the next tensor are obtained; the current convolution output result, the mean and variance of the next tensor are written into the storage unit, and the calculation is repeated until the last convolution output result of the last residual network layer in the generative model is obtained, and information is generated according to the last convolution output result, which solves the problem that the residual network layer in the generative model needs to access the storage unit multiple times when calculating. By calculating the mean and variance required for the next residual network layer in the current residual network layer, the access to the storage unit can be reduced and the calculation rate of the calculation unit can be accelerated; by splitting the Normalization layer into a mean-variance operator and an element-by-element normalization operator, the input tensor can be operated in blocks and in parallel to improve the calculation efficiency; by accumulating and parallelizing the mean and variance, the normalization layer can realize the block-by-block parallel operation of the input tensor, reduce the calculation error, and improve the stability of numerical operations.

[0089] The calculation method of the residual network layer in the generative model provided in the embodiment of the present invention can be applied to the image and / or video generative model to replace the residual network layer in the generative model. Figure 8 It is a schematic diagram of a cultural graph model structure provided according to the second embodiment of the present invention. Fig. 9 FIG. 1 is a schematic diagram of a graph-generated video model structure provided according to Embodiment 2 of the present invention. Figure 8 The conditional 2D UNet model (UNet2DConditional) and the autoencoder (AutoEncoderKL Decoder) in the generative model shown in the figure both include residual network layers. The calculation method of the residual network layer in the generative model provided in the embodiment of the present invention can be used to replace the original residual network layer in UNet2DConditional and AutoEncoderKL Decoder to improve the reasoning efficiency of the computing unit. Fig. 9The video generation neural network (Video UNet) and the variational decoder (Temporal VAE Decoder) in the generative model shown include residual network layers. The calculation method of the residual network layer in the generation model provided by the embodiment of the present invention can be used to replace the original residual network layer in Video UNet and Temporal VAE Decoder to improve the reasoning efficiency of the computing unit.

[0090] Embodiment 3

[0091] Fig.10 1 is a schematic diagram of the structure of a computing device for a residual network layer in a generative model provided according to Embodiment 3 of the present invention. Fig.10 As shown, the device includes: a tensor information acquisition module 1010, a tensor information transmission module 1020, a convolution output result determination module 1030, a mean variance calculation module 1040 and an information generation module 1050. Among them:

[0092] A tensor information acquisition module 1010 is used to read in a storage unit the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer;

[0093] A tensor information transmission module 1020 is used to transmit the current input tensor, the current tensor mean and the current tensor variance of the current residual network layer to the computing unit;

[0094] The convolution output result determination module 1030 is used to perform element-by-element normalization, element-by-element operation and convolution operation on the current input tensor of the current residual network layer in the calculation unit to obtain the current convolution output result of the current residual network layer;

[0095] A mean-variance operation module 1040 is used to perform mean and variance operations on the current convolution output result of the current residual network layer in the calculation unit to obtain the next tensor mean and the next tensor variance required in the next residual network layer;

[0096] The information generation module 1050 is used to write the current convolution output result, the next tensor mean and the next tensor variance into the storage unit, and repeat the calculation until the last convolution output result of the last residual network layer in the generation model is obtained, and information is generated according to the last convolution output result.

[0097] Optionally, the convolution output result determination module 1030 includes:

[0098] A current tensor small block acquisition unit is used to acquire a current tensor small block in a current input tensor of a current residual network layer through each computing subunit;

[0099] The current convolution output sub-result determination unit is used to perform element-by-element normalization, element-by-element operation and convolution operation on the corresponding current tensor blocks in each computing sub-unit to obtain the current convolution output sub-results corresponding to each current tensor block of the current residual network layer.

[0100] Optionally, the mean variance calculation module 1040 includes:

[0101] The block mean variance operation unit is used to perform mean and variance operations on the current convolution output sub-result of the current residual network layer in each calculation sub-unit to obtain the block mean and block variance corresponding to each current tensor block;

[0102] The block mean variance fusion unit is used to fuse the block means and block variances between tensor blocks in the calculation unit to obtain the next tensor mean and next tensor variance required in the next residual network layer.

[0103] Optional, block mean variance calculation unit, specifically used for:

[0104] In each computing subunit, the mean and variance recursive algorithm is used to perform mean and variance accumulation operations on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block.

[0105] Optional, block mean variance fusion unit, specifically used for:

[0106] In the calculation unit, the mean and variance parallel algorithm is used to pair the means of each block, and aggregate them level by level according to the binary tree to obtain the next tensor mean required in the next residual network layer;

[0107] In the computing unit, the mean and variance parallel algorithm is used to pair the variances of each block, and aggregate them level by level according to the binary tree to obtain the next tensor variance required in the next residual network layer.

[0108] Optionally, the tensor information acquisition module 1010 includes:

[0109] A current tensor block acquisition unit, used for reading each current tensor block of the current input tensor of the current residual network layer in the generation model in the storage unit;

[0110] Optionally, the tensor information transmission module 1020 includes:

[0111] A current tensor block transmission unit, used to transmit each current tensor block of the current input tensor of the current residual network layer to the corresponding computing subunit;

[0112] The tensor mean variance transmission unit is used to transmit the current tensor mean and current tensor variance of the current residual network layer to each computing subunit.

[0113] Optionally, the information generation module 1050 includes:

[0114] A tensor information writing unit is used to write the current convolution output result into the chip memory; write the next tensor mean and the next tensor variance into the on-chip cache;

[0115] The tensor information acquisition module 1010 includes:

[0116] A current input tensor acquisition unit, used to read the current input tensor of the current residual network layer in the generative model from the chip memory;

[0117] The tensor mean variance acquisition unit is used to read the current tensor mean and current tensor variance required by the current residual network layer in the on-chip cache.

[0118] The computing device for the residual network layer in the generative model provided in the embodiment of the present invention can execute the computing method for the residual network layer in the generative model provided in any embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method.

[0119] Embodiment 4

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

[0121] like Fig.11 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0122] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0123] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 performs the various methods and processes described above, such as the calculation method of the residual network layer in the generation model.

[0124] In some embodiments, the calculation method of the residual network layer in the generative model can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the calculation method of the residual network layer in the generative model described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute the calculation method of the residual network layer in the generative model in any other suitable manner (for example, by means of firmware).

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

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

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

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

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

[0130] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

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

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

Claims

1. A method for calculating a residual network layer in a generative model, characterized in that: include: Read the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer in the storage unit; The current input tensor, the current tensor mean and the current tensor variance of the current residual network layer are transmitted to the computing unit; In the computing unit, the current input tensor of the current residual network layer is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain a current convolution output result of the current residual network layer; In the calculation unit, the current convolution output result of the current residual network layer is subjected to mean and variance operations to obtain the next tensor mean and the next tensor variance required in the next residual network layer; The current convolution output result, the next tensor mean and the next tensor variance are written into a storage unit, and the calculation is repeated until the last convolution output result of the last residual network layer in the generative model is obtained, and information is generated according to the last convolution output result.

2. The method according to claim 1, characterized in that In the computing unit, the current input tensor of the current residual network layer is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain a current convolution output result of the current residual network layer, including: Obtaining a current tensor block in the current input tensor of the current residual network layer through each computing subunit; In each computing subunit, the corresponding current tensor block is subjected to element-by-element normalization, element-by-element operation, and convolution operation to obtain the current convolution output sub-result corresponding to each current tensor block of the current residual network layer.

3. The method according to claim 1, characterized in that In the calculation unit, the current convolution output result of the current residual network layer is subjected to mean and variance operations to obtain the next tensor mean and the next tensor variance required in the next residual network layer, including: In each computing subunit, the mean and variance operations are performed on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block; In the computing unit, the means and variances of each block are fused between small tensor blocks to obtain the next tensor mean and next tensor variance required in the next residual network layer.

4. The method according to claim 3, characterized in that In each computing subunit, the current convolution output sub-result of the current residual network layer is subjected to mean and variance operations to obtain the block mean and block variance corresponding to each current tensor block, including: In each computing subunit, the mean and variance recursive algorithm is used to perform mean and variance accumulation operations on the current convolution output sub-result of the current residual network layer to obtain the block mean and block variance corresponding to each current tensor block.

5. The method according to claim 3, characterized in that: In the calculation unit, the mean and variance of each block are fused between small tensor blocks to obtain the next tensor mean and next tensor variance required in the next residual network layer, including: In the calculation unit, the mean and variance parallel algorithm is used to pair the means of each block, and aggregate them level by level according to the binary tree to obtain the next tensor mean required in the next residual network layer; In the computing unit, the mean and variance parallel algorithm is used to pair the variances of each block, and aggregate them level by level according to the binary tree to obtain the next tensor variance required in the next residual network layer.

6. The method according to claim 1, characterized in that Read the current input tensor of the current residual network layer in the generative model in the storage unit, including: Reading each current tensor chunk of the current input tensor of the current residual network layer in the generative model in the storage unit; The current input tensor, current tensor mean, and current tensor variance of the current residual network layer are transmitted to the computing unit, including: Transfer each current tensor block of the current input tensor of the current residual network layer to the corresponding computing subunit; The current tensor mean and current tensor variance of the current residual network layer are transmitted to each computing subunit.

7. The method according to claim 1, characterized in that Writing the current convolution output result, the next tensor mean, and the next tensor variance into a storage unit includes: Writing the current convolution output result into the chip memory; writing the next tensor mean and the next tensor variance into the on-chip cache; Accordingly, the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer are read in the storage unit, including: Read the current input tensor of the current residual network layer in the generative model in the chip memory; Read the current tensor mean and current tensor variance required by the current residual network layer in the on-chip cache.

8. A computing device for a residual network layer in a generative model, characterized in that: include: A tensor information acquisition module, used for reading in a storage unit the current input tensor of the current residual network layer in the generation model, the current tensor mean and the current tensor variance required by the current residual network layer; A tensor information transmission module is used to transmit the current input tensor, the current tensor mean and the current tensor variance of the current residual network layer to the computing unit; A convolution output result determination module, configured to perform element-by-element normalization, element-by-element operation, and convolution operation on the current input tensor of the current residual network layer in a computing unit to obtain a current convolution output result of the current residual network layer; A mean-variance operation module, used for performing mean and variance operations on the current convolution output result of the current residual network layer in the calculation unit to obtain the next tensor mean and the next tensor variance required in the next residual network layer; An information generation module is used to write the current convolution output result, the next tensor mean and the next tensor variance into a storage unit, and repeatedly calculate until the last convolution output result of the last residual network layer in the generation model is obtained, and information is generated according to the last convolution output result.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the calculation method of the residual network layer in the generation model described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the calculation method of the residual network layer in the generation model described in any one of claims 1-7 when executed.

Citation Information

Patent Citations

  • Test duration determination method and device, equipment and storage medium

    CN115640231A

  • Building material purchasing mall suitable for buyer market environment and purchasing method thereof

    CN116051242A

  • Impact load action position inversion method based on residual connection convolution circulation network

    CN116757085A

  • Application starting method and device, electronic equipment and computer storage medium

    CN117407076A