Data migration method, device, server and storage medium

By establishing link relationships and similarity judgments between network layers in the neural network, intelligent pruning is performed, which solves the problem of performance loss caused by pruning the neural network model in the existing technology and improves the recognition accuracy.

CN117610634BActive Publication Date: 2024-09-13HEBEI SHINEYUE SOFTWARE TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311545921.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-20
Publication Date
2024-09-13
Estimated Expiration
2043-11-20

AI Technical Summary

Technical Problem

Existing neural network model pruning algorithms are usually performed independently for each network layer, resulting in model performance loss and reduced recognition accuracy, and cannot effectively reduce the performance loss of the neural network during the pruning process.

Method used

By obtaining the structural information of each network layer of the neural network, establishing the link relationship between adjacent network layers, determining the dimension nodes and channel groups that can be pruned, and pruning based on the similarity to reduce the loss of neural network performance. .

Benefits of technology

Through correlation judgment and similarity pruning, the performance loss of the neural network model during the pruning process is reduced, and the recognition accuracy is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117610634B
    Figure CN117610634B
Patent Text Reader

Abstract

The present application relates to the field of data processing, and in particular to a data migration method, device, server and storage medium, the method comprising obtaining structural information of each network layer in a neural network to be pruned, establishing a link relationship between dimensional nodes with the same order and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in each two adjacent network layers, determining all dimensional nodes in the same link relationship as a target group, determining the variable dimensional nodes that can be pruned in each target group, determining the target group with variable dimensional nodes as a variable group, determining two channels with a similarity greater than or equal to a preset threshold as a prunable channel group; pruning each prunable channel group, reconstructing each pruned network layer to obtain a pruned neural network; migrating the pruned neural network. The scheme of the present application can reduce the performance loss caused by pruning the neural network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a data migration method, device, server and storage medium. Background Art

[0002] With the rise of artificial intelligence, many applications have deployed deep neural network models to more efficiently process tasks such as optical character recognition, sensitive word detection, image classification, and speech recognition, and the service developers of these applications usually deploy neural network models on servers. Since the size of applications that deploy neural network models is usually large, when such application data needs to be transmitted, such as configuring the application to the local client's electronic device, the neural network model needs to be streamlined before transmission.

[0003] In the related art, pruning algorithms are usually used to streamline neural network models. However, these pruning algorithms can only prune each network layer of the neural network independently. Since neural network models generally include multiple network layers, and some network layers are related, changes in a certain network layer will also affect the performance of other network layers. Therefore, the performance of the streamlined neural network model obtained by the existing pruning algorithm will be reduced, that is, the recognition accuracy of the streamlined neural network model is low.

[0004] Therefore, how to reduce the performance loss of the neural network when the model is pruned is an urgent problem that needs to be solved. Summary of the invention

[0005] In order to reduce the performance loss when a neural network model is pruned, the present application provides a data migration method, device, server and storage medium.

[0006] In a first aspect, the present application provides a data migration method, which adopts the following technical solution:

[0007] A data migration method, comprising:

[0008] Acquire structural information of each network layer in the neural network to be pruned, the structural information including a parameter matrix and an output matrix of the network layer, the output matrix is ​​obtained by transforming input data of the network layer through the parameter matrix, each matrix includes at least one type of dimensional node, and each dimensional node includes at least two channels;

[0009] Establish a link relationship between the output matrix of the upper network layer and the two dimensional nodes with the same sequence and the same number of channels in the parameter matrix of the lower network layer in each of two adjacent network layers, wherein the output matrix of the upper network layer is the input data of the lower network layer;

[0010] All dimension nodes in the same link relationship are determined as a target group. In the parameter matrix and output matrix of the same network layer, there are link relationships between dimension nodes of the same order.

[0011] Determine that the dimensional nodes that can be pruned in each of the target groups are variable dimensional nodes, and determine the target group having the variable dimensional nodes as a variable group;

[0012] For each of the variable groups, determine the similarity between every two channels in the variable group, and determine two channels whose similarity is greater than or equal to a preset threshold as a prunable channel group;

[0013] Pruning each of the prunable channel groups to delete a channel, thereby obtaining pruned network layers;

[0014] Reconstructing each of the pruned network layers to obtain a pruned neural network;

[0015] The pruned neural network is migrated.

[0016] By adopting the above technical scheme, the correlation of each dimensional node between adjacent network layers is judged, the dimensional nodes with correlation are determined and a link relationship is established, and the channels with a link relationship in adjacent network layers, that is, each channel in each target group, are judged for similarity, and two channels with high similarity, that is, the similarity is greater than or equal to a preset threshold, are pruned. That is, the pruning process takes into account the relationship between the channels of the associated network layers, and only prunes the two channels with high similarity to reduce the performance loss caused by pruning the neural network.

[0017] In a possible implementation, determining that the dimensional nodes that can be pruned in each of the target groups are variable dimensional nodes includes:

[0018] For each parameter matrix in the network layer, determining whether there is a variable-dimensional node in the parameter matrix based on a preset condition;

[0019] The preset condition includes at least one of the following:

[0020] If the dimension node has a link relationship with any dimension node in the output matrix of the current network layer, and has no link relationship with the output matrix of the last network layer, then the dimension node is determined to be a variable dimension node;

[0021] If the dimension node has no link relationship with the input matrix of the first network layer, and the dimension node has a link relationship with any dimension node of the output matrix of the previous network layer of the current network layer, then the dimension node is determined to be a variable dimension node.

[0022] In a possible implementation, for each of the variable groups, determining the similarity between every two channels in the variable group includes:

[0023] Determine the distance between every two channels in each of the variable dimension nodes;

[0024] Based on the distance between every two channels in each of the variable dimension nodes, the similarity between every two channels in the variable group is determined.

[0025] In a possible implementation, determining the distance between every two channels in each of the variable-dimensional nodes includes:

[0026] Determine the number of channels M in the variable-dimensional node;

[0027] Divide the parameter matrix where each variable-dimensional node is located into M sub-matrices, wherein the first dimension of each sub-matrix is ​​a sequence channel in the corresponding variable-dimensional node;

[0028] For each of the variable-dimensional nodes, the distance between every two channels is determined based on the sub-matrices in which the two channels are located, and the distance between any two channels is the Euclidean distance between the sub-matrices in which the two channels are located.

[0029] In a possible implementation manner, pruning each of the prunable channel groups to delete a channel includes:

[0030] Based on the order of the channels, the channels with the highest order are determined as the channels that can be pruned;

[0031] Setting an attribute for each channel in each target group, wherein the attribute is pruneable or non-pruneable;

[0032] Prune each of the prunable channel groups to delete each of the channels with the attribute of being prunable.

[0033] In one possible implementation, before obtaining the structural information of each network layer in the neural network to be pruned, the following steps are also included:

[0034] Performing model conversion on the neural network to obtain an ONNX model;

[0035] The step of obtaining structural information of each network layer in the neural network to be pruned includes:

[0036] The structural information of each network layer in the neural network is obtained from the ONNX model.

[0037] In one possible implementation, the method further includes:

[0038] Extracting the preprocessing code in the target software and encapsulating it to obtain a preprocessing function, wherein the target software is software constructed with the neural network, and the preprocessing code is a code for preprocessing the output data and the output data of the neural network;

[0039] The configuration information of the target software is obtained, and packaging is performed based on the configuration information and the preprocessing function to obtain a package file, wherein the configuration information includes the name and version number of each module in the preprocessing code.

[0040] In a second aspect, the present application provides a data migration device, which adopts the following technical solution:

[0041] A data migration device, comprising:

[0042] A structural information acquisition module, used to acquire structural information of each network layer in the neural network to be pruned, wherein the structural information includes a parameter matrix and an output matrix of the network layer, wherein the output matrix is ​​obtained by transforming the input data of the network layer through the parameter matrix, wherein each matrix includes at least one type of dimensional node, and each dimensional node includes at least two channels;

[0043] A link relationship establishment module, used to establish a link relationship between two dimensional nodes with the same sequence and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in each of two adjacent network layers, wherein the output matrix of the upper network layer is the input data of the lower network layer;

[0044] The target group determination module is used to determine all dimension nodes in the same link relationship as a target group. In the parameter matrix and output matrix of the same network layer, there is a link relationship between dimension nodes of the same sequence;

[0045] A variable dimension node determination module, used for determining that the dimension nodes that can be pruned in each of the target groups are variable dimension nodes, and determining the target group having the variable dimension nodes as a variable group;

[0046] A similarity determination module, for each of the variable groups, is used to determine the similarity between every two channels in the variable group, and determine two channels whose similarity is greater than or equal to a preset threshold as a prunable channel group;

[0047] A pruning module, used for pruning each of the prunable channel groups to delete a channel, and obtaining each pruned network layer;

[0048] A reconstruction module, used for reconstructing the pruned network layers to obtain a pruned neural network;

[0049] A migration module is used to migrate the pruned neural network.

[0050] By adopting the above technical scheme, the correlation of each dimensional node between adjacent network layers is judged, the dimensional nodes with correlation are determined and a link relationship is established, and the channels with a link relationship in adjacent network layers, that is, each channel in each target group, are judged for similarity, and two channels with high similarity, that is, the similarity is greater than or equal to a preset threshold, are pruned. That is, the pruning process takes into account the relationship between the channels of the associated network layers, and only prunes the two channels with high similarity to reduce the performance loss caused by pruning the neural network.

[0051] In a possible implementation, when determining that the dimensional nodes that can be pruned in each of the target groups are dimensional nodes that can be pruned, the variable-dimensional node determination module is specifically configured to:

[0052] For each parameter matrix in the network layer, determining whether there is a variable-dimensional node in the parameter matrix based on a preset condition;

[0053] The preset condition includes at least one of the following:

[0054] If the dimension node has a link relationship with any dimension node in the output matrix of the current network layer, and has no link relationship with the output matrix of the last network layer, then the dimension node is determined to be a variable dimension node;

[0055] If the dimension node has no link relationship with the input matrix of the first network layer, and the dimension node has a link relationship with any dimension node of the output matrix of the previous network layer of the current network layer, then the dimension node is determined to be a variable dimension node.

[0056] In a possible implementation, the similarity determination module, for each variable group, when determining the similarity between each two channels in the variable group, is specifically configured to:

[0057] Determine the distance between every two channels in each of the variable dimension nodes;

[0058] Based on the distance between every two channels in each of the variable dimension nodes, the similarity between every two channels in the variable group is determined.

[0059] In a possible implementation, when determining the distance between every two channels in each of the variable-dimensional nodes, the similarity determination module is specifically configured to:

[0060] Determine the number of channels M in the variable-dimensional node;

[0061] Divide the parameter matrix where each variable-dimensional node is located into M sub-matrices, wherein the first dimension of each sub-matrix is ​​a sequence channel in the corresponding variable-dimensional node;

[0062] For each of the variable-dimensional nodes, the distance between every two channels is determined based on the sub-matrices in which the two channels are located, and the distance between any two channels is the Euclidean distance between the sub-matrices in which the two channels are located.

[0063] In a possible implementation, when the pruning module prunes each of the prunable channel groups to delete a channel, the pruning module is specifically configured to:

[0064] Based on the order of the channels, the channels with the highest order are determined as the channels that can be pruned;

[0065] Setting an attribute for each channel in each target group, wherein the attribute is pruneable or non-pruneable;

[0066] Prune each of the prunable channel groups to delete each of the channels with the attribute of being prunable.

[0067] In a possible implementation, the device further includes a model conversion module, and the model conversion module is specifically used to:

[0068] Performing model conversion on the neural network to obtain an ONNX model;

[0069] When obtaining the structural information of each network layer in the neural network to be pruned, the structural information acquisition module is specifically used to:

[0070] The structural information of each network layer in the neural network is obtained from the ONNX model.

[0071] In a possible implementation manner, the device further includes a code packaging module, and the code packaging module is specifically configured to:

[0072] Extracting the preprocessing code in the target software and encapsulating it to obtain a preprocessing function, wherein the target software is software constructed with the neural network, and the preprocessing code is a code for preprocessing the output data and the output data of the neural network;

[0073] The configuration information of the target software is obtained, and packaging is performed based on the configuration information and the preprocessing function to obtain a package file, wherein the configuration information includes the name and version number of each module in the preprocessing code.

[0074] In a third aspect, the present application provides a server, which adopts the following technical solution:

[0075] A server, comprising:

[0076] at least one processor;

[0077] Memory;

[0078] At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the above-mentioned data migration method.

[0079] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution:

[0080] A computer-readable storage medium includes: a computer program that can be loaded by a processor and execute the above-mentioned data migration method.

[0081] In summary, the present application includes at least one of the following beneficial technical effects:

[0082] By judging the correlation of each dimensional node between adjacent network layers, the dimensional nodes with correlation are determined and a link relationship is established, and the channels with link relationships in adjacent network layers, that is, channels in each target group, are judged for similarity. Two channels with high similarity, that is, the similarity is greater than or equal to a preset threshold, are pruned. That is, the pruning process takes into account the relationship between the channels of the associated network layers, and only prunes the two channels with high similarity to reduce the performance loss caused by pruning the neural network. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] Figure 1 It is a flowchart of a data migration method in an embodiment of the present application;

[0084] Figure 2 is a schematic diagram of sub-region division in an embodiment of the present application;

[0085] Figure 3 is a structural schematic diagram of a data migration device in an embodiment of the present application;

[0086] Figure 4 It is a schematic diagram of the structure of the server in the embodiment of the present application. DETAILED DESCRIPTION

[0087] The following is combined with Figure 1 -Attached Figure 4 This application is described in further detail.

[0088] After reading this specification, those skilled in the art may make modifications to this embodiment without any creative contribution as needed, but such modifications are protected by patent law as long as they are within the scope of the claims of this application.

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

[0090] In addition, the term "and / or" in this article is only a link relationship that describes the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally indicates that the associated objects before and after are in an "or" relationship.

[0091] The present application embodiment provides a data migration method, which is executed by a server, referring to Figure 1 The method includes steps S11 to S18, wherein:

[0092] Step S11, obtaining the structural information of each network layer in the neural network to be pruned, the structural information includes the parameter matrix and output matrix of the network layer, the output matrix is ​​the input data of the network layer obtained by parameter matrix transformation, wherein, for the first network layer of the neural network, the input data of the first network layer can be regarded as the unprocessed output matrix. Each matrix includes at least one type of dimensional node, and each dimensional node includes at least two channels.

[0093] For the embodiment of the present application, the neural network is converted into an ONNX model. ONNX is an open file format designed for machine learning and is used to store trained models. It enables different deep learning frameworks (such as Pytorch, MXNet) to store model data in the same format. Then, the structural information of each network layer in the neural network is obtained from the ONNX model.

[0094] Step S12: Establish a link relationship between two dimensional nodes with the same sequence and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in every two adjacent network layers;

[0095] Step S13: determine all dimension nodes in the same link relationship as a target group;

[0096] For the embodiment of the present application, each network layer includes at least one parameter matrix and at least one output matrix. In two adjacent network layers, the output matrix of the upper network layer is the input data of the lower network layer. The link relationship indicates that the number of channels between the two dimensional nodes is the same, and the order of the two dimensional nodes in their respective matrices is also the same.

[0097] In the embodiment of the present application, the link relationship is represented by an undirected edge, that is, an undirected edge is established between two dimensional nodes with the same sequence and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in each of two adjacent network layers; at the same time, there is also a link relationship between dimensional nodes with the same sequence in the parameter matrix and output matrix of the same network layer. The same link relationship, that is, it is characterized that the dimensional nodes are reachable to each other through the link of the undirected edge.

[0098] For example, for the convolution layer, assuming that the output matrix size of the previous network layer is N*C1*H*W, where N is the number of samples, C1 is the number of channels, H is the height, and W is the width. The parameter matrix size of the convolution layer is F*C2*K*K, where F is the number of filters, C2 is the number of channels, and K is the side length of the convolution kernel. According to the rules of convolution calculation, C1 and C2 must be equal, then an undirected edge is established between the two dimensional nodes C1 and C2.

[0099] For another example, for the summation layer, assuming that the output matrix of the previous network layer is N1*C1*H1*W1, and the output matrix of this layer is N2*C2*H2*W2, if N1 and N2 must be equal, C1 and C2 must be equal, H1 and H2 must be equal, and W1 and W2 must be equal, then an undirected edge is established between H1 and H2, and an undirected edge is established between W1 and W2, between N1 and N2, and between C1 and C2. The establishment of the link relationship in this embodiment includes but is not limited to the above two cases.

[0100] Step S14: Determine that the dimensional nodes that can be pruned in each target group are variable dimensional nodes, and determine the target group with variable dimensional nodes as a variable group.

[0101] For the embodiment of the present application, the variable-dimensional nodes only exist in the parameter matrix in each network layer, that is, there are no variable-dimensional nodes in the output matrix; each target group covers the parameter matrices of at least two network layers.

[0102] Step S15: For each variable group, determine the similarity between every two channels in the variable group, and determine two channels whose similarity is greater than or equal to a preset threshold as a prunable channel group.

[0103] Step S16: Prune each prunable channel group to delete a channel, and obtain each pruned network layer.

[0104] Step S17: reconstructing each network layer after pruning to obtain a pruned neural network;

[0105] Step S18: Migrate the pruned neural network.

[0106] For the embodiment of the present application, in each variable group, the similarity between each two channels in the variable group is determined, that is, the similarity between the two channel parameters is determined, which represents the probability that the two channels can replace each other; the higher the similarity, the greater the probability that the two channels can replace each other. Among them, the preset threshold is set by the user, and the preset threshold determines the performance loss of the pruned neural network compared to the unpruned neural network, that is, the recognition accuracy.

[0107] After the prunable channel group is determined, the prunable channels in the neural network are pruned, that is, one channel in the prunable channel group is deleted, and then the pruned network layers are obtained; after the pruned network layers are reconstructed, the pruned neural network is obtained. The pruned neural network is compressed for data migration.

[0108] In an embodiment of the present application, first, by performing a correlation judgment on each dimensional node between adjacent network layers, the dimensional nodes with correlation are determined and a link relationship is established, and a similarity judgment is performed on the adjacent network layers that have a link relationship, that is, between the channels in each target group, and two channels with high similarity, that is, the similarity is greater than or equal to a set preset threshold, are pruned. That is, the pruning process takes into account the relationship between the channels between the associated network layers, and only pruned the two channels with high similarity. Compared with independent pruning of each network layer, the solution of the embodiment of the present application can reduce the performance loss caused by pruning the network model.

[0109] Further, step S13 may specifically include: setting a visited attribute for each dimension node in each network layer, the visited attribute indicates whether the node has been visited, is initialized to False, and the visited attribute of the visited node is set to True. Traverse all dimension nodes, if the visited attribute of a dimension node is False, then establish a new target group, and then use the dimension node as the root node, use the depth-first search algorithm to visit all dimension nodes that can be linked to the root node with undirected edges, divide mutually reachable nodes into the same target group, and set the visited attribute of the visited node to True.

[0110] Further, step S14 may specifically include: for the parameter matrix in each network layer, judging whether there is a variable-dimensional node in the parameter matrix based on a preset condition, wherein the preset condition includes at least one of the following:

[0111] If the dimension node has a link relationship with any dimension node in the output matrix of the current network layer, and has no link relationship with the output matrix of the last network layer, then the dimension node is determined to be a variable dimension node;

[0112] If the dimension node has no link relationship with the input matrix of the first network layer, and the dimension node has a link relationship with any dimension node of the output matrix of the previous network layer of the current network layer, then the dimension node is determined to be a variable dimension node.

[0113] For example, for a convolutional layer, assuming that the dimension of its parameter matrix is ​​F*C*K*K, if its input is the input of the entire neural network, that is, the convolutional layer is the first network layer, then the first dimension in the parameter matrix of the convolutional layer is a variable dimension, and the remaining dimensions are not variable dimensions; if its input is not the input of the entire model, then the first and second dimensions of the parameter matrix are both variable dimensions, and the remaining dimensions are not variable dimensions. For another example, for a batch normalization layer, all its parameter matrices have only one dimension, and it is a variable dimension.

[0114] In the embodiments of the present application, the methods for determining the variable dimension nodes include but are not limited to the two examples mentioned above.

[0115] Furthermore, step S15, for each variable group, determines the similarity between every two channels in the variable group, which may specifically include step S151 (not shown in the figure) and step S152 (not shown in the figure), wherein:

[0116] Step S151, determining the distance between every two channels in each variable-dimension node;

[0117] Step S152: Determine the similarity between every two channels in the variable group based on the distance between every two channels in each variable dimension node.

[0118] Specifically, for step S151, it can specifically include: determining the number of channels M in the variable dimension node; dividing the parameter matrix where each variable dimension node is located into M sub-matrices, wherein the first dimension of each sub-matrix is ​​a sequence channel in the corresponding variable dimension node; for each variable dimension node, determining the distance between every two channels based on the sub-matrices where each two channels are located, and the distance between any two channels is the Euclidean distance between the sub-matrices where the two channels are located.

[0119] Specifically, if the variable dimension is not the first dimension in the parameter matrix corresponding to the node, the parameter matrix is ​​transposed so that the variable dimension is swapped with the first dimension in the parameter matrix where it is located, and the transposed parameter matrix is ​​further divided into sub-matrices.

[0120] Specifically, in a variable group, the number of channels of the variable dimension nodes is M, then the transposed parameter matrix corresponding to each variable dimension node i (i∈G) can be decomposed into M sub-matrices, where the variable dimension node i includes M channels (1, 2, 3...M), and each channel is taken as an independent item to form a sub-matrix with the remaining dimension nodes in the parameter matrix where the variable node i is located. The M sub-matrices are recorded as w[i,1], w[i,2],..., w[i,M]. The distance between each two sub-matrices is calculated, recorded as d[i,j,k], and d[i,j,k] also represents the distance between the j-th channel and the k-th channel of the variable dimension node i.

[0121] Further, for step S151, based on the distance between every two channels in each variable dimension node, determining the similarity between every two channels in the variable group may specifically include: determining the sum of the distances between two channels with the same sequence in each dimension node as ,but ,choose The maximum value in the matrix is ​​taken as unit 1, denoted as ,but .Will The matrix is ​​normalized, and the normalized distance is recorded as D[j,k]. Then D[j,k] is the distance between the jth channel and the kth channel in a variable group, and the distance represents the similarity between the jth channel and the kth channel in the variable group.

[0122] Among them, the smaller the normalized distance D[j,k] is, the higher the similarity between the two channels is, and conversely, the larger the normalized distance D[j,k] is, the lower the similarity between the two channels is. Furthermore, the preset threshold is set to limit the size of D[j,k], but the size of the D[j,k] threshold is inversely proportional to the similarity. Therefore, in actual comparison, D[j,k] is compared with the preset threshold, and when the normalized distance D[j,k] between the two channels is less than or equal to the preset threshold, it means that the similarity between the two channels is large, that is, it is determined to be a prunable channel group.

[0123] Further example to obtain process, such as Figure 2 As shown, further, specifically, referring to Figure 2 , Figure 2There are three network layers in the example, namely network layer 1, network layer 2 and network layer 3. Each network layer includes a parameter matrix and an output matrix. The dimension nodes in each matrix are as follows Figure 2 As shown in . C2, D2, S2 and N2 form a variable group, C2 and S2 are both nodes of variable dimension, and the number of channels M is 4. C2 includes 4 channels of order (1, 2, 3, 4), so C2 is divided into 4 sub-matrices, namely [1, C1, C3, C4], [2, C1, C3, C4], [3, C1, C3, C4] and [4, C1, C3, C4]; S2 includes 4 channels of order (1, 2, 3, 4), so the S2 matrix is ​​divided into 4 sub-matrices, namely [1, S1, S3, S4], [2, S1, S3, S4], [3, S1, S3, S4] and [4, S1, S3, S4]. Then the relationship between the first-order (j=1) and second-order (k=2) channels is Add the distance between the sub-matrices [1,C1,C3,C4] and [2,C1,C3,C4] to the distance between the sub-matrices [1,S1,S3,S4] and [2,S1,S3,S4].

[0124] Further, step S16, pruning each prunable channel group to delete a channel, may specifically include: based on the sequence of the channels, determining the channels with the preceding sequence as prunable channels, setting an attribute for each channel in each target group, the attribute being prunable or non-pruneable, and pruning each prunable channel group to delete each channel with the attribute being prunable.

[0125] Specifically, set the attribute deleted for all channels in each variable group. The deleted attribute is initialized to False, indicating that it cannot be pruned, and the deleted attribute is True, indicating that it can be pruned. For each variable group, traverse all channels in the variable group. For channels with the deleted attribute of False, set the deleted attribute of the remaining unpruned channels whose normalized distance D[j,k] to the channel is less than the set threshold to True. After traversing all channels, for each variable group, delete all channels marked with the deleted attribute as True from the parameter matrix corresponding to all variable-dimensional nodes in the variable group.

[0126] The above embodiment introduces the process of how to prune a neural network model, i.e., a neural network, and migrate the pruned neural network. However, in the actual application process, the application built with the neural network model as the core is deployed on the server. In addition to the network model, the application also includes preprocessing code and business code, wherein the preprocessing code is the code for preprocessing the output data and output data of the neural network, and the business code is the code for displaying the business interface to the user so that the user can interact with the operation.

[0127] Based on the actual scenario requirements, the data that needs to be migrated includes not only the neural network, but also the business code and the preprocessing code. Therefore, the data migration method in the embodiment of the present application also includes:

[0128] Extract the preprocessing code in the target software and encapsulate it to obtain a preprocessing function, the target software is software built with a neural network, and the preprocessing code is a code for preprocessing the output data of the neural network and the output data;

[0129] The configuration information of the target software is obtained, and the package is performed based on the configuration information and the preprocessing function to obtain a package file. The configuration information includes the name and version number of each module in the preprocessing code.

[0130] Specifically, extract the preprocessing code that has been deployed on the server, encapsulate it into a function corresponding to the preprocessing code language type, store it in the same folder, generate an empty file named in a preset format in the folder, and then write a module distribution standard file corresponding to the preprocessing code language type, that is, setup.XX, where XX is the file suffix corresponding to the preprocessing code language type. Introduce the setup function of the setuptools library, set parameters such as the module name and version number, and then run the setup.py script to package the preprocessing and postprocessing codes into a wheel file.

[0131] Furthermore, a business code file that implements business functions is written to implement interaction with users, and JavaScript code is called to perform inference using a neural network to display the final result to the user. The JavaScript code includes the following content: Use Pyodide's JavaScript library to load the encapsulated wheel file to obtain the preprocessing code; read the input data, convert the input data into a data format corresponding to the language format of the preprocessing code, and call the preprocessing function to process the input data after format conversion to obtain the preprocessing result; convert the preprocessing result into the corresponding data format of JavaScript, use ONNX Runtime's JavaScript library to read the compressed neural network model, and perform inference calculations; convert the inference result into a data format corresponding to the language format of the preprocessing code, and call the post-processing function to process the inference result; finally, convert the post-processing result into the data format of JavaScript and return the result.

[0132] After that, the server starts the HTTP service and listens for user requests. The user accesses the web address through the browser and sends the service request to the server. After the server listens to the request, it sends the service code file, JavaScript code file, and pruned neural network to the client. The client's browser will execute the JavaScript code and run the pruned neural network.

[0133] The above embodiment introduces a data migration method from the perspective of method flow, and the following embodiment introduces a data migration device from the perspective of a virtual module or a virtual unit. Please refer to the following embodiment for details.

[0134] The present application embodiment provides a data migration device, such as Figure 3 As shown, the data migration device may specifically include a structure information acquisition module 31, a link relationship establishment module 32, a target group determination module 33, a variable dimension node determination module 34, a similarity determination module 35, a pruning module 36, a reconstruction module 37 and a migration module 38, wherein:

[0135] A structural information acquisition module 31 is used to obtain structural information of each network layer in the neural network to be pruned, wherein the structural information includes a parameter matrix and an output matrix of the network layer, wherein the output matrix is ​​obtained by transforming the input data of the network layer through the parameter matrix, wherein each matrix includes at least one type of dimensional node, and each dimensional node includes at least two channels;

[0136] A link relationship establishment module 32 is used to establish a link relationship between two dimensional nodes with the same sequence and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in each of two adjacent network layers, wherein the output matrix of the upper network layer is the input data of the lower network layer;

[0137] The target group determination module 33 is used to determine all dimension nodes in the same link relationship as a target group, and there are link relationships between dimension nodes of the same order in the parameter matrix and output matrix of the same network layer;

[0138] A variable dimension node determination module 34 is used to determine the dimension nodes that can be pruned in each target group as variable dimension nodes, and determine the target group with variable dimension nodes as a variable group;

[0139] A similarity determination module 35, for each variable group, is used to determine the similarity between every two channels in the variable group, and determine two channels whose similarity is greater than or equal to a preset threshold as a pruneable channel group;

[0140] A pruning module 36, configured to prune each prunable channel group to delete a channel, and obtain pruned network layers;

[0141] A reconstruction module 37, used for reconstructing each network layer after pruning to obtain a pruned neural network;

[0142] The migration module 38 is used to migrate the pruned neural network.

[0143] By adopting the above technical scheme, the correlation of each dimensional node between adjacent network layers is judged, the dimensional nodes with correlation are determined and a link relationship is established, and the channels with a link relationship in adjacent network layers, that is, each target group, are judged for similarity, and two channels with high similarity, that is, the similarity is greater than or equal to a preset threshold, are pruned. That is, the pruning process takes into account the relationship between the channels of the associated network layers, and only prunes the two channels with high similarity, so as to further reduce the performance loss of the network model caused by independent pruning of a single network layer.

[0144] In a possible implementation, when determining that the dimensional nodes that can be pruned in each target group are dimensional nodes that can be pruned, the variable-dimensional node determination module 34 is specifically configured to:

[0145] For the parameter matrix in each network layer, determine whether there is a variable-dimensional node in the parameter matrix based on preset conditions;

[0146] The preconditions include at least one of the following:

[0147] If the dimension node has a link relationship with any dimension node in the output matrix of the current network layer, and has no link relationship with the output matrix of the last network layer, then the dimension node is determined to be a variable dimension node;

[0148] If the dimension node has no link relationship with the input matrix of the first network layer, and the dimension node has a link relationship with any dimension node of the output matrix of the previous network layer of the current network layer, then the dimension node is determined to be a variable dimension node.

[0149] In a possible implementation, the similarity determination module 35, for each variable group, when determining the similarity between every two channels in the variable group, is specifically configured to:

[0150] Determine the distance between every two channels in each variable dimension node;

[0151] Based on the distance between every two channels in each variable dimension node, the similarity between every two channels in the variable group is determined.

[0152] In a possible implementation, when determining the distance between every two channels in each variable-dimensional node, the similarity determination module 35 is specifically configured to:

[0153] Determine the number of channels M in the variable dimension node;

[0154] Divide the parameter matrix of each variable-dimensional node into M sub-matrices, where the first dimension of each sub-matrix is ​​a sequence channel in the corresponding variable-dimensional node;

[0155] For each variable-dimensional node, the distance between every two channels is determined based on the sub-matrices in which the two channels are located, and the distance between any two channels is the Euclidean distance between the sub-matrices in which the two channels are located.

[0156] In a possible implementation, when pruning each prunable channel group to delete a channel, the pruning module 36 is specifically configured to:

[0157] Based on the order of the channels, the channels with the highest order are determined as the channels that can be pruned;

[0158] Set the attribute for each channel in each target group, which can be pruned or not pruned;

[0159] Prune each group of prunable channels to remove each channel that has the attribute of being prunable.

[0160] In a possible implementation, the device further includes a model conversion module, and the model conversion module is specifically used to:

[0161] Convert the neural network model to obtain the ONNX model;

[0162] When obtaining the structural information of each network layer in the neural network to be pruned, the structural information acquisition module is specifically used to:

[0163] Get the structural information of each network layer in the neural network from the ONNX model.

[0164] In a possible implementation manner, the device further includes a code packaging module, and the code packaging module is specifically used to:

[0165] Extract the preprocessing code in the target software and encapsulate it to obtain a preprocessing function, the target software is software built with a neural network, and the preprocessing code is a code for preprocessing the output data of the neural network and the output data;

[0166] The configuration information of the target software is obtained, and the package is performed based on the configuration information and the preprocessing function to obtain a package file. The configuration information includes the name and version number of each module in the preprocessing code.

[0167] In an embodiment of the present application, a server is provided, such as Figure 4 As shown, Figure 4 The server 400 shown includes: a processor 401 and a memory 403. The processor 401 and the memory 403 are connected, such as through a bus 402. Optionally, the server 400 may also include a transceiver 404. It should be noted that in actual applications, the transceiver 404 is not limited to one, and the structure of the server 400 does not constitute a limitation on the embodiments of the present application.

[0168] Processor 401 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 401 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0169] The bus 402 may include a path to transmit information between the above components. The bus 402 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 402 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0170] The memory 403 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.

[0171] The memory 403 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 401. The processor 401 is used to execute the application code stored in the memory 403 to implement the contents shown in the above method embodiment.

[0172] Figure 4 The server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0173] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment.

[0174] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0175] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A data migration method, characterized in that: include: Obtaining structural information of each network layer in the neural network to be pruned, the structural information including a parameter matrix and an output matrix of the network layer, the output matrix being obtained by transforming input data of the network layer through the parameter matrix, each matrix including at least one type of dimensional node, each dimensional node including at least two channels, the neural network to be pruned is a network capable of analyzing target data, and the neural network to be pruned can realize any one of optical character recognition, sensitive word detection, image classification, and speech recognition functions; Establish a link relationship between the output matrix of the upper network layer and the two dimensional nodes with the same sequence and the same number of channels in the parameter matrix of the lower network layer in each of two adjacent network layers, wherein the output matrix of the upper network layer is the input data of the lower network layer; All dimension nodes in the same link relationship are determined as a target group. In the parameter matrix and output matrix of the same network layer, there are link relationships between dimension nodes of the same order. Determine that the dimensional nodes that can be pruned in each of the target groups are variable dimensional nodes, and determine the target group having the variable dimensional nodes as a variable group; For each of the variable groups, determine the similarity between every two channels in the variable group, and determine that two channels with a similarity greater than or equal to a preset threshold are the prunable channel groups; Pruning each of the prunable channel groups to delete a channel, thereby obtaining pruned network layers; Reconstructing each of the pruned network layers to obtain a pruned neural network; The pruned neural network is migrated so that after receiving the pruned neural network, the client device performs data processing based on the pruned neural network.

2. A data migration method according to claim 1, characterized in that: The determining that the prunable dimension nodes in each target group are variable dimension nodes includes: For each parameter matrix in the network layer, determining whether there is a variable-dimensional node in the parameter matrix based on a preset condition; The preset condition includes at least one of the following: If the dimension node has a link relationship with any dimension node in the output matrix of the current network layer, and has no link relationship with the output matrix of the last network layer, then the dimension node is determined to be a variable dimension node; If the network layer where the dimension node is currently located is not the first network layer of the neural network, and the dimension node has a link relationship with any dimension node of the output matrix of the previous network layer of the current network layer, then the dimension node is determined to be a variable dimension node.

3. A data migration method according to claim 1 or 2, characterized in that: For each of the variable groups, determining the similarity between every two channels in the variable group includes: Determine the distance between every two channels in each of the variable dimension nodes; Based on the distance between every two channels in each of the variable dimension nodes, the similarity between every two channels in the variable group is determined.

4. A data migration method according to claim 3, characterized in that: Determining the distance between every two channels in each of the variable-dimensional nodes includes: Determine the number of channels M in the variable-dimensional node; Divide the parameter matrix where each variable-dimensional node is located into M sub-matrices, wherein the first dimension of each sub-matrix is ​​a sequence channel in the corresponding variable-dimensional node; For each of the variable-dimensional nodes, the distance between every two channels is determined based on the sub-matrices in which the two channels are located, and the distance between any two channels is the Euclidean distance between the sub-matrices in which the two channels are located.

5. A data migration method according to claim 1, characterized in that: The step of pruning each of the prunable channel groups to delete a channel includes: Based on the order of the channels, the channels with the highest order are determined as the channels that can be pruned; Setting an attribute for each channel in each target group, wherein the attribute is pruneable or non-pruneable; Prune each of the prunable channel groups to delete each of the channels with the attribute of being prunable.

6. A data migration method according to claim 1, characterized in that: Before obtaining the structural information of each network layer in the neural network to be pruned, it also includes: Performing model conversion on the neural network to obtain an ONNX model; The step of obtaining structural information of each network layer in the neural network to be pruned includes: The structural information of each network layer in the neural network is obtained from the ONNX model.

7. A data migration method according to claim 1, characterized in that: Also includes: Extracting the preprocessing code in the target software and encapsulating it to obtain a preprocessing function, wherein the target software is software constructed with the neural network, and the preprocessing code is a code for preprocessing the output data and the output data of the neural network; The configuration information of the target software is obtained, and packaging is performed based on the configuration information and the preprocessing function to obtain a package file, wherein the configuration information includes the name and version number of each module in the preprocessing code.

8. A data migration device, characterized in that: The device includes: A structural information acquisition module, used to acquire structural information of each network layer in the neural network to be pruned, wherein the structural information includes a parameter matrix and an output matrix of the network layer, wherein the output matrix is ​​obtained by transforming the input data of the network layer through the parameter matrix, wherein each matrix includes at least one type of dimensional node, and each dimensional node includes at least two channels; the neural network to be pruned is a network capable of analyzing target data, and the neural network to be pruned can realize any one of optical character recognition, sensitive word detection, image classification, and speech recognition functions; A link relationship establishment module, used to establish a link relationship between two dimensional nodes with the same sequence and the same number of channels in the output matrix of the upper network layer and the parameter matrix of the lower network layer in each of two adjacent network layers, wherein the output matrix of the upper network layer is the input data of the lower network layer; The target group determination module is used to determine all dimension nodes in the same link relationship as a target group. In the parameter matrix and output matrix of the same network layer, there is a link relationship between dimension nodes of the same sequence; A variable dimension node determination module, used for determining that the dimension nodes that can be pruned in each of the target groups are variable dimension nodes, and determining the target group having the variable dimension nodes as a variable group; A prunable channel group determination module, for each of the variable groups, is used to determine the similarity between every two channels in the variable group, and determine that two channels whose similarity is greater than or equal to a preset threshold are the prunable channel group; A pruning module, used for pruning each of the prunable channel groups to delete a channel, and obtaining each pruned network layer; A reconstruction module, used for reconstructing the pruned network layers to obtain a pruned neural network; A migration module is used to migrate the pruned neural network so that the client device can perform data processing based on the pruned neural network after receiving the pruned neural network.

9. A server, characterized in that: The server includes: at least one processor; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the data migration method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: include: A computer program is stored which can be loaded by a processor and execute the data migration method according to any one of claims 1 to 7.