Large model training data filtering method and device, equipment and medium
By constructing a k-nearest neighbor graph and selecting nodes with high diversity representation scores, efficient pruning of large language model training data sets is achieved, solving the problem of high computational cost in the existing technology and reducing the computational load of the data set reduction process. , and maintains performance in LLM training.
Patent Information
- Application Number
- CN202410833803.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-18
Smart Images

Figure CN118797296A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data compression, and in particular relates to a large model training data filtering method, device, equipment and medium. Background Art
[0002] Large Language Models (LLMs) have significantly pushed the boundaries of machine language understanding. However, the sheer size of instruction-tuning datasets used to fine-tune them significantly increases the expense of LLM development.
[0003] Large language models can master a wide range of language, coding and even mathematical skills, thanks to the expansion of the model itself, computing power and training data sets. For example, the OPT-175B report used 992 A100 GPUs for pre-training; the OPT-IML model generated by fine-tuning its instructions required 128 A100 GPUs and 72 hours of training time.
[0004] Therefore, as large language models (LLMs) and their datasets continue to grow, the challenge of inefficient and costly training becomes more and more pressing. Although there are some existing data pruning methods including data distillation, core set selection and active learning, they are not convenient for instruction tuning of LLMs. On the one hand, distillation and active learning based methods are usually computationally intensive during the pruning process. For example, the entire training trajectory of the model on the full dataset is required as supervision to distill the dataset. On the other hand, although the core set selection methods originally designed for computer vision are usually efficient, recent studies have shown that these methods are not actually always better than random selection as the proportion of the selected subset increases. In addition, data distillation aims to synthesize a small number of samples to replace the original dataset. In a large number of works on data distillation, important features of the model during training on the full dataset are queried and matched. These features include soft labels, gradients, training trajectories, and dataset feature distributions. Although these methods perform well, they are usually computationally expensive and need to be implemented for specific models.
[0005] In summary, the existing data pruning and filtering methods need to be combined with the training process for inference calculation, and there is a problem of high computational cost that needs to be solved. Summary of the invention
[0006] In view of the above analysis, the embodiments of the present invention aim to provide a large model training data filtering method, device, equipment and medium to solve the problem of high computational cost in data filtering in the prior art.
[0007] The first embodiment of the present invention provides a large model training data filtering method, comprising the following steps:
[0008] S1. Obtain an original training data set, and convert samples in the original training data set into embedding vectors;
[0009] S2. Perform a k-nearest neighbor search on all embedded vectors to construct a k-nearest neighbor graph of the original training dataset.
[0010] S3. Select a subset from the k-nearest neighbor graph, and use the samples included in the subset as the filtered training data set. The method of selecting the subgraph includes:
[0011] S31, calculating the diversity representativeness score of all nodes that are not added to the subset;
[0012] S32, selecting the node with the highest diversity representativeness score to add to the subset;
[0013] S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
[0014] In some embodiments, the calculation of the diversity representativeness score is expressed as:
[0015] X=AB, where X represents the diversity representative score of the target node, A represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and do not belong to the subset, and B represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and belong to the subset.
[0016] In some embodiments, the k-nearest neighbor graph is constructed using the Faiss library or the Raft algorithm.
[0017] In some embodiments, the filtered training data set is used for training in the large model instruction tuning phase.
[0018] In some embodiments, the method is applied in an interstitial manner to the training of a downstream model.
[0019] A second aspect of the present invention provides a large model training data filtering device, comprising:
[0020] A conversion module, used to obtain an original training data set and convert samples in the original training data set into embedding vectors;
[0021] KNN building module, which performs k-nearest neighbor search on all embedding vectors to build the k-nearest neighbor graph of the original training dataset;
[0022] A filtering module selects a subset from the k-nearest neighbor graph and uses the samples contained in the subset as a filtered training data set. The method of selecting the subgraph includes:
[0023] S31, calculating the diversity representativeness score of all nodes that are not added to the subset;
[0024] S32, selecting the node with the highest diversity representativeness score to add to the subset;
[0025] S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
[0026] A third aspect of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the large model training data filtering method as described in any of the above embodiments is implemented.
[0027] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the large model training data filtering method as described in any of the above embodiments is implemented.
[0028] The above embodiments of the present invention have at least the following beneficial effects:
[0029] 1. The embodiment of the present invention constructs a k-nearest neighbor graph (KNN graph) for the samples in the original training data set, and then cuts the KNN graph through a greedy algorithm, that is, pruning the original training data set, and through the calculation of diverse representative scores, the pruned data set can achieve diverse representation of the characteristics of the original training data set.
[0030] 2. The embodiment of the present invention is a general and computationally efficient pruning method for a data set, which avoids the need for full data set training and maintains the effectiveness of data training while reducing compression costs.
[0031] 3. The embodiment of the present invention can be deployed on a GPU to process a data set of millions of samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] 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 recorded in the embodiments of this specification. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0033] Figure 1 Schematic diagram of the process of filtering large model training data provided by the embodiment of the present invention Figure 1 ;
[0034] Figure 2 Schematic diagram of the method flow provided by the embodiment of the present invention Figure 2 ;
[0035] Figure 3 A schematic diagram of the architecture of a large model training data filtering device provided in an embodiment of the third aspect of the present invention;
[0036] Figure 4 A schematic diagram of an electronic device architecture provided for an embodiment of the fourth aspect of the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. It should be noted that, in the absence of conflict, the embodiments and features in the embodiments disclosed in this disclosure can be combined, separated, interchanged and / or rearranged with each other. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0038] The terms used here are for the purpose of describing specific embodiments, and are not intended to be restrictive. As used here, unless the context clearly indicates otherwise, the singular forms "one (kind, person)" and "said (the)" are also intended to include plural forms. In addition, when the terms "comprise" and / or "include" and their variations are used in this specification, it is explained that there are stated features, integral bodies, steps, operations, parts, assemblies and / or their groups, but it is not excluded that there are or add one or more other features, integral bodies, steps, operations, parts, assemblies and / or their groups. It should also be noted that, as used here, the terms "substantially", "approximately" and other similar terms are used as approximate terms and not as degree terms, so that they are used to explain the inherent deviations of the measured values, calculated values and / or the values provided that will be recognized by those of ordinary skill in the art.
[0039] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, the present disclosure omits detailed descriptions of known functions and known components. Figure 1 and Figure 2 The first embodiment of the present invention provides a large model training data filtering method, comprising the following steps:
[0040] S1. Obtain an original training data set, and convert samples in the original training data set into embedding vectors;
[0041] S2. Perform a k-nearest neighbor search on all embedded vectors to construct a k-nearest neighbor graph of the original training dataset.
[0042] S3. Select a subset from the k-nearest neighbor graph, and use the samples included in the subset as the filtered training data set. The method of selecting the subgraph includes:
[0043] S31, calculating the diversity representativeness score of all nodes that are not added to the subset;
[0044] S32, selecting the node with the highest diversity representativeness score to add to the subset;
[0045] S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
[0046] In this embodiment, all samples are first converted into embedding vectors. This process can be completed by an existing embedding vector model, and this embodiment does not limit this and does not elaborate on it.
[0047] The complexity of calculating the cosine similarity between all sample embedding vectors is O(n^2), where n represents the size of the complete data set. This is inefficient considering that currently popular data sets usually contain millions or tens of millions of samples. In order to reduce the computational load, it is considered that this embodiment only wants to retain those significant edges. A k-nearest neighbor (KNN) search is performed on the embedding vector to obtain the k neighbors with the highest similarity for each sample. In this way, a KNN graph with k edges for each sample is obtained. This process can utilize an efficient implementation method for constructing a KNN graph provided by an open source library such as Faiss or Raft. In some embodiments, the k-nearest neighbor graph is constructed using the Faiss library or the Raft algorithm. It should be understood that other existing KNN graph construction methods can also be selected.
[0048] In some embodiments, the calculation of the diversity representativeness score is expressed as:
[0049] X=AB, where X represents the diversity representative score of the target node, A represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and do not belong to the subset, and B represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and belong to the subset.
[0050] It should be understood that the diversity representative score can also be called the maximum coverage score of unselected nodes. The embodiment of the present invention actually solves the selection of a subset of the original training data set. It is expected that the subset can cover the characteristics of the original data set to the greatest extent and have a smaller scale.
[0051] Specifically, in this embodiment, the above value of A represents the representativeness of the target node for the unselected nodes, and the above value of B represents the similarity between the target node and the selected nodes, because in this embodiment of KNN, the existence of an edge between two nodes indicates similarity, that is, representativeness. Through the above considerations, the subset selected by this embodiment can have the diversity characteristics of the original training data set, while reducing the data redundancy problem caused by a large amount of highly similar data in the data set. Efficient pruning of the data set is achieved.
[0052] In some embodiments, the filtered training data set is used for training in the large model instruction tuning phase.
[0053] In some embodiments, the method is applied in an interstitial manner to the training of a downstream model.
[0054] In some scenarios of large model training, the training effect depends on the inherent characteristics of the dataset or another auxiliary proxy model. Therefore, they can be applied to downstream model training in an intermittent manner.
[0055] In some embodiments, the method of this embodiment is able to process a dataset of millions of samples using only one GPU. This is a preprocessing method that is applied in an interstitial manner in subsequent LLM instruction tuning. Extensive testing on open source fine-tuning datasets, such as Flan1M-2021, ShareGPT, and Oasst1, demonstrates superiority over baseline selection methods. In the deployment of an internal commercial LLM, the method of this embodiment also showed no performance loss when the SFT dataset was pruned to 50%.
[0056] The second aspect of the present invention provides a large model training data filtering device, such as Figure 3 As shown, including:
[0057] A conversion module, used to obtain an original training data set and convert samples in the original training data set into embedding vectors;
[0058] KNN building module, which performs k-nearest neighbor search on all embedding vectors to build the k-nearest neighbor graph of the original training dataset;
[0059] A filtering module selects a subset from the k-nearest neighbor graph and uses the samples contained in the subset as a filtered training data set. The method of selecting the subgraph includes:
[0060] S31, calculating the diversity representativeness score of all nodes that are not added to the subset;
[0061] S32, selecting the node with the highest diversity representativeness score to add to the subset;
[0062] S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
[0063] A third aspect of the present invention provides an electronic device, such as Figure 4 As shown, it includes a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the large model training data filtering method described in any of the above embodiments is implemented.
[0064] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the large model training data filtering method as described in any of the above embodiments is implemented.
[0065] Computer readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0066] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by 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 the function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians 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 the present invention.
[0067] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0068] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A large model training data filtering method, characterized in that: The following steps are involved: S1. Obtain an original training data set, and convert samples in the original training data set into embedding vectors; S2. Perform a k-nearest neighbor search on all embedded vectors to construct a k-nearest neighbor graph of the original training dataset. S3. Select a subset from the k-nearest neighbor graph, and use the samples included in the subset as the filtered training data set. The method of selecting the subgraph includes: S31, calculating the diversity representativeness score of all nodes that are not added to the subset; S32, selecting the node with the highest diversity representativeness score to add to the subset; S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
2. The large model training data filtering method according to claim 1, characterized in that: The calculation of the diversity representation score is expressed as: X=AB, where X represents the diversity representative score of the target node, A represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and do not belong to the subset, and B represents the number of nodes in the k-nearest neighbor graph that have edges with the target node and belong to the subset.
3. The large model training data filtering method according to claim 1, characterized in that: The k-nearest neighbor graph is constructed by using the Faiss library or the Raft algorithm.
4. The large model training data filtering method according to claim 1, characterized in that: The filtered training data set is used for training in the large model instruction tuning phase.
5. The large model training data filtering method according to claim 1, characterized in that: The method is applied to the training of downstream models in an interstitial manner.
6. A large model data filtering device, characterized in that: include: A conversion module, used to obtain an original training data set and convert samples in the original training data set into embedding vectors; KNN building module, which performs k-nearest neighbor search on all embedding vectors to build the k-nearest neighbor graph of the original training dataset; A filtering module selects a subset from the k-nearest neighbor graph and uses the samples contained in the subset as a filtered training data set. The method of selecting the subgraph includes: S31, calculating the diversity representativeness score of all nodes that are not added to the subset; S32, selecting the node with the highest diversity representativeness score to add to the subset; S33. Repeat steps S31-S32 until the number of nodes in the subset reaches a preset value.
7. An electronic device, characterized in that: It includes a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the large model training data filtering method as described in any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the large model training data filtering method as described in any one of claims 1-5 is implemented.
Citation Information
Patent Citations
Vector coding learning method and device for neighbor graph vector retrieval
CN115408571A
Target node classification method, system and equipment in graph structure data and medium
CN115718826A
Online class-incremental continual learning with adversarial shapley value
US20210383158A1
