Tensor segmentation method, device and electronic device

The tensor data is obtained and divided through reverse search and stored in memory, which solves the problem of memory overlimit and low computing efficiency of the neural network model, and achieves efficient memory utilization and computing efficiency.

CN117172289BActive Publication Date: 2024-09-06SUZHOU YIZHU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311125349.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-01
Publication Date
2024-09-06
Estimated Expiration
2043-09-01

AI Technical Summary

Technical Problem

The neural network model may exceed the maximum memory capacity during the memory allocation process, causing memory allocation failure. Existing technology affects computing efficiency by storing and reading tensor data from external memory.

Method used

Obtain tensor segmentation groups through reverse search, segment tensor data, and store it in memory, reducing access to external memory and ensuring that tensor data can be read and stored in memory.

Benefits of technology

It realizes the reading and storage of neural network tensor data in memory, reduces external memory access, improves computing efficiency, and solves the problems of memory overrun and data segmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117172289B
    Figure CN117172289B
Patent Text Reader

Abstract

The present application discloses a tensor segmentation method and device, the tensor segmentation method includes: based on the input data of a neural network, obtaining the computational graph when the neural network calculates the input data and the tensor information of the tensor data; allocating memory for the tensor data of the neural network according to the topological order of the computational graph, and obtaining the current node and the current tensor data from the computational graph, the size of the current tensor data exceeds the allocatable space of the current memory; performing a reverse search from the current node to obtain the current node group and the current tensor segmentation group, the current tensor segmentation group includes at least 2 tensor data; segmenting the tensor data in the current tensor segmentation group so that the size of the segmented tensor data in the current tensor segmentation group does not exceed the allocatable space of the current memory. The present application can segment large tensor data to meet the memory space requirements, reduce the access to the external memory, and improve the computing efficiency.
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 more specifically, to a tensor segmentation method, device and electronic device. Background Art

[0002] During the operation of the neural network model, the calculation of each operator is performed in sequence according to the topological order of the calculation graph. Accordingly, during the compilation process, the tensor data of each operator is allocated in memory according to the topological order. With the development of artificial intelligence (AI) technology, neural network models are becoming more and more complex. During the memory allocation process, the tensor data of the neural network model may exceed the maximum capacity of the memory, resulting in memory allocation failure and inability to run.

[0003] In the related art, the output tensor data of the operator is stored in the external memory, and then the input tensor data of the operator and the generated output data stored in the memory space are deleted to free up the memory space. Finally, the output data of the operator is obtained from the external memory and used as the input data of the next operator. However, the reading speed of the external memory is much lower than the reading speed of the memory, which will affect the computational efficiency of the neural network model.

[0004] Therefore, in the process of compiling the neural network model, how to split the operators into tensors so that the intermediate data of each operator can be stored in the memory and reduce the access to the external memory is a technical problem that needs to be solved urgently. Summary of the invention

[0005] In view of the above problems, the purpose of the present invention is to provide a tensor segmentation method, device and electronic device, which can enable the reading and storage of tensor data of a neural network in the memory, reduce the access to the external memory, and improve computing efficiency.

[0006] According to a first aspect of the present invention, there is provided a tensor splitting method for a neural network, comprising: based on input data of the neural network, obtaining a computational graph when the neural network performs computations on the input data and tensor information of tensor data, wherein the computational graph comprises a plurality of computational nodes and tensor data between the respective computational nodes; allocating memory for the tensor data of the neural network according to the topological order of the computational graph, and obtaining a current node and current tensor data from the computational graph, wherein a size of the current tensor data exceeds an allocatable space of the current memory; performing a reverse search from the current node to obtain a current node group and a current tensor split group, wherein the current tensor split group comprises at least 2 tensor data; and splitting the tensor data in the current tensor split group so that the sizes of the split tensor data in the current tensor split group do not exceed the allocatable space of the current memory.

[0007] Preferably, performing a reverse search from the current node to obtain the current node group and the current tensor cut group includes: when the neural network has a branching structure, searching forward and backward from the current node to the starting node, the starting node is a fork node adjacent to the current node; searching backward from the starting node to the ending node to obtain the current node group, the ending node is the root node of the branch after the starting node, the root node is the merge node of all branches, and the current node group includes the starting node, the ending node, and the intermediate node between the starting node and the ending node; the tensor data between the starting node and the ending node and the output tensor of the ending node are divided into the current tensor cut group.

[0008] Preferably, performing a reverse search from the current node to obtain the current node grouping and the current tensor cut grouping also includes: determining whether the current node is a starting node or an ending node; if the current node is a starting node or an ending node, continuing to search backwards and forwards from the starting node of the current node grouping to update the starting node of the current node grouping, and the updated starting node is a fork node adjacent to the current starting node; searching backwards from the starting node to the ending node to obtain the current node grouping; when the current node is not a starting node or an ending node, dividing the tensor data between the starting node and the ending node and the output tensor of the ending node into the current tensor cut grouping; repeating the above steps until the current node is not a starting node or an ending node.

[0009] Preferably, performing a reverse search from the current node to obtain the current node group and the current tensor split group also includes: traversing whether there is an intermediate node that does not support splitting in the current node group; if there is an intermediate node that does not support splitting in the current node group, truncating the current node group from the intermediate node that does not support splitting to divide it into at least 2 node groups; when the node groups are all intermediate nodes that support splitting, dividing the tensor data between the starting node and the ending node and the output tensor of the ending node into the current tensor split group.

[0010] Preferably, performing a reverse search from the current node to obtain the current node grouping and the current tensor cut grouping also includes: when the number of intermediate nodes of the current node grouping exceeds a preset threshold, removing the branch structure with a close distance between the starting node and the ending node in the current node grouping to obtain the reduced current node grouping.

[0011] Preferably, splitting the tensor data in the current tensor split group includes: traversing all splitting strategies to split the tensor data in the current tensor split group; judging whether the size of the split tensor data in the current tensor split group exceeds the allocatable space of the memory; and performing memory allocation when the size of the split tensor data in the current tensor split group does not exceed the allocatable space of the current memory.

[0012] According to a second aspect of the present invention, there is provided a tensor splitting device, comprising: an acquisition unit, for acquiring, based on input data of a neural network, a computational graph when the neural network performs computations on the input data and tensor information of tensor data, wherein the computational graph comprises a plurality of computational nodes and tensor data between the respective computational nodes; an allocation unit, for performing memory allocation for tensor data of the neural network according to the topological order of the computational graph, and for acquiring a current node and current tensor data from the computational graph, wherein the size of the current tensor data exceeds the allocatable space of the current memory; a search unit, for performing a reverse search from the current node to acquire a current node group and a current tensor split group, wherein the current tensor split group comprises at least 2 tensor data; a splitting unit; , used to split the tensor data in the current tensor split group so that the size of the split tensor data in the current tensor split group does not exceed the allocatable space of the current memory; wherein the search unit is also used to, when the neural network has a branching structure, search forward and backward from the current node to the starting node, the starting node is a fork node adjacent to the current node; search backward from the starting node to the ending node to obtain the current node group, the ending node is the root node of the branch after the starting node, the root node is the merge node of all branches, and the current node group includes the starting node, the ending node, and the intermediate node between the starting node and the ending node; divide the tensor data between the starting node and the ending node and the output tensor of the ending node into the current tensor split group.

[0013] Preferably, the search unit is also used to determine whether the current node is a starting node or an ending node; if the current node is a starting node or an ending node, continue to search backward and forward from the starting node of the current node group to update the starting node of the current node group, and the updated starting node is a fork node adjacent to the current starting node; search backward from the starting node to the ending node to obtain the current node group; when the current node is not a starting node or an ending node, divide the tensor data between the starting node and the ending node and the output tensor of the ending node into the current tensor cut group; repeat the above steps until the current node is not a starting node or an ending node.

[0014] According to a third aspect of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the tensor splitting method described above when executing the computer program.

[0015] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the tensor segmentation method described above is implemented.

[0016] The tensor splitting method, device and electronic device provided by the present invention obtain the previous node group and the current tensor splitting group through reverse search, and split the tensor data in the current tensor splitting group so that the reading and storage of the tensor data of the neural network are both in the memory. Large tensor data can be split to meet the memory space requirements, reduce the access to the external memory, and improve the computing efficiency.

[0017] Furthermore, when there is an intermediate node in the current node group that does not support splitting, the current node group is divided into at least two node groups from the intermediate node that does not support splitting, so as to solve the problem that the input and output tensors of some nodes in the node group cannot be split.

[0018] Furthermore, when the intermediate nodes of the node grouping exceed a preset threshold, the node grouping is reduced to obtain the reduced node grouping, thereby reducing data overlap and repeated calculations, and further improving calculation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:

[0020] Figure 1 A schematic diagram showing a calculation diagram 10 of some embodiments of the present application;

[0021] Figure 2 A schematic diagram showing another calculation graph 20 of some embodiments of the present application;

[0022] Figure 3 A schematic diagram showing another calculation graph 30 of some embodiments of the present application;

[0023] Figure 4 A flowchart showing a tensor segmentation method of a neural network provided in an embodiment of the present application is shown;

[0024] Figure 5 A flowchart of step S130 provided in an embodiment of the present application is shown;

[0025] Figure 6 A schematic diagram showing the structure of a tensor segmentation device for a neural network provided in an embodiment of the present application is shown;

[0026] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0027] Various embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. In each of the accompanying drawings, the same elements are represented by the same or similar reference numerals. For the sake of clarity, the various parts in the accompanying drawings are not drawn to scale.

[0028] The specific implementation of the present invention is further described in detail below in conjunction with the drawings and examples.

[0029] Before introducing the technical solutions involved in the embodiments of the present application, some of the terms included in the embodiments of the present application are explained first.

[0030] (1) Computational Graph

[0031] The term "computational graph" included in the embodiments of the present application refers to a method of describing the computational process of a neural network model using a directed graph structure. In practical applications, there are two basic elements of a directed graph structure, namely nodes and directed edges. Among them, nodes refer to operators in the computational process of a neural network model; directed edges refer to the pointing directions between different operators, that is, the dependencies between different operators.

[0032] In some embodiments, the neural network model can be abstracted into tensor data and nodes, and the directed graph structure is generated based on the tensor data and nodes.

[0033] Figure 1 According to some embodiments of the present application, a schematic diagram of a calculation diagram 10 is shown. Figure 1 As shown, the computational graph 10 includes 5 nodes and 5 tensor data. Specifically, the 5 nodes are node a, node b, node c, node d and node e, and the 5 tensor data are tensor data T0, tensor data T1, tensor data T2, tensor data T3 and tensor data T4. Taking node a, node b and node c as examples, for node a, there is a directed edge between node a and node b, and the direction of the directed edge is from node a to node b. The directed edge indicates that the tensor data T0 generated by node a is the input of node b; at the same time, there is a directed edge between node a and node c, and the direction of the directed edge is from node a to node c. The directed edge indicates that the tensor data T1 generated by node a is the input of node c.

[0034] (2) Tensor

[0035] The term "tensor" in the embodiments of the present application refers to tensor data, which may include input tensor data and output tensor data in a neural network model, and may also include feature tensor data, etc. Among them, the tensor data in the embodiments of the present application mainly refers to the intermediate data generated by each node.

[0036] In some embodiments, the neural network model can be applied to scenarios such as speech recognition and image recognition. Based on input data, such as audio data or image data, the neural network model can determine the tensor data and nodes of the input data in the neural network model, and can generate a corresponding computational graph based on the tensor data and nodes.

[0037] For example, Figure 2 A schematic diagram of another computational graph of some embodiments of the present application is shown. Figure 2 As shown, the computation graph 20 includes 8 nodes and 7 tensor data. The 8 nodes are respectively node 0, node 1, node 2, node 3, node 4, node 5, node 6 and node 7, and the 7 tensor data are respectively tensor data T0, tensor data T1, tensor data T2, tensor data T3, tensor data T4, tensor data T5, tensor data T6 and tensor data T7.

[0038] like Figure 2 As shown, there is a directed edge between node 0 and node 1, the direction of which is from node 0 to node 1, and the directed edge indicates that the tensor data T0 generated by node 0 is the input of node 1; at the same time, there is a directed edge between node 0 and node 3, the direction of which is from node 0 to node 3, and the directed edge indicates that the tensor data T0 generated by node 0 is the input of node 3. There is a directed edge between node 1 and node 2, the direction of which is from node 1 to node 2, and the directed edge indicates that the tensor data T1 generated by node 1 is the input of node 2. There is a directed edge between node 2 and node 7, the direction of which is from node 2 to node 7, and the directed edge indicates that the tensor data T2 generated by node 2 is the input of node 7. There is a directed edge between node 3 and node 4, the direction of which is node 3 pointing to node 4, and the directed edge indicates that the tensor data t3 generated by node 3 is the input of node 4; at the same time, there is a directed edge between node 3 and node 5, the direction of which is node 3 pointing to node 5, and the directed edge indicates that the tensor data T3 generated by node 3 is the input of node 5. There is a directed edge between node 4 and node 6, the direction of which is node 4 pointing to node 6, and the directed edge indicates that the tensor data T4 generated by node 4 is the input of node 6. There is a directed edge between node 5 and node 6, the direction of which is node 5 pointing to node 6, and the directed edge indicates that the tensor data T5 generated by node 5 is the input of node 6. There is a directed edge between node 6 and node 7, the direction of which is node 6 pointing to node 7, and the directed edge indicates that the tensor data T6 generated by node 6 is the input of node 7.

[0039] For example, Figure 3 A schematic diagram of another computational graph of some embodiments of the present application is shown. Figure 3As shown, the computation graph 20 includes 7 nodes and 6 tensor data. The 7 nodes are respectively node 0, node 1, node 2, node 3, node 4, node 5 and node 6, and the 6 tensor data are respectively tensor data T0, tensor data T1, tensor data T2, tensor data T3, tensor data T4, tensor data T5 and tensor data T6.

[0040] As deep learning neural networks become larger and larger, the tensor data of the neural network model may exceed the maximum capacity of the memory during the memory allocation process, resulting in memory allocation failure and inability to run.

[0041] Figure 4 The flowchart of the tensor segmentation method of the neural network provided by the embodiment of the present invention is shown. This embodiment is applicable to the case of performing tensor segmentation on operators. The method can be executed by a tensor segmentation device, which can be implemented by software and / or hardware and can generally be integrated in an artificial intelligence processor. Figure 4 As shown, the tensor segmentation method of the neural network includes but is not limited to the following steps.

[0042] In step S110, based on the input data of the neural network, the computation graph and tensor information of the tensor data corresponding to the neural network are obtained.

[0043] In this embodiment, the neural network may be a convolutional neural network (CNN), a recurrent neural network (RNN), a deep neural network (DNN), etc. This application does not impose any restrictions on the type of neural network.

[0044] In this embodiment, the electronic device 100 obtains a computational graph corresponding to a neural network, wherein the computational graph includes N nodes and directed edges connecting different nodes, the directed edges of the computational graph carry tensor data, and the computational graph includes M tensor data, N is an integer greater than 1, and M is a positive integer. Then, the tensor name, tensor size, and dependency relationship between the tensor data of each tensor data are determined. It can be understood that the tensor name can be the number of the tensor data, and the tensor size can be the size of the tensor data.

[0045] Combination Figure 2 From the calculation graph shown, it can be seen that the tensor names corresponding to tensor data T0 to T6 can be T0, T1, T2, T3, T4, T5, the size of tensor data T0 is 4MB, the size of tensor data T1 is 4MB, the size of tensor data T2 is 4MB, the size of tensor data T3 is 4MB, the size of tensor data T4 is 4MB, the size of tensor data T5 is 1MB, and the size of tensor data T6 is 4MB.

[0046] In step S120, memory is allocated for tensor data of the neural network according to the topological order of the computation graph, and a current node and current tensor data are obtained from the computation graph, wherein the size of the current tensor data exceeds the allocatable space of the current memory.

[0047] In this embodiment, there is a dependency relationship between the output tensor and the input tensor of the node, so there is also a dependency relationship between the corresponding tensor data. For example, after the tensor data T0 is allocated to the memory space, after both nodes 1 and 3 have completed the calculation of the output tensor data T1 and tensor data T3, the calculation of the subsequent nodes will not depend on the tensor data T0. At this time, the tensor data T0 can be deleted from the memory to release the memory space. The current tensor data is used as the output tensor of the current node.

[0048] When the tensor data of the neural network is allocated memory according to the topological order of the computational graph, when the current tensor data is allocated, the size of the current tensor data exceeds the allocatable space of the current memory, and the current tensor data is the output tensor of the current node.

[0049] In step S130, a reverse search is performed from the current node to obtain the current node group and the current tensor cut group, wherein the current tensor cut group includes at least 2 tensor data.

[0050] In this embodiment, participating Figure 5 , step S130 includes step S131 to step S132.

[0051] Step S131: When the neural network has a branching structure, search forward and backward from the current node to the starting node, where the starting node is a bifurcation node adjacent to the current node.

[0052] In this embodiment, there is a dependency relationship between the forked node and multiple nodes, that is, the output tensor of the forked node is the input tensor of at least two nodes.

[0053] Step S132: Search backward from the starting node to the ending node to obtain the current node group, the ending node is the root node of the branch after the starting node, the root node is the merge node of all branches, and the current node group includes the starting node, the ending node, and the intermediate nodes between the starting node and the ending node.

[0054] In this embodiment, the output tensors of at least two branches are the input tensors of the root node.

[0055] Step S133: Divide the tensor data between the start node and the end node and the output tensor of the end node into current tensor cut groups.

[0056] In this embodiment, when a certain tensor data is used as an input tensor by multiple nodes according to the dependency relationship of the tensor data, the tensor data does not need to be split and is excluded when dividing the current tensor split groups.

[0057] Combination Figure 2 , when allocating tensor data T5 and the size of tensor data T5 exceeds the allocatable space of the current memory, search backward from the current node 5 to node 3 as the starting node, and then search backward from node 3 to node 6 as the ending node; the tensor data [T3, T4, T5] between node 3 and node 6 is grouped as the current tensor.

[0058] In a preferred embodiment, the following steps are further included between step S132 and step S133.

[0059] Step S134: Determine whether the current node is a start node or an end node.

[0060] Step S135: If the current node is the starting node or the ending node, continue to search backward and forward from the starting node of the current node group to update the starting node of the current node group. The updated starting node is the fork node adjacent to the current starting node and search backward from the starting node to the ending node to obtain the current node group.

[0061] When the current node is not the start node or the end node, step S136 is executed.

[0062] In this embodiment, step S134 and step S135 are repeated until the current node is not a start node or an end node.

[0063] Combination Figure 2 , when allocating tensor data T6 and the size of tensor data T6 exceeds the allocable space of the current memory, search backward from the current node 6 to node 3 as the starting node, and then search backward from node 3 to node 6 as the ending node; since the current node 6 is the ending node, continue to search backward from the starting node 3 to the adjacent fork node 0 as the updated starting node; then search backward from the starting node 0 to node 7 as the ending node. The tensor data [T0, T1, T2, T3, T4, T5, T6] between node 0 and node 7 is used as the current tensor cut group.

[0064] Step S136: traverse the current node group to see if there is an intermediate node that does not support segmentation.

[0065] Step S137: When there is an intermediate node that does not support splitting in the current node group, the current node group is cut from the intermediate node that does not support splitting to be divided into at least two node groups.

[0066] When the node groups are all intermediate nodes that support splitting, continue to execute step S133.

[0067] In a preferred embodiment, step S130 also includes step S138.

[0068] Step S138: When the number of intermediate nodes in the current node group exceeds a preset threshold, the branch structure with a short distance between the start node and the end node in the current node group is removed to obtain a reduced current node group.

[0069] In this embodiment, for example, there are at least two branches between the starting node and the ending node. If the number of all intermediate nodes exceeds a preset threshold, the branch with the least number of intermediate nodes on the branch can be removed to reduce the current node grouping. The branch structure with a short distance between the starting node and the ending node refers to the branch with the least number of intermediate nodes between the starting node and the ending node.

[0070] In a preferred embodiment, when the neural network does not have a branching structure, the current node is grouped as a current node and the input tensor and output tensor of the current node are grouped as current tensors.

[0071] In step S140, the tensor data in the current tensor split group is split so that the size of the split tensor data in the current tensor split group does not exceed the allocatable space of the current memory.

[0072] In this embodiment, all splitting strategies are traversed to split the tensor data of the current tensor splitting group, and it is determined whether the size of the split tensor data in the current tensor splitting group exceeds the allocatable space of the memory; when the size of the split tensor data in the current tensor splitting group does not exceed the allocatable space of the current memory, memory allocation is performed.

[0073] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0074] The tensor splitting method of the present application obtains the previous node grouping and the current tensor splitting group through reverse search, and splits the tensor data in the current tensor splitting group so that the reading and storage of the tensor data of the neural network are both in the memory. Large tensor data can be split to meet the memory space requirements, reduce the access to the external memory, and improve computing efficiency.

[0075] Furthermore, when there is an intermediate node in the current node group that does not support splitting, the current node group is divided into at least two node groups from the intermediate node that does not support splitting, so as to solve the problem that the input and output tensors of some nodes in the node group cannot be split.

[0076] Furthermore, when the intermediate nodes of the node grouping exceed a preset threshold, the node grouping is reduced to obtain the reduced node grouping, thereby reducing data overlap and repeated calculations, and further improving calculation efficiency.

[0077] Corresponding to the tensor segmentation method described in the above embodiment, Figure 6 is a structural block diagram of a tensor segmentation device provided in an embodiment of the present application. For the sake of convenience, only the parts related to the embodiment of the present application are shown. Figure 6 As shown, the tensor splitting device 60 includes an acquisition unit 61 , an allocation unit 62 , a search unit 63 and a splitting unit 64 .

[0078] Among them, the acquisition unit 61 is used to obtain the calculation graph when the neural network calculates the input data and the tensor information of the tensor data based on the input data of the neural network, wherein the calculation graph includes multiple computing nodes and tensor data between each computing node.

[0079] The allocation unit 62 is used to allocate memory for the tensor data of the neural network according to the topological order of the calculation graph, and obtain the current node and the current tensor data from the calculation graph, wherein the size of the current tensor data exceeds the allocatable space of the current memory.

[0080] The search unit 63 is used to perform a reverse search from the current node to obtain the current node group and the current tensor cut group, wherein the current tensor cut group includes at least 2 tensor data.

[0081] The segmentation unit 64 is used to segment the tensor data in the current tensor segmentation group so that the size of the segmented tensor data in the current tensor segmentation group does not exceed the allocatable space of the current memory.

[0082] Preferably, the search unit 63 is also used for searching forward and backward from the current node to the starting node when the neural network has a branching structure, the starting node is a bifurcation node adjacent to the current node; searching backward from the starting node to the terminating node to obtain the current node group, the terminating node is the root node of the branch after the starting node, the root node is the merge node of all branches, and the current node group includes the starting node, the terminating node, and the intermediate nodes between the starting node and the terminating node; dividing the tensor data between the starting node and the terminating node and the output tensor of the terminating node into the current tensor group.

[0083] Preferably, the search unit 63 is also used to determine whether the current node is a starting node or an ending node; if the current node is a starting node or an ending node, continue to search backward and forward from the starting node of the current node group to update the starting node of the current node group, and the updated starting node is the fork node adjacent to the current starting node; search backward from the starting node to the ending node to obtain the current node group; when the current node is not a starting node or an ending node, divide the tensor data between the starting node and the ending node and the output tensor of the ending node into the current tensor cut group; repeat the above steps until the current node is not a starting node or an ending node.

[0084] Figure 7 Schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Figure 7 As shown, the electronic device 70 of this embodiment includes: at least one processor 71 ( Figure 7 Only one is shown in the figure) a processor, a memory 72, and a computer program 73 stored in the memory 72 and executable on the at least one processor 71, and when the processor 71 executes the computer program 73, the steps in any of the above-mentioned storage space allocation method embodiments are implemented.

[0085] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that Figure 7 This is merely an example of the electronic device 70 and does not constitute a limitation on the electronic device 70 . The electronic device 70 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0086] The processor 71 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0087] In some embodiments, the memory 72 may be an internal storage unit of the electronic device 70, such as a hard disk or memory of the electronic device 70. In other embodiments, the memory 72 may also be an external storage device of the electronic device 70, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 70. Further, the memory 72 may also include both an internal storage unit of the electronic device 70 and an external storage device. The memory 72 is used to store an operating system, an application program, a boot loader (Boot Loader), data, and other programs, such as the program code of the computer program, etc. The memory 72 may also be used to temporarily store data that has been output or is to be output.

[0088] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0089] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0090] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the device / electronic device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0091] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0092] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0093] In the embodiments provided in the present application, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0094] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0095] According to the embodiments of the present invention as described above, these embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and changes can be made based on the above description. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can make good use of the present invention and the modified use based on the present invention. The present invention is limited only by the claims and their full scope and equivalents.

Claims

1. A tensor segmentation method, It is characterized in that include: Based on the input data of the neural network, obtaining a computational graph when the neural network calculates the input data and tensor information of the tensor data, wherein the computational graph includes a plurality of computational nodes and tensor data between each of the computational nodes; Allocating memory for tensor data of the neural network according to the topological order of the computation graph, and obtaining a current node and current tensor data from the computation graph, wherein a size of the current tensor data exceeds an allocatable space of the current memory; Perform a reverse search from the current node to obtain a current node group and a current tensor cut group, wherein the current tensor cut group includes at least 2 tensor data; Split the tensor data in the current tensor split group so that the size of the split tensor data in the current tensor split group does not exceed the allocatable space of the current memory; Among them, the reverse search from the current node to obtain the current node grouping and the current tensor cut grouping includes: When the neural network has a branching structure, searching backward from the current node to the starting node, the starting node is a bifurcation node adjacent to the current node; Search backward from the starting node to the ending node to obtain a current node group, the ending node is the root node of the branch after the starting node, the root node is the merged node of all branches, and the current node group includes the starting node, the ending node, and the intermediate nodes between the starting node and the ending node; Determine whether the current node is the starting node or the ending node; If the current node is the starting node or the ending node, continue searching backwards and forwards from the starting node of the current node group to update the starting node of the current node group, and the updated starting node is the fork node adjacent to the current starting node; Search backward from the starting node to the ending node to obtain the current node group; When the current node is not the starting node or the ending node, the tensor data between the starting node and the ending node and the output tensor of the ending node are divided into the current tensor cut group; Repeat the above steps until the current node is not the start node or the end node.

2. The tensor segmentation method according to claim 1, It is characterized in that Searching backward from the current node to get the current node group and the current tensor cut group also includes: Check whether there are any intermediate nodes in the current node group that do not support splitting; There is an intermediate node that does not support splitting in the current node group, and the current node group is cut off from the intermediate node that does not support splitting to be divided into at least two node groups; When the node groups are all intermediate nodes that support splitting, the tensor data between the starting node and the ending node and the output tensor of the ending node are divided into the current tensor splitting group.

3. The tensor segmentation method according to claim 2, It is characterized in that Searching backward from the current node to get the current node group and the current tensor cut group also includes: When the number of intermediate nodes in the current node group exceeds a preset threshold, a branch structure with a short distance between a start node and an end node in the current node group is removed to obtain a reduced current node group.

4. The tensor segmentation method according to claim 1, It is characterized in that Splitting the tensor data in the current tensor split group includes: Traverse all splitting strategies to split the tensor data of the current tensor splitting group; Determine whether the size of the split tensor data in the current tensor split group exceeds the allocatable space in the memory; Memory allocation is performed when the size of the split tensor data in the current tensor split group does not exceed the allocatable space of the current memory.

5. A tensor segmentation device, It is characterized in that include: An acquisition unit, configured to acquire, based on input data of a neural network, a computation graph when the neural network performs computation on the input data and tensor information of tensor data, wherein the computation graph includes a plurality of computation nodes and tensor data between the computation nodes; An allocation unit, configured to allocate memory for tensor data of a neural network according to a topological order of a computation graph, and obtain a current node and current tensor data from the computation graph, wherein a size of the current tensor data exceeds an allocatable space of a current memory; A search unit, configured to perform a reverse search from a current node to obtain a current node group and a current tensor cut group, wherein the current tensor cut group includes at least 2 tensor data; A splitting unit, used to split the tensor data in the current tensor splitting group so that the size of the split tensor data in the current tensor splitting group does not exceed the allocatable space of the current memory; Among them, the search unit is also used to search forward and backward from the current node to the starting node when the neural network has a branch structure, and the starting node is a fork node adjacent to the current node; search backward from the starting node to the terminating node to obtain the current node group, and the terminating node is the root node of the branch after the starting node, and the root node is the merge node of all branches. The current node group includes the starting node, the terminating node, and the intermediate nodes between the starting node and the terminating node; determine whether the current node is the starting node or the terminating node; if the current node is the starting node or the terminating node, continue to search backward and forward from the starting node of the current node group to update the starting node of the current node group, and the updated starting node is the fork node adjacent to the current starting node; search backward from the starting node to the terminating node to obtain the current node group; when the current node is not the starting node or the terminating node, divide the tensor data between the starting node and the terminating node and the output tensor of the terminating node into the current tensor cut group; repeat the above steps until the current node is not the starting node or the terminating node.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.

7. A computer-readable storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.