WO2023197857A1 - 一种模型切分方法及其相关设备 - Google Patents

一种模型切分方法及其相关设备 Download PDF

Info

Publication number
WO2023197857A1
WO2023197857A1 PCT/CN2023/084239 CN2023084239W WO2023197857A1 WO 2023197857 A1 WO2023197857 A1 WO 2023197857A1 CN 2023084239 W CN2023084239 W CN 2023084239W WO 2023197857 A1 WO2023197857 A1 WO 2023197857A1
Authority
WO
WIPO (PCT)
Prior art keywords
model
calculation graph
loss
segmentation
segmentation strategy
Prior art date
Application number
PCT/CN2023/084239
Other languages
English (en)
French (fr)
Inventor
唐振韬
王滨
钱俊
范礼
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2023197857A1 publication Critical patent/WO2023197857A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • This application relates to the technical field of artificial intelligence (AI), and in particular to a model segmentation method and related equipment.
  • AI artificial intelligence
  • neural network models of AI technology can be used to achieve various types of data such as image classification, text summary generation, speech recognition, and function solving. deal with.
  • the neural network model can be represented in the form of a calculation graph.
  • the calculation graph can usually contain multiple nodes connected to each other. One node corresponds to at least one neuron of a certain layer in the model, so one node can represent what the neural network model can achieve. part of the calculation.
  • multiple nodes of the calculation graph are usually run one by one, which may cause queuing and congestion, resulting in low efficiency of data processing.
  • the calculation graph can be divided into multiple sub-computation graphs, so the multiple sub-computation graphs can be operated in parallel, thereby improving the efficiency of data processing.
  • segmentation strategies for computational graphs are usually formulated based on expert experience, which involves a lot of human intervention and often only considers a single factor.
  • segmentation strategies can often only be used for computational graphs representing neural network models with certain specific structures.
  • the segmentation strategy obtained based on this method may not be the optimal segmentation strategy for the calculation graph.
  • the embodiments of the present application provide a model segmentation method and related equipment, which can avoid excessive human intervention when performing model segmentation, and consider comprehensive factors, and can implement models for neural network models of various structures. Segmentation, and can develop optimal segmentation strategies suitable for practical applications for neural network models of various structures.
  • the first aspect of the embodiment of the present application provides a model segmentation method, which method includes:
  • the first calculation graph of the first model can be obtained first.
  • the first model is a neural network model to be segmented.
  • the first model can be equipped with a certain data processing function.
  • the first model can be used to classify image data.
  • the first model can also be used to classify image data.
  • the text data is summarized and processed.
  • the first model can also be used to perform recognition processing on speech data and so on.
  • the first calculation graph of the first model usually includes a plurality of connected nodes. Among the plurality of nodes, one node corresponds to at least one neuron located in the same layer in the first model. Since the neurons in the first model can It is regarded as a calculation unit in the first model, so among the multiple nodes of the first calculation graph, one node can be used to represent a part of the calculations that can be implemented by the first model.
  • the first calculation graph After obtaining the first calculation graph of the first model, the first calculation graph can be input to the second model, so that the first calculation graph can be processed by the second model to obtain a processing result for the first calculation graph.
  • the processing results for the first computational graph usually include The probabilities of multiple slicing strategies (which can also be called slicing behaviors), so among the multiple slicing strategies, the slicing strategy with the highest probability can be determined as the first slicing strategy for the first calculation graph.
  • the first loss required after the first segmentation strategy is applied to the first calculation graph of the first model can be obtained.
  • the correspondence between the calculation graph, the segmentation strategy and the loss (which can also be called cost) can be obtained first. This correspondence can be used to evaluate the second calculation graph. Is the segmentation strategy for model output feasible? Then, based on the corresponding relationship, the first loss required after the first segmentation strategy is applied to the first calculation graph of the first model can be obtained, thereby determining whether the first loss is less than the preset threshold to determine the first segmentation Is the strategy feasible?
  • the first loss required after the first slicing strategy is applied to the first calculation graph is less than the preset threshold, it means that the first slicing strategy is feasible, so the first calculation graph can be cut based on the first slicing strategy. points, multiple sub-computation graphs are obtained, and among the multiple sub-computation graphs, one sub-computation graph contains at least one node of the first computation graph. At this point, the segmentation of the first calculation graph is completed, which is equivalent to the completion of the segmentation of the first model.
  • the first calculation graph after obtaining the first calculation graph of the first model, the first calculation graph can be processed through the second model to obtain the processing result, and the processing result is used to determine the first cut of the first calculation graph.
  • Strategies based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can analyze various structures.
  • the neural network model implements model segmentation (with strong generalization), and can formulate optimal segmentation strategies that fit practical applications (with better model segmentation effects) for neural network models of various structures.
  • the first calculation graph contains multiple nodes, and one node represents a part of the calculations that can be implemented by the first model.
  • the method also includes: encoding the multiple nodes of the first calculation graph to obtain A plurality of first codes corresponding to one node; processing the first calculation graph through the second model to obtain a processing result includes: processing a plurality of first codes through the second model to obtain a processing result.
  • the node before inputting the first calculation graph into the second model, among the multiple nodes of the first calculation graph, for any node, the node can be coded first to obtain the node corresponding to the node.
  • the data amount of the first encoding corresponding to the node is much smaller than the data amount of the node itself, so the input data amount of the second model can be reduced.
  • the same operation as that performed for this node can also be performed, so the first code corresponding to the other nodes can be obtained.
  • multiple calculations corresponding to the first calculation graph can be obtained.
  • Multiple first codes corresponding to each node one-to-one.
  • the multiple first codes can be input into the second model to process the multiple first codes through the second model to obtain process result.
  • the processing result usually includes the probabilities of codes of multiple segmentation strategies.
  • the code with the highest probability can be determined as the second code, and the segmentation strategy indicated by the second code can be determined.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is the correspondence between coding and loss. Based on the correspondence between the segmentation strategy and the loss, the first segmentation strategy is determined The first loss required after acting on the first calculation graph includes: fusing multiple first codes and second codes to obtain a third code; based on the correspondence between codes and losses and the third code, determining the third code. The first loss required after any split strategy is applied to the first calculation graph.
  • the correspondence between the calculation graph, the segmentation strategy and the loss can be presented as the correspondence between encoding and loss.
  • the correspondence can be a curve on a two-dimensional coordinate system.
  • the horizontal axis of the coordinate system The coordinates are the codes that combine the coding of the nodes in the calculation graph with the coding of the segmentation strategy.
  • the ordinate of the coordinate system is the loss, etc.
  • the first loss required after the first segmentation strategy is applied to the first calculation graph can be obtained in the following way: first, multiple first codes and second codes are fused to obtain a third code. After obtaining the third code, the loss corresponding to the third code can be accurately determined in the corresponding relationship between the code and the loss. This loss is the first cost required after the first segmentation strategy acts on the first calculation graph. loss.
  • fusing multiple first codes and second codes to obtain a third code includes: performing an iterative operation on multiple first codes and second codes using a graph kernel algorithm to obtain a third code.
  • the fusion operation can be realized through the graph kernel algorithm (Scheiler-lehman (WL) graph kernel algorithm), that is, multiple first codes and second codes can be first
  • the second codes are added (or spliced), and then the added (or spliced) codes are subjected to an iterative operation based on the graph kernel algorithm to accurately obtain the third code.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is usually deployed in advance.
  • the correspondence can be based on the second calculation graph of the third model, the third calculation graph for the second calculation graph.
  • the binary segmentation strategy and the second loss required after the second segmentation strategy acts on the second calculation graph are constructed, wherein the second calculation graph of the third model is to obtain the training data of the second model (that is, in the second model data used in the training process), and the second segmentation strategy for the second calculation graph and the second loss required after the second segmentation strategy acts on the second calculation graph are known data, that is real data.
  • the first loss can refer to implementing data processing (i.e., the first model) through these multiple sub-computation graphs.
  • the loss required for data processing can refer to the time required to implement data processing through these multiple sub-computation graphs.
  • the first loss can refer to the time required to achieve data processing through these multiple sub-computation graphs. Resources occupied by data processing (such as computing resources, storage resources and communication resources), etc.
  • the method further includes: if the first loss is greater than or equal to a preset threshold, not segmenting the first calculation graph.
  • the first loss required after the first segmentation strategy is applied to the first calculation graph is greater than or equal to the preset threshold, it means that the first segmentation strategy is not feasible, so the first calculation graph is not performed. Segmentation can make the plan more comprehensive.
  • the second aspect of the embodiment of the present application provides a method for evaluating the segmentation strategy of the model.
  • the method includes:
  • a batch of training data can be obtained first.
  • the batch of training data includes the second calculation graph of the third model.
  • the second calculation graph includes multiple nodes.
  • One node corresponds to at least one neuron located in the same layer in the third model, that is, one node can be used to represent a part of the operations that can be implemented by the third model. Since the second calculation graph of the third model is used as training data, the second segmentation strategy (real segmentation strategy) for the second calculation graph and the second cost required after the second segmentation strategy is applied to the second calculation graph Loss (real loss) is a known number according to.
  • the calculation can be constructed based on this information.
  • the correspondence between the graph, the segmentation strategy and the loss can be used to evaluate whether the segmentation strategy output by the second model is feasible.
  • the correspondence can be used to obtain the first segmentation strategy that acts on the first model. Calculate the first loss required after the graph to determine whether the first loss is less than a preset threshold to determine whether the first segmentation strategy is feasible.
  • the second model trained by the above method can be used to process the first calculation graph of the first model to obtain the first segmentation strategy for the first calculation graph, and the calculation graph, segmentation strategy and loss obtained by the above method are constructed The corresponding relationship between them is also used to estimate the first loss required after the first slicing strategy acts on the first calculation graph, thereby evaluating whether the first slicing strategy is feasible.
  • this model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can achieve model segmentation for neural network models of various structures (with strong Generalizability), and can formulate optimal segmentation strategies suitable for practical applications (with better model segmentation effects) for neural network models of various structures.
  • the second calculation graph contains multiple nodes, and one node represents a part of the operations that can be implemented by the third model.
  • the calculation graph is constructed,
  • the corresponding relationship between the segmentation strategy and the loss includes: encoding multiple nodes of the second calculation graph to obtain multiple fourth codes corresponding to the multiple nodes one-to-one, and encoding the second segmentation strategy to obtain The fifth code; fuse multiple fourth codes and fifth codes to obtain a sixth code; based on the sixth code and the second loss, construct a corresponding relationship between the code and the loss.
  • the correspondence between the calculation graph, segmentation strategy and loss can be presented as the correspondence between encoding and loss.
  • the correspondence between encoding and loss can be constructed in the following way:
  • the node can be encoded first to obtain the fourth code corresponding to the node.
  • the data amount of the fourth code corresponding to the node is much smaller than The amount of data of the node itself can be reduced, so the amount of input data of the fourth model can be reduced.
  • the same operation as that performed for this node can also be performed, so the fourth code corresponding to the other nodes can be obtained. In this way, multiple calculations with the second calculation graph can be obtained. A plurality of fourth codes corresponding one-to-one to each node.
  • the second segmentation strategy for the second calculation graph can also be coded to obtain a fifth code. That is, the fifth code is used to indicate the second segmentation strategy for the second calculation graph.
  • a sixth code is obtained by fusing a plurality of fourth codes that correspond one-to-one with a plurality of nodes of the second calculation graph and a fifth code used to indicate the second segmentation strategy.
  • fusing multiple fourth codes and fifth codes to obtain the sixth code includes: performing iterative operations on multiple fourth codes and fifth codes through a graph kernel algorithm to obtain the sixth code. .
  • it can be achieved through a graph kernel algorithm, that is, multiple fourth codes and fifth codes are first added (or spliced), The added (or spliced) codes are then subjected to an iterative operation based on the graph kernel algorithm, thereby obtaining the sixth code.
  • the method further includes: processing the second calculation graph through a fourth model to obtain a processing result, and the processing result is used to determine a third segmentation strategy of the second calculation graph; based on the second segmentation split strategy and the third split strategy to obtain the target loss.
  • the target loss is used to indicate the difference between the second split strategy and the third split strategy; based on the target loss, the parameters of the fourth model are updated until the model is satisfied. training conditions to obtain the second model.
  • the second calculation graph after obtaining the second calculation graph for the third model, the second calculation graph can be input to the fourth model, so that the second calculation graph can be processed by the fourth model to obtain a processing result.
  • the processing result is usually Contains the probability of multiple segmentation strategies, so it can Among the multiple segmentation strategies, the segmentation strategy with the highest probability is determined as the third segmentation strategy for the second calculation graph.
  • the third segmentation strategy for the second calculation graph is obtained. Since the second segmentation strategy for the second calculation graph is known, the second segmentation strategy for the second calculation graph can be calculated through the preset target loss function. And calculate the third segmentation strategy for the second calculation graph to obtain the target loss.
  • the target loss is used to indicate the difference between the second segmentation strategy for the second calculation graph and the third segmentation strategy for the second calculation graph. difference.
  • the parameters of the fourth model can be updated based on the target loss to obtain the updated fourth model. Thereafter, the next batch of training data can be obtained, and the updated fourth model can be continuously trained until the model training conditions (for example, target loss convergence, etc.) are met to obtain the second model.
  • processing the second calculation graph through the fourth model, and obtaining the processing result includes: encoding multiple nodes of the second calculation graph, and obtaining multiple third nodes corresponding to the multiple nodes one-to-one.
  • Four codes process the plurality of fourth codes through the fourth model to obtain the processing result.
  • the node among the multiple nodes of the second calculation graph, for any node, the node can be encoded first, thereby obtaining the fourth encoding corresponding to the node. It is worth noting that the node corresponds to The data amount of the fourth code is much smaller than the data amount of the node itself, so the input data amount of the fourth model can be reduced.
  • the same operation as that performed for this node can also be performed, so the fourth code corresponding to the other nodes can be obtained.
  • multiple calculations with the second calculation graph can be obtained.
  • the plurality of fourth codes can be input into the fourth model to process the plurality of fourth codes through the fourth model to obtain
  • the processing result usually includes the probabilities of codes of multiple segmentation strategies. Therefore, among these multiple codes, the segmentation strategy indicated by the code with the highest probability can be determined as the third segmentation for the second calculation graph. Strategy.
  • the third model is used to implement data processing
  • the second loss is the time required to implement data processing through multiple sub-computation graphs
  • the multiple sub-computation graphs perform the second sub-computation based on the second segmentation strategy.
  • the graph is segmented.
  • the second loss can refer to the realization of data processing through these multiple sub-computation graphs (that is, what can be achieved by the third model)
  • the loss required for data processing can be the time required to run these multiple sub-computation graphs to implement data processing.
  • the second loss can be the time required to run these multiple sub-computation graphs to implement data processing.
  • the resources occupied (computing resources, storage resources, communication resources, etc.) and so on.
  • a third aspect of the embodiment of the present application provides a model segmentation device.
  • the device includes: an acquisition module, used to acquire the first calculation graph of the first model; and a processing module, used to process the first calculation graph through the second model. Perform processing to obtain a processing result, which is used to determine the first segmentation strategy of the first calculation graph; the determination module is used to determine the first loss required after the first segmentation strategy acts on the first calculation graph; A dividing module is used to divide the first calculation graph based on the first dividing strategy to obtain multiple sub-calculation graphs if the first loss is less than a preset threshold.
  • the first calculation graph after obtaining the first calculation graph of the first model, the first calculation graph can be processed through the second model to obtain the processing result, and the processing result is used to determine the first cut of the first calculation graph. Strategies. Then, based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention. And the factors considered are relatively comprehensive, and model segmentation can be implemented for neural network models of various structures (with strong generalization), and optimal segmentation suitable for practical applications can be formulated for neural network models of various structures. Strategy (with better model segmentation effect).
  • the first calculation graph contains multiple nodes, and one node represents a part of the calculations that can be implemented by the first model.
  • the device further includes: a coding module for performing coding on the multiple nodes of the first calculation graph. Encoding is used to obtain multiple first codes corresponding to multiple nodes one-to-one; the processing module is used to process the multiple first codes through the second model to obtain processing results.
  • the determination module is configured to determine the first loss required after the first segmentation strategy is applied to the first calculation graph based on the correspondence between the calculation graph, the segmentation strategy and the loss.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is the correspondence between coding and loss
  • the processing result is used to determine the second coding
  • the second coding is used to indicate the first calculation
  • the first segmentation strategy of the graph determines the module, which is used to: fuse multiple first codes and second codes to obtain a third code; based on the correspondence between codes and losses and the third code, determine the first segmentation The first loss required after the sub-strategy is applied to the first calculation graph.
  • the determination module is configured to perform iterative operations on multiple first codes and second codes through a graph kernel algorithm to obtain a third code.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is based on the second calculation graph of the third model, the second segmentation strategy of the second calculation graph, and the second segmentation strategy acting on The second loss required after the second calculation graph is constructed.
  • the second calculation graph is to obtain the training data of the second model.
  • the second segmentation strategy and the second loss are known data.
  • the first model is used to implement data processing
  • the first loss is the time required to implement data processing through multiple sub-computation graphs.
  • the device further includes: a non-segmentation module, configured not to segment the first calculation graph if the first loss is greater than or equal to the preset threshold.
  • the fourth aspect of the embodiment of the present application provides a device for evaluating a segmentation strategy of a model.
  • the device includes: a first acquisition module for acquiring the second calculation graph of the third model and the second segmentation of the second calculation graph.
  • the second calculation graph is to obtain the training data of the second model.
  • the second segmentation strategy and the second loss are known data;
  • a building module for constructing a correspondence between the calculation graph, the second segmentation strategy and the loss based on the second calculation graph, the second segmentation strategy and the second loss.
  • the correspondence relationship is used to obtain the effect of the first segmentation strategy on the first
  • the first loss required after the first calculation graph of the model, the first segmentation strategy is obtained by processing the first calculation graph by the second model.
  • the second model trained by the above device can be used to process the first calculation graph of the first model to obtain the first segmentation strategy for the first calculation graph, and the calculation graph, segmentation strategy and loss obtained by the above device are constructed The corresponding relationship between them is also used to estimate the first loss required after the first slicing strategy acts on the first calculation graph, thereby evaluating whether the first slicing strategy is feasible.
  • this model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can achieve model segmentation for neural network models of various structures (with strong Generalizability), and can formulate optimal segmentation strategies suitable for practical applications (with better model segmentation effects) for neural network models of various structures.
  • the second calculation graph contains multiple nodes, one node represents a part of the operations that can be implemented by the third model, and the building module is used to: encode multiple nodes of the second calculation graph to obtain Multiple fourth codes corresponding to multiple nodes one-to-one, and the second segmentation strategy is coded to obtain the fifth code; multiple fourth codes and fifth codes are fused to obtain the sixth code; based on the sixth code and the second loss to construct the correspondence between coding and loss.
  • the building module is used to perform iterative operations on multiple fourth codes and fifth codes through a graph kernel algorithm to obtain a sixth code.
  • the device further includes: a processing module, configured to process the second calculation graph through the fourth model to obtain a processing result, and the processing result is used to determine the third segmentation strategy of the second calculation graph. ;
  • the second acquisition module is used to obtain the target loss based on the second segmentation strategy and the third segmentation strategy.
  • the target loss is used to indicate the difference between the second segmentation strategy and the third segmentation strategy;
  • the update module is used Based on the target loss, the parameters of the fourth model are updated until the model training conditions are met, and the second model is obtained.
  • the processing module is configured to: encode multiple nodes of the second calculation graph to obtain multiple fourth codes corresponding to the multiple nodes one-to-one; use a fourth model to encode the multiple nodes The fourth code is processed and the processing result is obtained.
  • the third model is used to implement data processing
  • the second loss is the time required to implement data processing through multiple sub-computation graphs
  • the multiple sub-computation graphs perform the second sub-computation based on the second segmentation strategy.
  • the graph is segmented.
  • the fifth aspect of the embodiment of the present application provides a model segmentation device, which includes a memory and a processor; the memory stores code, and the processor is configured to execute the code.
  • the model segmentation device performs the following Steps: Obtain the first calculation graph of the first model; process the first calculation graph through the second model to obtain the processing result, and the processing result is used to determine the first segmentation strategy of the first calculation graph; determine the first segmentation strategy The first loss required after acting on the first calculation graph; if the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-calculation graphs.
  • the first calculation graph after obtaining the first calculation graph of the first model, the first calculation graph can be processed through the second model to obtain the processing result, and the processing result is used to determine the first cut of the first calculation graph. Strategies. Then, based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can analyze various structures.
  • the neural network model implements model segmentation (with strong generalization), and can formulate optimal segmentation strategies that fit practical applications (with better model segmentation effects) for neural network models of various structures.
  • the model segmentation device is also used to encode multiple nodes of the first calculation graph to obtain multiple first codes corresponding to the multiple nodes one-to-one; the model segmentation device is used The plurality of first codes are processed through the second model to obtain a processing result.
  • determining the first loss required after the first segmentation strategy is applied to the first calculation graph includes: based on the correspondence between the calculation graph, the segmentation strategy and the loss, determining the first loss. All split strategies apply to the first plan The first loss required after calculating the diagram.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is the correspondence between coding and loss
  • the processing result is used to determine the second coding
  • the second coding is used to indicate the first calculation
  • the first segmentation strategy of the graph, the model segmentation device is used to: fuse multiple first codes and second codes to obtain a third code; based on the correspondence between codes and losses and the third code, determine the third code
  • the first loss required after any split strategy is applied to the first calculation graph.
  • the model segmentation device is used to perform iterative operations on multiple first codes and second codes through a graph kernel algorithm to obtain a third code.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is based on the second calculation graph of the third model, the second segmentation strategy of the second calculation graph, and the second segmentation strategy acting on The second loss required after the second calculation graph is constructed.
  • the second calculation graph is to obtain the training data of the second model.
  • the second segmentation strategy and the second loss are known data.
  • the first model is used to implement data processing
  • the first loss is the time required to implement data processing through multiple sub-computation graphs.
  • the model segmentation device is also configured to not segment the first calculation graph if the first loss is greater than or equal to a preset threshold.
  • the sixth aspect of the embodiment of the present application provides a model segmentation strategy evaluation device.
  • the device includes a memory and a processor; the memory stores code, and the processor is configured to execute the code.
  • the model segmentation strategy is evaluated.
  • the segmentation strategy evaluation device performs the following steps: obtaining the second calculation graph of the third model, the second segmentation strategy of the second calculation graph, and the second loss required after the second segmentation strategy acts on the second calculation graph,
  • the second calculation graph is to obtain the training data of the second model, and the second segmentation strategy and the second loss are known data; based on the second calculation graph, the second segmentation strategy and the second loss, the calculation graph and the segmentation strategy are constructed
  • the correspondence relationship between Figure is processed.
  • the second model trained by the above device can be used to process the first calculation graph of the first model to obtain the first segmentation strategy for the first calculation graph, and the calculation graph, segmentation strategy and loss obtained by the above device are constructed The corresponding relationship between them is also used to estimate the first loss required after the first slicing strategy acts on the first calculation graph, thereby evaluating whether the first slicing strategy is feasible.
  • this model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can achieve model segmentation for neural network models of various structures (with strong Generalizability), and can formulate optimal segmentation strategies suitable for practical applications (with better model segmentation effects) for neural network models of various structures.
  • the second calculation graph contains multiple nodes, one node represents a part of the operations that can be implemented by the third model, and the segmentation strategy evaluation device of the model is used to: evaluate multiple nodes of the second calculation graph. Encoding is performed to obtain multiple fourth codes corresponding to multiple nodes one-to-one, and the second segmentation strategy is encoded to obtain the fifth code; multiple fourth codes and fifth codes are fused to obtain the sixth code. ; Based on the sixth encoding and the second loss, construct the corresponding relationship between the encoding and the loss.
  • the model segmentation strategy evaluation device is used to evaluate multiple fourth chapters through a graph kernel algorithm. code and the fifth code are iteratively operated to obtain the sixth code.
  • the model segmentation strategy evaluation device is also used to: process the second calculation graph through the fourth model to obtain a processing result, and the processing result is used to determine the third segmentation of the second calculation graph.
  • segmentation strategy based on the second segmentation strategy and the third segmentation strategy, the target loss is obtained, and the target loss is used to indicate the difference between the second segmentation strategy and the third segmentation strategy; based on the target loss, the fourth model is The parameters are updated until the model training conditions are met, and the second model is obtained.
  • the model segmentation strategy evaluation device is used to: encode multiple nodes of the second calculation graph to obtain multiple fourth codes corresponding to the multiple nodes one-to-one; through the fourth The model processes the plurality of fourth codes and obtains the processing results.
  • the third model is used to implement data processing
  • the second loss is the time required to implement data processing through multiple sub-computation graphs
  • the multiple sub-computation graphs perform the second sub-computation based on the second segmentation strategy.
  • the graph is segmented.
  • a seventh aspect of the embodiments of the present application provides a circuit system.
  • the circuit system includes a processing circuit configured to perform the first aspect, any one of the possible implementations of the first aspect, or the second aspect. method described.
  • An eighth aspect of the embodiments of the present application provides a chip system.
  • the chip system includes a processor for calling a computer program or computer instructions stored in a memory, so that the processor executes the steps described in the first aspect and the first aspect. any possible implementation manner or the method described in the second aspect.
  • the processor is coupled to the memory through an interface.
  • the chip system further includes a memory, and computer programs or computer instructions are stored in the memory.
  • a ninth aspect of the embodiments of the present application provides a computer storage medium.
  • the computer storage medium stores a computer program.
  • the program When the program is executed by a computer, it makes it possible for the computer to implement any one of the first aspect and the first aspect. or the method described in the second aspect.
  • a tenth aspect of the embodiments of the present application provides a computer program product.
  • the computer program product stores instructions.
  • the instructions When the instructions are executed by a computer, the computer implements any one of the possible methods of the first aspect and the first aspect. implementation or the method described in the second aspect.
  • the first calculation graph after obtaining the first calculation graph of the first model, can be processed through the second model to obtain the processing result, and the processing result is used to determine the first segmentation of the first calculation graph.
  • Strategy based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can analyze various structures.
  • the neural network model implements model segmentation (with strong generalization), and can formulate optimal segmentation strategies that fit practical applications (with better model segmentation effects) for neural network models of various structures.
  • the input of the second model is not multiple nodes of the first calculation graph, but multiple first codes corresponding to the multiple nodes one-to-one.
  • the number of first codes is much smaller than the amount of data of the node itself, so First, it can effectively reduce the amount of data that the neural network model needs to process, reduce the time it takes for the model to obtain the segmentation strategy, and save the resources occupied by the model to obtain the segmentation strategy.
  • Figure 1 is a structural schematic diagram of the main framework of artificial intelligence
  • Figure 2a is a schematic structural diagram of the model segmentation system provided by the embodiment of the present application.
  • Figure 2b is another structural schematic diagram of the model segmentation system provided by the embodiment of the present application.
  • Figure 2c is a schematic diagram of related equipment for model segmentation processing provided by the embodiment of the present application.
  • Figure 3 is a schematic diagram of the architecture of the system 100 provided by the embodiment of the present application.
  • Figure 4 is a schematic flow chart of the model segmentation method provided by the embodiment of the present application.
  • Figure 5 is a schematic diagram of the first calculation graph provided by the embodiment of the present application.
  • Figure 6 is a schematic flowchart of segmentation strategy generation provided by the embodiment of the present application.
  • Figure 7 is a schematic flow chart of the graph kernel algorithm provided by the embodiment of the present application.
  • Figure 8 is a schematic flow chart of the model segmentation strategy evaluation method provided by the embodiment of the present application.
  • Figure 9 is a schematic diagram of the second calculation graph provided by the embodiment of the present application.
  • Figure 10 is a schematic diagram of a candidate segmentation strategy provided by an embodiment of the present application.
  • Figure 11 is another schematic diagram of a candidate segmentation strategy provided by an embodiment of the present application.
  • Figure 12 is a schematic structural diagram of a model segmentation device provided by an embodiment of the present application.
  • Figure 13 is a schematic structural diagram of a model segmentation strategy evaluation device provided by an embodiment of the present application.
  • Figure 14 is a schematic structural diagram of an execution device provided by an embodiment of the present application.
  • Figure 15 is a schematic structural diagram of the training equipment provided by the embodiment of the present application.
  • Figure 16 is a schematic structural diagram of a chip provided by an embodiment of the present application.
  • the embodiments of the present application provide a model segmentation method and related equipment, which can avoid excessive human intervention when performing model segmentation, and consider comprehensive factors, and can implement models for neural network models of various structures. Segmentation, and can develop optimal segmentation strategies suitable for practical applications for neural network models of various structures.
  • neural network models of AI technology can be used to achieve various types of data such as image classification, text summary generation, speech recognition, and function solving. deal with.
  • the data processing process of the neural network model can be regarded as the process of the neural network model calculating the data. Therefore, the neural network model can be represented in the form of a calculation graph.
  • the calculation graph can usually contain multiple nodes connected to each other. One node corresponds to the model. There is at least one neuron in a certain layer in the network, so a node can represent part of the calculations that the neural network model can achieve.
  • the processor of the electronic device usually runs multiple nodes of the calculation graph one by one, which may cause queuing and congestion, resulting in low efficiency of data processing.
  • the calculation graph can be divided in advance by the processor of the electronic device, and the multiple sub-calculation graphs obtained are stored in multiple registers of the processor. Therefore, the processor can be parallelized during data processing. Compute these multiple sub-computation graphs to improve the efficiency of data processing.
  • segmentation strategies for computational graphs are usually formulated based on expert experience, which involves a lot of human intervention and often takes into account a single factor.
  • segmentation strategies can often only be used for computational graphs representing neural network models with certain specific structures ( That is, poor generalization), and the segmentation strategy obtained based on this method may not be the optimal segmentation strategy for the calculation graph of the neural network model (the segmentation effect is not good).
  • the related technology can also process the calculation graph representing a certain neural network model through the trained neural network model to obtain the segmentation strategy of the calculation graph of the neural network model.
  • the trained neural network model The input is often the calculation graph of the entire neural network model, and the amount of data is usually very large, causing the process of obtaining the segmentation strategy to take a long time and consume a lot of resources.
  • embodiments of the present application provide a model segmentation method, which can be implemented in combination with artificial intelligence (artificial intelligence, AI) technology.
  • AI technology is a technical discipline that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence. AI technology obtains the best results by perceiving the environment, acquiring knowledge and using knowledge.
  • artificial intelligence technology is a branch of computer science that attempts to understand the nature of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence.
  • Using artificial intelligence for data processing is a common application method of artificial intelligence.
  • Figure 1 is a structural schematic diagram of the main framework of artificial intelligence.
  • the following is from the “intelligent information chain” (horizontal axis) and “IT value chain” (vertical axis)
  • the above artificial intelligence theme framework is elaborated on in two dimensions.
  • the "intelligent information chain” reflects a series of processes from data acquisition to processing. For example, it can be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, intelligent execution and output. In this process, the data has gone through the condensation process of "data-information-knowledge-wisdom".
  • the "IT value chain” reflects the value that artificial intelligence brings to the information technology industry, from the underlying infrastructure of human intelligence and information (providing and processing technology implementation) to the systematic industrial ecological process.
  • Infrastructure provides computing power support for artificial intelligence systems, enables communication with the external world, and supports it through basic platforms.
  • computing power is provided by smart chips (hardware acceleration chips such as CPU, NPU, GPU, ASIC, FPGA, etc.);
  • the basic platform includes distributed computing framework and network and other related platform guarantees and support, which can include cloud storage and Computing, interconnection networks, etc.
  • sensors communicate with the outside world to obtain data, which are provided to smart chips in the distributed computing system provided by the basic platform for calculation.
  • Data from the upper layer of the infrastructure is used to represent data sources in the field of artificial intelligence.
  • the data involves graphics, images, voice, and text, as well as IoT data of traditional equipment, including business data of existing systems as well as force, displacement, and fluid. Sensing data such as location, temperature, humidity, etc.
  • Data processing usually includes data training, machine learning, deep learning, search, reasoning, decision-making and other methods.
  • machine learning and deep learning can perform symbolic and formal intelligent information modeling, extraction, preprocessing, training, etc. on data.
  • Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formal information to perform machine thinking and problem solving based on reasoning control strategies. Typical functions are search and matching.
  • Decision-making refers to the process of decision-making after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
  • some general capabilities can be formed based on the results of further data processing, such as algorithms or a general system, such as translation, text analysis, computer vision processing, speech recognition, and image processing. identification, etc.
  • Intelligent products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of overall artificial intelligence solutions, productizing intelligent information decision-making and realizing practical applications. Its application fields mainly include: intelligent terminals, intelligent transportation, Smart healthcare, autonomous driving, smart cities, etc.
  • FIG 2a is a schematic structural diagram of a model segmentation system provided by an embodiment of the present application.
  • the model segmentation system includes user equipment and data processing equipment.
  • user equipment includes smart terminals such as mobile phones, personal computers, or information processing centers.
  • the user equipment is the initiator of the data sequence processing. As the initiator of the data sequence processing request, the user usually initiates the request through the user equipment.
  • the above-mentioned data processing equipment may be a cloud server, a network server, an application server, a management server, and other equipment or servers with data processing functions.
  • the data processing device receives text processing requests from smart terminals through interactive interfaces, and then performs text processing in machine learning, deep learning, search, reasoning, decision-making, etc. through the memory that stores data and the processor that processes data.
  • the memory in the data processing device can be a general term, including local storage and a database that stores historical data.
  • the database can be on the data processing device or on other network servers.
  • the user device can receive instructions from the user. For example, the user device can obtain a neural network model to be segmented input/selected by the user, and then initiate a request to the data processing device to enable data processing. The device performs a model segmentation application on the model obtained by the user device, thereby obtaining a processing result for the model.
  • the user device can obtain a neural network model to be segmented input by the user, and then initiate a processing request for the model to the data processing device, so that the data processing device represents the model in the form of a calculation graph, and
  • the calculation graph of the model is processed to obtain the processing result of the model, that is, the segmentation strategy for the calculation graph of the model, and then based on the segmentation strategy, the calculation graph of the model is divided into multiple sub-calculation graphs to complete the model. Segmentation of the calculation graph (equivalent to completing the segmentation of the model).
  • the data processing device can execute the model segmentation method according to the embodiment of the present application.
  • Figure 2b is another schematic structural diagram of the model segmentation system provided by the embodiment of the present application.
  • the user equipment directly serves as a data processing equipment.
  • the user equipment can directly obtain input from the user and directly use the hardware of the user equipment itself.
  • the specific process is similar to Figure 2a. Please refer to the above description and will not be repeated here.
  • the user device can receive the user's neural network model to be segmented.
  • the user device can obtain a neural network model selected by the user in the user device, and then use the user device itself to Execute the model segmentation application for the model (for example, convert the model into a computational graph and process the computational graph of the model) to obtain the processing results for the model, that is, segmentation of the computational graph for the model strategy, and then split the calculation graph of the model into multiple sub-calculation graphs based on the splitting strategy, thereby completing the segmentation of the calculation graph of the model (equivalent to completing the segmentation of the model).
  • the model segmentation application for the model for example, convert the model into a computational graph and process the computational graph of the model
  • the processing results for the model that is, segmentation of the computational graph for the model strategy
  • split the calculation graph of the model into multiple sub-calculation graphs based on the splitting strategy, thereby completing the segmentation of the calculation graph of the model (equivalent to completing the segmentation of the model
  • the user equipment itself can execute the model segmentation method according to the embodiment of the present application.
  • Figure 2c is a schematic diagram of related equipment for model segmentation processing provided by the embodiment of the present application.
  • the user equipment in Figure 2a and Figure 2b can be the local device 301 or the local device 302 in Figure 2c
  • the data processing device in Figure 2a can be the execution device 210 in Figure 2c
  • the data storage system 250 can To store the data to be processed by the execution device 210, the data storage system 250 can be integrated on the execution device 210, or can be set up on the cloud or other network servers.
  • the processors in Figure 2a and Figure 2b can perform data training/machine learning/deep learning through neural network models or other models (for example, models based on support vector machines), and use the data to finally train or learn the model to execute against the model
  • the model is segmented and applied to obtain corresponding processing results.
  • Figure 3 is a schematic diagram of the architecture of the system 100 provided by the embodiment of the present application.
  • the execution device 110 is configured with an input/output (I/O) interface 112 for data interaction with external devices.
  • the user Data can be input to the I/O interface 112 through the client device 140.
  • the input data may include: various to-be-scheduled tasks, callable resources, and other parameters.
  • the execution device 110 When the execution device 110 preprocesses the input data, or when the calculation module 111 of the execution device 110 performs calculation and other related processing (such as implementing the function of the neural network in this application), the execution device 110 can call the data storage system 150
  • the data, codes, etc. in the system can be used for corresponding processing, and the data, instructions, etc. obtained by corresponding processing can also be stored in the data storage system 150 .
  • the I/O interface 112 returns the processing results to the client device 140, thereby providing them to the user.
  • the training device 120 can generate corresponding target models/rules based on different training data for different goals or different tasks, and the corresponding target models/rules can be used to achieve the above goals or complete the above tasks. , thereby providing users with the desired results.
  • the training data may be stored in the database 130 and come from training samples collected by the data collection device 160 .
  • the user can manually enter the input data, and the manual input can be operated through the interface provided by the I/O interface 112 .
  • the client device 140 can automatically send input data to the I/O interface 112. If requiring the client device 140 to automatically send input data requires the user's authorization, the user can set corresponding permissions in the client device 140.
  • the user can view the results output by the execution device 110 on the client device 140, and the specific presentation form may be display, sound, action, etc.
  • the client device 140 can also be used as a data collection end to collect the input data of the input I/O interface 112 and the output results of the output I/O interface 112 as new sample data, and store them in the database 130 .
  • the I/O interface 112 directly uses the input data input to the I/O interface 112 and the output result of the output I/O interface 112 as a new sample as shown in the figure.
  • the data is stored in database 130.
  • Figure 3 is only a schematic diagram of a system architecture provided by an embodiment of the present application.
  • the positional relationship between the devices, devices, modules, etc. shown in the figure does not constitute any limitation.
  • the data The storage system 150 is an external memory relative to the execution device 110. In other cases, the data storage system 150 can also be placed in the execution device 110.
  • the neural network can be trained according to the training device 120.
  • An embodiment of the present application also provides a chip, which includes a neural network processor NPU.
  • the chip can be disposed in the execution device 110 as shown in FIG. 3 to complete the calculation work of the calculation module 111.
  • the chip can also be installed in the training device 120 as shown in Figure 3 to complete the training work of the training device 120 and output the target model/rules.
  • Neural network processor NPU is mounted on the main central processing unit (CPU) (host CPU) as a co-processor, and the main CPU allocates tasks.
  • the core part of the NPU is the arithmetic circuit.
  • the controller controls the arithmetic circuit to extract the data in the memory (weight memory or input memory) and perform operations.
  • the computing circuit includes multiple processing units (PE).
  • the arithmetic circuit is a two-dimensional systolic array.
  • the arithmetic circuit may also be a one-dimensional systolic array or other electronic circuit capable of performing mathematical operations such as multiplication and addition.
  • the arithmetic circuit is a general-purpose matrix processor.
  • the arithmetic circuit fetches the corresponding data of matrix B from the weight memory and caches it on each PE in the arithmetic circuit.
  • the operation circuit takes matrix A data and matrix B from the input memory to perform matrix operations, and the partial result or final result of the obtained matrix is stored in the accumulator (accumulator).
  • the vector calculation unit can further process the output of the arithmetic circuit, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc.
  • the vector computing unit can be used for network calculations in non-convolutional/non-FC layers in neural networks, such as pooling, batch normalization, local response normalization, etc.
  • the vector computation unit can store the processed output vectors into a unified buffer.
  • the vector calculation unit may apply a nonlinear function to the output of the arithmetic circuit, such as a vector of accumulated values, to generate activation values.
  • the vector computation unit generates normalized values, merged values, or both.
  • the processed output vector can be used as an activation input to an arithmetic circuit, such as for use in a subsequent layer in a neural network.
  • Unified memory is used to store input data and output data.
  • the weight data directly transfers the input data in the external memory to the input memory and/or the unified memory through the storage unit access controller (direct memory access controller, DMAC), stores the weight data in the external memory into the weight memory, and transfers the weight data to the unified memory.
  • DMAC direct memory access controller
  • the bus interface unit (BIU) is used to realize the interaction between the main CPU, DMAC and instruction memory through the bus.
  • the instruction fetch buffer connected to the controller is used to store instructions used by the controller
  • the controller is used to call instructions cached in the memory to control the working process of the computing accelerator.
  • the unified memory, input memory, weight memory and instruction memory are all on-chip memories, and the external memory is the memory outside the NPU.
  • the external memory can be double data rate synchronous dynamic random access memory (double data). rate synchronous dynamic random access memory (DDR SDRAM), high bandwidth memory (high bandwidth memory (HBM)) or other readable and writable memory.
  • DDR SDRAM double data rate synchronous dynamic random access memory
  • HBM high bandwidth memory
  • the neural network can be composed of neural units.
  • the neural unit can refer to an arithmetic unit that takes xs and intercept 1 as input.
  • the output of the arithmetic unit can be:
  • s 1, 2,...n, n is a natural number greater than 1
  • Ws is the weight of xs
  • b is the bias of the neural unit.
  • f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal. The output signal of this activation function can be used as the input of the next convolutional layer.
  • the activation function can be a sigmoid function.
  • a neural network is a network formed by connecting many of the above-mentioned single neural units together, that is, the output of one neural unit can be the input of another neural unit.
  • the input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field.
  • the local receptive field can be an area composed of several neural units.
  • W is a weight vector, and each value in the vector represents the weight value of a neuron in the neural network of this layer.
  • This vector W determines the spatial transformation from the input space to the output space described above, that is, the weight W of each layer controls how to transform the space.
  • the purpose of training a neural network is to finally obtain the weight matrix of all layers of the trained neural network (a weight matrix formed by the vector W of many layers). Therefore, the training process of neural network is essentially to learn how to control spatial transformation, and more specifically, to learn the weight matrix.
  • weight vector (of course, there is usually an initialization process before the first update, that is, pre-configuring parameters for each layer in the neural network). For example, if the predicted value of the network is high, adjust the weight vector to make it predict lower Some, constant adjustments are made until the neural network can predict the truly desired target value. Therefore, it is necessary to define in advance "how to compare the difference between the predicted value and the target value". This is the loss function (loss function) or objective function (objective function), which is used to measure the difference between the predicted value and the target value. Important equations. Among them, taking the loss function as an example, the higher the output value (loss) of the loss function, the greater the difference. Then the training of the neural network becomes a process of reducing this loss as much as possible.
  • the neural network can use the error back propagation (BP) algorithm to modify the size of the parameters in the initial neural network model during the training process, so that the reconstruction error loss of the neural network model becomes smaller and smaller. Specifically, forward propagation of the input signal until the output will produce an error loss, and the parameters in the initial neural network model are updated by backpropagating the error loss information, so that the error loss converges.
  • the backpropagation algorithm is a backpropagation movement dominated by error loss, aiming to Obtain the optimal parameters of the neural network model, such as the weight matrix.
  • Computational graphs can be used as a representation of neural networks.
  • the model segmentation strategy evaluation method provided by the embodiment of the present application involves the processing of data sequences, and can be specifically applied to methods such as data training, machine learning, and deep learning.
  • the training data for example, the third model of the third model in the present application (2 calculation graphs) to perform symbolic and formalized intelligent information modeling, extraction, preprocessing, training, etc., and finally obtain a trained neural network (for example, the second model in this application); and, the embodiments of this application provide
  • the model segmentation method can use the above-mentioned trained neural network, input the input data (for example, the first calculation graph of the first model in this application) into the trained neural network, and obtain the output data (such as this application The first slicing strategy of the first computational graph).
  • model segmentation strategy evaluation method and the model segmentation method provided in the embodiments of this application are inventions based on the same concept, and can also be understood as two parts of a system, or two parts of an overall process. stages: such as model training stage and model application stage.
  • Figure 4 is a schematic flow chart of the model segmentation method provided by the embodiment of the present application. As shown in Figure 4, the method includes:
  • the first calculation graph of the first model can be obtained first.
  • the first model is a neural network model to be segmented, and the first model can be used to implement data processing functions.
  • the first model can be used to classify image data.
  • the first model can be used to classify text data. Summary processing.
  • the first model can be used to perform recognition processing on speech data and so on.
  • the first calculation graph of the first model may include a plurality of connected nodes, and among the plurality of nodes, one node corresponds to at least one neuron located in the same layer of the first model, because the neurons in the first model may It is regarded as a computing unit in the first model (having certain computing functions), so among the multiple nodes of the first computing graph, one node can be used to represent a part of the calculations that can be realized by the first model.
  • Figure 5 is a schematic diagram of the first calculation graph provided by the embodiment of the present application
  • the first model contains 5 nodes, respectively located on the 5th layer
  • the 1st layer is the input layer
  • the 2nd layer The layers are convolutional layers
  • layer 3 is the normalization layer
  • layer 4 is the activation layer
  • layer 5 is the output layer.
  • the five neurons located in these five layers are used to implement different calculations. Among them, the neurons in the first layer are used to receive input data, the neurons in the second layer are used to convolve the data, and the neurons in the third layer are used to perform different calculations.
  • the neurons in layer 4 are used to normalize the convolution results, the neurons in layer 4 are used to activate the normalized results, and the neurons in layer 5 are used to weight the activation results and the original input data to obtain the process result. Then, these 5 neurons can be represented by 5 nodes respectively, namely node 0, node 1, node 2, node 3 and node 4.
  • Node 0 is used to represent the calculations that can be achieved by the neurons in the first layer.
  • Node 1 is used to represent the calculations that can be realized by the neurons in the second layer.
  • Node 2 is used to represent the calculations that can be realized by the neurons in the third layer.
  • Node 3 is used to represent the calculations that can be realized by the neurons in the fourth layer.
  • Node 4 Used to represent neurons in layer 5 Computation is achievable, so the five connected nodes constitute the first calculation graph of the first model.
  • the first model only includes 5 layers of neurons for schematic introduction, which does not limit the number of layers of the first model in this application.
  • each layer in the first model only contains one neuron for schematic introduction, and does not constitute a limit to the number of neurons in each layer of the first model.
  • first calculation graph A node in can also be used to represent the calculations that can be achieved by multiple neurons located in the same layer in the first model.
  • the first calculation graph can be input to the second model (i.e., the trained neural network model, used to implement the model segmentation function), so that the first calculation graph can be processed by the second model.
  • the processing result usually contains the probabilities of multiple segmentation strategies (which can also be called segmentation behaviors). Therefore, among these multiple segmentation strategies, the one with the highest probability can be
  • the segmentation strategy is determined as the first segmentation strategy for the first calculation graph.
  • the first segmentation strategy for the first calculation graph can be obtained.
  • the first splitting strategy is used to indicate the following: divide the first calculation graph into two sub-computation graphs, the first sub-computation graph contains node 1, node 2 and node 3, and the second sub-computation graph contains node 0 and node 4.
  • the processing result of the first calculation graph can be obtained in the following manner:
  • the node Before inputting the first calculation graph into the second model, for any node among the multiple nodes of the first calculation graph, the node can be encoded first to obtain the third node corresponding to the node.
  • First encoding it is worth noting that the data amount of the first encoding corresponding to the node is much smaller than the data amount of the node itself, so the input data amount of the second model can be reduced.
  • the same operation as that performed for this node can also be performed, so the first code corresponding to the other nodes can be obtained. In this way, multiple calculations corresponding to the first calculation graph can be obtained. Multiple first codes corresponding to each node one-to-one.
  • node 0 to node 4 are obtained Finally, the nodes 0 to 4 can be encoded respectively, thereby obtaining the code 0 of the node 0, the code 1 of the node 1, the code 2 of the node 2, the code 3 of the node 3 and the code 4 of the node 4.
  • the calculation graph, segmentation strategy and loss (also known as cost), and based on the corresponding relationship, determine the first loss required after the first slicing strategy is applied to the first calculation graph.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is usually deployed in advance.
  • This correspondence can be based on the third model (that is, the neural network model used as training data), and can also be used to implement data processing functions. ), the second segmentation strategy for the second calculation graph, and the second loss required after the second segmentation strategy acts on the second calculation graph, where the second calculation graph of the third model
  • the training data of the second model that is, the data used in the training process of the second model
  • the second segmentation strategy for the second calculation graph and the second segmentation strategy are applied to the second calculation graph.
  • the second losses to be paid are all known data (which can also be called real data).
  • the first loss can refer to realizing data processing (that is, the first model) by (running) these multiple sub-computation graphs.
  • the first loss can be the time required to run these multiple sub-computation graphs to implement data processing.
  • the first loss can be the time required to run these multiple sub-computation graphs.
  • the resources occupied by data processing (computing resources, storage resources, communication resources, etc.), etc.
  • the correspondence between the calculation graph, the segmentation strategy and the loss can be presented as the correspondence between encoding and loss.
  • the correspondence can be a curve on a two-dimensional coordinate system, and the abscissa of the coordinate system is The encoding of the nodes in the calculation graph and the encoding of the segmentation strategy are combined. The ordinate of the coordinate system is the loss and so on. Then, the first loss required after the first slicing strategy is applied to the first calculation graph can be obtained in the following way:
  • the loss corresponding to the third code can be determined in the corresponding relationship between the code and the loss. This loss is the cost required after the first segmentation strategy acts on the first calculation graph. First loss.
  • the relevant data when the second model is in the application phase is prediction data
  • the relevant data when the second model is in the training phase is real data. That is, the aforementioned first segmentation strategy for the first calculation graph can also be understood as the first segmentation strategy for the first calculation graph.
  • the first loss required after the first segmentation strategy acts on the first calculation graph can also be understood as the predicted loss required after the first segmentation strategy acts on the first calculation graph.
  • the second segmentation strategy for the second calculation graph can also be understood as the real segmentation strategy for the second calculation graph, and the second loss required after the second segmentation strategy acts on the second calculation graph can also be understood as the second The real loss required after the slicing strategy is applied to the second calculation graph.
  • the size of the preset threshold can be set in a variety of ways. For example, the size of the preset threshold can be set manually according to actual needs. For example, the size of the preset threshold can also be based on the second calculation graph. When segmenting, the loss required for data processing is determined directly through the second calculation graph, and there is no limit here.
  • the first calculation graph can be cut based on the first slicing strategy. points, multiple sub-computation graphs are obtained, and among the multiple sub-computation graphs, one sub-computation graph contains at least one node of the first computation graph. Still as in the above example, since the content of segmentation strategy 1 is to divide the first calculation graph into a sub-computation graph containing node 1, node 2 and node 3 and a sub-computation graph containing node 0 and node 4, so based on segmentation strategy 1 , the first calculation graph can be divided into two sub-calculation graphs. The first sub-calculation graph contains node 1, node 2 and node 3, and the second sub-calculation graph contains node 0 and node 4.
  • the first loss required after the first segmentation strategy is applied to the first calculation graph is greater than or equal to the preset threshold, it means that the first segmentation strategy is not feasible, and therefore the first calculation graph is not segmented. If there are subsequent data processing requirements for the first model, the entire first calculation graph can be directly run to realize the data processing function of the first model.
  • the first calculation graph after obtaining the first calculation graph of the first model, can be processed through the second model to obtain the processing result, and the processing result is used to determine the first segmentation of the first calculation graph.
  • Strategy based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can analyze various structures.
  • the neural network model implements model segmentation (with strong generalization), and can formulate optimal segmentation strategies that fit practical applications (with better model segmentation effects) for neural network models of various structures.
  • the input of the second model is not multiple nodes of the first calculation graph, but multiple first codes corresponding to the multiple nodes one-to-one.
  • the number of first codes is much smaller than the amount of data of the node itself, so First, it can effectively reduce the amount of data that the neural network model needs to process, reduce the time it takes for the model to obtain the segmentation strategy, and save the resources occupied by the model to obtain the segmentation strategy.
  • Figure 8 is a schematic flow chart of the model segmentation strategy evaluation method provided by the embodiment of the present application. As shown in Figure 8, the method includes:
  • a batch of training data can be obtained first.
  • the batch of training data includes the second calculation graph of the third model, and the second calculation graph Contains multiple nodes, one node corresponding to at least one neuron located in the same layer in the third model, that is, one node can be used to represent a part of the operations that can be implemented by the third model.
  • the second calculation graph of the third model you can Refer to the relevant description part of the first calculation diagram of the first model in the embodiment shown in FIG. 4 , which will not be described again here.
  • the second segmentation strategy (real segmentation strategy) for the second calculation graph and the second segmentation strategy after acting on the second calculation graph are The second loss to be paid (real losses) are all known data.
  • the second splitting strategy can be used to split the second calculation graph into multiple sub-computation graphs
  • the second loss can refer to realizing data processing through these multiple sub-computation graphs (that is, the data processing that can be achieved by the third model) The required loss.
  • the second loss can be the time required to run these multiple sub-computation graphs to implement data processing.
  • the second loss can be the resources occupied by running these multiple sub-computation graphs to implement data processing. (Computing resources, storage resources, communication resources, etc.) and so on.
  • candidate segmentation strategies for the second calculation graph there are multiple known candidate segmentation strategies for the second calculation graph, and the loss corresponding to each candidate segmentation strategy is known.
  • the candidate segmentation strategy with the smallest loss can be determined as the candidate segmentation strategy for the second calculation graph.
  • a second segmentation strategy for the second computational graph is known.
  • the second calculation graph shown in Figure 9 includes 4 layers and a total of 12 nodes, among which the first layer has 4 nodes (respectively are node 1_1, node 1_2, node 1_3 and node 1_4), the second layer has 2 nodes (respectively node 2_1 and node 2_2), the third layer has 4 nodes (respectively node 3_1, node 3_2, node 3_3 and Node 3_4), there are 2 nodes in layer 4 (node 4_1 and node 4_2 respectively).
  • the second calculation graph has two candidate segmentation strategies.
  • the first candidate segmentation strategy is shown in Figure 10 ( Figure 10 is a schematic diagram of the candidate segmentation strategy provided by the embodiment of this application).
  • the content of this strategy is:
  • the second calculation graph is divided into two sub-calculation graphs.
  • the first sub-calculation graph includes node 1_1, node 1_2, node 2_1, node 3_1, node 3_2 and node 4_1.
  • the second sub-calculation graph includes node 1_3, node 1_4 and node 2_2. , node3_3, node3_4 and node4_2.
  • the second candidate segmentation strategy is shown in Figure 11 ( Figure 11 is another schematic diagram of the candidate segmentation strategy provided by the embodiment of the present application).
  • the content of this strategy is: split the second calculation graph into four sub-calculation graphs.
  • the first sub-computation graph includes node 1_1 and node 3_1
  • the second sub-computation graph includes node 1_2, node 2_1, node 3_2 and node 4_1
  • the third sub-computation graph includes node 1_3, node 2_2, node 3_3 and node 4_2
  • the four sub-computation graphs include nodes 1_4 and nodes 3_4. Since the second candidate segmentation strategy requires less loss after being applied to the second calculation graph, the second candidate segmentation strategy can be used as the second segmentation strategy of the second calculation graph.
  • the second calculation graph can be input to the fourth model to process the second calculation graph through the fourth model to obtain a processing result.
  • the processing result usually includes multiple segmentations.
  • the probability of the strategy (segmentation behavior), therefore among the multiple segmentation strategies, the segmentation strategy with the highest probability can be determined as the third segmentation strategy (predictive segmentation strategy) for the second calculation graph.
  • the processing results of the second calculation graph can be obtained in the following ways:
  • the node can be encoded first to obtain the fourth code corresponding to the node. It is worth noting that the third code corresponding to the node The data amount of the fourth code is much smaller than the data amount of the node itself, so the input data amount of the fourth model can be reduced. Similarly, for other nodes except this node, the same operation as that performed for this node can also be performed, so the fourth code corresponding to the other nodes can be obtained. In this way, multiple calculations with the second calculation graph can be obtained. Multiple fourth codes corresponding to one node.
  • the plurality of fourth codes can be input into the fourth model, so that the plurality of fourth codes can be processed through the fourth model.
  • the processing result usually contains the probabilities of codes of multiple segmentation strategies. Therefore, among these multiple codes, the segmentation strategy indicated by the code with the highest probability can be determined as the second calculation graph for the second calculation graph. Three-part strategy.
  • the third segmentation strategy for the second calculation graph is obtained. Since the second segmentation strategy for the second calculation graph is known, the second segmentation strategy for the second calculation graph can be calculated through the preset target loss function. And calculate the third segmentation strategy for the second calculation graph to obtain the target loss. The target loss is used to indicate the difference between the second segmentation strategy for the second calculation graph and the third segmentation strategy for the second calculation graph. difference.
  • the parameters of the fourth model can be updated based on the target loss to obtain the updated fourth model.
  • the next batch of training data can be obtained, and the updated fourth model can be continued to be trained (ie, steps 802 to 804 are re-executed) until the model training conditions are met (for example, the target loss converges, etc.), and Figure 4 is obtained.
  • the second model can be used to process the first calculation graph of the first model (the neural network model to be segmented) to obtain the first segmentation strategy for the first model.
  • the first calculation graph of the first model the neural network model to be segmented
  • the relevant description part in the embodiment shown in FIG. 4 which will not be described again here.
  • the second segmentation strategy and the second loss construct a correspondence relationship between the calculation graph, the segmentation strategy and the loss.
  • the correspondence relationship is used to obtain the first segmentation strategy acting on the first model.
  • the first loss required after a calculation graph, the first segmentation strategy is obtained by processing the first calculation graph by the second model.
  • the calculation can be constructed based on this information.
  • the correspondence between the graph, the segmentation strategy and the loss can be used to evaluate whether the segmentation strategy output by the second model is feasible.
  • the correspondence can be used to obtain the first segmentation strategy that acts on the first model. Calculate the first loss required after the graph to determine whether the first loss is less than a preset threshold to determine whether the first segmentation strategy is feasible.
  • the correspondence between the calculation graph, segmentation strategy and loss can be presented as the correspondence between encoding and loss. Therefore, the correspondence between encoding and loss can be constructed in the following way:
  • step 802 it can be known that for multiple nodes of the second calculation graph, multiple fourth codes corresponding to the multiple nodes have been obtained. Then, the second code for the second calculation graph can also be obtained. The segmentation strategy is encoded to obtain a fifth code, that is, the fifth code is used to indicate the second segmentation strategy for the second calculation graph.
  • a corresponding relationship between the encoding and the loss can be constructed.
  • the corresponding relationship can be a two-dimensional coordinate system.
  • a curve on, the abscissa of the coordinate system is the code that combines the code of the nodes in the calculation graph with the code of the segmentation strategy, the ordinate of the coordinate system is the loss, etc.
  • the second model trained by the embodiment of the present application can be used to process the first calculation graph of the first model to obtain the first segmentation strategy for the first calculation graph, and the calculation graph and segmentation strategy constructed by the embodiment of the present application are The corresponding relationship between the splitting strategy and the loss is also used to estimate the first loss required after the first splitting strategy is applied to the first calculation graph, thereby evaluating whether the first splitting strategy is feasible. It can be seen that the implementation of this application The example provides a new model segmentation method (framework). This model segmentation method can avoid too much human intervention and considers more comprehensive factors. It can achieve model segmentation for neural network models of various structures ( It has strong generalization), and can formulate optimal segmentation strategies that fit practical applications for neural network models of various structures (with better model segmentation effects).
  • the input of the fourth model is not multiple nodes of the second calculation graph, but multiple fourth codes corresponding to the multiple nodes one-to-one.
  • the number of the fourth codes is much smaller than the data amount of the node itself, so First, it can effectively reduce the amount of data that the neural network model needs to process during the training process, reduce the time spent on model training, and save the resources occupied by model training.
  • Figure 12 is a schematic structural diagram of a model segmentation device provided by an embodiment of the present application. As shown in Figure 12, the device includes:
  • the processing module 1202 is used to process the first calculation graph through the second model to obtain a processing result, and the processing result is used to determine the first segmentation strategy of the first calculation graph;
  • the determination module 1203 is used to determine the first loss required after the first segmentation strategy is applied to the first calculation graph
  • the segmentation module 1204 is configured to segment the first calculation graph based on the first segmentation strategy to obtain multiple sub-computation graphs if the first loss is less than a preset threshold.
  • the first calculation graph contains multiple nodes, and one node represents a part of the calculations that can be implemented by the first model.
  • the device further includes: a coding module for performing coding on the multiple nodes of the first calculation graph. Coding to obtain multiple first codes corresponding to multiple nodes one-to-one; the processing module 1202 is used to process the multiple first codes through the second model to obtain processing results.
  • the determination module 1203 is configured to determine the first loss required after the first segmentation strategy is applied to the first calculation graph based on the correspondence between the calculation graph, the segmentation strategy and the loss. .
  • the correspondence between the calculation graph, the segmentation strategy and the loss is the correspondence between coding and loss
  • the processing result is used to determine the second coding
  • the second coding is used to indicate the first calculation
  • the first segmentation strategy of the graph, the determination module 1203, is used to: fuse multiple first codes and second codes to obtain a third code; based on the correspondence between codes and losses and the third code, determine the first The first loss required after the segmentation strategy is applied to the first calculation graph.
  • the determination module 1203 is configured to perform iterative operations on multiple first codes and second codes through a graph kernel algorithm to obtain a third code.
  • the correspondence between the calculation graph, the segmentation strategy and the loss is based on the second calculation graph of the third model, the second segmentation strategy of the second calculation graph, and the second segmentation strategy acting on The cost required after the second calculation graph
  • the second loss is constructed, the second calculation graph is to obtain the training data of the second model, the second segmentation strategy and the second loss are known data.
  • the first model is used to implement data processing
  • the first loss is the time required to implement data processing through multiple sub-computation graphs.
  • the device further includes: a non-segmentation module, configured not to segment the first calculation graph if the first loss is greater than or equal to the preset threshold.
  • the first calculation graph after obtaining the first calculation graph of the first model, can be processed through the second model to obtain the processing result, and the processing result is used to determine the first segmentation of the first calculation graph.
  • Strategy based on the correspondence between the calculation graph, the segmentation strategy and the loss, the first loss required after the first segmentation strategy is applied to the first calculation graph can be determined. If the first loss is less than the preset threshold, the first calculation graph is segmented based on the first segmentation strategy to obtain multiple sub-computation graphs.
  • the first segmentation strategy of the first calculation graph is obtained by the second model processing the first calculation graph by itself, and after obtaining the first segmentation strategy, it can also be estimated that the first segmentation strategy will act on The first loss required after the first calculation is used to evaluate whether the first segmentation strategy is feasible.
  • This model segmentation method can avoid too much human intervention, and considers more comprehensive factors, and can analyze various structures.
  • the neural network model implements model segmentation (with strong generalization), and can formulate optimal segmentation strategies that fit practical applications (with better model segmentation effects) for neural network models of various structures.
  • the input of the second model is not multiple nodes of the first calculation graph, but multiple first codes corresponding to the multiple nodes one-to-one.
  • the number of first codes is much smaller than the amount of data of the node itself, so First, it can effectively reduce the amount of data that the neural network model needs to process, reduce the time it takes for the model to obtain the segmentation strategy, and save the resources occupied by the model to obtain the segmentation strategy.
  • Figure 13 is a schematic structural diagram of a model segmentation strategy evaluation device provided by an embodiment of the present application. As shown in Figure 13, the device includes:
  • the first acquisition module 1301 is used to acquire the second calculation graph of the third model, the second segmentation strategy of the second calculation graph, and the second loss required after the second segmentation strategy is applied to the second calculation graph.
  • the second calculation diagram is to obtain the training data of the second model, and the second segmentation strategy and the second loss are known data;
  • the building module 1302 is configured to construct a corresponding relationship between the calculation graph, the second segmentation strategy and the loss based on the second calculation graph, the second segmentation strategy and the second loss.
  • the corresponding relationship is used to obtain the effect of the first segmentation strategy on the second loss.
  • the first loss required after the first calculation graph of a model is obtained by processing the first calculation graph by the second model.
  • the second calculation graph contains multiple nodes, and one node represents a part of the operations that can be implemented by the third model.
  • the building module 1302 is used to: encode multiple nodes of the second calculation graph, and obtain Multiple fourth codes corresponding to multiple nodes one-to-one, and the second segmentation strategy is coded to obtain the fifth code; multiple fourth codes and fifth codes are fused to obtain the sixth code; based on the sixth code Coding and the second loss, construct the corresponding relationship between coding and loss.
  • the building module is used to perform iterative operations on multiple fourth codes and fifth codes through a graph kernel algorithm to obtain a sixth code.
  • the device further includes: a processing module, configured to process the second calculation graph through the fourth model to obtain a processing result, and the processing result is used to determine the third segmentation strategy of the second calculation graph. ;
  • the second acquisition module is used to obtain the target loss based on the second segmentation strategy and the third segmentation strategy.
  • the target loss is used to indicate the second segmentation strategy.
  • the difference from the third segmentation strategy; the update module is used to update the parameters of the fourth model based on the target loss until the model training conditions are met to obtain the second model.
  • the processing module is configured to: encode multiple nodes of the second calculation graph to obtain multiple fourth codes corresponding to the multiple nodes one-to-one; use a fourth model to encode the multiple nodes The fourth code is processed and the processing result is obtained.
  • the third model is used to implement data processing
  • the second loss is the time required to implement data processing through multiple sub-computation graphs
  • the multiple sub-computation graphs perform the second sub-computation based on the second segmentation strategy.
  • the graph is segmented.
  • the second model trained by the embodiment of the present application can be used to process the first calculation graph of the first model to obtain the first segmentation strategy for the first calculation graph, and the calculation graph and segmentation strategy constructed by the embodiment of the present application are The corresponding relationship between the splitting strategy and the loss is also used to estimate the first loss required after the first splitting strategy is applied to the first calculation graph, thereby evaluating whether the first splitting strategy is feasible. It can be seen that the implementation of this application The example provides a new model segmentation method (framework). This model segmentation method can avoid too much human intervention and considers more comprehensive factors. It can achieve model segmentation for neural network models of various structures ( It has strong generalization), and can formulate optimal segmentation strategies that fit practical applications for neural network models of various structures (with better model segmentation effects).
  • the input of the fourth model is not multiple nodes of the second calculation graph, but multiple fourth codes corresponding to the multiple nodes one-to-one.
  • the number of the fourth codes is much smaller than the data amount of the node itself, so First, it can effectively reduce the amount of data that the neural network model needs to process during the training process, reduce the time spent on model training, and save the resources occupied by model training.
  • FIG. 14 is a schematic structural diagram of the execution device provided by the embodiment of the present application.
  • the execution device 1400 can be embodied as a mobile phone, a tablet, a laptop, a smart wearable device, a server, etc., and is not limited here.
  • the model segmentation device described in the corresponding embodiment of FIG. 4 may be deployed on the execution device 1400 to implement the function of model segmentation in the corresponding embodiment of FIG. 4 .
  • the execution device 1400 includes: a receiver 1401, a transmitter 1402, a processor 1403 and a memory 1404 (the number of processors 1403 in the execution device 1400 can be one or more, one processor is taken as an example in Figure 14) , wherein the processor 1403 may include an application processor 14031 and a communication processor 14032.
  • the receiver 1401, the transmitter 1402, the processor 1403, and the memory 1404 may be connected by a bus or other means.
  • Memory 1404 may include read-only memory and random access memory and provides instructions and data to processor 1403 .
  • a portion of memory 1404 may also include non-volatile random access memory (NVRAM).
  • NVRAM non-volatile random access memory
  • the memory 1404 stores processor and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, where the operating instructions may include various operating instructions for implementing various operations.
  • the processor 1403 controls the execution of operations of the device.
  • various components of the execution device are coupled together through a bus system.
  • the bus system may also include a power bus, a control bus, a status signal bus, etc.
  • various buses are called bus systems in the figure.
  • the methods disclosed in the above embodiments of the present application can be applied to the processor 1403 or implemented by the processor 1403. at The processor 1403 may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by instructions in the form of hardware integrated logic circuits or software in the processor 1403 .
  • the above-mentioned processor 1403 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, and can further include an application specific integrated circuit (ASIC), a field programmable Gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • the processor 1403 can implement or execute each method, step and logical block diagram disclosed in the embodiment of this application.
  • a general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
  • the steps of the method disclosed in conjunction with the embodiments of the present application can be directly implemented by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, registers and other mature storage media in this field.
  • the storage medium is located in the memory 1404.
  • the processor 1403 reads the information in the memory 1404 and completes the steps of the above method in combination with its hardware.
  • the receiver 1401 may be configured to receive input numeric or character information and generate signal inputs related to performing relevant settings and functional controls of the device.
  • the transmitter 1402 can be used to output numeric or character information through the first interface; the transmitter 1402 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 1402 can also include a display device such as a display screen .
  • the processor 1403 is used to generate the first segmentation strategy of the first calculation graph of the first model through the second model in the corresponding embodiment of Figure 4, and then based on the second Any segmentation strategy is used to segment the first calculation graph to obtain multiple sub-computation graphs, thereby completing the segmentation of the first model.
  • FIG. 15 is a schematic structural diagram of the training device provided by the embodiment of the present application.
  • the training device 1500 is implemented by one or more servers.
  • the training device 1500 can vary greatly due to different configurations or performance, and can include one or more central processing units (CPU) 1514 (eg, one or more processors) and memory 1532, one or more storage media 1530 (eg, one or more mass storage devices) storing applications 1542 or data 1544.
  • the memory 1532 and the storage medium 1530 may be short-term storage or persistent storage.
  • the program stored in the storage medium 1530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the training device.
  • the central processor 1514 may be configured to communicate with the storage medium 1530 and execute a series of instruction operations in the storage medium 1530 on the training device 1500 .
  • the training device 1500 may also include one or more power supplies 1526, one or more wired or wireless network interfaces 1550, one or more input and output interfaces 1558; or, one or more operating systems 1541, such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • operating systems 1541 such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • the training device can execute the segmentation strategy evaluation method of the model corresponding to the embodiment in Figure 8, and deploy the constructed calculation graph, the correspondence between the segmentation strategy and the loss, and the trained second model in in the aforementioned execution device.
  • Embodiments of the present application also relate to a computer storage medium.
  • the computer-readable storage medium stores a program for performing signal processing.
  • the program When the program is run on a computer, it causes the computer to perform the steps performed by the aforementioned execution device, or Or, causing the computer to perform the steps performed by the aforementioned training device.
  • Embodiments of the present application also relate to a computer program product that stores instructions that, when executed by a computer, cause the computer to perform the steps performed by the foregoing execution device, or cause the computer to perform the steps performed by the foregoing training device. A step of.
  • the execution device, training device or terminal device provided by the embodiment of the present application may specifically be a chip.
  • the chip includes: a processing unit and a communication unit.
  • the processing unit may be, for example, a processor.
  • the communication unit may be, for example, an input/output interface. Pins or circuits, etc.
  • the processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the data processing method described in the above embodiment, or so that the chip in the training device executes the data processing method described in the above embodiment.
  • the storage unit is a storage unit within the chip, such as a register, cache, etc.
  • the storage unit may also be a storage unit located outside the chip in the wireless access device, such as Read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (random access memory, RAM), etc.
  • ROM Read-only memory
  • RAM random access memory
  • Figure 16 is a schematic structural diagram of a chip provided by an embodiment of the present application.
  • the chip can be represented as a neural network processor NPU 1600.
  • the NPU 1600 serves as a co-processor and is mounted to the host CPU (Host CPU). ), tasks are allocated by the Host CPU.
  • the core part of the NPU is the arithmetic circuit 1603.
  • the arithmetic circuit 1603 is controlled by the controller 1604 to extract the matrix data in the memory and perform multiplication operations.
  • the computing circuit 1603 includes multiple processing units (Process Engine, PE).
  • arithmetic circuit 1603 is a two-dimensional systolic array.
  • the arithmetic circuit 1603 may also be a one-dimensional systolic array or other electronic circuit capable of performing mathematical operations such as multiplication and addition.
  • arithmetic circuit 1603 is a general-purpose matrix processor.
  • the arithmetic circuit obtains the corresponding data of matrix B from the weight memory 1602 and caches it on each PE in the arithmetic circuit.
  • the operation circuit takes matrix A data and matrix B from the input memory 1601 to perform matrix operations, and the partial result or final result of the matrix is stored in an accumulator (accumulator) 1608 .
  • the unified memory 1606 is used to store input data and output data.
  • the weight data directly passes through the storage unit access controller (Direct Memory Access Controller, DMAC) 1605, and the DMAC is transferred to the weight memory 1602.
  • Input data is also transferred to unified memory 1606 via DMAC.
  • DMAC Direct Memory Access Controller
  • BIU is the Bus Interface Unit, that is, the bus interface unit 1613, which is used for the interaction between the AXI bus and the DMAC and the Instruction Fetch Buffer (IFB) 1609.
  • IFB Instruction Fetch Buffer
  • the bus interface unit 1613 (Bus Interface Unit, BIU for short) is used to fetch the memory 1609 to obtain instructions from the external memory, and is also used for the storage unit access controller 1605 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
  • BIU Bus Interface Unit
  • DMAC is mainly used to transfer the input data in the external memory DDR to the unified memory 1606 or the weight data to the weight memory 1602 or the input data to the input memory 1601 .
  • the vector calculation unit 1607 includes multiple arithmetic processing units, and if necessary, further processes the output of the arithmetic circuit 1603, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc.
  • vector calculation unit 1607 can store the processed output vectors to unified memory 1606 .
  • the vector calculation unit 1607 can apply a linear function; or a nonlinear function to the output of the operation circuit 1603, such as linear interpolation on the prediction label plane extracted by the convolution layer, or a vector of accumulated values, to generate an activation value.
  • vector calculation unit 1607 generates normalized values, pixel-wise summed values, or both.
  • the processed output vector can be used as an activation input to the arithmetic circuit 1603, such as for use in a subsequent layer in a neural network.
  • the instruction fetch buffer 1609 connected to the controller 1604 is used to store instructions used by the controller 1604;
  • the unified memory 1606, the input memory 1601, the weight memory 1602 and the fetch memory 1609 are all On-Chip memories. External memory is private to the NPU hardware architecture.
  • the processor mentioned in any of the above places can be a general central processing unit, a microprocessor, an ASIC, or one or more integrated circuits used to control the execution of the above programs.
  • the device embodiments described above are only illustrative.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physically separate.
  • the physical unit can be located in one place, or it can be distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • the connection relationship between modules indicates that there are communication connections between them, which can be specifically implemented as one or more communication buses or signal lines.
  • the present application can be implemented by software plus necessary general hardware. Of course, it can also be implemented by dedicated hardware including dedicated integrated circuits, dedicated CPUs, dedicated memories, Special components, etc. to achieve. In general, all functions performed by computer programs can be easily implemented with corresponding hardware. Moreover, the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special-purpose circuits. circuit etc. However, for this application, software program implementation is a better implementation in most cases. Based on this understanding, the technical solution of the present application can be embodied in the form of a software product in essence or that contributes to the existing technology.
  • the computer software product is stored in a readable storage medium, such as a computer floppy disk. , U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including several instructions to cause a computer device (which can be a personal computer, training device, or network device, etc.) to execute the steps described in various embodiments of this application. method.
  • a computer device which can be a personal computer, training device, or network device, etc.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
  • the computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, the computer instructions may be transferred from a website, computer, training device, or data
  • the center transmits to another website site, computer, training equipment or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) means.
  • wired such as coaxial cable, optical fiber, digital subscriber line (DSL)
  • wireless such as infrared, wireless, microwave, etc.
  • the computer-readable storage medium may be any available medium that a computer can store, or a data storage device such as a training device or a data center integrated with one or more available media.
  • the available media may be magnetic media (eg, floppy disk, hard disk, magnetic tape), optical media (eg, DVD), or semiconductor media (eg, solid state disk (Solid State Disk, SSD)), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Molecular Biology (AREA)
  • Computational Linguistics (AREA)
  • Biophysics (AREA)
  • Biomedical Technology (AREA)
  • Mathematical Physics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Image Generation (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例公开了一种模型切分方法及其相关设备,在进行模型切分时,可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分,且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略。本申请的方法包括:获取第一模型的第一计算图;通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略;基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗;若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。

Description

一种模型切分方法及其相关设备
本申请要求于2022年4月11日提交中国专利局、申请号为202210375732.3、发明名称为“一种模型切分方法及其相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及人工智能(artificial intelligence,AI)技术领域,尤其涉及一种模型切分方法及其相关设备。
背景技术
随着技术的快速发展,越来越多的领域可使用AI技术的神经网络模型来实现数据处理,例如,可利用神经网络模型实现图像分类、文本摘要生成,语音识别以及函数求解等各类数据处理。
神经网络模型可以计算图的形式进行表示,计算图可通常包含相互连接的多个节点,一个节点对应于模型中某一层的至少一个神经元,故一个节点可表示神经网络模型所能实现的一部分计算。当使用某个神经网络模型的计算图进行数据处理时,通常会逐个运行计算图的多个节点,可能造成排队拥堵的情况发生,导致数据处理的效率低下。为了解决该问题,可对计算图进行切分,得到多个子计算图,故可并行运算这多个子计算图,从而提高数据处理的效率。
目前,通常基于专家经验来制定计算图的切分策略,涉及较多的人为干预,考虑的因素往往较为单一,导致切分策略往往仅能针对表示某些特定结构的神经网络模型的计算图,且基于此种方式所得的切分策略也有可能并非是计算图的最优切分策略。
发明内容
本申请实施例提供了一种模型切分方法及其相关设备,在进行模型切分时,可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分,且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略。
本申请实施例的第一方面提供了一种模型切分方法,该方法包括:
当需要对第一模型进行切分时,可先获取第一模型的第一计算图。其中,第一模型为待切分的神经网络模型,第一模型可具备实现某种数据处理功能,例如,第一模型可用于对图像数据进行分类处理,又如,第一模型也可用于对文本数据进行摘要处理,再如,第一模型还可用于对语音数据进行识别处理等等。第一模型的第一计算图通常包含相连接的多个节点,在这多个节点中,一个节点对应于第一模型中位于同一层的至少一个神经元,由于第一模型中的神经元可视为第一模型中的计算单元,故在第一计算图的多个节点中,一个节点可用于表示第一模型可实现的一部分计算。
得到第一模型的第一计算图后,可将第一计算图输入至第二模型,以通过第二模型对第一计算图进行处理,得到针对第一计算图的处理结果。针对第一计算图的处理结果通常包含 多个切分策略(也可以称为切分行为)的概率,故可在这多个切分策略中,将概率最大的切分策略确定为针对第一计算图的第一切分策略。
得到针对第一计算图的第一切分策略后,可获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗。具体地,在得到针对第一计算图的第一切分策略后,可先获取计算图、切分策略与损耗(也可以称为代价)之间的对应关系,该对应关系可用于评价第二模型输出的切分策略是否可行。那么,基于该对应关系,可获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,从而判断第一损耗是否小于预置阈值,以确定第一切分策略是否可行。
若第一切分策略作用于第一计算图后所需付出的第一损耗小于预置阈值,说明第一切分策略是可行的,故可基于第一切分策略对第一计算图进行切分,得到多个子计算图,着多个子计算图中,一个子计算图包含第一计算图的至少一个节点。至此,则完成了第一计算图的切分,也相当于完成了第一模型的切分。
从上述方法可以看出:在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,第一计算图包含多个节点,一个节点表示第一模型可实现的一部分计算,该方法还包括:对第一计算图的多个节点进行编码,得到与多个节点一一对应的多个第一编码;通过第二模型对第一计算图进行处理,得到处理结果包括:通过第二模型对多个第一编码进行处理,得到处理结果。前述实现方式中,在将第一计算图输入至第二模型之前,在第一计算图的多个节点中,对于任意一个节点而言,可先对该节点进行编码,从而得到与该节点对应的第一编码,值得注意的是,该节点对应的第一编码的数据量要远小于该节点自身的数据量,故可降低第二模型的输入的数据量。同样地,对于除该节点之外的其余节点,也可执行如同对该节点所执行的操作,故可得到与其余节点对应的第一编码,如此一来,可得到与第一计算图的多个节点一一对应的多个第一编码。得到与第一计算图的多个节点一一对应的多个第一编码后,可将这多个第一编码输入第二模型,以通过第二模型对这多个第一编码进行处理,得到处理结果。具体地,该处理结果通常包含多个切分策略的编码的概率,故可在这多个编码中,将概率最大的编码确定为第二编码,并将第二编码所指示的切分策略确定为针对第一计算图的第一切分策略。由于第二模型的输入并非为第一计算图的多个节点,而是与这多个节点一一对应的多个第一编码,第一编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型所需处理的数据量,减少模型获取切分策略的耗时,节省模型获取切分策略所占用的资源。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,基于切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗包括:对多个第一编码和第二编码进行融合,得到第三编码;基于编码与损耗之间的对应关系以及第三编码,确定第一切分策略作用于第一计算图后所需付出的第一损耗。前述实现方式中,计算图、切分策略与损耗之间的对应关系可以呈现为编码与损耗之间的对应关系,例如,该对应关系可以为二维坐标系上的一条曲线,坐标系的横坐标为将计算图中节点的编码与切分策略的编码融合后的编码,坐标系的纵坐标为损耗等等。那么,可通过以下方式来获取第一切分策略作用于第一计算图后所需付出的第一损耗:先将多个第一编码和第二编码进行融合,从而得到第三编码。得到第三编码后,可在编码与损耗之间的对应关系中,精准确定与第三编码对应的损耗,该损耗即为第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,对多个第一编码和第二编码进行融合,得到第三编码包括:通过图核算法对多个第一编码和第二编码进行迭代运算,得到第三编码。前述实现方式中,在对多个第一编码和第二编码进行融合时,可通过图核算法(weisfeiler-lehman(WL)graph kernel算法)实现融合操作,即可先将多个第一编码和第二编码进行相加(或拼接),再将相加后(或拼接后)的编码进行基于图核算法的迭代运算,以准确得到第三编码。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系通常是提前部署好的,该对应关系可基于第三模型的第二计算图、针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗构建,其中,第三模型的第二计算图为获取第二模型的训练数据(即在第二模型的训练过程中所使用的数据),且针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗均为已知的数据,即真实的数据。
在一种可能的实现方式中,由于第一切分策略可用于将第一计算图切分成多个子计算图,故第一损耗可以指通过这多个子计算图来实现数据处理(即第一模型所能实现的数据处理)所需的损耗,例如,第一损耗可以指通过这多个子计算图来实现数据处理所需的时间,又如,第一损耗可以指通过这多个子计算图来实现数据处理所占用的资源(例如,计算资源、存储资源和通信资源)等等。
在一种可能的实现方式中,该方法还包括:若第一损耗大于或等于预置阈值,则不对第一计算图进行切分。前述实现方式中,若第一切分策略作用于第一计算图后所需付出的第一损耗大于或等于预置阈值,说明第一切分策略是不可行的,故不对第一计算图进行切分,可使得方案更加全面。
本申请实施例的第二方面提供了一种模型的切分策略评价方法,该方法包括:
当需要对第四模型(即待训练的神经网络模型)进行训练时,可先获取一批训练数据,该批训练数据包含第三模型的第二计算图,第二计算图包含多个节点,一个节点对应于第三模型中位于同一层的至少一个神经元,即一个节点可用于表示第三模型可实现的一部分运算。由于第三模型的第二计算图作为训练数据,故针对第二计算图的第二切分策略(真实切分策略)以及第二切分策略作用于第二计算图后所需付出的第二损耗(真实损耗)均是已知的数 据。
得到第三模型的第二计算图、针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗后,可基于这些信息来构建计算图、切分策略与损耗之间的对应关系,该对应关系可用于评价第二模型输出的切分策略是否可行,例如,该对应关系可用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,从而判断第一损耗是否小于预置阈值,以确定第一切分策略是否可行。
上述方法训练得到的第二模型,可用于对第一模型的第一计算图进行处理,得到针对第一计算图的第一切分策略,且上述方法构建得到的计算图、切分策略与损耗之间的对应关系,还用于预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,可见,本申请实施例提供了一种新的模型切分方式(框架),此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,第二计算图包含多个节点,一个节点表示第三模型可实现的一部分运算,基于第二计算图、第二切分策略以及第二损耗,构建计算图、切分策略与损耗之间的对应关系包括:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码,并对第二切分策略进行编码,得到第五编码;对多个第四编码和第五编码进行融合,得到第六编码;基于第六编码以及第二损耗,构建编码与损耗之间的对应关系。前述实现方式中,计算图、切分策略与损耗之间的对应关系可以呈现为编码与损耗之间的对应关系,故可通过以下方式构建编码与损耗之间的对应关系:在第二计算图的多个节点中,对于任意一个节点而言,可先对该节点进行编码,从而得到与该节点对应的第四编码,值得注意的是,该节点对应的第四编码的数据量要远小于该节点自身的数据量,故可降低第四模型的输入的数据量。同样地,对于除该节点之外的其余节点,也可执行如同对该节点所执行的操作,故可得到与其余节点对应的第四编码,如此一来,可得到与第二计算图的多个节点一一对应的多个第四编码,进一步地,还可对针对第二计算图的第二切分策略进行编码,得到第五编码,即第五编码用于指示针对第二计算图的第二切分策略。对与第二计算图的多个节点一一对应的多个第四编码和用于指示第二切分策略的第五编码进行融合,得到第六编码。
在一种可能的实现方式中,对多个第四编码和第五编码进行融合,得到第六编码包括:通过图核算法对多个第四编码和第五编码进行迭代运算,得到第六编码。前述实现方式中,在对多个第四编码和第五编码之间的融合时,可通过图核算法实现,即可先将多个第四编码和第五编码进行相加(或拼接),再将相加后(或拼接后)的编码进行基于图核算法的迭代运算,从而得到第六编码。
在一种可能的实现方式中,该方法还包括:通过第四模型对第二计算图进行处理,得到处理结果,处理结果用于确定第二计算图的第三切分策略;基于第二切分策略以及第三切分策略,获取目标损失,目标损失用于指示第二切分策略与第三切分策略之间的差异;基于目标损失,对第四模型的参数进行更新,直至满足模型训练条件,得到第二模型。前述实现方式中,得到针对第三模型的第二计算图后,可将第二计算图输入至第四模型,以通过第四模型对第二计算图进行处理,得到处理结果,该处理结果通常包含多个切分策略的概率,故可 在这多个切分策略中,将概率最大的切分策略确定为针对第二计算图的第三切分策略。得到针对第二计算图的第三切分策略,由于针对第二计算图的第二切分策略已知,故可通过预置的目标损失函数,对针对第二计算图的第二切分策略以及针对第二计算图的第三切分策略进行计算,得到目标损失,目标损失用于指示针对第二计算图的第二切分策略以及针对第二计算图的第三切分策略之间的差异。得到目标损失后,可基于目标损失,对第四模型的参数进行更新,得到更新后的第四模型。此后,可再获取下一批训练数据,对更新后的第四模型继续进行训练,直至满足模型训练条件(例如,目标损失收敛等等),得到第二模型。
在一种可能的实现方式中,通过第四模型对第二计算图进行处理,得到处理结果包括:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码;通过第四模型对这多个第四编码进行处理,得到处理结果。前述实现方式中,在第二计算图的多个节点中,对于任意一个节点而言,可先对该节点进行编码,从而得到与该节点对应的第四编码,值得注意的是,该节点对应的第四编码的数据量要远小于该节点自身的数据量,故可降低第四模型的输入的数据量。同样地,对于除该节点之外的其余节点,也可执行如同对该节点所执行的操作,故可得到与其余节点对应的第四编码,如此一来,可得到与第二计算图的多个节点一一对应的多个第四编码。得到与第二计算图的多个节点一一对应的多个第四编码后,可将这多个第四编码输入第四模型,以通过第四模型对这多个第四编码进行处理,得到处理结果,该处理结果通常包含多个切分策略的编码的概率,故可在这多个编码中,将概率最大的编码所指示的切分策略确定为针对第二计算图的第三切分策略。
在一种可能的实现方式中,第三模型用于实现数据处理,第二损耗为通过多个子计算图实现数据处理所需的时间,多个子计算图基于第二切分策略对第二子计算图进行切分得到。前述实现方式中,由于第二切分策略可用于将第二计算图切分成多个子计算图,故第二损耗可以指通过这多个子计算图来实现数据处理(即第三模型所能实现的数据处理)所需付出的损耗,例如,第二损耗可以是运行这多个子计算图来实现数据处理所需的时间,又如,第二损耗可以是运行这多个子计算图来实现数据处理所占用的资源(计算资源、存储资源、通信资源等)等等。
本申请实施例的第三方面提供了一种模型切分装置,该装置包括:获取模块,用于获取第一模型的第一计算图;处理模块,用于通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略;确定模块,用于确定第一切分策略作用于第一计算图后所需付出的第一损耗;切分模块,用于若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。
从上述装置可以看出:在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预, 且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,第一计算图包含多个节点,一个节点表示第一模型可实现的一部分计算,该装置还包括:编码模块,用于对第一计算图的多个节点进行编码,得到与多个节点一一对应的多个第一编码;处理模块,用于通过第二模型对多个第一编码进行处理,得到处理结果。
在一种可能的实现方式中,确定模块,用于基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,处理结果用于确定第二编码,第二编码用于指示第一计算图的第一切分策略,确定模块,用于:对多个第一编码和第二编码进行融合,得到第三编码;基于编码与损耗之间的对应关系以及第三编码,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,确定模块,用于通过图核算法对多个第一编码和第二编码进行迭代运算,得到第三编码。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系基于第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗构建,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据。
在一种可能的实现方式中,第一模型用于实现数据处理,第一损耗为通过多个子计算图实现数据处理所需的时间。
在一种可能的实现方式中,该装置还包括:非切分模块,用于若第一损耗大于或等于预置阈值,则不对第一计算图进行切分。
本申请实施例的第四方面提供了一种模型的切分策略评价装置,该装置包括:第一获取模块,用于获取第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据;构建模块,用于基于第二计算图、第二切分策略以及第二损耗,构建计算图、切分策略与损耗之间的对应关系,对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,第一切分策略由第二模型对第一计算图进行处理得到。
上述装置训练得到的第二模型,可用于对第一模型的第一计算图进行处理,得到针对第一计算图的第一切分策略,且上述装置构建得到的计算图、切分策略与损耗之间的对应关系,还用于预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,可见,本申请实施例提供了一种新的模型切分方式(框架),此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,第二计算图包含多个节点,一个节点表示第三模型可实现的一部分运算,构建模块,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码,并对第二切分策略进行编码,得到第五编码;对多个第四编码和第五编码进行融合,得到第六编码;基于第六编码以及第二损耗,构建编码与损耗之间的对应关系。
在一种可能的实现方式中,构建模块,用于通过图核算法对多个第四编码和第五编码进行迭代运算,得到第六编码。
在一种可能的实现方式中,该装置还包括:处理模块,用于通过第四模型对第二计算图进行处理,得到处理结果,处理结果用于确定第二计算图的第三切分策略;第二获取模块,用于基于第二切分策略以及第三切分策略,获取目标损失,目标损失用于指示第二切分策略与第三切分策略之间的差异;更新模块,用于基于目标损失,对第四模型的参数进行更新,直至满足模型训练条件,得到第二模型。
在一种可能的实现方式中,处理模块,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码;通过第四模型对这多个第四编码进行处理,得到处理结果。
在一种可能的实现方式中,第三模型用于实现数据处理,第二损耗为通过多个子计算图实现数据处理所需的时间,多个子计算图基于第二切分策略对第二子计算图进行切分得到。
本申请实施例的第五方面提供了一种模型切分装置,该装置包括存储器和处理器;存储器存储有代码,处理器被配置为执行代码,当代码被执行时,模型切分装置执行以下步骤:获取第一模型的第一计算图;通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略;确定第一切分策略作用于第一计算图后所需付出的第一损耗;若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。
从上述装置可以看出:在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,模型切分装置,还用于对第一计算图的多个节点进行编码,得到与多个节点一一对应的多个第一编码;模型切分装置,用于通过第二模型对多个第一编码进行处理,得到处理结果。
在一种可能的实现方式中,确定所述第一切分策略作用于第一计算图后所需付出的第一损耗包括:基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计 算图后所需付出的第一损耗。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,处理结果用于确定第二编码,第二编码用于指示第一计算图的第一切分策略,模型切分装置,用于:对多个第一编码和第二编码进行融合,得到第三编码;基于编码与损耗之间的对应关系以及第三编码,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,模型切分装置,用于通过图核算法对多个第一编码和第二编码进行迭代运算,得到第三编码。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系基于第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗构建,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据。
在一种可能的实现方式中,第一模型用于实现数据处理,第一损耗为通过多个子计算图实现数据处理所需的时间。
在一种可能的实现方式中,模型切分装置,还用于若第一损耗大于或等于预置阈值,则不对第一计算图进行切分。
本申请实施例的第六方面提供了一种模型的切分策略评价装置,该装置包括存储器和处理器;存储器存储有代码,处理器被配置为执行代码,当代码被执行时,模型的切分策略评价装置执行以下步骤:获取第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据;基于第二计算图、第二切分策略以及第二损耗,构建计算图、切分策略与损耗之间的对应关系,对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,第一切分策略由第二模型对第一计算图进行处理得到。
上述装置训练得到的第二模型,可用于对第一模型的第一计算图进行处理,得到针对第一计算图的第一切分策略,且上述装置构建得到的计算图、切分策略与损耗之间的对应关系,还用于预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,可见,本申请实施例提供了一种新的模型切分方式(框架),此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
在一种可能的实现方式中,第二计算图包含多个节点,一个节点表示第三模型可实现的一部分运算,模型的切分策略评价装置,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码,并对第二切分策略进行编码,得到第五编码;对多个第四编码和第五编码进行融合,得到第六编码;基于第六编码以及第二损耗,构建编码与损耗之间的对应关系。
在一种可能的实现方式中,模型的切分策略评价装置,用于通过图核算法对多个第四编 码和第五编码进行迭代运算,得到第六编码。
在一种可能的实现方式中,模型的切分策略评价装置,还用于:通过第四模型对第二计算图进行处理,得到处理结果,处理结果用于确定第二计算图的第三切分策略;基于第二切分策略以及第三切分策略,获取目标损失,目标损失用于指示第二切分策略与第三切分策略之间的差异;基于目标损失,对第四模型的参数进行更新,直至满足模型训练条件,得到第二模型。
在一种可能的实现方式中,模型的切分策略评价装置,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码;通过第四模型对这多个第四编码进行处理,得到处理结果。
在一种可能的实现方式中,第三模型用于实现数据处理,第二损耗为通过多个子计算图实现数据处理所需的时间,多个子计算图基于第二切分策略对第二子计算图进行切分得到。
本申请实施例的第七方面提供了一种电路***,该电路***包括处理电路,该处理电路配置为执行如第一方面、第一方面中的任意一种可能的实现方式或第二方面所述的方法。
本申请实施例的第八方面提供了一种芯片***,该芯片***包括处理器,用于调用存储器中存储的计算机程序或计算机指令,以使得该处理器执行如第一方面、第一方面中的任意一种可能的实现方式或第二方面所述的方法。
在一种可能的实现方式中,该处理器通过接口与存储器耦合。
在一种可能的实现方式中,该芯片***还包括存储器,该存储器中存储有计算机程序或计算机指令。
本申请实施例的第九方面提供了一种计算机存储介质,该计算机存储介质存储有计算机程序,该程序在由计算机执行时,使得计算机实施如第一方面、第一方面中的任意一种可能的实现方式或第二方面所述的方法。
本申请实施例的第十方面提供了一种计算机程序产品,该计算机程序产品存储有指令,该指令在由计算机执行时,使得计算机实施如第一方面、第一方面中的任意一种可能的实现方式或第二方面所述的方法。
本申请实施例中,在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
进一步地,第二模型的输入并非为第一计算图的多个节点,而是与这多个节点一一对应的多个第一编码,第一编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型所需处理的数据量,减少模型获取切分策略的耗时,节省模型获取切分策略所占用的资源。
附图说明
图1为人工智能主体框架的一种结构示意图;
图2a为本申请实施例提供的模型切分***的一个结构示意图;
图2b为本申请实施例提供的模型切分***的另一结构示意图;
图2c为本申请实施例提供的模型切分处理的相关设备的一个示意图;
图3为本申请实施例提供的***100架构的一个示意图;
图4为本申请实施例提供的模型切分方法的一个流程示意图;
图5为本申请实施例提供的第一计算图的一个示意图;
图6为本申请实施例提供的切分策略生成的一个流程示意图;
图7为本申请实施例提供的图核算法的一个流程示意图;
图8为本申请实施例提供的模型的切分策略评价方法的一个流程示意图;
图9为本申请实施例提供的第二计算图的一个示意图;
图10为本申请实施例提供的候选切分策略的一个示意图;
图11为本申请实施例提供的候选切分策略的另一示意图;
图12为本申请实施例提供的模型切分装置的一个结构示意图;
图13为本申请实施例提供的模型的切分策略评价装置的一个结构示意图;
图14为本申请实施例提供的执行设备的一个结构示意图;
图15为本申请实施例提供的训练设备的一个结构示意图;
图16为本申请实施例提供的芯片的一个结构示意图。
具体实施方式
本申请实施例提供了一种模型切分方法及其相关设备,在进行模型切分时,可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分,且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”并他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、***、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。
随着技术的快速发展,越来越多的领域可使用AI技术的神经网络模型来实现数据处理,例如,可利用神经网络模型实现图像分类、文本摘要生成,语音识别以及函数求解等各类数据处理。
神经网络模型的数据处理过程可视为神经网络模型对数据进行计算的过程,故神经网络模型可通过计算图的形式进行表示,计算图可通常包含相互连接的多个节点,一个节点对应于模型中某一层的至少一个神经元,故一个节点可表示神经网络模型所能实现的一部分计算。当电子设备通过某个神经网络模型的计算图进行数据处理时,电子设备的处理器通常会逐个运行计算图的多个节点,可能造成排队拥堵的情况发生,导致数据处理的效率低下。为了解决该问题,可通过电子设备的处理器提前对计算图进行切分,并将得到的多个子计算图分别存放于处理器的多个寄存器上,故在进行数据处理时,处理器可并行运算这多个子计算图,从而提高数据处理的效率。
目前,通常基于专家经验来制定计算图的切分策略,涉及较多的人为干预,考虑的因素往往较为单一,导致切分策略往往仅能针对表示某些特定结构的神经网络模型的计算图(即泛化性不佳),且基于此种方式所得的切分策略也有可能并非是神经网络模型的计算图的最优切分策略(切分效果不佳)。
进一步地,相关技术还可通过已训练的神经网络模型来对表示某个神经网络模型的计算图进行处理,得到该神经网络模型的计算图的切分策略,然而,已训练的神经网络模型的输入往往是整个神经网络模型的计算图,其数据量通常很大,导致获取切分策略的过程耗时较长,耗费的资源较多。
为了解决上述问题,本申请实施例提供一种模型切分方法,该方法可结合人工智能(artificial intelligence,AI)技术实现。AI技术是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能的技术学科,AI技术通过感知环境、获取知识并使用知识获得最佳结果。换句话说,人工智能技术是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式做出反应的智能机器。利用人工智能进行数据处理是人工智能常见的一个应用方式。
首先对人工智能***总体工作流程进行描述,请参见图1,图1为人工智能主体框架的一种结构示意图,下面从“智能信息链”(水平轴)和“IT价值链”(垂直轴)两个维度对上述人工智能主题框架进行阐述。其中,“智能信息链”反映从数据的获取到处理的一列过程。举例来说,可以是智能信息感知、智能信息表示与形成、智能推理、智能决策、智能执行与输出的一般过程。在这个过程中,数据经历了“数据—信息—知识—智慧”的凝练过程。“IT价值链”从人智能的底层基础设施、信息(提供和处理技术实现)到***的产业生态过程,反映人工智能为信息技术产业带来的价值。
(1)基础设施
基础设施为人工智能***提供计算能力支持,实现与外部世界的沟通,并通过基础平台实现支撑。通过传感器与外部沟通;计算能力由智能芯片(CPU、NPU、GPU、ASIC、FPGA等硬件加速芯片)提供;基础平台包括分布式计算框架及网络等相关的平台保障和支持,可以包括云存储和计算、互联互通网络等。举例来说,传感器和外部沟通获取数据,这些数据提供给基础平台提供的分布式计算***中的智能芯片进行计算。
(2)数据
基础设施的上一层的数据用于表示人工智能领域的数据来源。数据涉及到图形、图像、语音、文本,还涉及到传统设备的物联网数据,包括已有***的业务数据以及力、位移、液 位、温度、湿度等感知数据。
(3)数据处理
数据处理通常包括数据训练,机器学习,深度学习,搜索,推理,决策等方式。
其中,机器学习和深度学习可以对数据进行符号化和形式化的智能信息建模、抽取、预处理、训练等。
推理是指在计算机或智能***中,模拟人类的智能推理方式,依据推理控制策略,利用形式化的信息进行机器思维和求解问题的过程,典型的功能是搜索与匹配。
决策是指智能信息经过推理后进行决策的过程,通常提供分类、排序、预测等功能。
(4)通用能力
对数据经过上面提到的数据处理后,进一步基于数据处理的结果可以形成一些通用的能力,比如可以是算法或者一个通用***,例如,翻译,文本的分析,计算机视觉的处理,语音识别,图像的识别等等。
(5)智能产品及行业应用
智能产品及行业应用指人工智能***在各领域的产品和应用,是对人工智能整体解决方案的封装,将智能信息决策产品化、实现落地应用,其应用领域主要包括:智能终端、智能交通、智能医疗、自动驾驶、智慧城市等。
接下来介绍几种本申请的应用场景。
图2a为本申请实施例提供的模型切分***的一个结构示意图,该模型切分***包括用户设备以及数据处理设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为数据序列处理的发起端,作为数据序列处理请求的发起方,通常由用户通过用户设备发起请求。
上述数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。数据处理设备通过交互接口接收来自智能终端的文本处理请求,再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的文本处理。数据处理设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。
在图2a所示的模型切分***中,用户设备可以接收用户的指令,例如用户设备可以获取用户输入/选择的一个待切分的神经网络模型,然后向数据处理设备发起请求,使得数据处理设备针对用户设备得到的该模型执行模型切分应用,从而得到针对该模型的处理结果。示例性的,用户设备可以获取用户输入的一个待切分的神经网络模型,然后向数据处理设备发起该模型的处理请求,使得数据处理设备将该模型以计算图的形式进行表示,并对该模型的计算图进行处理,从而得到该模型的处理结果,即针对该模型的计算图的切分策略,再基于该切分策略将该模型的计算图切分成多个子计算图,从而完成该模型的计算图的切分(相当于完成该模型的切分)。
在图2a中,数据处理设备可以执行本申请实施例的模型切分方法。
图2b为本申请实施例提供的模型切分***的另一结构示意图,在图2b中,用户设备直接作为数据处理设备,该用户设备能够直接获取来自用户的输入并直接由用户设备本身的硬件 进行处理,具体过程与图2a相似,可参考上面的描述,在此不再赘述。
在图2b所示的模型切分***中,用户设备可以接收用户的待切分的神经网络模型,例如用户设备可以获取用户在用户设备中所选择的一个神经网络模型,然后再由用户设备自身针对该模型的执行模型切分应用(例如,将该模型转换为计算图,并对该模型的计算图进行处理),从而得到针对该模型的处理结果,即针对该模型的计算图的切分策略,再基于该切分策略将该模型的计算图切分成多个子计算图,从而完成该模型的计算图的切分(相当于完成该模型的切分)。
在图2b中,用户设备自身就可以执行本申请实施例的模型切分方法。
图2c为本申请实施例提供的模型切分处理的相关设备的一个示意图。
上述图2a和图2b中的用户设备具体可以是图2c中的本地设备301或者本地设备302,图2a中的数据处理设备具体可以是图2c中的执行设备210,其中,数据存储***250可以存储执行设备210的待处理数据,数据存储***250可以集成在执行设备210上,也可以设置在云上或其它网络服务器上。
图2a和图2b中的处理器可以通过神经网络模型或者其它模型(例如,基于支持向量机的模型)进行数据训练/机器学习/深度学习,并利用数据最终训练或者学习得到的模型针对模型执行模型切分应用,从而得到相应的处理结果。
图3为本申请实施例提供的***100架构的一个示意图,在图3中,执行设备110配置输入/输出(input/output,I/O)接口112,用于与外部设备进行数据交互,用户可以通过客户设备140向I/O接口112输入数据,所述输入数据在本申请实施例中可以包括:各个待调度任务、可调用资源以及其他参数。
在执行设备110对输入数据进行预处理,或者在执行设备110的计算模块111执行计算等相关的处理(比如进行本申请中神经网络的功能实现)过程中,执行设备110可以调用数据存储***150中的数据、代码等以用于相应的处理,也可以将相应处理得到的数据、指令等存入数据存储***150中。
最后,I/O接口112将处理结果返回给客户设备140,从而提供给用户。
值得说明的是,训练设备120可以针对不同的目标或称不同的任务,基于不同的训练数据生成相应的目标模型/规则,该相应的目标模型/规则即可以用于实现上述目标或完成上述任务,从而为用户提供所需的结果。其中,训练数据可以存储在数据库130中,且来自于数据采集设备160采集的训练样本。
在图3中所示情况下,用户可以手动给定输入数据,该手动给定可以通过I/O接口112提供的界面进行操作。另一种情况下,客户设备140可以自动地向I/O接口112发送输入数据,如果要求客户设备140自动发送输入数据需要获得用户的授权,则用户可以在客户设备140中设置相应权限。用户可以在客户设备140查看执行设备110输出的结果,具体的呈现形式可以是显示、声音、动作等具体方式。客户设备140也可以作为数据采集端,采集如图所示输入I/O接口112的输入数据及输出I/O接口112的输出结果作为新的样本数据,并存入数据库130。当然,也可以不经过客户设备140进行采集,而是由I/O接口112直接将如图所示输入I/O接口112的输入数据及输出I/O接口112的输出结果,作为新的样本数据存入数据库130。
值得注意的是,图3仅是本申请实施例提供的一种***架构的示意图,图中所示设备、器件、模块等之间的位置关系不构成任何限制,例如,在图3中,数据存储***150相对执行设备110是外部存储器,在其它情况下,也可以将数据存储***150置于执行设备110中。如图3所示,可以根据训练设备120训练得到神经网络。
本申请实施例还提供的一种芯片,该芯片包括神经网络处理器NPU。该芯片可以被设置在如图3所示的执行设备110中,用以完成计算模块111的计算工作。该芯片也可以被设置在如图3所示的训练设备120中,用以完成训练设备120的训练工作并输出目标模型/规则。
神经网络处理器NPU,NPU作为协处理器挂载到主中央处理器(central processing unit,CPU)(host CPU)上,由主CPU分配任务。NPU的核心部分为运算电路,控制器控制运算电路提取存储器(权重存储器或输入存储器)中的数据并进行运算。
在一些实现中,运算电路内部包括多个处理单元(process engine,PE)。在一些实现中,运算电路是二维脉动阵列。运算电路还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)中。
向量计算单元可以对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。例如,向量计算单元可以用于神经网络中非卷积/非FC层的网络计算,如池化(pooling),批归一化(batch normalization),局部响应归一化(local response normalization)等。
在一些实现中,向量计算单元能将经处理的输出的向量存储到统一缓存器。例如,向量计算单元可以将非线性函数应用到运算电路的输出,例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元生成归一化的值、合并值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路的激活输入,例如用于在神经网络中的后续层中的使用。
统一存储器用于存放输入数据以及输出数据。
权重数据直接通过存储单元访问控制器(direct memory access controller,DMAC)将外部存储器中的输入数据搬运到输入存储器和/或统一存储器、将外部存储器中的权重数据存入权重存储器,以及将统一存储器中的数据存入外部存储器。
总线接口单元(bus interface unit,BIU),用于通过总线实现主CPU、DMAC和取指存储器之间进行交互。
与控制器连接的取指存储器(instruction fetch buffer),用于存储控制器使用的指令;
控制器,用于调用指存储器中缓存的指令,实现控制该运算加速器的工作过程。
一般地,统一存储器,输入存储器,权重存储器以及取指存储器均为片上(On-Chip)存储器,外部存储器为该NPU外部的存储器,该外部存储器可以为双倍数据率同步动态随机存储器(double data rate synchronous dynamic random access memory,DDR SDRAM)、高带宽存储器(high bandwidth memory,HBM)或其他可读可写的存储器。
由于本申请实施例涉及大量神经网络的应用,为了便于理解,下面先对本申请实施例涉及的相关术语及神经网络等相关概念进行介绍。
(1)神经网络
神经网络可以是由神经单元组成的,神经单元可以是指以xs和截距1为输入的运算单元,该运算单元的输出可以为:
其中,s=1、2、……n,n为大于1的自然数,Ws为xs的权重,b为神经单元的偏置。f为神经单元的激活函数(activation functions),用于将非线性特性引入神经网络中,来将神经单元中的输入信号转换为输出信号。该激活函数的输出信号可以作为下一层卷积层的输入。激活函数可以是sigmoid函数。神经网络是将许多个上述单一的神经单元联结在一起形成的网络,即一个神经单元的输出可以是另一个神经单元的输入。每个神经单元的输入可以与前一层的局部接受域相连,来提取局部接受域的特征,局部接受域可以是由若干个神经单元组成的区域。
神经网络中的每一层的工作可以用数学表达式y=a(Wx+b)来描述:从物理层面神经网络中的每一层的工作可以理解为通过五种对输入空间(输入向量的集合)的操作,完成输入空间到输出空间的变换(即矩阵的行空间到列空间),这五种操作包括:1、升维/降维;2、放大/缩小;3、旋转;4、平移;5、“弯曲”。其中1、2、3的操作由Wx完成,4的操作由+b完成,5的操作则由a()来实现。这里之所以用“空间”二字来表述是因为被分类的对象并不是单个事物,而是一类事物,空间是指这类事物所有个体的集合。其中,W是权重向量,该向量中的每一个值表示该层神经网络中的一个神经元的权重值。该向量W决定着上文所述的输入空间到输出空间的空间变换,即每一层的权重W控制着如何变换空间。训练神经网络的目的,也就是最终得到训练好的神经网络的所有层的权重矩阵(由很多层的向量W形成的权重矩阵)。因此,神经网络的训练过程本质上就是学习控制空间变换的方式,更具体的就是学习权重矩阵。
因为希望神经网络的输出尽可能的接近真正想要预测的值,所以可以通过比较当前网络的预测值和真正想要的目标值,再根据两者之间的差异情况来更新每一层神经网络的权重向量(当然,在第一次更新之前通常会有初始化的过程,即为神经网络中的各层预先配置参数),比如,如果网络的预测值高了,就调整权重向量让它预测低一些,不断的调整,直到神经网络能够预测出真正想要的目标值。因此,就需要预先定义“如何比较预测值和目标值之间的差异”,这便是损失函数(loss function)或目标函数(objective function),它们是用于衡量预测值和目标值的差异的重要方程。其中,以损失函数举例,损失函数的输出值(loss)越高表示差异越大,那么神经网络的训练就变成了尽可能缩小这个loss的过程。
(2)反向传播算法
神经网络可以采用误差反向传播(back propagation,BP)算法在训练过程中修正初始的神经网络模型中参数的大小,使得神经网络模型的重建误差损失越来越小。具体地,前向传递输入信号直至输出会产生误差损失,通过反向传播误差损失信息来更新初始的神经网络模型中参数,从而使误差损失收敛。反向传播算法是以误差损失为主导的反向传播运动,旨在 得到最优的神经网络模型的参数,例如权重矩阵。
(3)计算图
计算图可作为神经网络的一种呈现方式,计算图通常包含相连接的多个节点,在这多个节点中,对于任意一个节点而言,该节点可对应于神经网络中位于同一层的至少一个神经元。由于神经元为神经网络中的计算单元,神经元在接收输入后,可利用自身的参数对该输入进行计算,得到相应的输出,那么,该节点可表示为y=f(x),x为该节点对应的至少一个神经元的输入,f()表示该节点对应的至少一个神经元进行的计算,y为该节点对应的至少一个神经元的输出。可见,该节点可表示神经网络所能实现的一部分计算。如此一来,具有很多参数的神经网络可通过较为简化的计算图进行表示,有利于处理器去运行和存储神经网络。
下面从神经网络的训练侧和神经网络的应用侧对本申请提供的方法进行描述。
本申请实施例提供的模型的切分策略评价方法,涉及数据序列的处理,具体可以应用于数据训练、机器学习、深度学习等方法,对训练数据(例如,将本申请中第三模型的第二计算图)进行符号化和形式化的智能信息建模、抽取、预处理、训练等,最终得到训练好的神经网络(例如,本申请中的第二模型);并且,本申请实施例提供的模型切分方法可以运用上述训练好的神经网络,将输入数据(例如,本申请中第一模型的第一计算图)输入到所述训练好的神经网络中,得到输出数据(如本申请中第一计算图的第一切分策略)。需要说明的是,本申请实施例提供的模型的切分策略评价方法和模型切分方法是基于同一个构思产生的发明,也可以理解为一个***中的两个部分,或一个整体流程的两个阶段:如模型训练阶段和模型应用阶段。
图4为本申请实施例提供的模型切分方法的一个流程示意图,如图4所示,该方法包括:
401、获取第一模型的第一计算图。
本实施例中,当需要对第一模型进行切分时,可先获取第一模型的第一计算图。其中,第一模型为待切分的神经网络模型,第一模型可用于实现数据处理功能,例如,第一模型可用于对图像数据进行分类处理,又如,第一模型可用于对文本数据进行摘要处理,再如,第一模型可用于对语音数据进行识别处理等等。第一模型的第一计算图可包含相连接的多个节点,在这多个节点中,一个节点对应于第一模型中位于同一层的至少一个神经元,由于第一模型中的神经元可视为第一模型中的计算单元(具备一定的计算功能),故在第一计算图的多个节点中,一个节点可用于表示第一模型可实现的一部分计算。例如,如图5所示(图5为本申请实施例提供的第一计算图的一个示意图),设第一模型包含了5个节点,分别位于5层,第1层为输入层,第2层为卷积层,第3层为归一化层,第4层为激活层以及第5层为输出层。分别位于这5层的5个神经元用于实现不同的计算,其中,第1层的神经元用于接收输入的数据,第2层的神经元用于对数据进行卷积,第3的神经元用于对卷积结果进行归一化,第4层的神经元用于对归一化结果进行激活,第5层的神经元用于对激活结果和原始输入的数据进行加权,得到数据的处理结果。那么,可将这5个神经元分别用5个节点进行表示,分别为节点0、节点1、节点2、节点3和节点4,节点0用于表示第1层的神经元可实现的计算,节点1用于表示第2层的神经元可实现的计算,节点2用于表示第3层的神经元可实现的计算,节点3用于表示第4层的神经元可实现的计算,节点4用于表示第5层的神经元 可实现的计算,故相连接的这5个节点构成了第一模型的第一计算图。
应理解,图5所示的例子中,仅以第一模型包含5层神经元进行示意性介绍,并不对本申请中第一模型的层数构成限制。
还应理解,图5所示的例子中,仅以第一模型中每一层包含1个神经元进行示意性介绍,并不对第一模型每一层的神经元数量构成限制。
还应理解,图5所示的例子中,仅以第一计算图中一个节点用于表示第一模型中一个神经元所能实现的计算进行示意性介绍,在实际应用中,第一计算图中一个节点还可用于表示第一模型中位于同一层的多个神经元所能实现的计算。
402、通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。
得到第一模型的第一计算图后,可将第一计算图输入至第二模型(即已训练的神经网络模型,用于实现模型切分功能),以通过第二模型对第一计算图进行处理,得到针对第一计算图的处理结果,该处理结果通常包含多个切分策略(也可以称为切分行为)的概率,故可在这多个切分策略中,将概率最大的切分策略确定为针对第一计算图的第一切分策略,依旧如上述例子,通过第二模型对第一模型的第一计算图进行处理后,可得到针对第一计算图的第一切分策略,第一切分策略用于指示以下内容:将第一计算图分成两个子计算图,第1个子计算图包含节点1、节点2以及节点3,第2个子计算图包含节点0以及节点4。
具体地,可通过以下方式获取第一计算图的处理结果:
(1)在将第一计算图输入至第二模型之前,在第一计算图的多个节点中,对于任意一个节点而言,可先对该节点进行编码,从而得到与该节点对应的第一编码,值得注意的是,该节点对应的第一编码的数据量要远小于该节点自身的数据量,故可降低第二模型的输入的数据量。同样地,对于除该节点之外的其余节点,也可执行如同对该节点所执行的操作,故可得到与其余节点对应的第一编码,如此一来,可得到与第一计算图的多个节点一一对应的多个第一编码。依旧如上述例子,如图6所示(图6为本申请实施例提供的切分策略生成的一个流程示意图,图6是在图5的基础上进行绘制得到的),得到节点0至节点4后,可对节点0至节点4分别进行编码,从而得到节点0的编码0、节点1的编码1、节点2的编码2、节点3的编码3以及节点4的编码4。
(2)得到与第一计算图的多个节点一一对应的多个第一编码后,可将这多个第一编码输入第二模型,以通过第二模型对这多个第一编码进行处理,得到处理结果,该处理结果通常包含多个切分策略的编码的概率,故可在这多个编码中,将概率最大的编码确定为第二编码,并将第二编码所指示的切分策略确定为针对第一计算图的第一切分策略。依旧如上述例子,通过第二模型对编码1至编码4进行处理后,可得到处理结果,该处理结果包含编码5的概率、编码6的概率、编码7的概率,编码5用于指示切分策略1,编码6用于指示切分策略2,编码7用于指示切分策略3,由于编码5的概率最大,故可将切分策略1确定为针对第一计算图的切分策略。
403、基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
得到针对第一计算图的第一切分策略后,可获取计算图、切分策略与损耗(也可以称为 代价)之间的对应关系,并基于该对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
值得注意的是,计算图、切分策略与损耗之间的对应关系通常是提前部署好的,该对应关系可基于第三模型(即作为训练数据的神经网络模型,也可用于实现数据处理功能)的第二计算图、针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗构建,其中,第三模型的第二计算图为获取第二模型的训练数据(即在第二模型的训练过程中所使用的数据),且针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗均为已知的数据(也可以称为真实的数据)。
值得注意的是,由于第一切分策略可用于将第一计算图切分成多个子计算图,故第一损耗可以指通过(运行)这多个子计算图来实现数据处理(即第一模型所能实现的数据处理)所需付出的损耗,例如,第一损耗可以是运行这多个子计算图来实现数据处理所需的时间,又如,第一损耗可以是运行这多个子计算图来实现数据处理所占用的资源(计算资源、存储资源、通信资源等)等等。
具体地,计算图、切分策略与损耗之间的对应关系可以呈现为编码与损耗之间的对应关系,例如,该对应关系可以为二维坐标系上的一条曲线,坐标系的横坐标为将计算图中节点的编码与切分策略的编码融合后的编码,坐标系的纵坐标为损耗等等。那么,可通过以下方式来获取第一切分策略作用于第一计算图后所需付出的第一损耗:
(1)对与第一计算图的多个节点一一对应的多个第一编码和用于指示第一切分策略的第二编码进行融合,得到第三编码。需要说明的是,前述的融合处理可通过图核算法(weisfeiler-lehman(WL)graph kernel算法)实现,例如,如图7所示(图7为本申请实施例提供的图核算法的一个流程示意图),可先将多个第一编码和第二编码进行相加(或拼接),再将相加后(或拼接后)的编码进行基于图核算法的迭代运算,从而得到第三编码。
(2)得到第三编码后,可在编码与损耗之间的对应关系中,确定与第三编码对应的损耗,该损耗即为第一切分策略作用于第一计算图后所需付出的第一损耗。
应理解,第二模型处于应用阶段时的相关数据为预测数据,第二模型处于训练阶段时的相关数据为真实数据,即前述针对第一计算图的第一切分策略也可以理解针对第一计算图的预测切分策略,第一切分策略作用于第一计算图后所需付出的第一损耗也可以理解为第一切分策略作用于第一计算图后所需付出的预测损耗,针对第二计算图的第二切分策略也可以理解针对第二计算图的真实切分策略,第二切分策略作用于第二计算图后所需付出的第二损耗也可以理解为第二切分策略作用于第二计算图后所需付出的真实损耗。
404、检测第一损耗是否小于预置阈值。
得到第一切分策略作用于第一计算图后所需付出的第一损耗后,可检测第一损耗是否小于预置阈值(也可以称为预置的损耗阈值)。需要说明的是,预置阈值的大小可通过多种方式设置,例如,预置阈值的大小可以是人工根据实际需求来设置的,又如,预置阈值的大小还可以基于不对第二计算图进行切分时,直接通过第二计算图实现数据处理所需付出的损耗来确定,此处不做限制。
405、若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。
若第一切分策略作用于第一计算图后所需付出的第一损耗小于预置阈值,说明第一切分策略是可行的,故可基于第一切分策略对第一计算图进行切分,得到多个子计算图,着多个子计算图中,一个子计算图包含第一计算图的至少一个节点。依旧如上述例子,由于切分策略1的内容为将第一计算图分成包含节点1、节点2和节点3的子计算图以及包含节点0和节点4的子计算图,故基于切分策略1,可将第一计算图分成两个子计算图,第1个子计算图包含节点1、节点2和节点3,第2个子计算图包含节点0和节点4。
至此,则完成了第一计算图的切分,也相当于完成了第一模型的切分。若后续存在针对第一模型的数据处理需求,可并行运行这多个子计算图,以实现第一模型的数据处理功能。
406、若第一损耗大于或等于预置阈值,则不对第一计算图进行切分。
若第一切分策略作用于第一计算图后所需付出的第一损耗大于或等于预置阈值,说明第一切分策略是不可行的,故不对第一计算图进行切分。若后续存在针对第一模型的数据处理需求,可直接运行整个第一计算图,以实现第一模型的数据处理功能。
本申请实施例中,在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
进一步地,第二模型的输入并非为第一计算图的多个节点,而是与这多个节点一一对应的多个第一编码,第一编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型所需处理的数据量,减少模型获取切分策略的耗时,节省模型获取切分策略所占用的资源。
以上是对本申请实施例提供的模型切分方法所进行的详细说明,以下将对本申请实施例提供的模型的切分策略评价方法进行介绍。图8为本申请实施例提供的模型的切分策略评价方法的一个流程示意图,如图8所示,该方法包括:
801、获取第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗。
本实施例中,当需要对第四模型(即待训练的神经网络模型)进行训练时,可先获取一批训练数据,该批训练数据包含第三模型的第二计算图,第二计算图包含多个节点,一个节点对应于第三模型中位于同一层的至少一个神经元,即一个节点可用于表示第三模型可实现的一部分运算,关于第三模型的第二计算图的说明,可参考图4所示实施例中第一模型的第一计算图的相关说明部分,此处不再赘述。
需要说明的是,由于第三模型的第二计算图作为训练数据,故针对第二计算图的第二切分策略(真实切分策略)以及第二切分策略作用于第二计算图后所需付出的第二损耗(真实 损耗)均是已知的数据。其中,由于第二切分策略可用于将第二计算图切分成多个子计算图,故第二损耗可以指通过这多个子计算图来实现数据处理(即第三模型所能实现的数据处理)所需付出的损耗,例如,第二损耗可以是运行这多个子计算图来实现数据处理所需的时间,又如,第二损耗可以是运行这多个子计算图来实现数据处理所占用的资源(计算资源、存储资源、通信资源等)等等。
需要说明的是,已知的针对第二计算图的候选切分策略有多个,且每个候选切分策略对应的损耗均是已知的,可将损耗最小的候选切分策略确定为针对第二计算图的第二切分策略。例如,如图9所示的第二计算图(图9为本申请实施例提供的第二计算图的一个示意图),包含4层共12个节点,其中,第1层有4个节点(分别为节点1_1,节点1_2,节点1_3以及节点1_4),第2层有2个节点(分别为节点2_1以及节点2_2),第3层有4个节点(分别为节点3_1,节点3_2,节点3_3以及节点3_4),第4层有2个节点(分别为节点4_1以及节点4_2)。第二计算图有2个候选切分策略,第1个候选切分策略如图10所示(图10为本申请实施例提供的候选切分策略的一个示意图),该策略包含的内容为:将第二计算图切分成2个子计算图,第1个子计算图包含节点1_1、节点1_2、节点2_1、节点3_1、节点3_2以及节点4_1,第2个子计算图包含节点1_3、节点1_4、节点2_2、节点3_3、节点3_4以及节点4_2。第2个候选切分策略如图11所示(图11为本申请实施例提供的候选切分策略的另一示意图),该策略包含的内容为:将第二计算图切分成4个子计算图,第1个子计算图包含节点1_1以及节点3_1,第2个子计算图包含节点1_2、节点2_1、节点3_2以及节点4_1,第3个子计算图包含节点1_3、节点2_2、节点3_3以及节点4_2,第4个子计算图包含节点1_4以及节点3_4。由于第2候选切分策略作用于第二计算图后所需付出的损耗较少,故可将第2候选切分策略作为第二计算图的第二切分策略。
802、通过第四模型对第二计算图进行处理,得到处理结果,处理结果用于确定第二计算图的第三切分策略。
得到针对第三模型的第二计算图后,可将第二计算图输入至第四模型,以通过第四模型对第二计算图进行处理,得到处理结果,该处理结果通常包含多个切分策略(切分行为)的概率,故可在这多个切分策略中,将概率最大的切分策略确定为针对第二计算图的第三切分策略(预测切分策略)。
具体地,可通过以下方式获取第二计算图的处理结果:
(1)在第二计算图的多个节点中,对于任意一个节点而言,可先对该节点进行编码,从而得到与该节点对应的第四编码,值得注意的是,该节点对应的第四编码的数据量要远小于该节点自身的数据量,故可降低第四模型的输入的数据量。同样地,对于除该节点之外的其余节点,也可执行如同对该节点所执行的操作,故可得到与其余节点对应的第四编码,如此一来,可得到与第二计算图的多个节点一一对应的多个第四编码。
(2)得到与第二计算图的多个节点一一对应的多个第四编码后,可将这多个第四编码输入第四模型,以通过第四模型对这多个第四编码进行处理,得到处理结果,该处理结果通常包含多个切分策略的编码的概率,故可在这多个编码中,将概率最大的编码所指示的切分策略确定为针对第二计算图的第三切分策略。
803、基于第二切分策略以及第三切分策略,获取目标损失,目标损失用于指示第二切分 策略与第三切分策略之间的差异。
得到针对第二计算图的第三切分策略,由于针对第二计算图的第二切分策略已知,故可通过预置的目标损失函数,对针对第二计算图的第二切分策略以及针对第二计算图的第三切分策略进行计算,得到目标损失,目标损失用于指示针对第二计算图的第二切分策略以及针对第二计算图的第三切分策略之间的差异。
804、基于目标损失,对第四模型的参数进行更新,直至满足模型训练条件,得到第二模型。
得到目标损失后,可基于目标损失,对第四模型的参数进行更新,得到更新后的第四模型。此后,可再获取下一批训练数据,对更新后的第四模型继续进行训练(即重新执行步骤802至步骤804),直至满足模型训练条件(例如,目标损失收敛等等),得到图4所示实施例中的第二模型。
当第二模型在应用阶段时,第二模型可用于对第一模型(待切分的神经网络模型)的第一计算图进行处理,得到针对第一模型的第一切分策略。关于第二模型对第一模型的第一计算的处理的介绍,可参考图4所示实施例中的相关说明部分,此处不再赘述。
805、基于第二计算图、第二切分策略以及第二损耗,构建计算图、切分策略与损耗之间的对应关系,对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,第一切分策略由第二模型对第一计算图进行处理得到。
得到第三模型的第二计算图、针对第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗后,可基于这些信息来构建计算图、切分策略与损耗之间的对应关系,该对应关系可用于评价第二模型输出的切分策略是否可行,例如,该对应关系可用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,从而判断第一损耗是否小于预置阈值,以确定第一切分策略是否可行。
具体地,计算图、切分策略与损耗之间的对应关系可以呈现为编码与损耗之间的对应关系,故可通过以下方式构建编码与损耗之间的对应关系:
(1)基于步骤802可知,对于第二计算图的多个节点而言,已得到与这多个节点一一对应的多个第四编码,那么,还可对针对第二计算图的第二切分策略进行编码,得到第五编码,即第五编码用于指示针对第二计算图的第二切分策略。
(2)对与第二计算图的多个节点一一对应的多个第四编码和用于指示第二切分策略的第五编码进行融合,得到第六编码,需要说明的是,前述的融合处理可通过图核算法(weisfeiler-lehman(WL)graph kernel算法)实现,即可先将多个第四编码和第五编码进行相加(或拼接),再将相加后(或拼接后)的编码进行基于图核算法的迭代运算,从而得到第六编码。
(3)基于第六编码以及第二切分策略作用于第二计算图后所需付出的第二损耗,可构建编码与损耗之间的对应关系,例如,该对应关系可以为二维坐标系上的一条曲线,坐标系的横坐标为将计算图中节点的编码与切分策略的编码融合后的编码,坐标系的纵坐标为损耗等等。
应理解,在构建计算图、切分策略与损耗之间的对应关系,不仅仅只使用了当前批训练数据,通常还会使用下一批训练数据等等,即在第四模型的训练过程中,每一次迭代均会使 用一批训练数据,故这所有批次的训练数据均可用来构建计算图、切分策略与损耗之间的对应关系。
本申请实施例训练得到的第二模型,可用于对第一模型的第一计算图进行处理,得到针对第一计算图的第一切分策略,且本申请实施例构建得到的计算图、切分策略与损耗之间的对应关系,还用于预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,可见,本申请实施例提供了一种新的模型切分方式(框架),此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
进一步地,第四模型的输入并非为第二计算图的多个节点,而是与这多个节点一一对应的多个第四编码,第四编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型在训练过程中所需处理的数据量,减少模型训练的耗时,节省模型训练所占用的资源。
以上是对本申请实施例提供的模型的切分策略评价方法所进行的详细说明,以下将对本申请实施例提供的模型切分装置和模型的切分策略评价装置进行介绍。图12为本申请实施例提供的模型切分装置的一个结构示意图,如图12所示,该装置包括:
获取模块1201,用于获取第一模型的第一计算图;
处理模块1202,用于通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略;
确定模块1203,用于确定第一切分策略作用于第一计算图后所需付出的第一损耗;
切分模块1204,用于若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。
在一种可能的实现方式中,第一计算图包含多个节点,一个节点表示第一模型可实现的一部分计算,该装置还包括:编码模块,用于对第一计算图的多个节点进行编码,得到与多个节点一一对应的多个第一编码;处理模块1202,用于通过第二模型对多个第一编码进行处理,得到处理结果。
在一种可能的实现方式中,确定模块1203,用于基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,处理结果用于确定第二编码,第二编码用于指示第一计算图的第一切分策略,确定模块1203,用于:对多个第一编码和第二编码进行融合,得到第三编码;基于编码与损耗之间的对应关系以及第三编码,确定第一切分策略作用于第一计算图后所需付出的第一损耗。
在一种可能的实现方式中,确定模块1203,用于通过图核算法对多个第一编码和第二编码进行迭代运算,得到第三编码。
在一种可能的实现方式中,计算图、切分策略与损耗之间的对应关系基于第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第 二损耗构建,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据。
在一种可能的实现方式中,第一模型用于实现数据处理,第一损耗为通过多个子计算图实现数据处理所需的时间。
在一种可能的实现方式中,该装置还包括:非切分模块,用于若第一损耗大于或等于预置阈值,则不对第一计算图进行切分。
本申请实施例中,在获取第一模型的第一计算图后,可先通过第二模型对第一计算图进行处理,得到处理结果,处理结果用于确定第一计算图的第一切分策略。然后,可基于计算图、切分策略与损耗之间的对应关系,确定第一切分策略作用于第一计算图后所需付出的第一损耗。若第一损耗小于预置阈值,则基于第一切分策略对第一计算图进行切分,得到多个子计算图。前述过程中,第一计算图的第一切分策略是由第二模型自行对第一计算图进行处理得到的,且得到第一切分策略后,还可预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
进一步地,第二模型的输入并非为第一计算图的多个节点,而是与这多个节点一一对应的多个第一编码,第一编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型所需处理的数据量,减少模型获取切分策略的耗时,节省模型获取切分策略所占用的资源。
图13为本申请实施例提供的模型的切分策略评价装置的一个结构示意图,如图13所示,该装置包括:
第一获取模块1301,用于获取第三模型的第二计算图、第二计算图的第二切分策略以及第二切分策略作用于第二计算图后所需付出的第二损耗,第二计算图为获取第二模型的训练数据,第二切分策略和第二损耗为已知的数据;
构建模块1302,用于基于第二计算图、第二切分策略以及第二损耗,构建计算图、切分策略与损耗之间的对应关系,对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,第一切分策略由第二模型对第一计算图进行处理得到。
在一种可能的实现方式中,第二计算图包含多个节点,一个节点表示第三模型可实现的一部分运算,构建模块1302,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码,并对第二切分策略进行编码,得到第五编码;对多个第四编码和第五编码进行融合,得到第六编码;基于第六编码以及第二损耗,构建编码与损耗之间的对应关系。
在一种可能的实现方式中,构建模块,用于通过图核算法对多个第四编码和第五编码进行迭代运算,得到第六编码。
在一种可能的实现方式中,该装置还包括:处理模块,用于通过第四模型对第二计算图进行处理,得到处理结果,处理结果用于确定第二计算图的第三切分策略;第二获取模块,用于基于第二切分策略以及第三切分策略,获取目标损失,目标损失用于指示第二切分策略 与第三切分策略之间的差异;更新模块,用于基于目标损失,对第四模型的参数进行更新,直至满足模型训练条件,得到第二模型。
在一种可能的实现方式中,处理模块,用于:对第二计算图的多个节点进行编码,得到与多个节点一一对应的多个第四编码;通过第四模型对这多个第四编码进行处理,得到处理结果。
在一种可能的实现方式中,第三模型用于实现数据处理,第二损耗为通过多个子计算图实现数据处理所需的时间,多个子计算图基于第二切分策略对第二子计算图进行切分得到。
本申请实施例训练得到的第二模型,可用于对第一模型的第一计算图进行处理,得到针对第一计算图的第一切分策略,且本申请实施例构建得到的计算图、切分策略与损耗之间的对应关系,还用于预估第一切分策略作用于第一计算图后所需付出的第一损耗,从而评价第一切分策略是否可行,可见,本申请实施例提供了一种新的模型切分方式(框架),此种模型切分方式可避免过多的人为干预,且考虑的因素较为全面,可对各种结构的神经网络模型实现模型切分(具备较强的泛化性),且可为各类结构的神经网络模型制定贴合实际应用的最优切分策略(具备较优的模型切分效果)。
进一步地,第四模型的输入并非为第二计算图的多个节点,而是与这多个节点一一对应的多个第四编码,第四编码的数量远小于节点自身的数据量,如此一来,可以有效降低神经网络模型在训练过程中所需处理的数据量,减少模型训练的耗时,节省模型训练所占用的资源。
需要说明的是,上述装置各模块/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其带来的技术效果与本申请方法实施例相同,具体内容可参考本申请实施例前述所示的方法实施例中的叙述,此处不再赘述。
本申请实施例还涉及一种执行设备,图14为本申请实施例提供的执行设备的一个结构示意图。如图14所示,执行设备1400具体可以表现为手机、平板、笔记本电脑、智能穿戴设备、服务器等,此处不做限定。其中,执行设备1400上可部署有图4对应实施例中所描述的模型切分装置,用于实现图4对应实施例中模型切分的功能。具体的,执行设备1400包括:接收器1401、发射器1402、处理器1403和存储器1404(其中执行设备1400中的处理器1403的数量可以一个或多个,图14中以一个处理器为例),其中,处理器1403可以包括应用处理器14031和通信处理器14032。在本申请的一些实施例中,接收器1401、发射器1402、处理器1403和存储器1404可通过总线或其它方式连接。
存储器1404可以包括只读存储器和随机存取存储器,并向处理器1403提供指令和数据。存储器1404的一部分还可以包括非易失性随机存取存储器(non-volatile random access memory,NVRAM)。存储器1404存储有处理器和操作指令、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,操作指令可包括各种操作指令,用于实现各种操作。
处理器1403控制执行设备的操作。具体的应用中,执行设备的各个组件通过总线***耦合在一起,其中总线***除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都称为总线***。
上述本申请实施例揭示的方法可以应用于处理器1403中,或者由处理器1403实现。处 理器1403可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器1403中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器1403可以是通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器,还可进一步包括专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。该处理器1403可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器1404,处理器1403读取存储器1404中的信息,结合其硬件完成上述方法的步骤。
接收器1401可用于接收输入的数字或字符信息,以及产生与执行设备的相关设置以及功能控制有关的信号输入。发射器1402可用于通过第一接口输出数字或字符信息;发射器1402还可用于通过第一接口向磁盘组发送指令,以修改磁盘组中的数据;发射器1402还可以包括显示屏等显示设备。
本申请实施例中,在一种情况下,处理器1403,用于通过图4对应实施例中的第二模型,以生成第一模型的第一计算图的第一切分策略,再基于第一切分策略对第一计算图进行切分,得到多个子计算图,从而完成第一模型的切分。
本申请实施例还涉及一种训练设备,图15为本申请实施例提供的训练设备的一个结构示意图。如图15所示,训练设备1500由一个或多个服务器实现,训练设备1500可因配置或性能不同而产生比较大的差异,可以包括一个或一个以***处理器(central processing units,CPU)1514(例如,一个或一个以上处理器)和存储器1532,一个或一个以上存储应用程序1542或数据1544的存储介质1530(例如一个或一个以上海量存储设备)。其中,存储器1532和存储介质1530可以是短暂存储或持久存储。存储在存储介质1530的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对训练设备中的一系列指令操作。更进一步地,中央处理器1514可以设置为与存储介质1530通信,在训练设备1500上执行存储介质1530中的一系列指令操作。
训练设备1500还可以包括一个或一个以上电源1526,一个或一个以上有线或无线网络接口1550,一个或一个以上输入输出接口1558;或,一个或一个以上操作***1541,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
具体的,训练设备可以执行图8对应实施例中的模型的切分策略评价方法,并将构建得到的计算图、切分策略与损耗之间的对应关系以及训练得到的第二模型,部署在前述的执行设备中。
本申请实施例还涉及一种计算机存储介质,该计算机可读存储介质中存储有用于进行信号处理的程序,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或 者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例还涉及一种计算机程序产品,该计算机程序产品存储有指令,该指令在由计算机执行时使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例提供的执行设备、训练设备或终端设备具体可以为芯片,芯片包括:处理单元和通信单元,所述处理单元例如可以是处理器,所述通信单元例如可以是输入/输出接口、管脚或电路等。该处理单元可执行存储单元存储的计算机执行指令,以使执行设备内的芯片执行上述实施例描述的数据处理方法,或者,以使训练设备内的芯片执行上述实施例描述的数据处理方法。可选地,所述存储单元为所述芯片内的存储单元,如寄存器、缓存等,所述存储单元还可以是所述无线接入设备端内的位于所述芯片外部的存储单元,如只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)等。
具体的,请参阅图16,图16为本申请实施例提供的芯片的一个结构示意图,所述芯片可以表现为神经网络处理器NPU 1600,NPU 1600作为协处理器挂载到主CPU(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路1603,通过控制器1604控制运算电路1603提取存储器中的矩阵数据并进行乘法运算。
在一些实现中,运算电路1603内部包括多个处理单元(Process Engine,PE)。在一些实现中,运算电路1603是二维脉动阵列。运算电路1603还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路1603是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器1602中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器1601中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)1608中。
统一存储器1606用于存放输入数据以及输出数据。权重数据直接通过存储单元访问控制器(Direct Memory Access Controller,DMAC)1605,DMAC被搬运到权重存储器1602中。输入数据也通过DMAC被搬运到统一存储器1606中。
BIU为Bus Interface Unit即,总线接口单元1613,用于AXI总线与DMAC和取指存储器(Instruction Fetch Buffer,IFB)1609的交互。
总线接口单元1613(Bus Interface Unit,简称BIU),用于取指存储器1609从外部存储器获取指令,还用于存储单元访问控制器1605从外部存储器获取输入矩阵A或者权重矩阵B的原数据。
DMAC主要用于将外部存储器DDR中的输入数据搬运到统一存储器1606或将权重数据搬运到权重存储器1602中或将输入数据数据搬运到输入存储器1601中。
向量计算单元1607包括多个运算处理单元,在需要的情况下,对运算电路1603的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。主要用于神经网络中非卷积/全连接层网络计算,如Batch Normalization(批归一化),像素级求和,对预测 标签平面进行上采样等。
在一些实现中,向量计算单元1607能将经处理的输出的向量存储到统一存储器1606。例如,向量计算单元1607可以将线性函数;或,非线性函数应用到运算电路1603的输出,例如对卷积层提取的预测标签平面进行线性插值,再例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元1607生成归一化的值、像素级求和的值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路1603的激活输入,例如用于在神经网络中的后续层中的使用。
控制器1604连接的取指存储器(instruction fetch buffer)1609,用于存储控制器1604使用的指令;
统一存储器1606,输入存储器1601,权重存储器1602以及取指存储器1609均为On-Chip存储器。外部存储器私有于该NPU硬件架构。
其中,上述任一处提到的处理器,可以是一个通用中央处理器,微处理器,ASIC,或一个或多个用于控制上述程序执行的集成电路。
另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。 所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。

Claims (29)

  1. 一种模型切分方法,其特征在于,包括:
    获取第一模型的第一计算图;
    通过第二模型对所述第一计算图进行处理,得到处理结果,所述处理结果用于确定所述第一计算图的第一切分策略;
    确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗;
    若所述第一损耗小于预置阈值,则基于所述第一切分策略对所述第一计算图进行切分,得到多个子计算图。
  2. 根据权利要求1所述的方法,其特征在于,所述第一计算图包含多个节点,一个节点表示所述第一模型可实现的一部分计算,所述方法还包括:
    对所述第一计算图的多个节点进行编码,得到与所述多个节点一一对应的多个第一编码;
    所述通过第二模型对所述第一计算图进行处理,得到处理结果包括:
    通过第二模型对所述多个第一编码进行处理,得到处理结果。
  3. 根据权利要求2所述的方法,其特征在于,所述确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗包括:
    基于计算图、切分策略与损耗之间的对应关系,确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗。
  4. 根据权利要求3所述的方法,其特征在于,所述计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,所述处理结果用于确定第二编码,所述第二编码用于指示所述第一计算图的第一切分策略,所述基于计算图、切分策略与损耗之间的对应关系,确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗包括:
    对所述多个第一编码和所述第二编码进行融合,得到第三编码;
    基于所述编码与损耗之间的对应关系以及所述第三编码,确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗。
  5. 根据权利要求4所述的方法,其特征在于,所述对所述多个第一编码和所述第二编码进行融合,得到第三编码包括:
    通过图核算法对所述多个第一编码和所述第二编码进行迭代运算,得到第三编码。
  6. 根据权利要求1至5任意一项所述的方法,其特征在于,所述计算图、切分策略与损耗之间的对应关系基于第三模型的第二计算图、所述第二计算图的第二切分策略以及所述第二切分策略作用于所述第二计算图后所需付出的第二损耗构建,所述第二计算图为获取所述第二模型的训练数据,所述第二切分策略和所述第二损耗为已知的数据。
  7. 根据权利要求1至6任意一项所述的方法,其特征在于,所述第一模型用于实现数据处理,所述第一损耗为通过所述多个子计算图实现所述数据处理所需的时间。
  8. 根据权利要求1至7任意一项所述的方法,其特征在于,所述方法还包括:
    若所述第一损耗大于或等于所述预置阈值,则不对所述第一计算图进行切分。
  9. 一种模型的切分策略评价方法,其特征在于,所述方法包括:
    获取第三模型的第二计算图、所述第二计算图的第二切分策略以及所述第二切分策略作用于所述第二计算图后所需付出的第二损耗,所述第二计算图为获取第二模型的训练数据, 所述第二切分策略和所述第二损耗为已知的数据;
    基于所述第二计算图、所述第二切分策略以及所述第二损耗,构建所述计算图、切分策略与损耗之间的对应关系,所述对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,所述第一切分策略由所述第二模型对所述第一计算图进行处理得到。
  10. 根据权利要求9所述的方法,其特征在于,所述第二计算图包含多个节点,一个节点表示所述第三模型可实现的一部分运算,所述基于所述第二计算图、所述第二切分策略以及所述第二损耗,构建所述计算图、切分策略与损耗之间的对应关系包括:
    对所述第二计算图的多个节点进行编码,得到与所述多个节点一一对应的多个第四编码,并对所述第二切分策略进行编码,得到第五编码;
    对所述多个第四编码和所述第五编码进行融合,得到第六编码;
    基于所述第六编码以及所述第二损耗,构建编码与损耗之间的对应关系。
  11. 根据权利要求10所述的方法,其特征在于,所述对所述多个第四编码和所述第五编码进行融合,得到第六编码包括:
    通过图核算法对所述多个第四编码和所述第五编码进行迭代运算,得到第六编码。
  12. 根据权利要求9至11任意一项所述的方法,其特征在于,所述方法还包括:
    通过第四模型对所述第二计算图进行处理,得到处理结果,所述处理结果用于确定所述第二计算图的第三切分策略;
    基于所述第二切分策略以及所述第三切分策略,获取目标损失,所述目标损失用于指示所述第二切分策略与所述第三切分策略之间的差异;
    基于所述目标损失,对所述第四模型的参数进行更新,直至满足模型训练条件,得到所述第二模型。
  13. 根据权利要求9至12任意一项所述的方法,其特征在于,所述第三模型用于实现数据处理,所述第二损耗为通过多个子计算图实现所述数据处理所需的时间,所述多个子计算图基于所述第二切分策略对所述第二子计算图进行切分得到。
  14. 一种模型切分装置,其特征在于,所述装置包括:
    获取模块,用于获取第一模型的第一计算图;
    处理模块,用于通过第二模型对所述第一计算图进行处理,得到处理结果,所述处理结果用于确定所述第一计算图的第一切分策略;
    确定模块,用于确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗;
    切分模块,用于若所述第一损耗小于预置阈值,则基于所述第一切分策略对所述第一计算图进行切分,得到多个子计算图。
  15. 根据权利要求14所述的装置,其特征在于,所述第一计算图包含多个节点,一个节点表示所述第一模型可实现的一部分计算,所述装置还包括:
    编码模块,用于对所述第一计算图的多个节点进行编码,得到与所述多个节点一一对应的多个第一编码;
    所述处理模块,用于通过第二模型对所述多个第一编码进行处理,得到处理结果。
  16. 根据权利要求15所述的装置,其特征在于,所述确定模块,用于基于计算图、切分 策略与损耗之间的对应关系,确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗。
  17. 根据权利要求16所述的装置,其特征在于,所述计算图、切分策略与损耗之间的对应关系为编码与损耗之间的对应关系,所述处理结果用于确定第二编码,所述第二编码用于指示所述第一计算图的第一切分策略,所述确定模块,用于:
    对所述多个第一编码和所述第二编码进行融合,得到第三编码;
    基于所述编码与损耗之间的对应关系以及所述第三编码,确定所述第一切分策略作用于所述第一计算图后所需付出的第一损耗。
  18. 根据权利要求17所述的装置,其特征在于,所述确定模块,用于通过图核算法对所述多个第一编码和所述第二编码进行迭代运算,得到第三编码。
  19. 根据权利要求14至18任意一项所述的装置,其特征在于,所述计算图、切分策略与损耗之间的对应关系基于第三模型的第二计算图、所述第二计算图的第二切分策略以及所述第二切分策略作用于所述第二计算图后所需付出的第二损耗构建,所述第二计算图为获取所述第二模型的训练数据,所述第二切分策略和所述第二损耗为已知的数据。
  20. 根据权利要求14至19任意一项所述的装置,其特征在于,所述第一模型用于实现数据处理,所述第一损耗为通过所述多个子计算图实现所述数据处理所需的时间。
  21. 根据权利要求14至20任意一项所述的装置,其特征在于,所述装置还包括:
    非切分模块,用于若所述第一损耗大于或等于所述预置阈值,则不对所述第一计算图进行切分。
  22. 一种模型的切分策略评价装置,其特征在于,所述装置包括:
    第一获取模块,用于获取第三模型的第二计算图、所述第二计算图的第二切分策略以及所述第二切分策略作用于所述第二计算图后所需付出的第二损耗,所述第二计算图为获取第二模型的训练数据,所述第二切分策略和所述第二损耗为已知的数据;
    构建模块,用于基于所述第二计算图、所述第二切分策略以及所述第二损耗,构建所述计算图、切分策略与损耗之间的对应关系,所述对应关系用于获取第一切分策略作用于第一模型的第一计算图后所需付出的第一损耗,所述第一切分策略由所述第二模型对所述第一计算图进行处理得到。
  23. 根据权利要求22所述的装置,其特征在于,所述第二计算图包含多个节点,一个节点表示所述第三模型可实现的一部分运算,所述构建模块,用于:
    对所述第二计算图的多个节点进行编码,得到与所述多个节点一一对应的多个第四编码,并对所述第二切分策略进行编码,得到第五编码;
    对所述多个第四编码和所述第五编码进行融合,得到第六编码;
    基于所述第六编码以及所述第二损耗,构建编码与损耗之间的对应关系。
  24. 根据权利要求23所述的装置,其特征在于,所述构建模块,用于通过图核算法对所述多个第四编码和所述第五编码进行迭代运算,得到第六编码。
  25. 根据权利要求22至24任意一项所述的装置,其特征在于,所述装置还包括:
    处理模块,用于通过第四模型对所述第二计算图进行处理,得到处理结果,所述处理结果用于确定所述第二计算图的第三切分策略;
    第二获取模块,用于基于所述第二切分策略以及所述第三切分策略,获取目标损失,所述目标损失用于指示所述第二切分策略与所述第三切分策略之间的差异;
    更新模块,用于基于所述目标损失,对所述第四模型的参数进行更新,直至满足模型训练条件,得到所述第二模型。
  26. 根据权利要求22至25任意一项所述的装置,其特征在于,所述第三模型用于实现数据处理,所述第二损耗为通过多个子计算图实现所述数据处理所需的时间,所述多个子计算图基于所述第二切分策略对所述第二子计算图进行切分得到。
  27. 一种模型切分装置,其特征在于,所述装置包括存储器和处理器;
    所述存储器存储有代码,所述处理器被配置为执行所述代码,当所述代码被执行时,所述装置执行如权利要求1至13任一项所述的方法。
  28. 一种计算机存储介质,其特征在于,所述计算机存储介质存储有计算机程序,该程序由计算机执行时,使得所述计算机实施权利要求1至13任一项所述的方法。
  29. 一种计算机程序产品,其特征在于,所述计算机程序产品存储有指令,所述指令在由计算机执行时,使得所述计算机实施权利要求1至13任一项所述的方法。
PCT/CN2023/084239 2022-04-11 2023-03-28 一种模型切分方法及其相关设备 WO2023197857A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210375732.3 2022-04-11
CN202210375732.3A CN114707643A (zh) 2022-04-11 2022-04-11 一种模型切分方法及其相关设备

Publications (1)

Publication Number Publication Date
WO2023197857A1 true WO2023197857A1 (zh) 2023-10-19

Family

ID=82172462

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/084239 WO2023197857A1 (zh) 2022-04-11 2023-03-28 一种模型切分方法及其相关设备

Country Status (2)

Country Link
CN (1) CN114707643A (zh)
WO (1) WO2023197857A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114707643A (zh) * 2022-04-11 2022-07-05 华为技术有限公司 一种模型切分方法及其相关设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674936A (zh) * 2019-09-24 2020-01-10 上海寒武纪信息科技有限公司 一种神经网络处理方法、装置、计算机设备及存储介质
CN111562977A (zh) * 2019-02-14 2020-08-21 上海寒武纪信息科技有限公司 神经网络模型拆分方法、装置、存储介质和计算机***
WO2021057746A1 (zh) * 2019-09-24 2021-04-01 安徽寒武纪信息科技有限公司 神经网络处理方法、装置、计算机设备及存储介质
WO2021248138A1 (en) * 2020-06-05 2021-12-09 Google Llc Learned graph optimizations for compilers
CN114707643A (zh) * 2022-04-11 2022-07-05 华为技术有限公司 一种模型切分方法及其相关设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111562977A (zh) * 2019-02-14 2020-08-21 上海寒武纪信息科技有限公司 神经网络模型拆分方法、装置、存储介质和计算机***
CN110674936A (zh) * 2019-09-24 2020-01-10 上海寒武纪信息科技有限公司 一种神经网络处理方法、装置、计算机设备及存储介质
WO2021057746A1 (zh) * 2019-09-24 2021-04-01 安徽寒武纪信息科技有限公司 神经网络处理方法、装置、计算机设备及存储介质
WO2021248138A1 (en) * 2020-06-05 2021-12-09 Google Llc Learned graph optimizations for compilers
CN114707643A (zh) * 2022-04-11 2022-07-05 华为技术有限公司 一种模型切分方法及其相关设备

Also Published As

Publication number Publication date
CN114707643A (zh) 2022-07-05

Similar Documents

Publication Publication Date Title
WO2022042002A1 (zh) 一种半监督学习模型的训练方法、图像处理方法及设备
US20210012198A1 (en) Method for training deep neural network and apparatus
WO2022022274A1 (zh) 一种模型训练方法及装置
WO2022068623A1 (zh) 一种模型训练方法及相关设备
EP4283520A1 (en) Pruning processing method for convolutional neural network, data processing method and devices
US20230117973A1 (en) Data processing method and apparatus
WO2022111617A1 (zh) 一种模型训练方法及装置
WO2024001806A1 (zh) 一种基于联邦学习的数据价值评估方法及其相关设备
US20240232575A1 (en) Neural network obtaining method, data processing method, and related device
WO2022179586A1 (zh) 一种模型训练方法及其相关联设备
WO2021129668A1 (zh) 训练神经网络的方法和装置
WO2023231954A1 (zh) 一种数据的去噪方法以及相关设备
WO2022111387A1 (zh) 一种数据处理方法及相关装置
US20240185568A1 (en) Image Classification Method and Related Device Thereof
WO2023179482A1 (zh) 一种图像处理方法、神经网络的训练方法以及相关设备
WO2022100607A1 (zh) 一种神经网络结构确定方法及其装置
WO2023197857A1 (zh) 一种模型切分方法及其相关设备
WO2021120177A1 (zh) 编译神经网络模型的方法和装置
WO2024140973A1 (zh) 一种动作计数方法及其相关设备
WO2024114659A1 (zh) 一种摘要生成方法及其相关设备
CN114169393A (zh) 一种图像分类方法及其相关设备
WO2024046144A1 (zh) 一种视频处理方法及其相关设备
WO2023246735A1 (zh) 一种项目推荐方法及其相关设备
WO2024017282A1 (zh) 一种数据处理方法及其装置
WO2023197910A1 (zh) 一种用户行为预测方法及其相关设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23787503

Country of ref document: EP

Kind code of ref document: A1