Method for obtaining thread number of music generation model, computer equipment and medium
By obtaining the model node path information and dependencies of the music generation model, the number of nodes without interdependence is calculated, which solves the problem of low-efficiency in the existing technology, realizes automatic determination of the number of threads, and improves the music Generate model operation efficiency.
Patent Information
- Application Number
- CN202411143767.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-13
AI Technical Summary
The way to set the number of threads in the existing music generation model requires multiple manual experimental tests, resulting in low acquisition efficiency.
By obtaining the path information of the model nodes, determining the dependencies between the model nodes, and calculating the number of nodes with no interdependence, as the number of threads running concurrently.
无需用户人工实验测试即可确定最优线程数量,提高了音乐生成模型线程数量的获取效率。
Smart Images

Figure CN119127476A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of music generation, and in particular to a method, apparatus, computer device, computer-readable storage medium and computer program product for obtaining the number of threads of a music generation model. Background Art
[0002] With the development of music generation technology, a technology for generating music using a music generation model has emerged, and the reasoning framework of the music generation model usually includes a setting for the number of threads, thereby allowing the music generation model to be run in a concurrent manner, thereby speeding up the process of generating music.
[0003] Moreover, the larger the number of threads of a music generation model, the better. Therefore, when determining the optimal number of threads for a music generation model, users usually conduct manual testing and verification experiments on the music generation model to collect statistics on the performance test data of the music generation model for different combinations, so as to obtain the test results of each combination and determine the optimal number of threads.
[0004] However, the above method of setting the number of threads requires multiple manual experimental tests by the user to obtain the optimal number of threads for the music generation model, so the efficiency of obtaining the number of threads for the music generation model is low. Summary of the invention
[0005] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product for obtaining the number of threads of a music generation model, which can improve the efficiency of obtaining the number of threads of the music generation model, in response to the above technical problems.
[0006] In a first aspect, the present application provides a method for obtaining the number of threads of a music generation model, comprising:
[0007] Obtain model node path information of the music generation model for which the number of threads is to be determined, wherein the model node path information is used to represent the running order relationship between the model nodes of the music generation model; and obtain the dependency relationship between the model nodes in the music generation model according to the model node path information;
[0008] According to the dependency relationship, the number of model nodes in the music generation model that do not have a mutual dependency relationship is obtained;
[0009] The number of nodes is used as the number of threads for concurrently running the music generation model.
[0010] In one embodiment, the dependency relationship between the model nodes is represented by a model node dependency graph of the music generation model; the obtaining of the dependency relationship between the model nodes in the music generation model according to the model node path information includes: obtaining the model node dependency graph of the music generation model according to the model node path information; wherein each vertex of the model node dependency graph is used to represent each model node of the music generation model, and the model node dependency graph is used to represent the dependency relationship between each model node; the obtaining of the number of model nodes in the music generation model that do not have mutual dependencies according to the dependency relationship includes: obtaining the maximum independent set corresponding to the model node dependency graph, and obtaining the number of model nodes included in the maximum independent set; wherein the maximum independent set is the independent set that contains the most model nodes among the independent sets corresponding to the model node dependency graph, and the independent set is a set composed of non-adjacent model nodes in the model node dependency graph; the number of model nodes included in the maximum independent set is used as the number of model nodes in the music generation model that do not have mutual dependencies.
[0011] In one embodiment, the method of obtaining the model node dependency graph according to the model node path information includes: obtaining a dependency node pair corresponding to the music generation model according to the model node path information; the dependency node pair is composed of two model nodes having a dependency relationship in the music generation model; deduplicating the dependency node pair, and constructing the model node dependency graph according to the deduplicated dependency node pairs.
[0012] In one embodiment, the model node dependency graph is represented in the form of a target two-dimensional matrix; the number of matrix rows and matrix columns of the target two-dimensional matrix match the number of model nodes contained in the music generation model, and each matrix row of the target two-dimensional matrix corresponds to each model node contained in the music generation model, and each matrix column of the target two-dimensional matrix corresponds to each model node contained in the music generation model; the model node dependency graph is constructed according to the deduplicated dependent node pairs, including: for each of the deduplicated dependent node pairs, obtaining the two model nodes constituting the deduplicated dependent node pair; setting the matrix elements in the initial two-dimensional matrix that match the two model nodes constituting the deduplicated dependent node pair to the first element value; the initial two-dimensional matrix is a target two-dimensional matrix without set element values; setting the remaining matrix elements in the initial two-dimensional matrix to the second element value to obtain the target two-dimensional matrix; the remaining matrix elements are the matrix elements in the initial two-dimensional matrix that are not set to the first element value.
[0013] In one embodiment, obtaining the maximum independent set corresponding to the model node dependency graph includes: obtaining a complement graph corresponding to the model node dependency graph; and using the maximum complete subgraph of the complement graph as the maximum independent set corresponding to the model node dependency graph.
[0014] In one embodiment, the method of obtaining the model node path information of the music generation model with a to-be-determined number of threads includes: obtaining a directed acyclic graph composed of the model nodes of the music generation model; obtaining an initial model node of the music generation model from the directed acyclic graph; the initial model node is the first model node of the music generation model to be run; and taking the initial model node as the starting point, traversing the directed acyclic graph through a depth-first search algorithm to obtain the model node path information.
[0015] In one embodiment, the directed acyclic graph stores the next model node corresponding to the next running order of each model node; the traversing the directed acyclic graph by a depth-first search algorithm with the initial model node as the starting point includes: taking the initial model node as the starting point, taking the initial model node as the current model node, and setting the current model node as a traversed node in the directed acyclic graph; judging whether the current model node corresponds to at least one next model node that is not set as a traversed node; if so, taking one of the next model nodes corresponding to the current model node that is not set as a traversed node as the new current model node, And return to execute the step of setting the current model node as a traversed node in the directed acyclic graph until the current model node does not correspond to at least one next model node that is not set as a traversed node; if not, obtain the previous model node corresponding to the current model node according to the directed acyclic graph, use the previous model node as the new current model node, and return to execute the step of determining whether the current model node corresponds to at least one next model node that is not set as a traversed node, until the current model node does not correspond to at least one next model node that is not set as a traversed node, and the current model node does not correspond to the previous model node.
[0016] In a second aspect, the present application also provides a device for obtaining the number of threads of a music generation model, including:
[0017] A dependency relationship acquisition module, used to acquire model node path information of a music generation model whose number of threads is to be determined, wherein the model node path information is used to represent the running order relationship between the model nodes of the music generation model; and to acquire the dependency relationship between the model nodes in the music generation model according to the model node path information;
[0018] A node quantity acquisition module, used for obtaining the number of model nodes that do not have mutual dependence in the music generation model according to the dependency relationship;
[0019] The thread number acquisition module is used to use the node number as the thread number of threads that concurrently run the music generation model.
[0020] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in any one of the embodiments of the first aspect when executing the computer program.
[0021] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.
[0022] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.
[0023] The method, device, computer equipment, computer-readable storage medium and computer program product for obtaining the number of threads of the music generation model described above obtain the model node path information of the music generation model whose number of threads is to be determined, and obtain the dependency relationship between each model node in the music generation model according to the model node path information; obtain the number of nodes of the model nodes in the music generation model that do not have a mutual dependency relationship according to the dependency relationship; and use the number of nodes as the number of threads of the music generation model. The present application obtains the node path of the music generation model, and then uses the node path to obtain the dependency relationship between each model node in the music generation model, and then determines the number of nodes of the model nodes that do not have a mutual dependency relationship, thereby obtaining the number of threads of the music generation model. Compared with the prior art that requires multiple manual experimental tests by the user to obtain the optimal number of threads of the music generation model, the present application can obtain the optimal number of threads without the need for manual experimental tests by the user, thereby improving the efficiency of obtaining the number of threads of the music generation model. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0025] FIG1 is a schematic flow chart of a method for obtaining the number of threads of a music generation model in one embodiment;
[0026] FIG2 is a schematic diagram of a process of obtaining the number of nodes without mutual dependence in one embodiment;
[0027] FIG3 is a schematic diagram of a process for constructing a model node dependency graph in one embodiment;
[0028] FIG4 is a schematic diagram of a directed acyclic graph composed of model nodes in one embodiment;
[0029] FIG5 is a schematic diagram of a directed acyclic graph composed of model nodes in another embodiment;
[0030] FIG6 is a schematic diagram of a directed acyclic graph composed of model nodes in yet another embodiment;
[0031] FIG7 is a block diagram of a thread quantity device for a music generation model in one embodiment;
[0032] FIG. 8 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0034] In one embodiment, as shown in FIG1 , a method for obtaining the number of threads of a music generation model is provided. This embodiment is illustrated by applying the method to a server. It is understandable that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0035] Step S101, obtaining model node path information of the music generation model whose number of threads is to be determined, where the model node path information is used to represent the running order relationship between each model node of the music generation model; and obtaining the dependency relationship between each model node in the music generation model according to the model node path information.
[0036] The music generation model for which the number of threads is to be determined refers to a music generation model for which the optimal number of threads needs to be determined. For example, it may be a neural network model for synthesizing AI singing. The music generation model may include multiple model nodes, that is, multiple model operators. After a model operator completes the corresponding operation task, it passes the result data obtained by the operation to the next model operator for operation. The model node path information represents the path information between multiple model nodes, and specifically can represent the operation order relationship between model nodes. The dependency relationship between model nodes refers to the operation dependency relationship between model nodes, which can be obtained based on the operation order between nodes. For example, the model nodes in the music generation model may include node A, node B, and node C, where node B needs to run after node A is completed, and node C needs to run after node B is completed. Then the path information can be node A-node B-node C, and the dependency relationship is that node B depends on node A, and node C depends on both node A and node B.
[0037] If the model nodes in another music generation model may include node D, node E and node F, where node E must be run after node D is completed, and node F must be run after node D is completed, but node E and node F do not need to consider the running order, then the path information can be node D-node E, and node D-node F, and the dependency relationship is that node E depends on node D, and node F depends on node D.
[0038] Specifically, after obtaining the music generation model for which the number of threads needs to be determined, the server can also obtain the model node path information of the music generation model, and thereby use the model node path information to determine the dependency relationship between the model nodes.
[0039] Step S102, according to the dependency relationship, obtain the number of model nodes in the music generation model that do not have a mutual dependency relationship.
[0040] Step S103: Using the number of nodes as the number of threads for concurrently running the music generation model.
[0041] Since the dependency between model nodes represents the operational dependency between model nodes, if there is a mutual dependency between two model nodes, then they cannot run concurrently at the same time. If there is no mutual dependency between the two model nodes, it means that the operation of the two model nodes will not affect each other, then the two model nodes can run concurrently. At this time, the number of threads can be increased to allow the above two model nodes to run concurrently on different threads to improve the operational efficiency. In other words, the number of nodes that do not have a mutual dependency, that is, the number of nodes that can run simultaneously, is exactly the maximum number of threads that the music generation model can process concurrently. Therefore, the server can use this number of nodes as the number of threads of the music generation model.
[0042] Specifically, after the server obtains the dependency relationship between each model node in the music generation model, it can determine the number of model nodes that do not have mutual dependencies, and set the number of nodes as the number of threads running concurrently in the music generation model.
[0043] In the above-mentioned method for obtaining the number of threads of the music generation model, the model node path information of the music generation model whose number of threads is to be determined is obtained, and the dependency relationship between each model node in the music generation model is obtained according to the model node path information; according to the dependency relationship, the number of nodes of the model nodes in the music generation model that do not have a mutual dependency relationship is obtained; and the number of nodes is used as the number of threads of the music generation model. The present application obtains the node path of the music generation model, and then uses the node path to obtain the dependency relationship between each model node in the music generation model, and then determines the number of nodes of the model nodes that do not have a mutual dependency relationship, thereby obtaining the number of threads of the music generation model. Compared with the prior art that requires multiple manual experimental tests by the user to obtain the optimal number of threads of the music generation model, the present application can obtain the optimal number of threads without the need for manual experimental tests by the user, thereby improving the efficiency of obtaining the number of threads of the music generation model.
[0044] In one embodiment, the dependency relationship between model nodes is represented by a model node dependency graph of the music generation model; as shown in FIG2 , step S101 may further include:
[0045] Step S201, obtaining a model node dependency graph according to the model node path information; wherein each vertex of the model node dependency graph is used to represent each model node of the music generation model, and the model node dependency graph is used to represent the dependency relationship between each model node.
[0046] In this embodiment, the dependency relationship of the model nodes can be presented in the form of a graph, that is, presented through a model node dependency graph, which can be an undirected graph, in which the vertices in the graph can be model nodes, and the edges in the graph can represent the dependency relationship between the model nodes. For example, vertex A and vertex B are connected by an edge, which indicates that there is a dependency relationship between the model node corresponding to vertex A and the model node corresponding to vertex B. Specifically, after obtaining the model node path information, the server can generate a model node dependency graph to represent the dependency relationship between the model nodes of the music generation model.
[0047] Step S102 may further include steps S202-S203:
[0048] Step S202, obtaining the maximum independent set corresponding to the model node dependency graph, and obtaining the number of model nodes contained in the maximum independent set; wherein the maximum independent set is the independent set containing the most model nodes in the independent sets corresponding to the model node dependency graph, and the independent set is a set consisting of non-adjacent model nodes in the model node dependency graph;
[0049] Step S203, taking the number of model nodes included in the maximum independent set as the number of model nodes that have no mutual dependence in the music generation model.
[0050] Among them, the maximum independent set refers to the independent set containing the most model nodes in the independent set corresponding to the model node dependency graph, and the independent set refers to the set composed of vertices that are not adjacent to each other in the model node dependency graph. In this embodiment, since the model node dependency graph represents the dependency relationship between model nodes, if two model nodes are not adjacent to each other in the model node dependency graph, it indicates that there is no mutual dependency between the two model nodes. Therefore, the model nodes included in the maximum independent set corresponding to the model node dependency graph indicate that there is no mutual dependency between the two of the above model nodes. For example, the maximum independent set can include model node C, model node D and model node E, which indicates that there is no mutual dependency between model node C and model node D, there is no mutual dependency between model node C and model node E, and there is no mutual dependency between model node D and model node E, that is, the number of model nodes that do not have mutual dependency in the music generation model is 3. It can be seen. The number of model nodes that have no mutual dependencies in the music generation model can be the same as the number of model nodes included in the maximum independent set. Therefore, after the server obtains the maximum independent set corresponding to the model node dependency graph, it can also determine the number of model nodes included in the maximum independent set, and thus use the number of nodes as the number of model nodes that have no mutual dependencies in the music generation model.
[0051] In this embodiment, the server can represent the dependency relationship between each model node through a model node dependency graph, and thus use the node number of model nodes contained in the largest independent set in the graph as the node number of model nodes that do not have mutual dependencies in the music generation model. In this way, the efficiency of obtaining the node number of model nodes that do not have mutual dependencies in the music generation model can be improved.
[0052] Furthermore, step S201 may further include: obtaining dependent node pairs corresponding to the music generation model according to the model node path information; the dependent node pairs are composed of two model nodes that have a dependency relationship in the music generation model; deduplicating the dependent node pairs, and constructing a model node dependency graph based on the deduplicated dependent node pairs.
[0053] A dependent node pair refers to a node pair consisting of two model nodes with a dependent relationship. The dependent node pair can be determined by the model node path information. After obtaining the model node path information, the server can first determine all two model nodes with a dependent relationship based on the model node path information to form a dependent node pair. Deduplication refers to removing duplicate dependent node pairs. Some dependent node pairs may appear repeatedly on different paths. Therefore, the server can also first deduplicate the dependent node pairs determined by the model node path information, and then use the deduplicated dependent node pairs to construct the model node dependency graph.
[0054] For example, a music generation model contains two model node paths, namely node A-node B-node C-node E, and node A-node B-node D-node E. Then for the path of node A-node B-node C-node E, the dependent node pairs may include: AB, AC, AE, BC, BE and CE, and for the path of node A-node B-node D-node E, the dependent node pairs may include: AB, AD, AE, BD, BE and DE. It can be seen that there are repeated dependent node pairs AB, AE and BE, so the server can deduplicate the above dependent node pairs, and the final deduplicated dependent node pairs are: AB, AC, AE, BC, BE, CE, AD, BD and DE, and then the above deduplicated dependent node pairs can be used to construct a model node dependency graph.
[0055] In this embodiment, the server can determine the dependent node pairs based on the model node path information, and then construct the model node dependency graph by deduplicating the dependent node pairs. This method can improve the construction efficiency of the model node dependency graph.
[0056] Furthermore, the model node dependency graph is represented in the form of a target two-dimensional matrix; the number of matrix rows and the number of matrix columns of the target two-dimensional matrix match the number of model nodes included in the music generation model, each matrix row of the target two-dimensional matrix corresponds to each model node included in the music generation model, and each matrix column of the target two-dimensional matrix corresponds to each model node included in the music generation model; as shown in FIG3 , constructing a model node dependency graph based on the deduplicated dependent node pairs may further include:
[0057] Step S301, for each pair of dependent nodes after deduplication, obtain two model nodes constituting the pair of dependent nodes after deduplication.
[0058] In this embodiment, the model node dependency graph can be represented in the form of a two-dimensional matrix, namely a target two-dimensional matrix, and the number of matrix rows and matrix columns of the two-dimensional matrix are the same as the number of nodes of the model nodes included in the music generation model. For example, when the number of nodes of the model nodes included is 5, the number of matrix rows and matrix columns of the target two-dimensional matrix are both 5, and each matrix row and matrix column respectively corresponds to a model node. For example, the model node includes node A, node B, node C, node D and node E, then the 5 rows and 5 columns of the two-dimensional matrix correspond to different nodes respectively.
[0059] In this embodiment, after the server obtains the deduplicated dependent node pairs, it can obtain the two model nodes that constitute the deduplicated dependent node pairs for each pair of deduplicated dependent node pairs. For example, the deduplicated dependent node pairs are AB, AC, AE, BC, BE, CE, AD, BD and DE. Then, for the dependent node pair AB, the two model nodes that constitute the node pair are divided into node A and node B, and for the dependent node pair AC, the two model nodes that constitute the node pair are divided into node A and node C, and so on.
[0060] Step S302, setting the matrix elements in the initial two-dimensional matrix that match the two model nodes constituting the dependent node pair after deduplication as the first element value; the initial two-dimensional matrix is a target two-dimensional matrix without set element values.
[0061] The initial two-dimensional matrix refers to a target two-dimensional matrix without element values set. In this embodiment, the server can determine a matrix element in the initial two-dimensional matrix based on each of the two model nodes that make up the deduplicated dependent node pair, and can set the element value of the matrix element to the first element value, and the first element value can be set to 1. For example, for the dependent node pair AB, the two model nodes that make up the node pair are node A and node B, then the corresponding matrix elements can be the matrix elements in the first row and second column, and the matrix elements in the second row and first column in the two-dimensional matrix, which are AB and BA respectively, so the server can set the above matrix elements to the element value 1. Similarly, for the dependent node pair AC, the corresponding matrix elements can be the matrix elements in the first row and third column, and the matrix elements in the third row and first column in the two-dimensional matrix, which are AC and CA respectively, so the server can set the above matrix elements to the element value 1.
[0062] Step S303, setting the remaining matrix elements in the initial two-dimensional matrix to the second element value to obtain the target two-dimensional matrix; the remaining matrix elements are the matrix elements in the initial two-dimensional matrix that are not set to the first element value.
[0063] After completing the matrix element setting of all the deduplicated dependent node pairs, the server can set the matrix elements in the initial two-dimensional matrix that are not set to the first element value to the second element value, and the second element value can be set to 0, thereby obtaining a target two-dimensional matrix. The target two-dimensional matrix can describe the dependency relationship between the model nodes. For example, if a matrix element has a first element value of 1, it indicates that there is a dependency relationship between the two model nodes corresponding to the matrix element, and if a matrix element has a second element value of 0, it indicates that there is no mutual dependency relationship between the two model nodes corresponding to the matrix element.
[0064] In this embodiment, the server can represent the model node dependency graph in the form of a two-dimensional matrix, wherein the element value of the matrix element may include a first element value and a second element value, and the two model nodes corresponding to the matrix element corresponding to the first element value represent that there is a dependency relationship between the model nodes, while the two model nodes corresponding to the matrix element corresponding to the second element value represent that there is no mutual dependency relationship between the model nodes. The model node dependency graph constructed in this way can improve the efficiency of obtaining the maximum independent set through the model node dependency graph.
[0065] In addition, step S202 may further include: obtaining a complement graph corresponding to the model node dependency graph; and using the maximum complete subgraph of the complement graph as the maximum independent set corresponding to the model node dependency graph.
[0066] The complement graph refers to the graph obtained by removing the edges contained in the model node dependency graph from the complete graph composed of the model nodes in the music generation model. Generally speaking, the maximum independent set of a graph is the maximum clique of its complement graph, that is, the maximum complete subgraph of its complement graph. Therefore, in this embodiment, since the maximum independent set of a graph is difficult to calculate, the maximum independent set corresponding to the model node dependency graph can be determined by converting the graph into its complement graph and obtaining the maximum clique of the complement graph, that is, the maximum complete subgraph of the complement graph.
[0067] Specifically, after obtaining the model node dependency graph, the server can also obtain the complementary graph corresponding to the model node dependency graph. If the model node dependency graph is represented by elements of a two-dimensional matrix, and the two model nodes corresponding to the matrix elements corresponding to the first element value represent that there is a dependency relationship between the model nodes, and the two model nodes corresponding to the matrix elements corresponding to the second element value represent that there is no mutual dependency relationship between the model nodes, then the server can obtain the complementary graph by numerically inverting the matrix element values, that is, converting the matrix elements originally set to the first element value to be set to the second element value, and converting the matrix elements originally set to the second element value to be set to the first element value. In this way, the two-dimensional matrix obtained after the conversion can be used to represent the complementary graph corresponding to the model node dependency graph.
[0068] Afterwards, the server can further obtain the maximum cluster of the complement graph based on the complement graph, for example, by using the Bron-Kerbosch algorithm or the backtracking method to obtain the maximum cluster, thereby using the maximum cluster as the maximum independent set corresponding to the model node dependency graph.
[0069] In this embodiment, the server can determine the maximum independent set corresponding to the model node dependency graph by obtaining the complement graph corresponding to the model node dependency graph and then obtaining the maximum clique of the complement graph. This method can reduce the complexity of calculating the maximum independent set, thereby improving the efficiency of obtaining the maximum independent set.
[0070] In one embodiment, step S101 may further include: obtaining a directed acyclic graph composed of model nodes of the music generation model; and obtaining model node path information according to the directed acyclic graph.
[0071] A directed acyclic graph refers to a dag graph, which may be composed of model nodes of a music generation model and directed lines between the model nodes, wherein the directed lines may represent the operating order between the model nodes. In this embodiment, the model node path information may be determined through the directed acyclic graph of the music generation model. Specifically, the server may first obtain a directed acyclic graph composed of model nodes of the music generation model according to the operating order between each model node in the music generation model. Afterwards, the server may obtain the model node path information based on the directed acyclic graph.
[0072] In this embodiment, after obtaining the music generation model, the server can also determine the directed acyclic graph of the music generation model, and further obtain the path information of the model node based on the directed acyclic graph. In this way, the accuracy of obtaining the model node path information can be improved.
[0073] Furthermore, obtaining model node path information based on the directed acyclic graph can further include: obtaining an initial model node of the music generation model from the directed acyclic graph; the initial model node is the first model node running the music generation model; taking the initial model node as the starting point, traversing the directed acyclic graph through a depth-first search algorithm to obtain the model node path information.
[0074] Among them, the initial model node refers to the first model node run by the music generation model, that is, the first model node in the directed acyclic graph, and the depth-first search algorithm refers to the DFS algorithm, which is an algorithm for traversing or searching a tree or graph. In a tree, this algorithm searches for the deepest node, and in a graph, it backtracks to unexplored paths. DFS starts from the root (or an arbitrary node in the graph) and explores branches as deep as possible until the target node is reached or there are no more nodes accessible on the current branch. Then, the search backtracks to the next node on the path where the exploration began. DFS is usually implemented using a stack or recursion, of which recursive implementation is more common and intuitive.
[0075] In this embodiment, the model node path information can be implemented through a depth-first search algorithm, i.e., a DFS algorithm, by obtaining the initial model node of the music generation model in the directed acyclic graph and using the node as the starting point to implement a traversal search of the directed acyclic graph, thereby obtaining the model node path information. Compared with the model node path search implemented by the BFS algorithm, i.e., the breadth-first search algorithm, since the BFS algorithm is characterized by traversing in a hierarchical manner, first visiting the node closest to the starting node, then visiting the node one level farther from the starting node, and so on. In other words, although BFS can retain more of the hierarchical relationship of the directed acyclic graph, so that nodes of the same level are gathered together, the concurrent dependency relationship depends more on the upper and lower dependencies of the nodes. Therefore, the method of traversing the directed acyclic graph by the depth-first search algorithm DFS provided in this embodiment can more accurately obtain the model node path information than the traversal implemented by the BFS algorithm.
[0076] In this embodiment, the model node path information can be obtained from the initial model node in the directed acyclic graph, and then the directed acyclic graph is traversed using a depth-first search algorithm with the initial model node as the starting point. Compared with traversing the directed acyclic graph using a breadth-first search algorithm, this embodiment can obtain the model node path information more accurately.
[0077] Furthermore, the directed acyclic graph stores the next model node corresponding to the next running order of each model node; taking the initial model node as the starting point, traversing the directed acyclic graph through a depth-first search algorithm may further include: taking the initial model node as the starting point, taking the initial model node as the current model node, and setting the current model node as a traversed node in the directed acyclic graph; determining whether the current model node corresponds to at least one next model node that is not set as a traversed node; if so, taking one of the next model nodes corresponding to the current model node that is not set as a traversed node as the new current model node, and Return to the step of setting the current model node as a traversed node in the directed acyclic graph until the current model node does not correspond to at least one next model node that is not set as a traversed node; if not, obtain the previous model node corresponding to the current model node according to the directed acyclic graph, use the previous model node as the new current model node, and return to the step of determining whether the current model node corresponds to at least one next model node that is not set as a traversed node, until the current model node does not correspond to at least one next model node that is not set as a traversed node, and the current model node does not correspond to the previous model node.
[0078] In this embodiment, the directed acyclic graph can be represented by a certain data format, which can store the next model node corresponding to the next running order of each model node. For example, after model node A is completed, model node B is run, then model node B is used as the next model node of model node A. Traversing the directed acyclic graph requires traversing all model nodes in the directed acyclic graph, and the current model node refers to any one of all the model nodes in the directed acyclic graph.
[0079] Specifically, after obtaining the initial model node, the server can use the initial model node as the starting point of the traversal, and use it as the current model node, and mark it as a traversed node, indicating that the model node has been traversed. After that, the server can determine whether the current model node corresponds to at least one next model node that has not been traversed and is located after the current model node in the running order. If so, one of the next model nodes that has not been traversed is used as the new current model node, and the process of marking it as a traversed node and determining whether the current model node corresponds to at least one next model node that has not been traversed and is located after the current model node in the running order is repeated until the current model node does not correspond to the next model node, at which time it is indicated that the current model node is already the last model node in the running order, or the next model nodes of the current model node are all set to traversed nodes, and the model nodes located after the current model node in the running order have all been traversed.
[0080] At this time, if the current model node does not correspond to at least one next model node that has not been traversed and is located after the current model node in the running order, then the server can determine the previous model node that is located before the current model node in the running order according to the directed acyclic graph, and use the previous model node as the new current model node to determine whether the current model node corresponds to at least one next model node that has not been set as a traversed node. If so, the step of using one of the next model nodes that has not been traversed of the model node as the new current model node is executed again, and if not, the step of using the previous model node before the current model node as the new current model node is executed again, until the current model node does not correspond to the next model node that has not been traversed, indicating that all model nodes after the current model node have completed the traversal, and the current model node does not correspond to the previous model node, which indicates that all model nodes have been traversed, and thus the traversal of the directed acyclic graph is completed.
[0081] Take a directed acyclic graph including three paths as an example, path 1 is node A-node B-node C, path 2 is node A-node B-node D, and path 3 is node A-node E. When traversing through the above depth-first search algorithm, node A is the initial model node and can be used as the initial current model node. At this time, the server sets it as a traversed node. Then, it is determined whether node A corresponds to at least one untraversed next model node. At this time, node B and node E are both untraversed next model nodes. Then the server can use one of the untraversed next model nodes, such as node B, as the new current model node and set it to the traversed state.
[0082] Afterwards, the server can determine again whether node B corresponds to at least one untraversed next model node. Similarly, at this time, node C and node D both belong to the untraversed next model nodes. Then the server can use node C as the new current model node. After setting it as the traversed node, since node C is already the last model node, it satisfies the condition that the current model node does not correspond to the next model node, that is, it satisfies the condition that the current model node does not correspond to at least one next model node that has not been set as a traversed node. Then the server can use the previous model node of node C, that is, node B, as the new current model node again. At this time, node B still corresponds to at least one untraversed next model node, that is, node E, then node D can be used as the new current model node to set the traversed node.
[0083] And, similar to node C, since node D is already the last model node and satisfies the condition that the current model node does not correspond to the next model node, the server can use the previous model node of node D, that is, node B, as the new current model node again. At this time, since the next model node of node B is set as a traversed node, the server can use the previous model node of node B, that is, node A, as the new current model node. At this time, node A satisfies that there is at least one untraversed next model node, that is, node E, so the server can use node E as the new current model node. After setting it as a traversed node, since node E is also the last model node, the server can use the previous model node of node E, that is, node A, as the new current model node again. At this time, the next model node of node A, that is, node B and node E, have been traversed, and at the same time, node A does not have a previous model node, which indicates that all model nodes have been traversed.
[0084] In this embodiment, the branch paths of the graph can be searched first through a depth-first search algorithm, and after reaching the end of the graph, backtracking to the previous node can be performed to continue searching other branches. In this way, the model node path information can be obtained more accurately.
[0085] In one embodiment, a method for obtaining the optimal number of threads applied to a computing end-side reasoning framework is also provided. The method can be applied to a music generation model. Specifically, a model actually has one or more directed acyclic graphs (DAGs) inside, where the maximum number of threads supported is related to the number of independent sub-nodes inside the directed acyclic graph (DAG).
[0086] Taking the directed acyclic graph shown in Figure 4 as an example, it can be seen that only one node can be executed at most here at the same time, because each node depends on the previous node, and the setting of multiple threads can not bring the improvement of efficiency. And if the form of directed acyclic graph is as shown in Figure 5, it can be seen that after calculating A, B and C can be calculated at the same time, so the number of threads allowed to be set is 2. It can be seen that if the selected number of threads exceeds the number of parallel nodes of the directed acyclic graph itself, it will cause a waste of system resources. Therefore, the purpose of the present embodiment is to calculate the maximum concurrency of the entire directed acyclic graph.
[0087] Taking the directed acyclic graph shown in FIG6 as an example, this embodiment can obtain the maximum concurrency of the directed acyclic graph through the following process, including the following steps:
[0088] Step 1: First, use the depth-first search algorithm, i.e., the DFS algorithm, to find all complete paths. Referring to Figure 6, we can see that the directed acyclic graph has three complete paths, namely:
[0089] A – B – D – F
[0090] A – C – F
[0091] A – B – E – F
[0092] The traversal algorithm needs to use the DFS algorithm instead of the breadth-first search algorithm, namely the BFS algorithm. The BFS algorithm retains more of the hierarchical relationship of the directed acyclic graph, and nodes of the same level are clustered together, but the concurrent dependency relationship depends more on the upper and lower dependencies of the nodes, so the DFS algorithm is needed.
[0093] Step 2: Based on the full path, all the dependent point pairs are obtained. The obtained dependent point pairs are undirected, that is, AB and BA are the same. At the same time, deduplication processing is also required. Finally, the following dependent point pairs can be obtained: AB, AD, AF, AC, AE, BD, BF, CF, BE, EF and DF.
[0094] The combination of these point pairs can clearly show which nodes have dependencies, such as A and E. They are at different levels, and their dependencies can be easily missed using the BFS algorithm.
[0095] Step 3: Based on the dependent point pair information, a two-dimensional dependency graph is obtained, wherein the two-dimensional form of the dependency graph can be shown in Table 1 and can be stored in the form of a two-dimensional array or matrix.
[0096] Table 1 Schematic diagram of the two-dimensional form of the dependency graph
[0097]
[0098] Among them, if AB exists, AB / BA are both set to 1, otherwise they are both set to 0. The diagonal is the dependency of each node on itself, which is set to 0. This is a two-dimensional unweighted graph.
[0099] Step 4: Find the maximum independent set of the dependency graph. The maximum number of threads allowed in this embodiment is actually the maximum independent set of the dependency graph, which is the number of nodes in it. However, the maximum independent set of a graph is not easy to calculate, so the problem is transformed into calculating the maximum clique of the complement graph of the original graph.
[0100] First, the values in Table 1 are reversed to obtain the two-dimensional representation of the complement graph of the dependency graph, as shown in Table 2.
[0101] Table 2 Schematic diagram of two-dimensional form of supplementary image
[0102]
[0103] After that, the Bron-Kerbosch algorithm or the backtracking method can be used to calculate the maximum cluster. The number of nodes in the maximum cluster is the maximum number of concurrent threads supported. The maximum cluster of the complement graph is the three nodes CDE, so the number of nodes in the maximum cluster is 3. Then, for the directed acyclic graph shown in Figure 6, three threads can be used to run concurrently, that is, node C, node D, and node E can run concurrently in three threads respectively.
[0104] The optimal thread number acquisition method provided in this embodiment can quickly calculate the maximum allowed number of threads when deploying a neural network model, namely a music generation model, thereby reducing manual attempts. In this way, the efficiency of acquiring the number of threads of the music generation model can be improved.
[0105] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0106] Based on the same inventive concept, the embodiment of the present application also provides a device for obtaining the number of threads of a music generation model for implementing the method for obtaining the number of threads of a music generation model involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of one or more devices for obtaining the number of threads of a music generation model provided below can refer to the limitations of the method for obtaining the number of threads of a music generation model above, and will not be repeated here.
[0107] In an exemplary embodiment, as shown in FIG. 7 , a device for obtaining the number of threads of a music generation model is provided, including: a dependency acquisition module 701, a node number acquisition module 702, and a thread number acquisition module 703, wherein:
[0108] The dependency relationship acquisition module 701 is used to acquire the model node path information of the music generation model whose number of threads is to be determined, where the model node path information is used to represent the running order relationship between each model node of the music generation model; and to acquire the dependency relationship between each model node in the music generation model according to the model node path information;
[0109] A node number acquisition module 702 is used to obtain the number of model nodes that do not have mutual dependencies in the music generation model according to the dependencies;
[0110] The thread number acquisition module 703 is used to use the node number as the thread number of threads that concurrently run the music generation model.
[0111] Each module in the device for obtaining the number of threads of the music generation model can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0112] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG8. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store dependency data between model nodes. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for obtaining the number of threads of a music generation model is implemented.
[0113] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0114] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0115] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0116] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0117] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0118] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0119] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for obtaining the number of threads of a music generation model, characterized in that: The method comprises: Obtain model node path information of the music generation model for which the number of threads is to be determined, wherein the model node path information is used to represent the running order relationship between the model nodes of the music generation model; and obtain the dependency relationship between the model nodes in the music generation model according to the model node path information; According to the dependency relationship, the number of model nodes in the music generation model that do not have a mutual dependency relationship is obtained; The number of nodes is used as the number of threads for concurrently running the music generation model.
2. The method according to claim 1, characterized in that The step of obtaining the dependency relationship between each model node in the music generation model according to the model node path information comprises: obtaining a model node dependency graph of the music generation model according to the model node path information; wherein each vertex of the model node dependency graph is used to represent each model node of the music generation model, and the model node dependency graph is used to represent the dependency relationship between each model node; The step of obtaining the number of model nodes in the music generation model that do not have a mutual dependency relationship according to the dependency relationship includes: Obtain the maximum independent set corresponding to the model node dependency graph, and obtain the number of model nodes contained in the maximum independent set; wherein the maximum independent set is the independent set containing the most model nodes among the independent sets corresponding to the model node dependency graph, and the independent set is a set consisting of non-adjacent model nodes in the model node dependency graph; The number of model nodes included in the maximum independent set is used as the number of model nodes that have no mutual dependence in the music generation model.
3. The method according to claim 2, characterized in that The obtaining the model node dependency graph according to the model node path information includes: According to the model node path information, a dependent node pair corresponding to the music generation model is obtained; the dependent node pair is composed of two model nodes having a dependent relationship in the music generation model; Deduplication processing is performed on the dependent node pairs, and the model node dependency graph is constructed according to the dependent node pairs after deduplication.
4. The method according to claim 3, characterized in that The model node dependency graph is represented in the form of a target two-dimensional matrix; the number of matrix rows and the number of matrix columns of the target two-dimensional matrix match the number of model nodes included in the music generation model, each matrix row of the target two-dimensional matrix corresponds to each model node included in the music generation model, and each matrix column of the target two-dimensional matrix corresponds to each model node included in the music generation model; The step of constructing the model node dependency graph according to the duplicated dependency node pairs includes: For each of the deduplicated dependent node pairs, obtaining two model nodes constituting the deduplicated dependent node pair; Setting the matrix elements in the initial two-dimensional matrix that match the two model nodes constituting the dependent node pair after duplication removal to the first element value; the initial two-dimensional matrix is a target two-dimensional matrix without element values set; The remaining matrix elements in the initial two-dimensional matrix are set to the second element value to obtain the target two-dimensional matrix; the remaining matrix elements are the matrix elements in the initial two-dimensional matrix that are not set to the first element value.
5. The method according to claim 2, characterized in that: The obtaining of the maximum independent set corresponding to the model node dependency graph includes: Obtaining a complement graph corresponding to the model node dependency graph; The maximum complete subgraph of the complement graph is used as the maximum independent set corresponding to the model node dependency graph.
6. The method according to claim 1, characterized in that The step of obtaining model node path information of the music generation model of the number of threads to be determined includes: Obtaining a directed acyclic graph consisting of model nodes of the music generation model; From the directed acyclic graph, obtaining an initial model node of the music generation model; the initial model node is the first model node of the music generation model to be run; Taking the initial model node as the starting point, the directed acyclic graph is traversed by a depth-first search algorithm to obtain the model node path information.
7. The method according to claim 6, characterized in that The method of traversing the directed acyclic graph by using a depth-first search algorithm with the initial model node as a starting point includes: Taking the initial model node as a starting point, taking the initial model node as a current model node, and setting the current model node as a traversed node in the directed acyclic graph; Determine whether the current model node corresponds to at least one next model node that is not set as a traversed node; If so, one of the next model nodes corresponding to the current model node that has not been set as a traversed node is used as the new current model node, and the step of setting the current model node as a traversed node in the directed acyclic graph is returned to be executed until all the next model nodes corresponding to the current model node are set as traversed nodes; If not, then according to the directed acyclic graph, the previous model node corresponding to the current model node is obtained as the new current model node, and the step of determining whether the current model node corresponds to at least one next model node that is not set as a traversed node is returned to execute, until all next model nodes corresponding to the current model node are set as traversed nodes, and the current model node does not correspond to a previous model node.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
