An adaptive multi-strategy fusion large language model training optimization method
By constructing a multi-strategy data processing framework and intelligent strategy selection algorithm, combined with LoRA parameter fine-tuning technology, the problem of non-automation in data processing strategy selection in existing technologies is solved, realizing efficient and resource-optimized training of large language models, adapting to diverse application scenarios and hardware environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 北京国御网络安全技术有限公司
- Filing Date
- 2025-12-03
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies lack automated data processing strategy selection mechanisms, resulting in low training efficiency, low resource utilization, poor scalability, and a lack of systematic evaluation mechanisms, making them unable to adapt to diverse application scenarios and hardware environments.
A multi-strategy data processing framework is constructed, including dynamic concatenation batch processing strategy, fixed-length padding strategy, and dynamic length adaptive strategy. It combines intelligent strategy selection algorithm and LoRA parameter efficient fine-tuning technology, and trains large language models through gradient optimization strategy.
It achieves automated strategy selection, significantly improves training efficiency and resource utilization, enhances the versatility and scalability of model training, and reduces training costs and deployment difficulty.
Smart Images

Figure CN121615726B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, specifically to an adaptive multi-strategy fusion method for training and optimizing large language models. Background Technology
[0002] Large language models, as a core technology in the field of natural language processing, play an increasingly important role in numerous tasks such as text generation, question answering systems, machine translation, code generation, and knowledge reasoning. As the scale of model parameters grows from billions to hundreds of billions or even trillions, how to efficiently train large language models has become a key technical challenge that urgently needs to be addressed in the field of artificial intelligence.
[0003] The choice of data processing strategy has a significant impact on training efficiency and model performance. Currently, the main data processing strategies include:
[0004] Fixed-length padding strategy: This strategy uniformly pads or truncates all training samples to a preset fixed length. Its advantages include: simple implementation, predictable memory usage, high batch processing efficiency, suitability for hardware parallel computing, balanced computational load, and stable GPU utilization. However, this strategy has significant drawbacks: when data length distribution is uneven, it causes severe waste of computational resources; short samples require padding with a large number of invalid PAD tokens, which not only consumes memory and computational resources but may also interfere with the model's attention mechanism; truncation of long samples may result in the loss of key contextual information, affecting the model's semantic understanding ability.
[0005] Dynamic length adaptive strategy: This strategy dynamically adjusts the sequence length based on the actual data length of each batch, avoiding unnecessary PAD padding operations. Its advantages include: significantly reducing invalid computation and improving training efficiency; preserving complete contextual information; and adapting to data distributions of different lengths. However, this strategy is highly complex to implement: it requires complex data preprocessing and batch assembly logic; uneven computational load between batches leads to fluctuations in GPU utilization; unpredictable memory usage increases system stability risks; and some batches may become training bottlenecks due to containing long sequences.
[0006] Dynamic batch processing strategy: Concatenating multiple short samples into a longer sequence for training can improve GPU utilization and reduce the number of batches. However, improper concatenation can lead to semantic interference between samples, affecting the model's learning performance. In instruction fine-tuning scenarios, concatenating samples from different tasks may confuse the model's understanding of task boundaries.
[0007] The existing technology has the following shortcomings:
[0008] Different datasets and hardware environments are suited to different processing strategies, but currently there is a lack of automated strategy selection mechanisms. Existing methods mainly rely on human experience, which is inefficient, error-prone, and unable to adapt to diverse application scenarios.
[0009] Lack of adaptability: Existing methods typically employ a single strategy to process all data, failing to dynamically adjust based on the statistical characteristics of the dataset and hardware resources. This rigid approach results in suboptimal training efficiency.
[0010] Low resource utilization: Fixed processing strategies are difficult to fully utilize the computing resources of different hardware configurations. On GPUs with small video memory, memory overflow is prone to occur, requiring frequent adjustments to batch size and sequence length. On GPUs with large video memory, computing power cannot be fully utilized, resulting in resource waste.
[0011] Lack of a systematic evaluation mechanism: Existing technologies lack a systematic evaluation and comparison mechanism for the effects of different strategies. Users often need to select strategies through trial and error, which is time-consuming, labor-intensive, and prone to missing the optimal configuration. There are no unified benchmarks and metrics to evaluate the merits of different strategies.
[0012] Poor scalability: Existing methods are typically designed for models of a specific size and datasets of a specific type, making it difficult to scale to new scenarios. When the model size, data type, or hardware environment changes, the entire training process often needs to be redesigned and adjusted. Summary of the Invention
[0013] The purpose of this invention is to provide an adaptive multi-strategy fusion large language model training optimization method to solve the problems mentioned in the background art.
[0014] To achieve the above objectives, the present invention provides the following technical solution: an adaptive multi-strategy fusion large language model training optimization method, comprising the following steps:
[0015] Step 1: Construct a multi-strategy data processing framework, which includes three complementary data processing strategies: dynamic batch processing strategy A, fixed-length padding strategy B, and dynamic length adaptive strategy C.
[0016] Step 2: Design an intelligent strategy selection algorithm, extract dataset features and hardware features, calculate the score of each strategy based on a multi-dimensional scoring function, select the strategy with the highest score and calculate the confidence level;
[0017] Step 3: Employ LoRA parameter fine-tuning technology to update the weight matrix of the pre-trained large language model by performing low-rank decomposition, thereby reducing the number of trainable parameters;
[0018] Step 4: Employ gradient optimization strategies, using gradient clipping to prevent gradient explosion and gradient accumulation to support large-batch training.
[0019] Step 5: Process the training data based on the selected optimal data processing strategy, combine LoRA fine-tuning and gradient optimization strategies to perform large language model training, and output the trained model and loss curve.
[0020] Preferably, in step one, the specific algorithm for the dynamic batch processing strategy A is as follows:
[0021] Let the input sample set be Each sample The length after tokenization is The algorithm is defined as follows: Maximum sequence length is set to Max_length, batch size is D, total capacity is E = Max_length × D, final output batch set is G, temporary buffer is set to buffer, and the current data length of the buffer is set to utilized_length.
[0022] Initialization: G = Φ, buffer = Φ, utilized_length = 0
[0023] for each ∈ S:
[0024] if > C:
[0025] G = G ∪ {Truncate( , C)}
[0026] continue
[0027] if utilized_length + > C:
[0028] if |buffer| > 0:
[0029] G = G ∪ {Padding(buffer, C)}
[0030] buffer = Φ
[0031] utilized_length = 0
[0032] buffer = buffer ∪ { }
[0033] utilized_length = utilized_length +
[0034] if |buffer| > 0:
[0035] G = G ∪ {Padding(buffer, C)}
[0036] The formula for calculating the space utilization of dynamic batch processing strategy A is as follows:
[0037] .
[0038] Preferably, the specific processing procedure of the fixed-length filling strategy B in step one is as follows:
[0039] All samples are uniformly processed into a fixed length L_fixed. :
[0040]
[0041] Here, ⊕ represents the concatenation operation, and PAD is the padding token. Indicates the extraction of samples The first L_fixed tokens;
[0042] The key performance indicator calculation formula for fixed-length fill strategy B is as follows:
[0043] The memory usage per batch is constant. .
[0044] Sample fill rate:
[0045] Sample cutoff rate:
[0046] Information retention rate:
[0047] Here, sizeof(token) represents the number of bytes required for a token.
[0048] Preferably, the dynamic length calculation formula for the dynamic length adaptive C in step one is:
[0049] For batch size The corresponding length is :
[0050]
[0051] Where Percentile_p represents the p-th percentile, with a default value of p=95, α is the alignment factor, rounded up to a multiple of 8 to optimize GPU computation, with a default value of α=8, and [] indicates rounding up.
[0052] Preferably, the dataset and hardware feature extraction in step two includes the following parameters and their calculation formulas:
[0053] Coefficient of variation: CV = = , where σ is the standard deviation and μ is the mean.
[0054] Length ratio: ,in The length of the token for the largest sample;
[0055] Number of samples: N_samples;
[0056] GPU memory size: M_gpu (GB);
[0057] Batch size: D.
[0058] Preferably, the scoring function in step two includes a dynamic weight matrix and a multi-dimensional scoring function;
[0059] For each strategy k∈{A,B,C}, calculate the overall score:
[0060]
[0061] in Let i be the weight of the i-th rule. Let i be the i-th rule function;
[0062] The weight values of the dynamic weight matrix W are determined according to the following rules:
[0063] Dynamic weight matrix design:
[0064]
[0065] The weight values are dynamically determined based on the conditions, achieving adaptive adjustment:
[0066] Rule 1 - Weights for data variability:
[0067]
[0068] Rule 2 - Long-tail distribution ratio weights:
[0069]
[0070] Rule 3 - Sample Size Weight:
[0071]
[0072] Rule 4 - Hardware Resource Weighting:
[0073]
[0074] Rule 5 - Training Batch Size Weights:
[0075] ;
[0076] The multidimensional scoring function includes f1-f5, and its expression is:
[0077] f1(CV) - Data variability scoring function:
[0078]
[0079] f2(R_length) - Long-tailed distribution ratio scoring function:
[0080]
[0081] f3(N_samples) - Sample size scoring function:
[0082]
[0083] f4(M_gpu) - Hardware resource scoring function:
[0084]
[0085] f5(D) - Training batch size weights:
[0086]
[0087] Where p and q are shape parameters, with a default value of 2, which can be adjusted according to actual needs.
[0088] The highest-scoring strategy selection and confidence calculation are as follows:
[0089] Choose the strategy with the highest score:
[0090]
[0091] Policy confidence calculation:
[0092] .
[0093] Preferably, the parameter update formula for the LoRA parameter efficient fine-tuning technique in step three is:
[0094] For the pre-trained weight matrix ∈ R d×d , LoRA updates parameters through low-rank factorization:
[0095]
[0096] Among them, ∈R d×r , ∈R r×d , the rank r << d, and only and are updated during training, keeping frozen. The number of trainable parameters changes from the original d×d to 2×r×d.
[0097] Preferably, the gradient optimization strategy in the fourth step includes gradient clipping and gradient accumulation. The specific formula is:
[0098] To prevent gradient explosion, gradient clipping is adopted:
[0099]
[0100] Among them, θ is the clipping threshold, and the default value is 1.0;
[0101] The gradient accumulation strategy is adopted to support large-batch training:
[0102]
[0103] Among them, A steps is the cumulative step, and g j represents the gradient of the j-th step.
[0104] Preferably, the applicable scenarios of the three data processing strategies are respectively:
[0105] [[ID=5 / 4]]Dynamic concatenation batch processing strategy A: scenarios with high variability in data length, a large number of short samples, sufficient GPU memory, and a large number of samples;
[0106] Fixed-length padding strategy B: scenarios with uniform data length distribution, limited hardware resources requiring predictable memory usage, strict batch processing alignment requirements, and simple implementation and debugging requirements;
[0107] Dynamic length adaptation strategy C: scenarios with medium data length variation, limited GPU memory requiring flexible adjustment, and precise control of batch size.
[0108] Compared with the prior art, the beneficial effects of the present invention are:
[0109] The adaptive multi-strategy fusion training optimization method for large language models based on data feature awareness proposed in this invention fundamentally changes the traditional training mode that relies on human experience, and achieves the following significant technical advantages:
[0110] a) Automated strategy selection: Through intelligent scoring algorithms, the dataset features and hardware environment are automatically analyzed, reducing the decision-making time from several hours of manual debugging to minutes. The confidence level of strategy selection can reach over 80%, significantly improving the reliability of decision-making.
[0111] b) Significantly improved training efficiency: Through multi-strategy collaboration and dynamic optimization, the dynamic concatenation batching strategy can reduce invalid computation by 50-70% for datasets with uneven length distribution. For small datasets, the fixed-length padding strategy enables fast data processing, allowing the model to learn effective features more quickly. For large datasets, the dynamic length adaptation strategy and the dynamic concatenation batching strategy can significantly accelerate training speed.
[0112] c) Resource utilization optimization: The processing strategy is adaptively adjusted according to the GPU memory size. On GPUs with 8GB of small memory, OOM errors can be avoided, and on GPUs with 24GB of large memory, parallel computing capabilities can be fully utilized to improve GPU utilization.
[0113] d) High versatility and scalability: It is suitable for various large language models with multiple parameter scales, supports multiple vertical datasets, and the framework design supports the rapid integration of new strategies.
[0114] e) Parameter efficiency: By adopting LoRA technology, the number of trainable parameters is only 0.1-1% of the original model, which significantly reduces training costs and deployment difficulty. Attached Figure Description
[0115] Figure 1 This is the system architecture diagram of the adaptive multi-strategy fusion large language model training and optimization system based on data feature perception of the present invention;
[0116] Figure 2 This is a flowchart of the intelligent strategy selection algorithm of the present invention;
[0117] Figure 3 This is a schematic diagram of the three data processing strategies of the present invention;
[0118] Figure 4 This is a flowchart of the model training process of this invention;
[0119] Figure 5 This is a comparison chart of training loss curves in an embodiment of the present invention. Detailed Implementation
[0120] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0121] Please see Figure 1-5 This invention provides an adaptive multi-strategy fusion method for training and optimizing large language models, comprising the following steps:
[0122] Step 1: Construct a multi-strategy data processing framework, which includes three complementary data processing strategies: dynamic batch processing strategy A, fixed-length padding strategy B, and dynamic length adaptive strategy C.
[0123] Step 2: Design an intelligent strategy selection algorithm, extract dataset features and hardware features, calculate the score of each strategy based on a multi-dimensional scoring function, select the strategy with the highest score and calculate the confidence level;
[0124] Step 3: Employ LoRA parameter fine-tuning technology to update the weight matrix of the pre-trained large language model by performing low-rank decomposition, thereby reducing the number of trainable parameters;
[0125] Step 4: Employ gradient optimization strategies, using gradient clipping to prevent gradient explosion and gradient accumulation to support large-batch training.
[0126] Step 5: Process the training data based on the selected optimal data processing strategy, combine LoRA fine-tuning and gradient optimization strategies to perform large language model training, and output the trained model and loss curve.
[0127] In step one, the specific algorithm for dynamic batch processing strategy A is as follows:
[0128] Let the input sample set be Each sample The length after tokenization is The algorithm is defined as follows: Maximum sequence length is set to Max_length, batch size is D, total capacity is E = Max_length × D, final output batch set is G, temporary buffer is set to buffer, and the current data length of the buffer is set to utilized_length.
[0129] Initialization: G = Φ, buffer = Φ, utilized_length = 0
[0130] for each ∈ S:
[0131] if E:
[0132] G = G ∪ {Truncate( , E)}
[0133] continue
[0134] if utilized_length + E:
[0135] if |buffer| > 0:
[0136] G = G ∪ {Padding(buffer, E)}
[0137] buffer = Φ
[0138] utilized_length = 0
[0139] buffer = buffer ∪ { }
[0140] utilized_length = utilized_length +
[0141] if |buffer| > 0:
[0142] G = G ∪ {Padding(buffer, E)}
[0143] The formula for calculating the space utilization of dynamic batch processing strategy A is as follows:
[0144] .
[0145] The specific processing procedure for fixed-length padding strategy B in step one is as follows:
[0146] All samples are uniformly processed into a fixed length L_fixed. :
[0147]
[0148] Here, ⊕ represents the concatenation operation, and PAD is the padding token. Indicates the extraction of samples The first L_fixed tokens;
[0149] The key performance indicator calculation formula for fixed-length fill strategy B is as follows:
[0150] The memory usage per batch is constant. .
[0151] Sample fill rate:
[0152] Sample cutoff rate:
[0153] Information retention rate:
[0154] Here, sizeof(token) represents the number of bytes required for a token.
[0155] The formula for calculating the dynamic length of the adaptive C in step one is:
[0156] For batch The corresponding length is :
[0157]
[0158] Where Percentile_p represents the p-th percentile, with a default value of p=95, α is the alignment factor, rounded up to a multiple of 8 to optimize GPU computation, with a default value of α=8, and [] indicates rounding up.
[0159] Step two, the dataset and hardware feature extraction, includes the following parameters and their calculation formulas:
[0160] Coefficient of variation: CV = = , where σ is the standard deviation and μ is the mean.
[0161] Length ratio: ,in The length of the token for the largest sample;
[0162] Number of samples: N_samples;
[0163] GPU memory size: M_gpu (GB);
[0164] Batch size: D.
[0165] The scoring function in step two includes a dynamic weight matrix and a multi-dimensional scoring function;
[0166] For each strategy k∈{A,B,C}, calculate the overall score:
[0167]
[0168] in Let i be the weight of the i-th rule. Let i be the i-th rule function;
[0169] The weight values of the dynamic weight matrix W are determined according to the following rules:
[0170] Dynamic weight matrix design:
[0171]
[0172] The weight values are dynamically determined based on the conditions, achieving adaptive adjustment:
[0173] Rule 1 - Weights for data variability:
[0174]
[0175] Rule 2 - Long-tail distribution ratio weights:
[0176]
[0177] Rule 3 - Sample Size Weight:
[0178]
[0179] Rule 4 - Hardware Resource Weighting:
[0180]
[0181] Rule 5 - Training Batch Size Weights:
[0182] ;
[0183] The multidimensional scoring function includes f1-f5, and its expression is:
[0184] f1(CV) - Data variability scoring function:
[0185]
[0186] f2(R_length) - Long-tailed distribution ratio scoring function:
[0187]
[0188] f3(N_samples) - Sample size scoring function:
[0189]
[0190] f4(M_gpu) - Hardware resource scoring function:
[0191]
[0192] f5(D)-Training Batch Size Weight:
[0193]
[0194] Where p and q are shape parameters with default values of 2, which can be adjusted according to actual needs.
[0195] The specific calculation of the strategy selection with the highest score and confidence is as follows:
[0196] Select the strategy with the highest score:
[0197]
[0198] Calculation of strategy confidence:
[0199] .
[0200] The parameter update formula of the LoRA parameter efficient fine-tuning technology in step three is:
[0201] For the pre-trained weight matrix ∈ R d×d , LoRA updates parameters through low-rank decomposition:
[0202]
[0203] Where ∈R d×r , ∈R r×d , the rank r << d, and only and are updated during training, keeping frozen. The number of trainable parameters changes from the original d×d to 2×r×d.
[0204] The gradient optimization strategies in step four include gradient clipping and gradient accumulation, and the specific formulas are:
[0205] To prevent gradient explosion, gradient clipping is adopted:
[0206]
[0207] Where θ is the clipping threshold with a default value of 1.0;
[0208] The gradient accumulation strategy is adopted to support large batch training:
[0209]
[0210] Where A steps is the cumulative step, and g j represents the gradient at the j-th step.
[0211] The applicable scenarios for the three data processing strategies are as follows:
[0212] Dynamic batch processing strategy A: Scenarios with high data length variability, a large number of short samples, sufficient GPU memory, and a large number of samples.
[0213] Fixed-length padding strategy B: Scenarios where data length is evenly distributed, hardware resources are limited and predictable memory usage is required, batch processing requires strict alignment, and implementation and debugging requirements are simple.
[0214] Dynamic length adaptive strategy C: Scenarios where data length has moderate variation, GPU memory is limited and flexible adjustment is required, and batch size needs to be precisely controlled.
[0215] Example: Instruction fine-tuning training based on the Qwen2.5-7B model
[0216] It includes dynamic splicing batch processing strategy A (hereinafter referred to as strategy A), fixed length padding strategy B (hereinafter referred to as strategy B), and dynamic length adaptive strategy C (hereinafter referred to as strategy C).
[0217] Step 1: Loading and parsing the configuration file
[0218] Set the maximum sample token length Max_length=512, training batch size D=4, training epochs=3, learning rate Lr=1e-05, gradient accumulation steps A_steps=64, model save and loss record interval Steps=1000, LoRA rank r=8, LoRA scaling factor α=32.
[0219] Step 2: Dataset Analysis
[0220] A comprehensive statistical analysis was performed on a dataset containing 17,892 samples. Each sample contains three fields: instruction, input, and output. Data characteristics and hardware information were obtained and analyzed: number of samples N_samples=17892, average token length μ=284.91, maximum token length l_max=2066, minimum token length l_min=36, token variance l_variance=7622.88, standard deviation σ=87.31, number of GPUs gpu_count=4, available memory per GPU gpu_memory=25.4GB, total available memory M_gpu=25.4×4=101.6GB, long-tail distribution ratio R_length=2066 / 284.91=7.25, coefficient of variation CV=87.31 / 284.91=0.31.
[0221] Step 3: Smart Strategy Selection
[0222] according to Figure 2 The intelligent strategy selection process shown in the diagram involves the system automatically evaluating and selecting strategies.
[0223] (1) Determine the dynamic weight matrix
[0224] Based on the data characteristics, the system automatically determines the weight matrix:
[0225]
[0226] (2) Calculate the scoring function value
[0227]
[0228]
[0229]
[0230]
[0231]
[0232] (3) Strategy selection results and confidence level
[0233]
[0234]
[0235] The best strategy is chosen as Strategy A, with a confidence level of 83.92%.
[0236] Step 4: Strategy Execution
[0237] Based on the intelligent strategy selection result, the system automatically executes strategy A (dynamic batch processing strategy). For example... Figure 3 As shown, the strategy execution flow is as follows:
[0238] (1) Parameter settings
[0239] The maximum sequence length of the sample token is set to 512, the batch size is 4, and the total sequence length is 512 × 4 = 2048.
[0240] (2) Control experiment setup
[0241] To verify the effectiveness of the strategy selection, a control group was set up under the same conditions:
[0242] Control group 1: Directly use strategy B (fixed length fill)
[0243] Control group 2: Directly use strategy C (dynamic length adaptive)
[0244] (3) Data processing flow
[0245] Strategy A preprocesses and analyzes the data, calculates the token sample length, and checks if the token sample length is greater than the total sequence length. If it is, the sample is truncated to the total sequence length and the complete batch is output. If it is less, it is added to the current batch. The current batch length is then checked against the total sequence length. If it is, the current sample is removed, and the current batch is padded to the total sequence length and the complete batch is output. If not, new samples are added to the current batch until the current batch length exceeds the total sequence length. Strategy B preprocesses and analyzes the data, calculates the token sample length, and checks if the token sample length is greater than the sequence length. If it is, the sample is truncated to the maximum sequence length. If it is less, the sample is padded to the maximum sequence length. Finally, batches are formed according to batch_size. Strategy C preprocesses and analyzes the data, calculates the token sample length, and checks if the token sample length is greater than the sequence length. If it is, the sample is truncated to the maximum sequence length. If it is less, the original sample length is maintained. Batches are then collected according to batch_size. The batch length is analyzed, rounded up to a multiple of 8 based on the 95th percentile, and dynamically padded according to the maximum length within the batch. Finally, the padded batches are output.
[0246] Step 5: Model Training and Result Analysis
[0247] (1) Model Training
[0248] according to Figure 4 The training process shown is used for model training. Before training, the Qwen2.5-7B pre-trained model is loaded and the LoRA parameters are configured. The training process is as follows: batch partitioning and random shuffling of the training set, traversing data batches, forward propagation to calculate loss, backpropagation to calculate gradient, gradient clipping to prevent gradient explosion, gradient accumulation to a specified number of steps for gradient update and gradient zeroing, recording the loss curve and saving the model.
[0249] (2) Training Result Analysis
[0250] like Figure 5 As shown, the training effects of the three strategies are compared:
[0251] Strategy A (Automatic selection of results):
[0252] Training steps: Step (slight variations exist depending on the sample splicing process).
[0253] Training session duration: 2 hours 20 minutes
[0254] Loss reduction characteristics: smooth and stable decline, making full use of sample data.
[0255] Strategy B (fixed length padding):
[0256] Training steps: step
[0257] Training session duration: 3 hours 22 minutes
[0258] Loss reduction characteristics: early convergence, with a risk of overfitting.
[0259] Strategy C (Dynamic Length Adaptation):
[0260] Training steps: step
[0261] Training session duration: 2 hours 35 minutes
[0262] Loss reduction characteristics: early convergence, with a risk of overfitting.
[0263] (3) Experimental conclusions
[0264] Through verification using examples, the intelligent strategy selection method proposed in this invention has the following advantages:
[0265] High accuracy: Strategy A, automatically selected by the system, performed optimally on this dataset, verifying the effectiveness of the algorithm.
[0266] Significant efficiency improvement: Compared to strategy B, training time is reduced by 30.8%; compared to strategy C, training time is reduced by 9.7%.
[0267] High degree of automation: The entire strategy selection process is fully automated and requires no human intervention.
[0268] Highly interpretable: It provides an 83.92% confidence level assessment, and the decision-making process is transparent and credible.
[0269] Good adaptability: This method has been successfully applied to large-scale models of 7B, proving its feasibility on large-scale models.
[0270] Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An adaptive multi-strategy fusion large language model training optimization method, characterized in that: Includes the following steps: Step 1: Construct a multi-strategy data processing framework, which includes three complementary data processing strategies: dynamic batch processing strategy A, fixed-length padding strategy B, and dynamic length adaptive strategy C. Step 2: Design an intelligent strategy selection algorithm, extract dataset features and hardware features, calculate the score of each strategy based on a multi-dimensional scoring function, select the strategy with the highest score and calculate the confidence level; Step 3: Employ LoRA parameter fine-tuning technology to update the weight matrix of the pre-trained large language model by performing low-rank decomposition, thereby reducing the number of trainable parameters; Step 4: Employ gradient optimization strategies, using gradient clipping to prevent gradient explosion and gradient accumulation to support large-batch training. Step 5: Process the training data based on the selected optimal data processing strategy, combine LoRA fine-tuning and gradient optimization strategies to perform large language model training, and output the trained model and loss curve; The dataset and hardware feature extraction in step two includes the following parameters and their calculation formulas: Coefficient of variation: CV = σ / μ = σ / μ where σ is the standard deviation and μ is the mean. Length ratio: ,in The length of the token for the largest sample; Number of samples: N_samples; GPU memory size: M_gpu (GB); Batch size: D; The scoring function in step two includes a dynamic weight matrix and a multi-dimensional scoring function; For each strategy k∈{A,B,C}, calculate the overall score: in Let i be the weight of the i-th rule. Let i be the i-th rule function; The weight values of the dynamic weight matrix W are determined according to the following rules: Dynamic weight matrix design: The weight values are dynamically determined based on the conditions, achieving adaptive adjustment: Rule 1 - Weights for data variability: Rule 2 - Long-tail distribution ratio weights: Rule 3 - Sample Size Weight: Rule 4 - Hardware Resource Weighting: Rule 5 - Training Batch Size Weights: ; The multidimensional scoring function includes f1-f5, and its expression is: f1(CV) - Data variability scoring function: f2(R_length) - Long-tailed distribution ratio scoring function: f3(N_samples) - Sample size scoring function: f4(M_gpu) - Hardware resource scoring function: f5(D) - Training batch size weights: Where p and q are shape parameters, with a default value of 2, which can be adjusted according to actual needs; The highest-scoring strategy selection and confidence calculation are as follows: Choose the strategy with the highest score: Policy confidence calculation: 。 2. The adaptive multi-strategy fusion large language model training optimization method according to claim 1, characterized in that: In step one, the specific algorithm for the dynamic batch processing strategy A is as follows: Let the input sample set be Each sample The length after tokenization is The algorithm is defined as follows: Maximum sequence length is set to Max_length, batch size is D, total capacity is E = Max_length × D, final output batch set is G, temporary buffer is set to buffer, and the current data length of the buffer is set to utilized_length. Initialization: G = Φ, buffer = Φ, utilized_length = 0 for each ∈ S: if > E: G = G ∪ {Truncate( , E)} continue if utilized_length + > E: if |buffer| > 0: G = G ∪ {Padding(buffer, E)} buffer = Φ utilized_length = 0 buffer = buffer ∪ { } utilized_length = utilized_length + if |buffer| > 0: G = G ∪ {Padding(buffer, E)} The formula for calculating the space utilization of dynamic batch processing strategy A is as follows: 。 3. The adaptive multi-strategy fusion large language model training optimization method according to claim 1, characterized in that: The specific processing procedure for the fixed-length filling strategy B in step one is as follows: All samples are uniformly processed into a fixed length L_fixed. : Here, ⊕ represents the concatenation operation, and PAD is the padding token. Indicates the extraction of samples The first L_fixed tokens; The key performance indicator calculation formula for fixed-length fill strategy B is as follows: The memory usage per batch is constant. ; Sample fill rate: Sample cutoff rate: Information retention rate: Here, sizeof(token) represents the number of bytes required for a token.
4. The adaptive multi-strategy fusion large language model training optimization method according to claim 1, characterized in that: The dynamic length calculation formula for the adaptive dynamic length C in step one is as follows: For batch size The corresponding length is : Where Percentile_p represents the p-th percentile, with a default value of p=95, α is the alignment factor, rounded up to a multiple of 8 to optimize GPU computation, with a default value of α=8, and [] indicates rounding up.
5. The adaptive multi-strategy fusion large language model training optimization method according to claim 1, characterized in that: The parameter update formula for the LoRA parameter high-efficiency fine-tuning technique in step three is as follows: For the pre-trained weight matrix ∈ R d×d LoRA updates parameters through low-rank decomposition: wherein, ∈R d×r , ∈R r×d , the rank r << d, and only and are updated during the training process, is frozen, and the number of trainable parameters changes from the original d×d to 2×r×d.
6. The adaptive multi-strategy fusion large language model training optimization method according to claim 1, characterized in that: The gradient optimization strategy in step four includes gradient clipping and gradient accumulation, and the specific formula is as follows: To prevent gradient explosion, gradient clipping is used: Where θ is the clipping threshold, with a default value of 1.0; Employ gradient accumulation strategy to support large batch training: where A steps is the cumulative step count, g j denotes the gradient of the jth step.