Model fusion method and device based on topological structure and computer equipment
By building a ring topology in model fusion and realizing local fusion between devices, the problem of excessive peak resource demand in the existing technology is solved, and efficient model fusion and storage efficiency are achieved.
Patent Information
- Application Number
- CN202510305666.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2045-03-14
AI Technical Summary
Existing model fusion techniques require loading all models onto a single device when processing a large number of models, resulting in a sharp increase in peak demand for storage and computing resources, limiting the application of model fusion on resource-constrained devices.
By building a ring topology, each device is locally fused with up to two adjacent devices, ensuring constant storage peaks, reducing storage requirements, and ensuring the efficiency and convergence of the model fusion process through limited rounds of updates.
It significantly reduces storage requirements and improves storage efficiency. It is suitable for resource-constrained devices, such as edge devices and GPUs with limited video memory, and promotes the wide deployment of model convergence technology in practical applications.
Smart Images

Figure CN119830225A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to a topology-based model fusion method, device, and computer equipment. Background Art
[0002] Model fusion is a common method used in the field of artificial intelligence and machine learning to enhance the generalization ability of models. Compared with traditional multi-task learning technology, it does not require a large amount of training data and a complex training process. Model fusion obtains a new model with strong generalization ability by fusing multiple models that have been fine-tuned in different tasks according to certain weights. Commonly used model fusion methods include Ties-Merging, Task Arithmetic, Weight Averaging, and AdaMerging. These methods enhance the effect of the fused model by constructing task vectors, eliminating conflicts in model fusion, and automatically determining model fusion parameters.
[0003] However, existing technologies also have their shortcomings. For methods that manually set model parameters, it usually takes a lot of time to determine a suitable parameter; and for methods that automatically determine fusion parameters, a large amount of video memory is usually required, which limits their use in practical applications. In addition, the challenges faced by model fusion include model selection, fusion strategy design, and the risk of overfitting.
[0004] For example, when inter-layer AdaMerging processes a large number of models, all models need to be loaded onto a single device at the same time. It is difficult for a single device to infinitely expand its storage and computing capabilities, which leads to a sharp increase in the peak demand for storage resources and computing resources. Especially when using GPUs for model fusion, the consumption of video memory becomes a bottleneck, and it is difficult to implement on resource-constrained end devices, limiting the application of model fusion technology in mobile devices or edge computing scenarios.
[0005] Task algorithms or task arithmetic and weight averaging methods do not require complex training processes and can quickly fuse multiple models into one model. However, these two methods usually require manual parameter adjustment, requiring a lot of experiments and expertise to determine the best parameter combination, resulting in low efficiency, especially when the parameter space is large or the model is complex; and these two methods still require all models to be imported into the same device, which is not suitable for resource-constrained environments (such as edge devices); when the number of models that need to be fused increases, performance bottlenecks may be encountered. Summary of the invention
[0006] To solve the problems in the prior art, the present specification provides a model fusion method, apparatus and computer equipment based on a topological structure, the method comprising: constructing a topological structure, determining the objects to be fused deployed in each node in the topological structure, wherein the topological structure includes multiple nodes and each node corresponds to a device; according to the model fusion algorithm, merging and iterating the objects to be fused deployed in multiple nodes within a preset node range in the topological structure, to obtain a local fusion model generated after each merging iteration of all nodes in the topological structure; when the coefficients of the local fusion models generated after multiple merging iterations of all nodes are consistent, determining the local fusion models corresponding to each node to complete the merging, to obtain multiple multi-task models in the topological structure.
[0007] According to one aspect of the embodiments of the present specification, according to the model fusion algorithm, merging and iterating the objects to be fused deployed by each node includes: determining a certain node in the topological structure as the node to be fused; using the adjacent nodes of the node to be fused in the topological structure as the local fusion nodes of the node to be fused; merging and iterating the objects to be fused of the node to be fused and the objects to be fused of the local fusion nodes.
[0008] According to one aspect of an embodiment of the present specification, constructing a topological structure and determining the objects to be fused deployed in each node in the topological structure include: configuring multiple devices and treating each device as a node in the topological structure; storing an object to be fused in each node, and the object to be fused includes: at least one of an initial fine-tuning model or a task vector.
[0009] According to one aspect of an embodiment of the present specification, when the model fusion algorithm is a weighted averaging algorithm, the object to be fused of each node is an initial fine-tuning model, and according to the model fusion algorithm, the objects to be fused deployed at multiple nodes within a preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merging iteration of all nodes in the topological structure, including: based on the weight algorithm, assigning the same first initial weight to the initial fine-tuning model of each node; according to the first initial weight, merging and iterating the initial fine-tuning model of the node to be fused and the initial fine-tuning model of the local fusion node to obtain a merged first local fusion model.
[0010] According to one aspect of the embodiments of the present specification, when the fusion algorithm is a task algorithm, the object to be fused of each node is a task vector, and according to the model fusion algorithm, the objects to be fused deployed by multiple nodes within the preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merge iteration of all nodes in the topological structure, including: determining a preset number of merge iterations; judging whether the coefficients of the task vectors of all nodes after the preset merge iteration are basically consistent; if so, determining a unified coefficient, and performing coefficient conversion based on the unified coefficient, the preset number of merge iterations and the coefficients corresponding to the task vectors of each node in the naive task algorithm, and determining the value of the unified coefficient. If not, update the preset number of merge iterations, continue to merge and iterate, and repeat the above steps; according to the unified coefficient, determine the second local fusion model of the current node.
[0011] According to one aspect of an embodiment of this specification, after each node undergoes a preset round of merging iterations, the method includes:
[0012] Determine whether the weights corresponding to the first local fusion model after the merging and iteration of each node are consistent; if so, determine that the merging of the first local fusion model is complete, and obtain multiple first local fusion models in the topological structure; determine whether the weights corresponding to the second local fusion model after the merging and iteration of each node are consistent; if so, determine that the merging of the second local fusion model is complete, and obtain multiple second local fusion models in the topological structure.
[0013] According to one aspect of an embodiment of the present specification, when the model fusion algorithm is an inter-layer AdaMerging algorithm, the objects to be fused of each node are pre-trained models and task vectors, and according to the model fusion algorithm, the objects to be fused deployed at each node are merged and iterated to obtain a local fusion model of each node after each merge iteration, including: based on the inter-layer AdaMerging algorithm, assigning a third initial weight to the task vector of each node; using the third initial weight, merging and iterating the pre-trained model, the task vector of the node to be fused, and the task vector of the local fusion node according to the information entropy loss function to obtain a merged third local fusion model.
[0014] The embodiment of the present specification provides a model fusion device based on a topological structure, and the device includes: a determination unit, which is used to construct a topological structure and determine the objects to be fused deployed in each node in the topological structure, wherein the topological structure includes multiple nodes and each node is connected to a device; a local fusion model determination unit, which is used to merge and iterate the objects to be fused deployed in each node according to the model fusion algorithm to obtain a local fusion model generated after each merging iteration of each node; a fusion model determination unit, which is used to determine that the local fusion models corresponding to each node are merged when the coefficients of the local fusion models generated after multiple merging iterations of each node are consistent, so as to obtain multiple multi-task models in the topological structure.
[0015] The embodiments of the present specification also provide a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the topology-based model fusion method when executing the computer program.
[0016] The embodiments of this specification also provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the topology-based model fusion method is implemented.
[0017] This solution builds a ring topology structure to achieve local fusion of each device with at most two adjacent devices, thereby ensuring a constant storage peak and significantly reducing storage requirements. It not only improves storage efficiency but also ensures the efficiency of the model fusion process and the convergence of the final model through a limited number of rounds of updates. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 It is a flowchart of a model fusion method based on topological structure according to an embodiment of this specification;
[0020] Figure 2 The flowchart of a method for merging and iterating objects to be merged deployed by each node according to an embodiment of the present specification is shown;
[0021] Figure 3 The flowchart of the method for determining the object to be merged of each node in the topological structure according to the embodiment of this specification is shown;
[0022] Figure 4 The figure is a flow chart of a method for merging iterations using a weighted average algorithm according to an embodiment of the present specification;
[0023] Figure 5 The figure is a flow chart of a method for merging and iterating using a task algorithm according to an embodiment of the present specification;
[0024] Figure 6 This is a flow chart of a method for determining a first local fusion model according to an embodiment of this specification;
[0025] Figure 7 The figure is a flow chart of a method for determining a third local fusion model according to an embodiment of the present specification;
[0026] Figure 8a Shown is a schematic diagram of a topological structure applied to a weighted average algorithm according to an embodiment of this specification;
[0027] Figure 8b Shown is a schematic diagram of a topological structure applied to a task algorithm according to an embodiment of this specification;
[0028] Figure 8c It is a schematic diagram of a topological structure applied to the inter-layer AdaMerging algorithm according to an embodiment of this specification;
[0029] Fig. 9 The figure shows a schematic diagram of the structure of a model fusion device based on a topological structure according to an embodiment of the present specification;
[0030] Fig.10 The figure shows a storage peak value comparison schematic diagram of an embodiment of this specification;
[0031] Fig.11 The figure shows a schematic diagram of the structure of a computer device according to an embodiment of the present specification.
[0032] Description of the accompanying symbols:
[0033] 901. Determine the unit;
[0034] 902. Local fusion model determination unit;
[0035] 903, multi-task model determination unit;
[0036] 1102. Computer equipment;
[0037] 1104. Processor;
[0038] 1106. Memory;
[0039] 1108. Driving mechanism;
[0040] 1110, input / output module;
[0041] 1112. Input device;
[0042] 1114. Output device;
[0043] 1116. Presentation equipment;
[0044] 1118. Graphical user interface;
[0045] 1120. Network interface;
[0046] 1122. Communication link;
[0047] 1124. Communication bus. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0049] It should be noted that the terms "first", "second", etc. in the description and claims of this specification and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of this specification described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or equipment that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0050] This specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on routine or non-creative work. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the system or device product is executed in practice, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel.
[0051] It should be noted that the model fusion method, device and computer equipment based on topological structure in this specification can be used in the field of machine learning technology, and can also be used in the field of artificial intelligence technology. This specification does not limit the application field of the model fusion method, device and computer equipment based on topological structure.
[0052] In the field of artificial intelligence and machine learning, model fusion or model ensemble is a strategy to improve the overall prediction performance by combining the prediction results of multiple models. The basic idea of this strategy is to use the "collective wisdom" of multiple models to obtain better prediction results than any single model. Model fusion technology can be divided into parameter-level fusion and prediction-level fusion, where parameter-level fusion refers to combining the parameters of multiple models, while prediction-level fusion refers to combining the prediction results of multiple models. With the rapid growth of data volume and the improvement of computing power, multi-model fusion technology will play an increasingly important role in future artificial intelligence systems.
[0053] Figure 1 The flowchart of a model fusion method based on topological structure in an embodiment of this specification is shown, which specifically includes the following steps:
[0054] Step 101 : construct a topological structure, and determine the object to be integrated deployed in each node in the topological structure, wherein the topological structure includes a plurality of nodes, and each node corresponds to a device.
[0055] In this step, construct Figures 8a to 8c The topology shown in the figure can be applied to computer networks or communication systems. The topology shown in the figure is a ring topology, which includes multiple nodes, and each node is deployed with a device, so each node corresponds to each device. Figures 8a to 8c As shown, there are multiple circles in the topology structure, each circle represents a node in the topology structure, and each node represents a device, where the device can be a GPU or a terminal device, and the device in the node is used to receive, parse, and forward data. Furthermore, each circle in the topology structure can have a different color, and nodes of different colors represent different devices. Each device stores the object to be fused, and the object to be fused will participate in model fusion in the subsequent process.
[0056] In this specification, the device in each node is deployed with a corresponding object to be fused, and the object to be fused in each node can be merged with the object to be fused in the device of the adjacent node to achieve local merging or local fusion in the topological structure. In the embodiment of this specification, the object to be fused is a model or task vector to be merged. Among them, the model to be merged can be regarded as an initial fine-tuning model when it is stored in the node. Specifically, each initial fine-tuning model to be merged is placed in a separate device, and these devices are linked through a ring topology structure so that each device can only communicate with two adjacent devices. In each update, the model on each device is only locally fused with the model on the adjacent device, thereby ensuring that the number of models stored on each device does not exceed 3 at most (if pre-trained models are included, no more than 4). This local fusion process stops after a limited number of rounds, and eventually the models on each device will converge and converge to form the final merged model.
[0057] In some embodiments of this specification, the following can be deployed: Figures 8a to 8c The topology shown may also be deployed in a star, mesh, graph, hierarchical or other form of topology. The present application does not specifically limit the form of the topology composed of multiple nodes.
[0058] Step 102, according to the model fusion algorithm, the objects to be fused deployed in multiple nodes within a preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merging and iteration of all nodes in the topological structure.
[0059] In this step, the devices in the nodes in the topology structure can communicate with each other. In the embodiments of this specification, in order to reduce storage requirements and improve hardware efficiency, and reduce dependence on hardware resources, a preset node range can be set, wherein the preset node range is used to determine the range for local fusion. Specifically, the preset node range refers to the node where the object to be fused is located and the nodes adjacent to the node. Figures 8a to 8c In the topology shown, a device on one node can communicate with devices on two adjacent nodes, and during the communication process, model parameters of the models deployed in their respective devices are transmitted to each other.
[0060] Furthermore, after the objects to be fused deployed in the devices of each node are merged once, each node calculates the parameters of the objects to be fused in the current node and the adjacent nodes to obtain a merged model, which can be called a local fusion model after a merge iteration. The local fusion model is used as the new model deployed in the current node and continues to participate in the next merge iteration until the merge iteration stop condition is met.
[0061] Step 103, when the coefficients of the local fusion models generated after multiple merging iterations of each node are consistent, it is determined that the local fusion models corresponding to each node are merged to obtain multiple multi-task models in the topological structure.
[0062] In this step, local fusion requires multiple rounds of iterations to achieve global consistency. After each node performs multiple merging iterations for local fusion, if it is determined that the local fusion models of all nodes in the topological structure have converged and the coefficients before all local fusion models are consistent, then it is determined that the local fusion models corresponding to all nodes in the topological structure have been merged, and the merging iterations are stopped to form the final new fusion model. The fusion model finally stored in each node has a strong generalization ability and can improve the overall prediction performance.
[0063] This manual reduces the need for large amounts of storage (especially video memory), reduces the time cost of parameter adjustment, and improves the effect and generalization ability of model fusion to adapt to the growing data processing needs and improve the performance of artificial intelligence systems.
[0064] Figure 2 The flowchart of a method for merging and iterating objects to be merged deployed by each node according to an embodiment of the present specification is shown, which specifically includes the following steps:
[0065] Step 201: determine a node in the topology structure as a node to be merged.
[0066] Model fusion improves the overall prediction performance by combining the prediction results of multiple models. In this step, each device deployed in each node in the topology structure stores an initial model in the initial state, and each initial model needs to be merged, so each node can be called a node to be fused.
[0067] Step 202: taking the neighboring nodes of the node to be fused in the topological structure as the local fusion nodes of the node to be fused.
[0068] Figure 8a FIG. 1 is a schematic diagram of a topological structure applied to a weighted average algorithm in an embodiment of this specification. The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as The local fusion node of the node. The initial fine-tuned model of each node is transmitted during the communication between adjacent nodes. .
[0069] Figure 8b FIG. 1 is a schematic diagram of a topological structure applied to a task algorithm in an embodiment of this specification. The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as The local fusion node of the node. The product of the task vector of each node and the second weight is transmitted during the communication between adjacent nodes. .
[0070] Figure 8c FIG. 1 is a schematic diagram of a topological structure applied to an inter-layer AdaMerging algorithm according to an embodiment of this specification. The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as The local fusion node of the node. The product of the task vector of each node and the third weight is transmitted during the communication between adjacent nodes. In this specification, the inter-layer AdaMerging algorithm may also be referred to as the AdaMerging algorithm.
[0071] Step 203 : Iteratively merge the objects to be merged of the nodes to be merged and the objects to be merged of the local fusion nodes.
[0072] In this specification, the weight averaging method, task algorithm or task arithmetic method and inter-layer AdaMerging method can be used to merge and iterate the objects to be merged of the fusion node and the objects to be merged of the local fusion node of the fusion node. For different fusion methods, the specific objects to be merged of the fusion node are also different. For details, see Figures 3 to 5 describe.
[0073] Task arithmetic and weight averaging are widely used as model fusion methods to improve the generalization ability and performance of models, and mainly rely on direct operations on model parameters. Among them, weight averaging achieves model fusion by calculating the average value of multiple model parameters. Specifically, each model parameter is assigned different weights according to its performance or confidence, and then the weighted average is calculated to form the final fusion model.
[0074] Task Arithmetic adjusts the behavior of the pre-trained model through task vectors, where the task vector represents the weight change from the pre-trained model to the model after fine-tuning for a specific task. Specifically, these task vectors are combined through simple arithmetic operations (such as addition, subtraction, and negation) to achieve precise control of model behavior.
[0075] Figure 3 The flowchart of a method for determining an object to be merged of each node in a topological structure according to an embodiment of the present specification is shown, which specifically includes the following steps:
[0076] Step 301 , configure multiple devices and deploy each device in a node in the topology structure.
[0077] Different from the traditional method, loading all the models that need to be fused onto a single device at the same time will lead to a sharp increase in the peak demand for storage resources. This manual deploys each device independently on a node to reduce the consumption of storage resources of a node and ensure the storage and computing power of the node.
[0078] Step 302: store an object to be fused in each node, the object to be fused includes: at least one of an initial fine-tuning model or a task vector. When the Weight Averaging method is used to merge and iterate each node, the object to be fused of the node to be fused is the initial fine-tuning model; when the Task Arithmetic method is used to merge and iterate each node, the object to be fused of the node to be fused is the task vector; when the inter-layer AdaMerging method is used to merge and iterate, the object to be fused of the node to be fused is the initial fine-tuning model.
[0079] Figure 4 The flowchart of a method for merging iterations using a weighted average algorithm according to an embodiment of the present specification is shown, which specifically includes the following steps:
[0080] Step 401 : Based on a weight algorithm, the same first initial weight is assigned to the initial fine-tuning model of each node.
[0081] In this specification, the weight averaging algorithm (Weight Averaging) assigns the same initial weight to the initial fine-tuning models in all nodes before the merging iteration begins, and the initial weight is recorded as the first initial weight.
[0082] Step 402: According to the first initial weight, the initial fine-tuning model of the node to be fused and the initial fine-tuning model of the local fusion node are merged and iterated to obtain a merged first local fusion model.
[0083] The merging formula of simple Weight Averaging is: , Indicates the local fusion model. In this specification, k is designed to be 3, and after the merging starts, the initial fine-tuned model on each device can only be merged with the initial fine-tuned model on the adjacent device.
[0084] For example, in Figure 8a In the topology shown, the formula for local merging is: ,in, represents the initial fine-tuned model in node i, represents the initial fine-tuned model in the neighboring node i-1 of node i, represents the initial fine-tuned model in the neighboring node i+1 of the node i, Represents the new local fusion model obtained by node i after the first round of local fusion. The new local fusion model will replace the original initial fine-tuning model on the device of node i .
[0085] After repeated rounds of merging iterations, the models on each device converge to the final merged model, i.e. , where n is the number of combined iterations of the entire algorithm, represents the local fusion model on node i after the nth round of local fusion, Represents a multi-task model. At this point, the parameters of the model on all devices of all nodes are consistent and also converge to the naive coefficient.
[0086] Figure 5 The flowchart of a method for merging iterations using a task algorithm is shown in an embodiment of this specification. This method is applicable to the Task Arithmetic algorithm and specifically includes the following steps:
[0087] Step 501, determine a preset number of merging iterations.
[0088] In this step, an estimated number of merge iterations (assuming it is n) is pre-set to guide the task algorithm to perform local merges according to the preset number of merge iterations. In subsequent steps, the number of merge iterations needs to be further adjusted according to the results of local merges until the coefficients corresponding to the model in the device of each node converge and remain consistent after the merge iteration using the task algorithm.
[0089] In this specification, Task Arithmetic adjusts the behavior of the pre-trained model through task vectors. Task vectors represent the weight changes from the pre-trained model to the model after fine-tuning for a specific task. These task vectors are combined through simple arithmetic operations (such as addition, subtraction, and negation) to achieve precise control of the model behavior.
[0090] Step 502: determine whether the second weights corresponding to the task vectors of all nodes after the preset merging iteration are substantially consistent.
[0091] In this step, the coefficients corresponding to the models on all devices of each node are consistent and converge to the naive coefficients, which is the condition for ending the merging iteration using the task vector algorithm. Therefore, in step 501, after the preset number of merging iterations using the task vector algorithm, it is calculated whether the coefficients corresponding to the task vectors of each node are consistent.
[0092] In this specification, the naive Task Arithmetic merging formula is as follows:
[0093] ;in, represents the fine-tuning model, represents the pre-trained model, represents the fusion model, and K represents the number of nodes for local fusion. In order to simplify the calculation, this manual removes the constant term when using the task vector algorithm for local merging. , only the task vector is merged. After n merging iterations, the model converges and the constant term is Add back the model.
[0094] In this step, first
[0095] , represents the fine-tuned model minus the pre-trained model, This can be called a task vector.
[0096] In the method of this specification, a merge iteration is performed on the i-th node.
[0097] For example, the task vector of the first merge iteration of the i-th node can be as follows:
[0098] ;
[0099] The task vector of the i-th node after the n-th merge iteration can be as follows:
[0100] .
[0101] In this specification, a topology with 5 nodes and corresponding 5 models is used as an example, and the merging formula for determining the naive task algorithm is as follows:
[0102] ;
[0103] Among them, the task vector is defined as: ;in, represents the initial fine-tuned model in node i, represents the pre-trained model, Represents the manually adjusted model merging coefficient.
[0104] In this manual, the initial fine-tuning model in each node is converged to , the formula for the corresponding node i after n merge iterations is:
[0105] ; In the formula Compared with the above formula are not equivalent. The task vector corresponding to the first node Take it as an example, the merge iteration process is as follows:
[0106] Step 1: In the initial state, when no iterative merging is performed:
[0107] Among them, Figure 8bAs an example of the topological structure in, the task vector and is the task vector The task vector to be fused.
[0108] Step 2: After the first iterative merge, the task vector after the local iterative merge of the first node is as follows:
[0109] ;
[0110] Step 3: Perform the second iterative merge. The task vector after the local iterative merge of the first node is as follows:
[0111]
[0112] = + ;
[0113] = + ;
[0114] + + +2 ;
[0115] Step 30: The task vector after local iteration and merging of the first node is as follows:
[0116]
[0117] When n is large enough, + . Currently n is 30, that is, According to the simple Task Arithmetic formula: Therefore, we hope that = ,even though The coefficients of each task vector in Therefore, the maximum difference in coefficients of the task vector after 29 iterations of merging is further calculated as follows:
[0118] It can be seen that the difference is extremely small and further decreases with iteration. Therefore, it can be determined that after 29 iterations, the second weights corresponding to the task vectors of the nodes in the embodiment of this step are basically the same, and the merging formula of the naive Task Arithmetic can be achieved.
[0119] Step 503: If yes, perform coefficient conversion according to the second weight, the preset number of merge iterations and the coefficients corresponding to the task vectors of each node in the naive task algorithm to determine the value of the second weight.
[0120] In this specification, the merging coefficient and the unification coefficient in the simple Task Arithmetic formula are different, but the two can be converted to each other. Taking the embodiment in step 502 as an example, after executing the preset merging iterations, the obtained The coefficients corresponding to all task vectors in the formula are unified as , and used as a uniform coefficient.
[0121] Further let the unification coefficient be the same as the merging coefficient in the naive Task Arithmetic formula, that is: ;when When 0.3 is taken, k is calculated , thus completing the coefficient conversion and determining the specific value of the unified coefficient.
[0122] Step 504: If not, update the preset number of merge iterations, continue to perform merge iterations, and repeat the determination step.
[0123] If after executing step 502, it is determined that the coefficients corresponding to the task vectors of all nodes after the preset number of merge iterations are inconsistent, it means that the current number of merge iterations cannot make the models of each node converge, and the models in each node have not achieved the expected prediction effect. Therefore, it is necessary to increase the number of merge iterations and control each node to continue the merge iteration.
[0124] Step 505: Determine the second local fusion model of the current node according to the second weight. In this step, after the second weight is determined after n rounds of iterations, the constant term Adding it back to the model, we finally get Fusion model, which combines multiple fine-tuned models into a multi-task model.
[0125] Figure 6 The flowchart of a method for determining a third local fusion model according to an embodiment of the present specification is shown, which specifically includes the following steps:
[0126] Step 601 : assigning a third initial weight to the task vector of each node based on the inter-layer AdaMerging algorithm.
[0127] The inter-layer AdaMerging algorithm uses unlabeled data to continuously update the model merging coefficient during the merging process, thereby determining the optimal model merging coefficient. Since the use of inter-layer AdaMerging to update the model merging coefficient requires an inference model, the entire merging process must use the GPU. In order to minimize the peak memory of each device, each device in each node stores a different fine-tuned model in the initial state. , and store a pre-trained model at the same time .
[0128] The inter-layer AdaMerging algorithm formula is as follows:
[0129] ;in, Represents the set of all training data; represents a multi-task model, represents the initial fine-tuning model of node i. For the initial fine-tuning model on k nodes , each model is in the corresponding dataset Fine-tune, use N initial fine-tuned models to construct a new model by merging models , so that it is in all test sets Good performance.
[0130] When using a ring topology, each device communicates only with two adjacent devices, passing each other's model parameters. (No need to pass In this way, even if a large number of models need to be merged in one merging iteration, the peak memory of each device will not exceed 4, which greatly reduces the hardware requirements during the merging process and increases the use scenarios of model merging.
[0131] Step 602, using the third initial weight, according to the information entropy loss function, the pre-trained model, the task vector of the node to be fused, and the task vector of the local fusion node are merged and iterated to obtain a merged third local fusion model.
[0132] In this specification, the information entropy function is used to merge and iterate each node. The information entropy loss function in this specification replaces the traditional loss function, and the formula of information entropy is as follows:
[0133] ;in represents the i-th sample predicted by the initial fine-tuning model The probability of belonging to category c. Information entropy is used to measure the uncertainty of model predictions.
[0134] In this specification, during each round of merging iteration, the fusion coefficient α of the model is automatically determined and changed. The local merging formula for each round is as follows:
[0135] ; represents the pre-trained model, represents the initial fine-tuned model in node i, represents the task vector of node i, represents the task vector of node i+1, Represents the task vector of node i-1.
[0136] In this specification, the optimization goal of inter-layer AdaMerging is to minimize information entropy. In each iteration, the inter-layer AdaMerging algorithm uses a small amount of unlabeled data to calculate the gradient of the fusion coefficient α using stochastic gradient descent (SGD) to update the fusion coefficient α of the model. In this way, the optimal model merging coefficient is determined, and then the merging operation is performed to replace the model with the new model. The merging iteration is repeated n times. When n is large enough, the models on all devices will converge and unify the parameters. At this time, the model on any device can be used as the final model output. Improve the generalization ability of the final model.
[0137] Figure 7 The flowchart of a method for determining a first local fusion model in an embodiment of this specification is shown. In this specification, local fusion requires multiple rounds of iterations to achieve global consistency. When globally consistent, the weights or coefficients of the current local fusion models on all devices need to be consistent. Therefore, when using different algorithms for local fusion, it is necessary to further determine whether the weights or parameters corresponding to the local models are consistent. This method specifically includes the following steps:
[0138] Step 701, determine whether the weights corresponding to the first local fusion model after merging and iterating each node are consistent. Figure 8a As shown, after each merging iteration is completed, it is determined whether the weights corresponding to the first local fusion models of all nodes in the topological structure are the same according to the first local fusion models currently formed by each node.
[0139] In this specification, when multiple merging iterations are completed and the first local fusion models corresponding to all nodes in the topological structure are converged, the weights of all the first local fusion models are substantially the same.
[0140] Step 702: If yes, determine that the first local fusion model is merged and completed, and obtain multiple first local fusion models in the topological structure. If they are consistent, determine to use the weighted average algorithm to complete the model fusion of all nodes in the topological structure. At this point, the current local fusion model in each node has become a multi-task model, which can be used to process complex tasks.
[0141] Step 703, determine whether the weights corresponding to the third local fusion model after merging and iterating each node are consistent. Figure 8c As shown, after each merging iteration is completed, it is determined whether the weights corresponding to the third local fusion models of all nodes in the topological structure are the same according to the third local fusion model currently formed by each node.
[0142] In this specification, when multiple merging iterations are completed and the third local fusion models corresponding to all nodes in the topological structure are converged, the weights of all the third local fusion models are substantially the same.
[0143] Step 704: If yes, determine that the third local fusion model is merged and completed, and obtain multiple third local fusion models in the topological structure. If they are consistent, determine to use the weighted average algorithm to complete the model fusion of all nodes in the topological structure. At this point, the current local fusion model in each node has become a multi-task model, which can be used to process complex tasks.
[0144] In order to verify the effectiveness of this scheme, the implementation of design Table 1 to Table 4 is adopted.
[0145] Table 1 is a multi-task performance table of merging 8 corresponding initial fine-tuning models on 8 image classification tasks. The right part of the first row in the table shows 8 different datasets, namely SUN397, Cars, RESISC45, EuroSAT, SVHN, GTSRB, MNIST, and DTD, corresponding to 8 different initial fine-tuning models fused on these 8 different datasets. The "reference method" row in the table shows that without model fusion, the prediction accuracy of each initial pre-trained model on each dataset is 63.2, 59.8, and 60.7, etc., which shows that the prediction accuracy is not high. The initial fine-tuning model can only perform well on its corresponding fine-tuning dataset, but performs poorly on other datasets.
[0146] The “Multi-task Model Fusion Methods” row in Table 1 uses the conventional model fusion method to obtain the prediction results of each initial fine-tuned model on 8 image classification tasks after local fusion. The “Multi-task Model Fusion Methods with Memory Efficient Merging” row in Table 1 shows the prediction accuracy after constant storage peak using three algorithms using the method in this manual. The model performs the image classification prediction task. The results in the table are the image classification prediction accuracy results. After 20 iterations of each algorithm, the initial fine-tuned model on each node becomes a fusion model. From Table 1, it can be seen that the prediction results of Weight Averaging w / MEM and Task Arithmetic w / MEM on 8 image classification tasks are very close to the prediction values of the naive weight averaging method and naive task arithmetic. If the number of iterations continues to increase, the gap between the prediction results of Weight Averaging w / MEM and Task Arithmetic w / MEM on 8 image classification tasks and the prediction results of the naive weight averaging method and naive task arithmetic will be further reduced. Therefore, the model parameters of the multi-task model on the device where the SUN397 fine-tuned model is initially stored can be output as the final result.
[0147] In addition, inter-layer AdaMerging w / MEM improves the results by 0.9% compared to naive AdaMerging.
[0148] Table 1
[0149]
[0150] Table 2 shows that after multiple merging iterations, the initial fine-tuning model stored in each of the 8 nodes (node 1, node 2...node 8) is the fine-tuning model corresponding to the 8 image classification tasks. After multiple merging iterations, the prediction accuracy of the fusion models in the 8 nodes on 8 different data sets (SUN397, Cars, RESISC45, EuroSAT, SVHN, GTSRB, MNIST, DTD) is basically consistent, so it can be considered that the fusion models in each node have basically converged, and any of the fusion models can be used as the final output result.
[0151] Table 2
[0152]
[0153] Since the inter-layer AdaMerging w / MEM cannot predetermine the final merging coefficient like the other two algorithms, more experiments are designed in this specification to demonstrate the prediction effect of inter-layer AdaMerging w / MEM, as shown in Table 3. Table 3 is a table of merging models on six image recognition tasks using the inter-layer AdaMerging w / MEM algorithm to perform the generalization effect of two unseen tasks.
[0154] Table 3: Merging CLIP-ViT-B / 32 models on 6 tasks
[0155]
[0156] In the first generalization task, inter-layer AdaMerging w / MEM outperforms inter-layer AdaMerging in both Seen Tasks and Unseen Tasks by 1.7% and 2.8% respectively. In the second generalization task, the accuracy of inter-layer AdaMerging w / MEM decreases slightly, but overall it remains at the same level as inter-layer AdaMerging.
[0157] In the robustness task test (see Table 4), 7 damaged test data sets were created, namely: Motion Blur, Impulse Noise, Gaussian Noise, Pixelate, Spatter, Contrast and JPEG Compression. The inter-layer AdaMerging w / MEM algorithm can maintain comparable accuracy with the inter-layer AdaMerging algorithm in most tasks. At the same time, in the three tasks of Motion Blur, Contrast and Compression, the inter-layer AdaMerging w / MEM leads the inter-layer AdaMerging by 0.7%, 0.7% and 0.6% respectively.
[0158] The above results fully prove that the method in this manual can be applied to three models: weight averaging, task arithmetic and inter-layer AdaMerging.
[0159] Table 4: Robustness results of the combined CLIP-ViT-B / 32 model on four tasks
[0160]
[0161] During the model fusion process, the number of models stored on each device will not exceed 4. In the task of merging 8 models, the original AdaMerging algorithm will store 9 models in the video memory. In comparison, this solution reduces the peak video memory for inter-layer AdaMerging by nearly 60%, greatly reducing the hardware requirements. This specification reduces the reliance on hardware resources by reducing storage requirements and improving hardware efficiency. It is suitable for storage-constrained scenarios such as edge devices and GPUs with limited video memory, and promotes the widespread deployment and technological innovation of model fusion technology in practical applications.
[0162] Figures 8a to 8c Shown are schematic diagrams of three topological structures of the embodiments of this specification.
[0163] The nodes of different colors in the figure represent different devices (which can be GPUs or client-side devices). , ,T_i represents the initial fine-tuning model, the pre-training model and the task vector, respectively, where For the task algorithm and the inter-layer AdaMerging algorithm, it is also necessary to assign an initial merging weight to each model. .
[0164] Figure 8a In The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as Local fusion node of nodes.
[0165] Figure 8b In The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as Local fusion node of nodes.
[0166] Figure 8c In The node is the node to be fused, and its adjacent nodes in the topology structure are and , will soon and Node as The local fusion node of the node. The node is the node to be fused, and its adjacent nodes in the topology structure are and , you can and Node as The local fusion node of the node. The product of the task vector of each node and the third weight is transmitted during the communication between adjacent nodes. .
[0167] This solution builds a ring topology structure to achieve local fusion of each device with at most two adjacent devices, thereby ensuring a constant storage peak and significantly reducing storage requirements. It not only improves storage efficiency but also ensures the efficiency of the model fusion process and the convergence of the final model through a limited number of rounds of updates.
[0168] Fig. 9 The figure shows a schematic diagram of a topology-based model fusion device according to an embodiment of the present specification. The figure describes the basic structure of the topology-based model fusion device, in which the functional units and modules can be implemented in software, or a general chip or a specific chip can be used to implement the topology-based model fusion. The device specifically includes:
[0169] A determination unit 901 is used to construct a topology structure and determine an object to be integrated deployed in each node in the topology structure, wherein the topology structure includes multiple nodes, and each node is connected to a device;
[0170] The local fusion model determination unit 902 is used to merge and iterate the objects to be merged deployed in multiple nodes within a preset node range in the topological structure according to the model fusion algorithm to obtain a local fusion model generated after each merging and iteration of all nodes in the topological structure;
[0171] The multi-task model determination unit 903 is used to determine the local fusion model corresponding to each node to complete the merging when the coefficients of each local fusion model generated after multiple merging iterations of all nodes are consistent, so as to obtain multiple multi-task models in the topological structure.
[0172] Fig.10 Shown is a storage peak comparison schematic diagram of an embodiment of this specification. Fig.10 The theoretical storage peak comparison of the two model fusion methods is shown in Figure 2. The advantage of the constant storage peak model fusion method proposed in this scheme will continue to increase with the increase in the number of model fusions.
[0173] like Fig.11 As shown, it is a schematic diagram of a computer device provided by an embodiment of this specification. The model fusion method based on topology structure described in this application can be applied to the computer device. The computer device 1102 may include one or more processors 1104, such as one or more central processing units (CPUs), and each processing unit may implement one or more hardware threads. The computer device 1102 may also include any memory 1106, which is used to store any kind of information such as code, settings, data, etc. Non-limiting, for example, the memory 1106 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory device, hard disk, optical disk, etc. More generally, any memory can use any technology to store information. Further, any memory can provide volatile or non-volatile retention of information. Further, any memory can represent a fixed or removable component of the computer device 1102. In one case, when the processor 1104 executes an associated instruction stored in any memory or a combination of memories, the computer device 1102 can perform any operation of the associated instruction. The computer device 1102 also includes one or more drive mechanisms 1108 for interacting with any storage, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.
[0174] The computer device 1102 may also include an input / output module 1110 (I / O) for receiving various inputs (via input devices 1112) and for providing various outputs (via output devices 1114). A specific output mechanism may include a presentation device 1116 and an associated graphical user interface (GUI) 1118. In other embodiments, the input / output module 1110 (I / O), input device 1112, and output device 1114 may not be included, and the computer device 1102 may be used as a computer device in a network. The computer device 1102 may also include one or more network interfaces 1120 for exchanging data with other devices via one or more communication links 1122. One or more communication buses 1124 couple the components described above together.
[0175] The communication link 1122 may be implemented in any manner, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 1122 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.
[0176] Corresponds to Figures 1 to 7 The method in the embodiment of the present specification also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are executed.
[0177] The embodiment of the present specification also provides a computer-readable instruction, wherein when the processor executes the instruction, the program therein causes the processor to execute the following Figures 1 to 7 The method shown.
[0178] It should be understood that in the various embodiments of this specification, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this specification.
[0179] It should also be understood that in the embodiments of this specification, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this specification generally indicates that the associated objects before and after are in an "or" relationship.
[0180] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this specification can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this specification.
[0181] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0182] In the several embodiments provided in this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.
[0183] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of this specification.
[0184] In addition, each functional unit in each embodiment of this specification may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0185] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this specification is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of this specification. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0186] Specific embodiments are used in this specification to illustrate the principles and implementation methods of this specification. The description of the above embodiments is only used to help understand the methods and core ideas of this specification. At the same time, for those skilled in the art, according to the ideas of this specification, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on this specification.
Claims
1. A model fusion method based on topological structure, characterized in that: The method comprises: Constructing a topological structure, and determining an object to be integrated deployed in each node in the topological structure, wherein the topological structure includes a plurality of nodes, and each node corresponds to a device; According to the model fusion algorithm, the objects to be fused deployed in multiple nodes within a preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merging and iteration of all nodes in the topological structure; When the coefficients of the local fusion models generated after multiple merging iterations of all nodes are consistent, the local fusion models corresponding to each node are determined to complete the merger, and multiple multi-task models in the topological structure are obtained.
2. The method according to claim 1, characterized in that According to the model fusion algorithm, merging and iterating the objects to be fused deployed in multiple nodes within a preset node range in the topological structure includes: Select a node in the topological structure as the node to be merged; Using the neighboring nodes of the node to be fused in the topological structure as local fusion nodes of the node to be fused in a preset node range; The objects to be fused of the nodes to be fused and the objects to be fused of the local fusion nodes are merged and iterated.
3. The method according to claim 2, characterized in that Constructing a topological structure, and determining the objects to be integrated deployed in each node in the topological structure includes: Configure multiple devices and deploy each device in a node in the topology; An object to be fused is stored in each node, and the object to be fused includes at least one of an initial fine-tuning model or a task vector.
4. The method according to claim 3, characterized in that When the model fusion algorithm is a weighted average algorithm, the object to be fused of each node is the initial fine-tuning model. According to the model fusion algorithm, the objects to be fused deployed in multiple nodes within a preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merging iteration of all nodes in the topological structure, including: Based on the weighted average algorithm, the same first initial weight is assigned to the initial fine-tuning model of each node; According to the first initial weight, the initial fine-tuning model of the node to be fused and the initial fine-tuning model of the local fusion node are merged and iterated to obtain a merged first local fusion model.
5. The method according to claim 3, characterized in that: When the fusion algorithm is a task algorithm, the object to be fused of each node is a task vector. According to the model fusion algorithm, the objects to be fused deployed in multiple nodes within a preset node range in the topological structure are merged and iterated to obtain a local fusion model generated after each merging iteration of all nodes in the topological structure, including: Determine the preset number of merge iterations; Determine whether the second weights corresponding to the task vectors of all nodes after the preset merge iteration are substantially consistent; If so, performing coefficient conversion according to the second weight, the preset number of merge iterations, and the coefficients corresponding to the task vectors of each node in the naive task algorithm to determine the value of the second weight; If not, update the preset number of merge iterations, continue to merge iterations, and repeat the judgment step; A second local fusion model of the current node is determined according to the second weight.
6. The method according to claim 5, characterized in that After each node undergoes a preset round of merging iterations, the method further includes: Determine whether the weights corresponding to the first local fusion model after merging and iterating each node are consistent; If so, it is determined that the first local fusion model is merged and completed, and a fusion model in the topological structure is obtained.
7. The method according to claim 3, characterized in that When the model fusion algorithm is the inter-layer AdaMerging algorithm, the objects to be fused of each node are the pre-trained model and the task vector. According to the model fusion algorithm, the objects to be fused deployed by each node are merged and iterated, and the local fusion model of each node after each merge iteration is obtained, including: Based on the inter-layer AdaMerging algorithm, the third initial weight is assigned to the task vector of each node; Using the third initial weight, the pre-trained model, the task vector of the node to be fused, and the task vector of the local fusion node are merged and iterated according to the information entropy loss function to obtain a merged third local fusion model.
8. A model fusion device based on topological structure, characterized in that: The device comprises: A determination unit, configured to construct a topology structure and determine an object to be integrated deployed in each node in the topology structure, wherein the topology structure includes a plurality of nodes, and each node corresponds to a device; A local fusion model determination unit is used to merge and iterate the objects to be fused deployed in multiple nodes within a preset node range in the topological structure according to a model fusion algorithm to obtain a local fusion model generated after each merging and iteration of all nodes in the topological structure; The fusion model determination unit is used to determine the local fusion models corresponding to each node to complete the merging when the coefficients of the local fusion models generated after multiple merging iterations of all nodes are consistent, so as to obtain multiple multi-task models in the topological structure.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Model calculation method, device and equipment
CN115965065A
Network-centric architecture and algorithms to accelerate distributed training of neural networks
US20210374503A1
Model training method and face recognition method based on adaptive split learning-federated learning
WO2023185485A1
Cited By
Water conservancy multi-model coupling parallel architecture design method
CN120951607A
A water conservancy multi-model coupling parallel architecture design method
CN120951607B