Code generation method and device, electronic equipment and computer readable medium
By automatically generating code for neural network models, the problem of inefficient writing of manual code is solved, efficient code acquisition and resource saving is achieved, storage requirements are reduced, and memory overflow is avoided.
Patent Information
- Application Number
- CN202410146046.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-01
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, the code of manual writing of neural network models is inefficient, resulting in inefficient code acquisition and high storage requirements, which can easily lead to memory overflow and other problems.
By obtaining candidate operators and their data dependencies in the neural network model, determining the subgroup to be fused, and generating the fusion operator code according to the operator type, automatically generating the code of the neural network model to reduce the amount of storage space usage and access.
It improves the efficiency of code acquisition, reduces storage space requirements, avoids memory overflow and other problems, and improves resource utilization efficiency.
Smart Images

Figure CN120406949A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a code generation method, apparatus, electronic device, and computer-readable medium. Background Art
[0002] For some application scenarios, such as image-related scenarios, voice-related scenarios, etc., after obtaining a neural network model, first manually write the code for the model; then, based on this code, deploy the model on a device. However, because the time-consuming of manually writing code is relatively long, the code acquisition efficiency is relatively low. Summary of the Invention
[0003] This application provides a code generation method, apparatus, electronic device, and computer-readable medium, which can improve the code acquisition efficiency.
[0004] To achieve the above object, the technical solutions provided in this application are as follows:
[0005] This application provides a code generation method, and the method includes:
[0006] Obtain a neural network model, where the neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators;
[0007] Determine a group of operators to be fused from the plurality of candidate operators according to the data dependency relationships and the operator types of the candidate operators, where the group of operators to be fused includes at least two of the candidate operators;
[0008] Determine the fused operator code corresponding to the group of operators to be fused according to the operator types of the group of operators to be fused and the operator types of each operator in the group of operators to be fused; the operator type of the group of operators to be fused is determined according to the operator types of each operator in the group of operators to be fused;
[0009] Determine the code of the neural network model according to the fused operator code.
[0010] In a possible implementation manner, the determining a group of operators to be fused from the plurality of candidate operators according to the data dependency relationships and the operator types of the candidate operators includes:
[0011] Determine the path representation data of each candidate operator according to the data dependency relationships; for any one of the candidate operators, the path representation data of the candidate operator is determined according to the longest path between the candidate operator and the output operator in the neural network model;
[0012] Determine a set of operators to be fused from the multiple candidate operators according to the data dependency relationship, the path representation data of each candidate operator, and the operator type of each candidate operator.
[0013] In a possible implementation manner, the process of determining the path representation data includes:
[0014] Determine the path representation data of the output operator as the preset path representation data, and add at least one upstream operator of the output operator to the first set; the initial value of the first set is an empty set; the upstream operator is determined according to the data dependency relationship;
[0015] Select a first operator from the first set;
[0016] If it is determined that the path representation data of all downstream operators of the first operator has been obtained, then determine the path representation data of the first operator according to the path representation data of the downstream operators, delete the first operator from the first set, add at least one upstream operator of the first operator to the first set, and continue to execute the step of selecting a first operator from the first set until the first set is an empty set and then end; the downstream operator is determined according to the data dependency relationship.
[0017] In a possible implementation manner, the process of determining the path representation data of the first operator includes:
[0018] Perform a maximum value analysis process on the path representation data of all downstream operators of the first operator to obtain the maximum path representation data;
[0019] Determine the sum value between the maximum path representation data and the preset path step value as the path representation data of the first operator.
[0020] In a possible implementation manner, the process of determining the set of operators to be fused includes:
[0021] Put the output operator into the second set; the initial value of the second set is an empty set;
[0022] Take out a second operator from the second set;
[0023] If the data dependency relationship indicates that there is no downstream operator of the second operator, then add an operator combination including the second operator to the third set; the initial value of the third set is an empty set;
[0024] If the data dependency indicates the existence of a downstream operator of the second operator, update the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator; there is an operator combination including the second operator in the updated third set;
[0025] Put at least one upstream operator of the second operator into the second set, and continue to execute the step of taking out the second operator from the second set until, when the second set is an empty set, determine the operator combination including at least two operators in the third set as the operator group to be fused; the upstream operator is determined according to the data dependency.
[0026] In a possible implementation, the neural network model includes at least one downstream operator of the second operator;
[0027] The updating the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator includes:
[0028] Find a target operator from the at least one downstream operator, where the path representation data of the target operator is greater than the path representation data of any other downstream operator except the target operator among the at least one downstream operator;
[0029] Judge whether the second operator meets a preset fusion condition according to the operator type of the second operator, the operator type of the target operator, and the operator type of the operator combination including the target operator in the third set;
[0030] If so, put the second operator into the operator combination including the target operator in the third set;
[0031] If not, add an operator combination including the second operator to the third set.
[0032] In a possible implementation, the process of determining the operator type of the operator group to be fused includes:
[0033] For any operator in the operator group to be fused, determine the complexity of the operator according to the operator type of the operator;
[0034] Find a third operator from the operator group to be fused according to the complexity of each operator in the operator group to be fused, where the complexity of the third operator is higher than the complexity of any other operator except the third operator in the operator group to be fused;
[0035] Determine the operator type of the operator group to be fused according to the operator type of the third operator.
[0036] In a possible implementation manner, the process of determining the fusion operator code corresponding to the operator group to be fused includes:
[0037] For any operator in the operator group to be fused, according to the operator type of this operator, determine the code template of this operator and the code parameters of this operator;
[0038] According to the code parameters of the fourth operator in the operator group to be fused, update the code parameters of any other operator in the operator group to be fused except the fourth operator; the operator type of the fourth operator is the same as the operator type of the operator group to be fused;
[0039] For any operator in the operator group to be fused, generate the code of this operator according to the code template of this operator and the code parameters of this operator;
[0040] According to the code fusion rule corresponding to the operator group to be fused, fuse the codes of all operators in the operator group to be fused to obtain the fusion operator code corresponding to the operator group to be fused; the code fusion rule is determined according to the operator type of the operator group to be fused.
[0041] In a possible implementation manner, the method further includes:
[0042] Compile the fusion operator code corresponding to the operator group to be fused to obtain an executable file corresponding to the operator group to be fused;
[0043] Determine the deployment file of the neural network model according to the executable file.
[0044] This application provides a code generation device, including:
[0045] A model acquisition unit, configured to acquire a neural network model, where the neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators;
[0046] A first determination unit, configured to determine an operator group to be fused from the plurality of candidate operators according to the data dependency relationships and the operator types of the candidate operators, where the operator group to be fused includes at least two of the candidate operators;
[0047] A second determination unit, configured to determine the fusion operator code corresponding to the operator group to be fused according to the operator type of the operator group to be fused and the operator types of the operators in the operator group to be fused; the operator type of the operator group to be fused is determined according to the operator types of the operators in the operator group to be fused;
[0048] A third determination unit, configured to determine the code of the neural network model according to the fusion operator code.
[0049] This application provides an electronic device, which includes: a processor and a memory;
[0050] The memory is used to store instructions or computer programs;
[0051] The processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes the code generation method provided by this application.
[0052] This application provides a computer-readable medium, in which instructions or computer programs are stored. When the instructions or computer programs run on a device, the device is enabled to execute the code generation method provided by this application.
[0053] This application provides a computer program product, which includes a computer program carried on a non-transitory computer-readable medium. The computer program contains program code for executing the code generation method provided by this application.
[0054] Compared with the related art, this application has at least the following advantages:
[0055] In the technical solution provided by this application, first, a neural network model is obtained. The neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators; then, according to the data dependency relationships and the operator types of each of the candidate operators, a group of operators to be fused is determined from the plurality of candidate operators, so that the group of operators to be fused includes at least two candidate operators; then, after determining the operator type of the group of operators to be fused according to the operator types of each operator in the group of operators to be fused, according to the operator type of the group of operators to be fused and the operator types of each operator in the group of operators to be fused, the fusion operator code corresponding to the group of operators to be fused is determined; finally, according to the fusion operator code, the code of the neural network model is determined, so that the code of the neural network model includes the fusion operator code. In this way, automatic generation of model code can be achieved, which can effectively avoid defects caused by manually writing code, and thus is beneficial to improving the code acquisition efficiency. In addition, since the fusion operator code is used to describe the fusion operator obtained by fusing a plurality of candidate operators in the neural network model, when implementing the neural network model with the fusion operator code, the usage amount and access amount of the storage space can be effectively reduced, which is beneficial to saving resources, and thus can effectively overcome defects caused by the relatively high storage requirements of some models, such as defects like memory overflow. In this way, it is beneficial to reduce the impact of memory on the application range of the neural network model. Brief Description of the Drawings
[0056] To more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the related art. Obviously, the accompanying drawings in the following description are only some embodiments recorded in the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0057] Figure 1 Flowchart of a code generation method provided by an embodiment of the present application;
[0058] Figure 2 Structural schematic diagram of a code generation device provided by an embodiment of the present application;
[0059] Figure 3 Structural schematic diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0060] In order to enable those skilled in the art to better understand the solutions of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present application.
[0061] To better understand the technical solutions provided by the present application, the following will first describe the code generation method provided by the present application in conjunction with some accompanying drawings. As Figure 1 shown, the code generation method provided by the embodiment of the present application includes S1 - S4 below. Among them, the Figure 1 is a flowchart of a code generation method provided by an embodiment of the present application.
[0062] S1: Obtain a neural network model, where the neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators.
[0063] Among them, the neural network model refers to the model that needs to be deployed; moreover, the present application does not limit the implementation manner of the neural network model. For example, the neural network model can refer to any model that needs to be deployed on a device. It should be noted that the present application does not limit the implementation manner of the device. For example, the device can be implemented using any terminal device with a model deployment requirement or any server with a model deployment requirement.
[0064] In addition, for the neural network model described above, the neural network model can be composed of some operators so that the neural network model can represent the data dependency relationships between these operators. It can be seen that, in a possible implementation manner, the neural network model can include a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators. Among them, the candidate operator refers to an operator existing in the neural network model and used to implement a certain process. The data dependency relationship is used to describe the data dependency state between two operators. For example, if operator 1 performs corresponding processing based on the output data of operator 2, there is a data dependency relationship between operator 1 and operator 2, and the data dependency relationship existing between operator 1 and operator 2 can specifically be: operator 2 is the upstream operator of operator 1 and operator 1 is the downstream operator of operator 2.
[0065] In addition, the present application does not limit the implementation manner of the "plurality of candidate operators" in the above paragraph. For example, the plurality of candidate operators can include all the operators in the neural network model described above, so that the plurality of candidate operators can represent which operators the neural network model is composed of, thereby enabling the data dependency relationships between the plurality of candidate operators to represent the data dependency states between different operators in the neural network model. Another example is that in some application scenarios, the plurality of candidate operators can include some of the operators in the neural network model described above, so as to be able to complete the fusion processing for the part of the operators based on the plurality of candidate operators subsequently.
[0066] S2: Determine a group of operators to be fused from the plurality of candidate operators according to the data dependency relationships and the operator types of the respective candidate operators. The group of operators to be fused includes at least two candidate operators.
[0067] Among them, the operator type of the nth candidate operator is used to describe which category of operator the nth candidate operator belongs to. n is a positive integer, n ≤ N, and N is a positive integer, where N represents the number of operators in the plurality of candidate operators described above.
[0068] In addition, the present application does not limit the implementation manner of the operator type of the nth candidate operator described above. For example, the operator type of the nth candidate operator can be an elementwise operator class, a broadcast operator class, a reduce operator class, an elefusible operator class, or an unfusible operator class. For the sake of easy understanding, the characteristics of these types are introduced separately below.
[0069] The characteristics of the above-mentioned element processing operator class are as follows: For any operator belonging to this element processing operator class, the input data of this operator can include one or more input data, and the size of each input data of this operator is consistent with the size of the output data of this operator. In addition, this application does not limit the implementation manner of this element processing operator class. For example, this element processing operator class includes single-input operators and multi-input operators. Among them, the single-input operator is used to process some or all of the elements in the input data of the single-input operator so that the size of the input data of the single-input operator is consistent with the size of the output data of the single-input operator; and this application does not limit the implementation manner of the single-input operator. The multi-input operator is used to process the input data of the multi-input operator so that the size of each input data of the multi-input operator is consistent with the size of the output data of the multi-input operator; and this application does not limit the implementation manner of the multi-input operator. For example, the multi-input operator can be implemented using an addition operator.
[0070] The characteristics of the above-mentioned data dilation operator class are as follows: For any operator belonging to this data dilation operator class, this operator is used to perform data amplification processing on a certain data so that this operator presents a state of single input and single output; and the size of the input data of this operator is smaller than the size of the output data of this operator. It should be noted that this application does not limit the implementation manner of this data amplification processing. For example, it can be implemented using any existing or future method that can perform amplification processing on a matrix data, such as methods using the replication results of some data in the matrix data for amplification, etc.
[0071] The characteristics of the above-mentioned data compression operator class are as follows: For any operator belonging to this data compression operator class, this operator is used to perform data compression processing on a certain data so that this operator presents a state of single input and single output; and the size of the input data of this operator is larger than the size of the output data of this operator. It should be noted that this application does not limit the implementation manner of this data compression processing. For example, it can be implemented using any existing or future method that can perform compression processing on a matrix data, such as upsampling or downsampling, etc.
[0072] The characteristics of the above-mentioned data fusion operator class are as follows: For any operator belonging to this data fusion operator class, this operator is used to perform relatively complex data fusion processing on multiple data, so that this operator presents a state of multiple inputs and a single output. In addition, this application does not limit the implementation manner of this data fusion operator class. For example, this data fusion operator class may include various convolution operators and various matrix multiplication operators. It should be noted that this application does not limit the implementation manner of this data fusion processing. For example, this data fusion processing may be implemented by using a certain convolution processing or a certain matrix multiplication processing.
[0073] The characteristics of the above-mentioned non-fusable operator class are as follows: For any operator belonging to this non-fusable operator class, this operator cannot perform operator fusion processing with other operators. In addition, this application does not limit the implementation manner of this non-fusable operator class. For example, this non-fusable operator class may include gather operators, split operators, etc.
[0074] In addition, this application does not limit the determination method of the operator type of the nth candidate operator above. For example, it can be implemented by manual annotation. Also, in some application scenarios, in order to improve efficiency, the operator type of the nth candidate operator can be obtained through automatic classification processing based on the parallel attribute of the nth candidate operator. Among them, the parallel attribute of the nth candidate operator refers to the parameter information required for parallel processing of the nth candidate operator, such as the tile parameter, etc. It should be noted that the tile parameter is used to describe how to perform data chunking processing when performing parallel processing on the nth candidate operator. In addition, this application does not limit the implementation manner of this automatic classification processing.
[0075] The operator group to be fused is used to record at least two operators that can perform operator fusion processing. It can be seen that for the operator group to be fused determined from multiple candidate operators above, this operator group to be fused can include at least two candidate operators.
[0076] In addition, this application does not limit the determination process of the above-mentioned operator group to be fused. For example, it can specifically be: According to the pre-constructed operator fusion rule, determine the operator group to be fused from multiple candidate operators above, so that this operator group to be fused is used to represent at least two operators that can perform operator fusion processing. Among them, the operator fusion rule refers to the characteristics presented among multiple operators that can perform operator fusion processing, which are set in advance according to the application scenario; and this application does not limit the implementation manner of this operator fusion rule. For example, this operator fusion rule may include the first fusion rule shown in Table 1 below and the second fusion rule shown in Table 2 below.
[0077] basis\basis elementwise broadcast reduce elefusible unfusible elementwise fusible fusible fusible non - fusible non - fusible broadcast fusible non - fusible fusible non - fusible non - fusible reduce fusible non - fusible non - fusible non - fusible non - fusible elefusible fusible non - fusible non - fusible non - fusible non - fusible unfusible non - fusible non - fusible non - fusible non - fusible non - fusible
[0078] Table 1 shows the first fusion rule for describing whether any two basic operators can be fused
[0079] basis\fusion elementwise broadcast reduce elefusible unfusible elementwise fusible fusible fusible non - fusible non - fusible broadcast fusible non - fusible fusible non - fusible non - fusible reduce fusible non - fusible non - fusible non - fusible non - fusible elefusible fusible non - fusible non - fusible non - fusible non - fusible unfusible non - fusible non - fusible non - fusible non - fusible non - fusible
[0080] Table 2 shows the second fusion rule for describing whether a basic operator and a fused operator can be fused
[0081] It should be noted that for Table 1 and Table 2 above, the basic operator refers to the component operators in the neural network model above, such as each candidate operator. The fused operator refers to an operator fused by at least two basic operators. Additionally, for any pair of operators appearing in Table 1 and Table 2 above, such as the pair of operators of the basic operator belonging to elefusible \ the basic operator belonging to elementwise, the input data of the operator located after the symbol "\ " includes the output data of the operator located before the symbol "\ ", so that the operator located after the symbol "\ " is the downstream operator of the operator located before the symbol "\ ", and the operator located before the symbol "\ " is the upstream operator of the operator located after the symbol "\ ", thus making this pair of operators refer to two operators with a data dependency relationship. Furthermore, in Table 1 and Table 2 above, the first column represents the operator type of the upstream operator; the first row represents the operator type of the downstream operator.
[0082] Based on the relevant content of Table 1 to Table 2 above, for any pair of basic operators, if there is a data dependency relationship between this pair of basic operators and this pair of basic operators meets the fusion situation shown in Table 1 above, it can be determined that this pair of operators can be subjected to operator fusion processing. Additionally, for a basic operator and a fused operator, if there is a data dependency relationship between this basic operator and this fused operator and this basic operator and this fused operator meet the fusion situation shown in Table 2 above, it can be determined that this basic operator and this fused operator can be subjected to operator fusion processing.
[0083] Actually, in order to better improve efficiency, the present application also provides a possible implementation manner of S2 above. In this implementation manner, S2 may specifically include the following steps 11 - step 12.
[0084] Step 11: Determine the path representation data of each candidate operator according to the data dependency relationship between multiple candidate operators above; for any candidate operator, the path representation data of this candidate operator is determined according to the longest path between this candidate operator and the output operator in the neural network model.
[0085] Among them, the path representation data of the nth candidate operator is used to represent the longest path between the nth candidate operator and the output operator in the above neural network model. The output operator refers to the operator existing in the neural network model and used to output the final output data of the neural network model. n is a positive integer, n ≤ N, N is a positive integer, and N represents the number of operators among the above multiple candidate operators.
[0086] In addition, for the nth candidate operator above, the path representation data of the nth candidate operator is determined based on the longest path between the nth candidate operator and the output operator in the above neural network model; moreover, this application does not limit the determination process. For example, specifically, it can be: determining the path length of the longest path between the nth candidate operator and the output operator as the path representation data of the nth candidate operator. It should be noted that this application does not limit the implementation manner of the path length. For example, the path length can be determined based on the number of operators that appear in the path and are between the nth candidate operator and the output operator, so that the path length is positively correlated with the number of operators.
[0087] In addition, this application does not limit the determination process of the path representation data of the nth candidate operator above. For example, specifically, it can be: first, determining each path from the nth candidate operator to the output operator above based on the data dependency relationship between the above multiple candidate operators; then, finding the longest path from these paths; and then, determining the path representation data of the nth candidate operator based on the found longest path.
[0088] Furthermore, in order to better improve efficiency, this application also provides a possible implementation manner of step 11 above. In this implementation manner, step 11 may specifically include steps 111 - 113 below.
[0089] Step 111: Determining the preset path representation data as the path representation data of the output operator above, and adding at least one upstream operator of the output operator to the first set; the initial value of the first set is an empty set; the upstream operator is determined based on the data dependency relationship between the above multiple candidate operators.
[0090] Among them, the preset path representation data refers to the path representation data preset for the output operator in the above neural network model; moreover, this application does not limit the implementation manner of the preset path representation data. For example, the preset path representation data can be 0.
[0091] In addition, for the output operator in the neural network model described above, at least one upstream operator of the output operator is used to provide input data for the output operator, so that the output operator can perform corresponding processing based on the output data of these upstream operators; moreover, at least one upstream operator of the output operator is determined according to the data dependency relationship between multiple candidate operators described above.
[0092] Furthermore, the present application does not limit the implementation manner of at least one upstream operator of the output operator described above. For example, at least one upstream operator of the output operator may include all upstream operators of the output operator.
[0093] The first set refers to the set required to be used when performing path representation data determination processing on all or part of the operators in the neural network model described above, so that the first set is used to record some operators that need to perform path representation data determination processing; and the initial value of the first set is an empty set.
[0094] Based on the relevant content of step 111 described above, for the neural network model described above, after determining the output operator from the neural network model, the path representation data of the output operator can be set to a preset path representation data, such as 0, etc., and at least one upstream operator of the output operator is put into the first set, so that the first set includes these upstream operators.
[0095] Step 112: Select a first operator from the first set described above.
[0096] Wherein, the first operator refers to the operator that needs to perform path representation data determination processing in the current round.
[0097] In addition, the present application does not limit the selection manner of the first operator described above. For example, it can be implemented by means of random selection.
[0098] Furthermore, in some application scenarios, for any operator in the first set described above, if the first set includes the operator and one or more downstream operators of the operator, and the position of the operator in the first set is later than the positions of each downstream operator of the operator in the first set, then in order to better improve the efficiency, step 112 described above can specifically be: select the operator with the most forward arrangement position from the first set described above as the first operator, so as to ensure as much as possible that the path representation data of all downstream operators of the first operator has been determined before performing path representation data determination processing on the first operator.
[0099] Step 113: If it is determined that the path representation data of all downstream operators of the first operator has been obtained, then determine the path representation data of the first operator based on the path representation data of the downstream operator, delete the first operator from the first set, add at least one upstream operator of the first operator to the first set, and return to continue executing the above Step 112 and its subsequent steps until the process ends when the first set is an empty set; the downstream operator is determined based on the data dependency relationship among the above-mentioned multiple candidate operators.
[0100] Among them, the downstream operator of the first operator is used to perform corresponding processing based on the output data of the first operator, so that the input data of the downstream operator of the first operator includes the output data of the first operator; moreover, the downstream operator of the first operator is determined based on the data dependency relationship among the above-mentioned multiple candidate operators.
[0101] In addition, for the above-mentioned first operator, the path representation data of the first operator is used to represent the longest path between the first operator and the output operator in the above-mentioned neural network model; moreover, the path representation data of the first operator is determined based on the path representation data of one or more downstream operators of the first operator.
[0102] Furthermore, the present application does not limit the determination process of the path representation data of the above-mentioned first operator. For example, it may specifically include the following Step 1131 - Step 1132.
[0103] Step 1131: Perform maximum value analysis processing on the path representation data of all downstream operators of the above-mentioned first operator to obtain the maximum path representation data.
[0104] In the present application, for the above-mentioned first operator, after determining all downstream operators of the first operator based on the data dependency relationship among the above-mentioned multiple candidate operators, if it is determined that the path representation data of all downstream operators of the first operator has been obtained, then it can be determined that the first operator has reached the path representation data determination condition. Therefore, maximum value analysis processing can be performed on the path representation data of all downstream operators of the first operator to obtain the maximum path representation data, so that the maximum path representation data can represent the maximum value among the path representation data of all downstream operators of the first operator, so as to be able to determine the path representation data of the first operator based on the maximum path representation data subsequently.
[0105] Step 1132: Determine the sum value between the above-mentioned maximum path representation data and the preset path step value as the path representation data of the first operator.
[0106] Among them, the preset path step value is used to describe the distance between two adjacent operators on a path; moreover, the preset path step value can be preset. For example, the preset path step value can be 1.
[0107] Based on the relevant content from step 1131 to step 1132 above, for the first operator above, after determining all the downstream operators of the first operator from the neural network model, if it is determined that the path representation data of all the downstream operators of the first operator has been obtained, then the maximum value analysis process can be performed on the path representation data of all the downstream operators to obtain the maximum path representation data, so that the maximum path representation data can represent the maximum value among the path representation data of all the downstream operators; then the maximum path representation data is added to the preset path step value to obtain the path representation data of the first operator, so that the path representation data can be used to represent the longest path between the first operator and the output operator in the neural network model above.
[0108] In addition, for the first operator above, at least one upstream operator of the first operator is used to provide input data for the first operator, so that the first operator can perform corresponding processing based on the output data of these upstream operators; and at least one upstream operator of the first operator is determined according to the data dependency relationship among the multiple candidate operators above.
[0109] Furthermore, the present application does not limit the implementation manner of at least one upstream operator of the first operator above. For example, at least one upstream operator of the first operator may include all the upstream operators of the first operator. Another example is that in some application scenarios, in order to avoid resource waste caused by the repeated appearance of the same operator in the first set above, at least one upstream operator of the first operator may be determined according to the upstream operators that do not appear in the first set among all the upstream operators of the first operator, so that at least one upstream operator of the first operator includes these upstream operators that do not appear in the first set, so that the first set after adding at least one upstream operator of the first operator includes all the upstream operators of the first operator.
[0110] Moreover, the present application does not limit the implementation manner of the step of "adding at least one upstream operator of the first operator to the first set" in step 113 above. For example, it may specifically be: directly placing each operator in at least one upstream operator of the first operator at any position in the first set. Another example is that in order to better improve efficiency, it may specifically be: for any one upstream operator in at least one upstream operator of the first operator, putting the upstream operator into the first set so that the position of the upstream operator in the first set is behind the positions of all the downstream operators of the upstream operator in the first set, which is conducive to ensuring that the operators subsequently selected in order from the first set can as much as possible meet the path representation data determination conditions, thus being conducive to improving efficiency.
[0111] Based on the relevant content of the above steps 111 to 113, it can be seen that in some application scenarios, for the above neural network model, first determine the output operator from the neural network model, set the path representation data of the output operator to 0, and put all the upstream operators of the output operator into the first set; then, take out the first operator from the first set. If it is determined that the path representation data of all the downstream operators of the first operator has been obtained, then add 1 to the maximum value in the path representation data of these downstream operators to obtain the path representation data of the first operator, and put at least one upstream operator of the first operator into the first set so that the first set includes all the upstream operators of the first operator; however, if it is determined that the path representation data of all the downstream operators of the first operator has not been obtained yet, then directly put the first operator back into the first set; then, return to continue to execute the foregoing steps of selecting the first operator from the first set and its subsequent steps to implement the next round of process, and iterate in this way until the first set is an empty set and then end. In this way, it is possible to perform the determination process of the path representation data for each operator in the neural network model.
[0112] Based on the relevant content of the above step 11, it can be seen that in some application scenarios, for the N candidate operators in the above neural network model, first determine the longest path between the nth candidate operator and the output operator in the neural network model according to the data dependence relationship between these candidate operators; then determine the path representation data of the nth candidate operator according to the longest path. Wherein, n is a positive integer, n ≤ N, and N is a positive integer.
[0113] Step 12: Determine the operator group to be fused from the multiple candidate operators according to the data dependence relationship between the multiple candidate operators above, the path representation data of each candidate operator, and the operator type of each candidate operator.
[0114] It should be noted that the present application does not limit the implementation manner of the above step 12. For example, this step 12 can specifically be: input the data dependence relationship between the multiple candidate operators above, the path representation data of each candidate operator, and the operator type of each candidate operator into a pre-constructed fusion recognition model, so that the fusion recognition model can identify the operator group to be fused from the multiple candidate operators according to these data, so as to be able to fuse all the operators in the operator group to be fused subsequently. Wherein, the fusion recognition model is used to determine which operators among the multiple candidate operators can perform operator fusion processing according to the fusion rules shown in Table 1 and Table 2 above; and the fusion recognition model can be pre-constructed. In addition, the present application does not limit the construction process of the fusion recognition model.
[0115] Actually, in order to better improve efficiency, the present application also provides a possible implementation manner of step 12 above. Under this implementation manner, step 12 may include steps 121-125 below.
[0116] Step 121: Put the output operator above into the second set; the initial value of the second set is an empty set.
[0117] Among them, the second set refers to the set required for the fusion determination process of all or part of the operators in the neural network model above, so that the second set is used to record some operators that need to be processed for fusion determination; and the initial value of the second set is an empty set.
[0118] Based on the relevant content of step 121 above, for the neural network model above, first determine the output operator from the neural network model; then put the output operator into the second set, so that the second set includes the output operator, so that subsequent fusion determination processing can be performed on all or part of the operators in the neural network model based on the second set.
[0119] Step 122: Take out the second operator from the second set above.
[0120] Among them, the second operator refers to the operator that needs to be processed for fusion determination in the current round.
[0121] In addition, the present application does not limit the selection method of the second operator above. For example, it can be implemented by means of random selection.
[0122] Step 123: If the data dependency relationship above indicates that there is no downstream operator of the second operator, add the operator combination including the second operator to the third set; the initial value of the third set is an empty set.
[0123] Among them, the third set is used to record the operator combinations that can be processed for operator fusion.
[0124] Based on the relevant content of step 123 above, for the second operator in the current round, if the data dependency relationship above indicates that there is no downstream operator of the second operator in the neural network model above, it can be determined that the second operator belongs to the output operator. Therefore, a new combination can be directly created in the third set, and the second operator can be put into the new combination, so that there is an operator combination including the second operator in the third set. Among them, the initial value of the new combination is empty.
[0125] Step 124: If the data dependency relationship above indicates that there is a downstream operator of the second operator, update the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator, so that there is an operator combination including the second operator in the updated third set.
[0126] It should be noted that the implementation manner of step 124 is not limited in this application. For example, it can be implemented by means of a pre-constructed machine learning model with the function of identifying fusible operators.
[0127] In addition, in order to better improve efficiency, this application also provides a possible implementation manner of the above-mentioned step 124. In this implementation manner, when the above-mentioned neural network model includes at least one downstream operator of the above-mentioned second operator, this step 124 may specifically include the following steps 1241 to 1244.
[0128] Step 1241: Search for a target operator from at least one downstream operator of the above-mentioned second operator, where the path characterization data of the target operator is greater than the path characterization data of any other downstream operator among the at least one downstream operator except the target operator.
[0129] Among them, at least one downstream operator of the second operator is used to perform corresponding processing according to the output data of the second operator; moreover, the implementation manner of at least one downstream operator of the second operator is not limited in this application. For example, it may include all downstream operators of the second operator.
[0130] The target operator refers to the downstream operator with the largest path characterization data found from at least one downstream operator of the above-mentioned second operator. It can be seen that the path characterization data of the target operator is greater than the path characterization data of any other downstream operator among the at least one downstream operator except the target operator.
[0131] Based on the relevant content of the above-mentioned step 1241, for the above-mentioned second operator, after obtaining all downstream operators of the second operator, the downstream operator with the largest path characterization data among these downstream operators is determined as the target operator corresponding to the second operator, so that it can be determined whether the second operator can be fused with other operators based on the relevant information of the target operator in the subsequent process.
[0132] Step 1242: Determine whether the second operator meets the preset fusion condition according to the operator type of the above-mentioned second operator, the operator type of the above-mentioned target operator, and the operator type of the operator combination including the target operator in the above-mentioned third set.
[0133] Among them, the operator combination including the target operator refers to the combination existing in the above-mentioned third set and used to represent which operators the target operator can be fused with.
[0134] In addition, for any operator combination in the above-mentioned third set, the operator type of the operator combination is used to represent which category the operator obtained by fusing all operators in the operator combination belongs to.
[0135] In addition, for any operator combination in the third set above, the operator type of the operator combination is determined based on the operator types of the individual operators in the operator combination; moreover, the present application does not limit the determination process of the operator type of the operator combination. For example, it may specifically include steps 12421 - 12423 below.
[0136] Step 12421: For any operator in the operator combination above, determine the complexity of the operator based on the operator type of the operator.
[0137] In the present application, for any operator in the operator combination above, look up the complexity corresponding to the operator type of the operator in the pre-constructed first mapping relationship, and determine it as the complexity of the operator. Among them, the first mapping relationship is used to record the complexity corresponding to each operator type; and the first mapping relationship can be set in advance according to the actual application scenario. In addition, the present application does not limit the implementation manner of the complexity corresponding to each operator type. For example, in some application scenarios, the complexity corresponding to different operator types satisfies the following relationship: Elementwise < broadcast < reduce < ele-fusible < unfusible.
[0138] Step 12422: Based on the complexities of the individual operators in the operator combination above, look up a reference operator in the operator combination. The complexity of the reference operator is higher than the complexity of any other operator in the operator combination except the reference operator.
[0139] Among them, the reference operator refers to the operator with the highest complexity in the operator combination above. It can be seen that the complexity of the reference operator is higher than the complexity of any other operator in the operator combination except the reference operator.
[0140] Step 12423: Based on the operator type of the reference operator above, determine the operator type of the operator combination above.
[0141] It should be noted that the present application does not limit the implementation manner of step 12423. For example, it may specifically be: directly determine the operator type of the operator combination above as the operator type of the reference operator above.
[0142] Based on the relevant content of steps 12421 to 12423 above, it can be seen that in some application scenarios, for any operator combination, the operator type of the operator combination can be determined based on the operator type of the operator with the highest complexity in the operator combination, so that the operator type of the operator combination is consistent with the operator type of the operator with the highest complexity.
[0143] The preset fusion condition refers to the condition required for determining whether an operator can be fused with the existing operators in an operator combination; moreover, the present application does not limit this preset fusion condition. For example, if the second operator above and the target operator above satisfy the first fusion rule shown in Table 1 above, and the second operator and the operator combination including the target operator above satisfy the second fusion rule shown in Table 2 above, it can be determined that the second operator can be fused with the existing operators in the operator combination including the target operator, so it can be determined that the second operator satisfies the preset fusion condition.
[0144] Based on the relevant content of step 1242 above, in some application scenarios, for the second operator above, after determining the target operator with the largest path representation data from all the downstream operators of the second operator, first determine whether the second operator and the target operator satisfy the first fusion rule above according to the operator type of the second operator and the operator type of the target operator, and determine whether the second operator and the fusion operator described by the operator combination including the target operator in the third set above satisfy the second fusion rule above according to the operator type of the second operator and the operator type of the operator combination including the target operator in the third set above; then, based on these two determination results, determine whether the second operator satisfies the preset fusion condition.
[0145] Step 1243: If the second operator above satisfies the preset fusion condition, put the second operator into the operator combination including the target operator in the third set above.
[0146] In the present application, if the second operator above satisfies the preset fusion condition, it can be determined that the second operator can be fused with the existing operators in the operator combination including the target operator above, so the second operator can be directly put into the operator combination including the target operator in the third set above, so that there is an operator combination including the second operator and the target operator in the third set.
[0147] Step 1244: If the second operator above does not satisfy the preset fusion condition, add an operator combination including the second operator to the third set above.
[0148] In the present application, if the second operator above does not satisfy the preset fusion condition, it can be determined that the second operator cannot be fused with the existing operators in the operator combination including the target operator above, so a new combination can be directly created in the third set and the second operator can be put into the new combination, so that there is an operator combination including the second operator in the third set. Among them, the initial value of the new combination is empty.
[0149] Based on the relevant content of the above steps 1241 to 1244, in some application scenarios, for the second operator in the current round, after determining at least one downstream operator of the second operator from the above neural network model, first determine the target operator with the largest path representation data from at least one downstream operator of the second operator; then determine whether the second operator and the target operator satisfy the above first fusion rule, and determine whether the second operator and the fusion operator described by the operator combination including the target operator satisfy the above second fusion rule. If both are satisfied, put the second operator into the operator combination including the target operator in the above third set; otherwise, a new combination can be created in the third set, and the second operator is put into the new combination. Among them, the initial value of the new combination is an empty set.
[0150] Based on the relevant content of the above step 124, in some application scenarios, for the second operator in the current round, if the above data dependency indicates that there are at least one downstream operator of the second operator in the above neural network model, then first, according to the path representation data of these downstream operators, determine the target operator with the largest path representation data from at least one downstream operator; then, according to the operator type of the second operator, the operator type of the target operator, and the operator type of the operator combination including the target operator in the above third set, determine whether the second operator satisfies the preset fusion condition; then, update the third set according to the determination result, so that there is an operator combination including the second operator in the updated third set.
[0151] Step 125: Put at least one upstream operator of the above second operator into the above second set, and return to continue executing the above step 122 and its subsequent steps until when the second set is an empty set, determine the operator combination including at least two operators in the above third set as the operator group to be fused; the upstream operator is determined according to the above data dependency.
[0152] Among them, at least one upstream operator of the second operator is used to provide input data to the second operator so that the second operator can perform corresponding processing based on the output data of these upstream operators; moreover, at least one upstream operator of the second operator is determined according to the data dependency between the above multiple candidate operators.
[0153] In addition, the present application does not limit the implementation manners of at least one upstream operator of the second operator above. For example, at least one upstream operator of the second operator may include all upstream operators of the second operator. For another example, in some application scenarios, in order to avoid resource waste caused by the repeated appearance of the same operator in the second set above, at least one upstream operator of the second operator may be determined based on the upstream operators that do not appear in the second set among all upstream operators of the second operator, so that at least one upstream operator of the second operator includes these upstream operators that do not appear in the second set, thereby making the second set after adding at least one upstream operator of the second operator include all upstream operators of the second operator.
[0154] Based on the relevant content of steps 121 to 125 above, for the neural network model above, first determine the output operator from the neural network model and put the output operator into the second set; then take out the second operator from the second set; if there is no downstream operator of the second operator in the neural network model, a new combination can be directly created in the third set and the second operator can be put into the new combination; if there is at least one downstream operator of the second operator in the neural network model, determine whether the second operator meets the preset fusion condition according to the operator type of the second operator, the operator type of the target operator with the largest path representation data among these downstream operators, and the operator type of the operator combination including the target operator in the third set. If it meets, the second operator can be directly added to the operator combination including the target operator in the third set; if it does not meet, a new combination can be directly created in the third set and the second operator can be put into the new combination, so as to update the third combination, so that after updating the second set with at least one upstream operator of the second operator, the next round of fusion determination process can be performed based on the updated third set and the updated second set, and so on in an iterative loop until when the second set is an empty set, first traverse the third set to delete the combinations composed of a single operator in the third set, so that each combination in the third set after the deletion process includes at least two operators; then determine each combination in the third set as a group of operators to be fused.
[0155] Based on the relevant content of S2 above, for the above-mentioned multiple candidate operators, one or more groups of operators to be fused can be determined from the multiple candidate operators according to the data dependency relationship between the multiple candidate operators and the operator type of each candidate operator, so that each group of operators to be fused includes at least two operators capable of performing operator fusion processing.
[0156] S3: Determine the fusion operator code corresponding to the operator group to be fused according to the operator types of the operator group to be fused and the operator types of each operator in the operator group to be fused; the operator type of the operator group to be fused is determined according to the operator types of each operator in the operator group to be fused.
[0157] Wherein, the operator type of the operator group to be fused is used to represent which category the operator obtained by fusing all the operators in the operator group to be fused belongs to; and the operator type of the operator group to be fused is determined according to the operator types of each operator in the operator group to be fused.
[0158] In addition, the determination process of the operator type of the above-mentioned operator group to be fused is similar to the determination process of the operator type of the above-mentioned operator combination. For the convenience of understanding, the following will be described with examples.
[0159] As an example, in a possible implementation manner, the determination process of the operator type of the above-mentioned operator group to be fused may include the following steps 21-step 23.
[0160] Step 21: For any operator in the above-mentioned operator group to be fused, determine the complexity of the operator according to the operator type of the operator.
[0161] It should be noted that the implementation manner of step 21 is similar to the implementation manner of step 12421 above.
[0162] Step 22: According to the complexities of each operator in the above-mentioned operator group to be fused, search for a third operator in the operator group to be fused, and the complexity of the third operator is higher than the complexity of any other operator in the operator group to be fused except the third operator.
[0163] Wherein, the third operator refers to the operator with the highest complexity in the above-mentioned operator group to be fused. It can be seen that the complexity of the third operator is higher than the complexity of any other operator in the operator group to be fused except the third operator.
[0164] Step 23: Determine the operator type of the above-mentioned operator group to be fused according to the operator type of the above-mentioned third operator.
[0165] It should be noted that the implementation manner of step 23 is similar to the implementation manner of step 12423 above.
[0166] Based on the relevant content of the above steps 21 to 23, it can be seen that in some application scenarios, for the above-mentioned operator group to be fused, the operator type of the operator group to be fused can be determined according to the operator type of the operator with the highest complexity in the operator group to be fused, so that the operator type of the operator group to be fused is consistent with the operator type of the operator with the highest complexity.
[0167] In addition, for the operator group to be fused mentioned above, the fused operator code corresponding to the operator group to be fused is used to implement the fused operator obtained by fusing all the operators in the operator group to be fused; moreover, this application does not limit the determination process of the fused operator code corresponding to the operator group to be fused. For example, it can be implemented by means of a pre-constructed code generation model. Among them, the code generation model is used to perform fused operator code generation processing based on some operators; moreover, this application does not limit the implementation manner of the code generation model.
[0168] In addition, in order to better improve efficiency, this application also provides a possible implementation manner of the above S3. In this implementation manner, S3 can specifically include the following steps 31-step 34.
[0169] Step 31: For any operator in the operator group to be fused mentioned above, determine the code template and the code parameters of the operator according to the operator type of the operator.
[0170] Among them, the code template of the m-th operator refers to the code template required when generating the implementation code of the m-th operator. m is a positive integer, m≤M, M is a positive integer, and M represents the number of operators in the operator group to be fused mentioned above.
[0171] In addition, this application does not limit the implementation manner of the code template of the m-th operator mentioned above. For example, specifically, it can be: search for the code template corresponding to the operator type of the m-th operator from the pre-constructed second mapping relationship, and determine it as the code template of the m-th operator. Among them, the second mapping relationship is used to record the code templates corresponding to various operator types; moreover, the second mapping relationship can be set in advance according to the actual application scenario.
[0172] The code parameters of the m-th operator refer to some constraint information required when generating the implementation code of the m-th operator; moreover, this application does not limit the implementation manner of the code parameters of the m-th operator. For example, the code parameters of the m-th operator can include the parallel attribute of the m-th operator. Among them, the parallel attribute of the m-th operator is used to describe the parameter information required when performing parallel processing on the m-th operator; moreover, this application does not limit the parallel attribute of the m-th operator. For example, the parallel attribute of the m-th operator can include the tile parameter of the m-th operator. m is a positive integer, m≤M, M is a positive integer, and M represents the number of operators in the operator group to be fused mentioned above.
[0173] In addition, the present application does not limit the implementation manner of the code parameters of the m-th operator above. For example, specifically, it may be: searching for the code parameters corresponding to the operator type of the m-th operator from the pre-constructed third mapping relationship, and determining them as the code parameters of the m-th operator. Among them, the third mapping relationship is used to record the code parameters corresponding to various operator types; and the third mapping relationship can be set in advance according to the actual application scenario.
[0174] Step 32: Update the code parameters of any other operator in the operator group to be fused except the fourth operator according to the code parameters of the fourth operator in the operator group to be fused above; the operator type of the fourth operator is the same as the operator type of the operator group to be fused.
[0175] Among them, the fourth operator refers to the operator that exists in the operator group to be fused above and whose operator type is the same as the operator type of the operator group to be fused. It can be seen that the operator group to be fused includes the fourth operator, and the operator type of the fourth operator is the same as the operator type of the operator group to be fused.
[0176] Based on the relevant content of Step 32 above, for the operator group to be fused above, if the operator type of the operator group to be fused is the same as the operator type of the fourth operator in the operator group to be fused, then the code parameters of the fourth operator can be used to update the code parameters of any other operator in the operator group to be fused except the fourth operator, so that the code parameters of all operators in the operator group to be fused are consistent, which is beneficial to improving the parallel processing effect in the future.
[0177] Step 33: For any operator in the operator group to be fused above, generate the code of the operator according to the code template and the code parameters of the operator.
[0178] Among them, the code of the m-th operator is used to implement the m-th operator; and the code of the m-th operator is generated according to the code template and the code parameters of the m-th operator. It should be noted that the present application does not limit this generation process. m is a positive integer, m ≤ M, M is a positive integer, and M represents the number of operators in the operator group to be fused above.
[0179] Step 34: Fuse the codes of all operators in the operator group to be fused according to the code fusion rule corresponding to the operator group to be fused above, and obtain the fused operator code corresponding to the operator group to be fused; the code fusion rule is determined according to the operator type of the operator group to be fused.
[0180] Among them, the code fusion rule corresponding to the operator group to be fused refers to the rule required when fusing the codes of all operators in the operator group to be fused; and the code fusion rule is determined according to the operator type of the operator group to be fused.
[0181] In addition, this application does not limit the determination process of the code fusion rule corresponding to the above-mentioned operator group to be fused. For example, specifically, it can be: searching for the code fusion rule corresponding to the operator type of the operator group to be fused from the pre-constructed fourth mapping relationship as the fusion operator code corresponding to the operator group to be fused. Among them, the fourth mapping relationship is used to record the code fusion rules corresponding to each operator type; and the fourth mapping relationship can be set in advance according to the actual application scenario.
[0182] Based on the relevant content of steps 31 to 34 above, in some application scenarios, for any operator group to be fused, first determine the code templates and code parameters of each operator in the operator group to be fused according to the operator types of the operators in the operator group to be fused, such as tile parameters, etc.; then update the code parameters of other operators in the operator group to be fused according to the code parameters of the operators in the operator group to be fused that are consistent with the operator type of the operator group to be fused, so that the code parameters of all operators in the operator group to be fused are consistent; then, automatically generate the code of each operator according to the code templates and code parameters of each operator in the operator group to be fused; finally, fuse the codes of all operators in the operator group to be fused according to the code fusion rule corresponding to the operator group to be fused to obtain the fusion operator code corresponding to the operator group to be fused, so that the fusion operator code is used to implement the fusion operator obtained by fusing all operators in the operator group to be fused.
[0183] Based on the relevant content of S3 above, after determining one or more operator groups to be fused from the above neural network model, for any operator group to be fused, determine the fusion operator code corresponding to the operator group to be fused according to the operator type of the operator group to be fused and the operator types of each operator in the operator group to be fused, so that the fusion operator code is used to implement the fusion operator obtained by fusing all operators in the operator group to be fused.
[0184] S4: Determine the code of the neural network model according to the fusion operator code corresponding to the operator group to be fused.
[0185] In this application, for some operator groups to be fused determined from the above neural network model, after determining the fusion operator codes corresponding to each operator group to be fused, the code of the neural network model can be determined according to the fusion operator codes corresponding to these operator groups to be fused, so that the code of the neural network model includes the fusion operator codes corresponding to these operator groups to be fused, so that the code of the neural network model is used to implement the neural network model.
[0186] It should be noted that for the above neural network model, if the neural network model includes some basic operators that cannot be fused and some groups of operators to be fused that can be fused, the code of the neural network model may include the code of these basic operators and the fused operator code corresponding to these groups of operators to be fused.
[0187] It should also be noted that the present application does not limit the process of obtaining the code of the basic operators in the above paragraph. For example, specifically, it can be: according to the operator type of the basic operator, determine the code template and code parameters of the basic operator; then, according to the code template and code parameters of the basic operator, automatically generate the code of the basic operator.
[0188] Based on the relevant content of S1 to S4 above, for the code generation method provided in the embodiments of the present application, first obtain a neural network model, the neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators; then, according to the data dependency relationships and the operator types of each of the candidate operators, determine a group of operators to be fused from the plurality of candidate operators, so that the group of operators to be fused includes at least two candidate operators; then, after determining the operator type of the group of operators to be fused according to the operator types of each operator in the group of operators to be fused, according to the operator type of the group of operators to be fused and the operator types of each operator in the group of operators to be fused, determine the fused operator code corresponding to the group of operators to be fused; finally, according to the fused operator code, determine the code of the neural network model, so that the code of the neural network model includes the fused operator code, so as to be able to automatically generate model code, thereby effectively avoiding the defects caused by manually writing code, and then being beneficial to improving the code acquisition efficiency. In addition, since the fused operator code is used to describe the fused operator obtained by fusing a plurality of candidate operators in the neural network model, when implementing the neural network model with the help of the fused operator code, the usage amount and access amount of the storage space can be effectively reduced, thereby being beneficial to saving resources, and then being able to effectively overcome the defects caused by the relatively high storage requirements of some models, such as defects such as memory overflow, so that it is beneficial to reduce the impact of memory on the application range of the neural network model.
[0189] In addition, the present application does not limit the execution subject of the code generation method provided in the embodiments of the present application. For example, the code generation method provided in the embodiments of the present application can be applied to a terminal device or a server. Another example is that the code generation method provided in the embodiments of the present application can also be implemented by means of the data interaction process between the terminal device and the server. Among them, the terminal device can be a smart phone, a computer, a personal digital assistant (Personal Digital Assitant, PDA), a tablet computer, etc. The server can be an independent server, a cluster server or a cloud server.
[0190] In addition, in some application scenarios, to better meet user requirements, the present application also provides a possible implementation manner of the above-mentioned code generation method. In this implementation manner, the code generation method not only includes the above-mentioned S1 - S4, but may also include the following steps 41 - step 42.
[0191] Step 41: Compile the fusion operator code corresponding to the above-mentioned operator group to be fused to obtain an executable file corresponding to the operator group to be fused.
[0192] The executable file corresponding to the operator group to be fused refers to the file required to implement the fusion operator described by the operator group to be fused on the device.
[0193] In addition, the present application does not limit the acquisition method of the executable file corresponding to the above-mentioned operator group to be fused. For example, specifically, it can be: use a pre-set compiler to compile the fusion operator code corresponding to the above-mentioned operator group to be fused to obtain an executable file corresponding to the operator group to be fused. Among them, the compiler can be pre-set according to the actual application scenario. For example, in some application scenarios, if the fusion operator code corresponding to the operator group to be fused belongs to Triton code, the compiler can be implemented using the Triton compiler.
[0194] Step 42: Determine the deployment file of the above-mentioned neural network model based on the executable file corresponding to the above-mentioned operator group to be fused.
[0195] In the present application, for some operator groups to be fused determined from the above-mentioned neural network model, after determining the executable files corresponding to each operator group to be fused, the deployment file of the above-mentioned neural network model can be determined based on the executable files corresponding to these operator groups, so that the deployment file includes these executable files, so that when using the neural network model on a device deployed according to the deployment file, the fusion operator obtained by fusing all the operators in the operator group to be fused can be implemented by calling the executable file corresponding to the operator group to be fused.
[0196] Based on the relevant content of the above-mentioned steps 41 to step 42, it can be seen that in some application scenarios, for the above-mentioned neural network model, after determining some operator groups to be fused from the neural network model, the fusion operator code corresponding to each operator group to be fused can be compiled first to obtain an executable file corresponding to each operator group to be fused; then, based on the executable files corresponding to these operator groups to be fused, the deployment file of the neural network model can be determined, so as to be able to implement the neural network model through the deployment file in the future, which is beneficial to automatically deploying the neural network model on the device.
[0197] Based on the code generation method provided in the embodiments of the present application, the embodiments of the present application further provide a code generation device, which will be explained and described below in conjunction with Figure 2 as follows. Among them, Figure 2 is a schematic structural diagram of a code generation device provided in the embodiments of the present application. It should be noted that for the technical details of the code generation device provided in the embodiments of the present application, please refer to the relevant content of the above-mentioned code generation method.
[0198] As Figure 2 shown, the code generation device 200 provided in the embodiments of the present application includes:
[0199] A model acquisition unit 201, configured to acquire a neural network model, where the neural network model includes a plurality of candidate operators and data dependency relationships between the plurality of candidate operators;
[0200] A first determination unit 202, configured to determine a group of operators to be fused from the plurality of candidate operators according to the data dependency relationship and the operator types of the candidate operators, where the group of operators to be fused includes at least two of the candidate operators;
[0201] A second determination unit 203, configured to determine the fusion operator code corresponding to the group of operators to be fused according to the operator types of the group of operators to be fused and the operator types of each operator in the group of operators to be fused; the operator type of the group of operators to be fused is determined according to the operator types of each operator in the group of operators to be fused;
[0202] A third determination unit 204, configured to determine the code of the neural network model according to the fusion operator code.
[0203] In a possible implementation manner, the first determination unit 202 includes:
[0204] A first determination subunit, configured to determine the path representation data of each candidate operator according to the data dependency relationship; for any one of the candidate operators, the path representation data of the candidate operator is determined according to the longest path between the candidate operator and the output operator in the neural network model;
[0205] A second determination subunit, configured to determine a group of operators to be fused from the plurality of candidate operators according to the data dependency relationship, the path representation data of each candidate operator, and the operator types of the candidate operators.
[0206] In a possible implementation manner, the first determination subunit is specifically configured to: determine the preset path representation data as the path representation data of the output operator, and add at least one upstream operator of the output operator to the first set; the initial value of the first set is an empty set; the upstream operator is determined according to the data dependency relationship; select a first operator from the first set; if it is determined that the path representation data of all downstream operators of the first operator has been obtained, then determine the path representation data of the first operator according to the path representation data of the downstream operators, delete the first operator from the first set, add at least one upstream operator of the first operator to the first set, and continue to execute the step of selecting a first operator from the first set until the first set is an empty set and then end; the downstream operator is determined according to the data dependency relationship.
[0207] In a possible implementation manner, the process of determining the path representation data of the first operator includes: performing a maximum value analysis process on the path representation data of all downstream operators of the first operator to obtain the maximum path representation data; determining the sum value between the maximum path representation data and the preset path step value as the path representation data of the first operator.
[0208] In a possible implementation manner, the second determination subunit is specifically configured to: put the output operator into the second set; the initial value of the second set is an empty set; take out a second operator from the second set; if the data dependency relationship indicates that there is no downstream operator of the second operator, then add an operator combination including the second operator to the third set; the initial value of the third set is an empty set; if the data dependency relationship indicates that there is a downstream operator of the second operator, then update the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator; there is an operator combination including the second operator in the updated third set; put at least one upstream operator of the second operator into the second set, and continue to execute the step of taking out a second operator from the second set until the second set is an empty set, and then determine the operator combination including at least two operators in the third set as the operator group to be fused; the upstream operator is determined according to the data dependency relationship.
[0209] In a possible implementation manner, the neural network model includes at least one downstream operator of the second operator;
[0210] The second determination subunit is specifically configured to: find a target operator from the at least one downstream operator, where the path representation data of the target operator is greater than the path representation data of any other downstream operator except the target operator among the at least one downstream operator; determine whether the second operator meets a preset fusion condition according to the operator type of the second operator, the operator type of the target operator, and the operator type of the operator combination including the target operator in the third set; if so, put the second operator into the operator combination including the target operator in the third set; if not, add an operator combination including the second operator to the third set.
[0211] In a possible implementation manner, the process of determining the operator type of the operator group to be fused includes: for any operator in the operator group to be fused, determine the complexity of the operator according to the operator type of the operator; according to the complexities of the operators in the operator group to be fused, find a third operator from the operator group to be fused, where the complexity of the third operator is higher than the complexity of any other operator except the third operator in the operator group to be fused; determine the operator type of the operator group to be fused according to the operator type of the third operator.
[0212] In a possible implementation manner, the second determination unit 203 is specifically configured to: for any operator in the operator group to be fused, determine the code template and the code parameters of the operator according to the operator type of the operator; update the code parameters of any other operator except the fourth operator in the operator group to be fused according to the code parameters of the fourth operator in the operator group to be fused; the operator type of the fourth operator is the same as the operator type of the operator group to be fused; for any operator in the operator group to be fused, generate the code of the operator according to the code template and the code parameters of the operator; fuse the codes of all the operators in the operator group to be fused according to the code fusion rule corresponding to the operator group to be fused to obtain the fused operator code corresponding to the operator group to be fused; the code fusion rule is determined according to the operator type of the operator group to be fused.
[0213] In a possible implementation manner, the code generation device 200 further includes:
[0214] A code compilation unit, configured to compile the fused operator code corresponding to the operator group to be fused to obtain an executable file corresponding to the operator group to be fused;
[0215] A fourth determination unit, configured to determine the deployment file of the neural network model according to the executable file.
[0216] Based on the relevant content of the above-mentioned code generation device 200, for the code generation device 200 provided in the embodiments of the present application, first, a neural network model is obtained. The neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators. Then, according to the data dependency relationships and the operator types of each of the candidate operators, a group of operators to be fused is determined from the plurality of candidate operators, so that the group of operators to be fused includes at least two candidate operators. Next, after determining the operator type of the group of operators to be fused according to the operator types of the operators in the group of operators to be fused, according to the operator type of the group of operators to be fused and the operator types of the operators in the group of operators to be fused, the fused operator code corresponding to the group of operators to be fused is determined. Finally, according to the fused operator code, the code of the neural network model is determined, so that the code of the neural network model includes the fused operator code. In this way, automatic generation of model code can be achieved, which can effectively avoid the defects caused by manually writing code, and thus is beneficial to improving the code acquisition efficiency. In addition, since the fused operator code is used to describe the fused operator obtained by fusing a plurality of candidate operators in the neural network model, when implementing the neural network model with the fused operator code, the usage amount of storage space and the access amount of storage space can be effectively reduced, which is beneficial to saving resources, and thus can effectively overcome the defects caused by the relatively high storage requirements of some models, such as defects like memory overflow. In this way, it is beneficial to reduce the impact of memory on the application scope of the neural network model.
[0217] In addition, an embodiment of the present application further provides an electronic device, which includes a processor and a memory: the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes any implementation manner of the code generation method provided in the embodiments of the present application.
[0218] See Figure 3 , which shows a schematic structural diagram of an electronic device 300 suitable for implementing the embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The electronic device shown is only an example and should not bring any limitation to the functions and usage scope of the embodiments of the present disclosure.
[0219] Such as Figure 3As shown, the electronic device 300 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 301, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage device 308 into the random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other through a bus 304. The input / output (I / O) interface 305 is also connected to the bus 304.
[0220] Generally, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 3 the electronic device 300 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.
[0221] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart may be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program codes for performing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above functions defined in the method of the embodiment of the present disclosure are executed.
[0222] The electronic device provided by the embodiment of the present disclosure and the method provided by the above embodiment belong to the same inventive concept. Technical details not described in detail in this embodiment may be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0223] The embodiment of the present application also provides a computer-readable medium, in which instructions or a computer program are stored. When the instructions or the computer program run on a device, the device is caused to execute any implementation manner of the code generation method provided by the embodiment of the present application.
[0224] It should be noted that the computer-readable medium described above in the present disclosure may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0225] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (Hyper Text Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LANs"), wide area networks ("WANs"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0226] The above computer-readable medium may be included in the above electronic device; or it may exist separately and not be assembled into the electronic device.
[0227] The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device can execute the above method.
[0228] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or combinations thereof. The foregoing programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, execute partially on the user's computer, execute as a stand-alone software package, execute partially on the user's computer and partially on a remote computer, or execute entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0229] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0230] The units involved in the embodiments described in this disclosure can be implemented in software or in hardware. Among them, the name of the unit / module does not constitute a limitation on the unit itself in some cases.
[0231] The functions described above herein can be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that can be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.
[0232] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0233] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts among the various embodiments, reference may be made to each other. For the systems or apparatuses disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and reference may be made to the descriptions in the method section for relevant parts.
[0234] It should be understood that in this application, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects and indicates that three relationships may exist. For example, "A and / or B" may mean: only A exists, only B exists, and both A and B exist simultaneously. Here, A and B may be singular or plural. The character " / " generally indicates an "or" relationship between the associated objects before and after. "At least one (one)" or a similar expression thereof refers to any combination of these items, including any combination of single items (ones) or plural items (ones). For example, at least one (one) of a, b, or c may mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c may be single or multiple.
[0235] It should also be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0236] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0237] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A code generation method, characterized in that, The method includes: Obtaining a neural network model, where the neural network model includes a plurality of candidate operators and the data dependency relationships between the plurality of candidate operators; Determining a group of operators to be fused from the plurality of candidate operators according to the data dependency relationships and the operator types of the candidate operators, where the group of operators to be fused includes at least two of the candidate operators; Determining the fusion operator code corresponding to the group of operators to be fused according to the operator type of the group of operators to be fused and the operator types of the individual operators in the group of operators to be fused; the operator type of the group of operators to be fused is determined according to the operator types of the individual operators in the group of operators to be fused; Determining the code of the neural network model according to the fusion operator code.
2. The method according to claim 1, characterized in that, The determining, from the plurality of candidate operators, a group of operators to be fused according to the data dependency relationships and the operator types of the candidate operators includes: Determining the path representation data of each candidate operator according to the data dependency relationships; for any one of the candidate operators, the path representation data of the candidate operator is determined according to the longest path between the candidate operator and the output operator in the neural network model; Determining a group of operators to be fused from the plurality of candidate operators according to the data dependency relationships, the path representation data of the candidate operators, and the operator types of the candidate operators.
3. The method according to claim 2, wherein The process of determining the path representation data includes: Determining the preset path representation data as the path representation data of the output operator, and adding at least one upstream operator of the output operator to the first set; the initial value of the first set is an empty set; the upstream operator is determined according to the data dependency relationships; Selecting a first operator from the first set; If it is determined that the path representation data of all the downstream operators of the first operator has been obtained, then determining the path representation data of the first operator according to the path representation data of the downstream operators, deleting the first operator from the first set, adding at least one upstream operator of the first operator to the first set, and continuing to perform the step of selecting a first operator from the first set until the first set is an empty set and then ending; the downstream operator is determined according to the data dependency relationships.
4. The method according to claim 3, wherein The process of determining the path representation data of the first operator includes: Performing a maximum value analysis process on the path representation data of all the downstream operators of the first operator to obtain the maximum path representation data; Determining the sum value between the maximum path representation data and a preset path step value as the path representation data of the first operator.
5. The method according to claim 2, characterized in that, The process of determining the group of operators to be fused includes: Putting the output operator into a second set; the initial value of the second set is an empty set; Taking out a second operator from the second set; If the data dependency relationships indicate that there are no downstream operators of the second operator, then adding the operator combination including the second operator to a third set; the initial value of the third set is an empty set; If the data dependency relationship indicates the existence of a downstream operator of the second operator, update the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator; there is an operator combination including the second operator in the updated third set; Put at least one upstream operator of the second operator into the second set, and continue to execute the step of taking out the second operator from the second set until, when the second set is an empty set, determine the operator combination including at least two operators in the third set as the operator group to be fused; the upstream operator is determined according to the data dependency relationship.
6. The method according to claim 5, characterized in that The neural network model includes at least one downstream operator of the second operator; The updating the third set according to the operator type of the second operator, the operator type of the downstream operator, and the path representation data of the downstream operator includes: Find a target operator from the at least one downstream operator, and the path representation data of the target operator is greater than the path representation data of any other downstream operator except the target operator among the at least one downstream operator; Judge whether the second operator meets a preset fusion condition according to the operator type of the second operator, the operator type of the target operator, and the operator type of the operator combination including the target operator in the third set; If so, put the second operator into the operator combination including the target operator in the third set; If not, add an operator combination including the second operator to the third set.
7. The method according to claim 1, characterized in that, The determining process of the operator type of the operator group to be fused includes: For any operator in the operator group to be fused, determine the complexity of the operator according to the operator type of the operator; Find a third operator from the operator group to be fused according to the complexity of each operator in the operator group to be fused, and the complexity of the third operator is higher than the complexity of any other operator except the third operator in the operator group to be fused; Determine the operator type of the operator group to be fused according to the operator type of the third operator.
8. The method according to claim 1, wherein The determining process of the fusion operator code corresponding to the operator group to be fused includes: For any operator in the operator group to be fused, determine the code template and the code parameters of the operator according to the operator type of the operator; Update the code parameters of any operator except the fourth operator in the operator group to be fused according to the code parameters of the fourth operator in the operator group to be fused; the operator type of the fourth operator is the same as the operator type of the operator group to be fused; For any operator in the operator group to be fused, generate the code of the operator according to the code template and the code parameters of the operator; Fuse the codes of all operators in the operator group to be fused according to the code fusion rule corresponding to the operator group to be fused to obtain the fusion operator code corresponding to the operator group to be fused; the code fusion rule is determined according to the operator type of the operator group to be fused.
9. The method according to claim 1, characterized in that, The method further includes: Compile the fusion operator code corresponding to the to-be-fused operator group to obtain an executable file corresponding to the to-be-fused operator group; Determine the deployment file of the neural network model according to the executable file.
10. A code generation device, characterized in that, It includes: A model acquisition unit, configured to acquire a neural network model, where the neural network model includes a plurality of candidate operators and data dependency relationships between the plurality of candidate operators; A first determination unit, configured to determine a to-be-fused operator group from the plurality of candidate operators according to the data dependency relationships and the operator types of the candidate operators, where the to-be-fused operator group includes at least two of the candidate operators; A second determination unit, configured to determine the fusion operator code corresponding to the to-be-fused operator group according to the operator type of the to-be-fused operator group and the operator types of each operator in the to-be-fused operator group; the operator type of the to-be-fused operator group is determined according to the operator types of each operator in the to-be-fused operator group; A third determination unit, configured to determine the code of the neural network model according to the fusion operator code.
11. An electronic device, characterized in that, The device includes: a processor and a memory; The memory is configured to store instructions or computer programs; The processor is configured to execute the instructions or computer programs in the memory, so that the electronic device executes the method according to any one of claims 1-9.
12. A computer-readable medium, characterized in that, Instructions or computer programs are stored in the computer-readable medium, and when the instructions or computer programs run on the device, the device executes the method according to any one of claims 1-9.