FP8 gradient adaptive optimization method and device for large language model training

The innovative FP8 gradient adaptation method solves the technical problems existing in the prior art, realizes efficient training of large language models, solves the problems of gradient information loss and optimizer mechanism mismatch, and improves the learning efficiency and accuracy of the model.

CN121168680AActive Publication Date: 2025-12-19SHANDONG XIEHE UNIV +1

Patent Information

Application Number
CN202511728728.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-24
Publication Date
2025-12-19
Estimated Expiration
2045-11-24

AI Technical Summary

Technical Problem

Existing low-precision training techniques suffer from gradient information loss, insufficient dynamic range, and optimizer mechanism mismatch in large language models, resulting in slow model convergence, decreased accuracy, and difficulty in achieving efficient training.

Method used

By synchronously acquiring the original high-precision gradient and historical gradient information of the current iteration step, quantizing them into FP8 format, and using filtering and noise reduction processing, combined with the base learning rate and system parameters to update the optimizer state, a closed-loop iterative optimization is formed, which adapts to the characteristics of FP8 gradient and alleviates insufficient dynamic range and noise interference.

Benefits of technology

It significantly improves model learning efficiency, ensures a balance between accuracy and resource consumption under low-precision training, shortens training time, and improves accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121168680A_ABST
    Figure CN121168680A_ABST
Patent Text Reader

Abstract

The invention discloses a large language model training-oriented FP8 gradient adaptive optimization method and device, and relates to the technical field of computer machine learning. The method comprises the steps that in the learning iteration process of a large language model for data input by a user, a processor obtains an original high-precision gradient tensor of a current iteration step and historical information which is stored in a storage and contains historical gradients, and a scaling factor and a gradient value are quantized according to a target FP8 format to obtain quantized input data; after the quantized input data stored in the memory is filtered and denoised, the state of the optimizer is updated and stored in the memory, and the processor obtains the update quantity of the system parameters by utilizing a learning mechanism corresponding to the optimizer according to the basic learning rate and the system parameters. And optimizing the large language model according to the system parameter update quantity and a preset evaluation strategy to obtain a trained large language model. By adopting the method, the optimal balance of computer storage precision, efficiency and system resource consumption under large language model low-precision training is realized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer machine learning, in particular to an FP8 gradient adaptive optimization method and device for large language model training. BACKGROUND

[0002] With the breakthrough of large language model parameter scale from hundreds of billions to trillions, the demand for computing resources (such as GPU computing power and memory bandwidth) for its training and inference increases exponentially. Traditional high-precision (such as FP32 and FP16) training mode gradually becomes a bottleneck restricting the development of model scale due to large storage occupation and low computing efficiency. To alleviate this contradiction, low-precision numerical format (FP16, BF16, especially FP8) has become a core technology direction for efficient training of large language models due to its lower memory occupation (only 1 / 4 of FP32) and higher computing throughput. However, existing low-precision training techniques face insurmountable technical barriers in practical applications, which are rooted in the inherent "low representation precision" and "narrow dynamic range" characteristics of low-precision format. Specifically, the effective number of bits of FP8 and other low-precision formats is only 8 bits, which has a significant precision loss compared to FP32 (23 effective bits), and the dynamic range (the ratio of the maximum value to the minimum value of the representable numerical value) is only about 1 / 1000 of FP32, resulting in information loss of gradient, weight and other key parameters during storage and calculation. This characteristic directly causes the parameter update deviation of traditional optimizers (such as SGD Adam): low representation precision makes the subtle changes of gradient truncated or covered by quantization noise, and the optimizer cannot accurately capture the direction and amplitude of parameter adjustment; narrow dynamic range leads to extreme gradient values (such as large gradient truncated due to overflow and small gradient zeroed due to insufficient precision), causing gradient vanishing or explosion, and further causing the loss function to oscillate sharply or even diverge during training. Existing technologies lack systematic solutions to this problem: most low-precision training methods simply rely on quantization algorithms to compress data formats without designing adaptive mechanisms for the temporal correlation of gradients, resulting in historical gradient information being unable to effectively assist current update decisions; the learning rate scheduling and momentum update mechanisms of traditional optimizers are based on high-precision assumptions, which are prone to mechanism mismatch in low-precision scenarios - for example, the second moment estimation of Adam will produce cumulative errors under the interference of quantization noise, exacerbating the instability of parameter updates. These defects collectively result in a model convergence speed that is more than 30% slower than high-precision training, and ultimately in ImageNet classification, GLUE language understanding and other tasks, the accuracy decreases by 5%-15%, the perplexity increases by more than 20%, and the practical value of low-precision technology in large language models is severely restricted. Therefore, it is urgent to build a gradient adaptive mechanism that adapts to the characteristics of low precision, while maintaining the stability and performance of model training while ensuring resource efficiency. SUMMARY

[0003] Therefore, it is necessary to provide an FP8 gradient adaptive optimization method and device for large language model training, which can improve the learning efficiency of the large language model and balance the computer storage precision, efficiency and resource consumption.

[0004] An FP8 gradient adaptive optimization method for large language model training, the method comprising: In the learning iteration process of the large language model on the user input data, the processor obtains the original high-precision gradient tensor of the current iteration step and the historical information containing the historical gradient stored in the memory, and the processor quantizes the scaling factor and the gradient value according to the target FP8 format to obtain quantized input data; the quantized input data is stored in the memory.

[0005] After the processor filters and denoises the quantized input data stored in the memory, the state of the optimizer is updated and stored in the memory, and the processor obtains the system parameter update amount using the learning mechanism corresponding to the optimizer according to the base learning rate and the system parameter.

[0006] The processor optimizes the large language model according to the system parameter update amount and the preset evaluation strategy to obtain a trained large language model, and uses the trained large language model to complete the gradient adaptive optimization of the input data of the next iteration step, and outputs high-precision data, wherein the intermediate data in the iteration process are stored through the memory and processed through the processor.

[0007] An FP8 gradient adaptive optimization device for large language model training, the device comprising: A quantization module is configured to, in the learning iteration process of the large language model on the user input data, obtain the original high-precision gradient tensor of the current iteration step and the historical information containing the historical gradient stored in the memory by the processor, and obtain quantized input data by quantizing the scaling factor and the gradient value according to the target FP8 format by the processor; the quantized input data is stored in the memory.

[0008] A gradient optimization module is configured to, after the processor filters and denoises the quantized input data stored in the memory, update the state of the optimizer and store it in the memory, and the processor obtains the system parameter update amount using the learning mechanism corresponding to the optimizer according to the base learning rate and the system parameter.

[0009] A gradient adaptive module is configured to, the processor optimizes the large language model according to the system parameter update amount and the preset evaluation strategy to obtain a trained large language model, and uses the trained large language model to complete the gradient adaptive optimization of the input data of the next iteration step, and outputs high-precision data, wherein the intermediate data in the iteration process are stored through the memory and processed through the processor.

[0010] The above FP8 gradient self-adaptive optimization method and device for large language model training first synchronously acquires the current iteration step original high-precision gradient tensor and historical gradient information, breaks through the limitation of traditional single-step gradient dependence, provides a data basis for processing narrow dynamic range, dynamically captures the global characteristics of gradient distribution by incorporating historical gradient, avoids representation deviation caused by single-step gradient fluctuation, and alleviates the problem of insufficient dynamic range under low precision. On this basis, the scaling factor and gradient value are quantized according to the target FP8 format, and the key gradient information is preserved while reducing the representation precision (FP8) through a precisely designed scaling strategy, which not only reduces the system storage and computing resource occupation (consistent with the low resource requirement), but also avoids information loss caused by simple low-precision quantization, solving the performance decline problem caused by low representation precision. In view of the noise that may be introduced in the quantization process, the scheme purifies the input data through filtering and denoising processing, directly weakens the interference of noise on the parameter update of the optimizer, and alleviates the inaccurate update problem of the traditional optimizer caused by noise amplification under low precision. When updating the optimizer state, the adaptive mechanism of the basic learning rate and the system parameters is combined to make the optimizer learning mechanism and the FP8 gradient characteristics deeply collaborative, avoid the mechanism mismatch of the traditional optimizer under low precision, and reduce the numerical instability phenomena such as gradient vanishing / explosion and loss shock. Finally, through the preset evaluation strategy, the model is continuously optimized, and the training results are fed back to the gradient self-adaptive optimization of the next iteration step, forming a “quantization-optimization-feedback” closed loop, accelerating the model convergence speed, and ensuring that the final model approaches the high-precision training level in terms of accuracy, perplexity and other performance indicators. The overall scheme manages the FP8 gradient adaptively, reduces the system resource occupation rate, significantly improves the model learning efficiency, and realizes the balance between precision, efficiency and resource consumption under low-precision training. BRIEF DESCRIPTION OF DRAWINGS

[0011] Figure 1 A flowchart of an embodiment of the FP8 gradient self-adaptive optimization method for large language model training; Figure 2 A flowchart of an embodiment of the multi-scale gradient noise filtering and signal enhancement module implementation method; Figure 3 A structural block diagram of an embodiment of the FP8 gradient self-adaptive optimization device for large language model training. DETAILED DESCRIPTION

[0012] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.

[0013] In one embodiment, as Figure 1As shown, an FP8 gradient adaptive optimization method for large language model training is provided, comprising the following steps: Step 102, in the learning iteration process of the large language model to the user input data, the processor acquires the original high-precision gradient tensor of the current iteration step and the historical information containing the historical gradient stored in the memory, and the processor quantizes the scaling factor and the gradient value according to the target FP8 format to obtain quantized input data; the quantized input data is stored in the memory.

[0014] Step 104, the processor updates the state of the optimizer after filtering and denoising the quantized input data stored in the memory and stores it in the memory, and the processor acquires the system parameter update amount using the learning mechanism corresponding to the optimizer according to the base learning rate and the system parameter.

[0015] Step 106, the processor optimizes the large language model according to the system parameter update amount and the preset evaluation strategy to obtain a trained large language model, and uses the trained large language model to complete the gradient adaptive optimization of the input data of the next iteration step, and outputs high-precision data, wherein the intermediate data in the iteration process are stored through the memory and processed through the processor.

[0016] The aforementioned FP8 gradient adaptive optimization method for training large language models constructs a complete chain of "full gradient information capture - adaptive quantization precision - noise suppression - optimizer collaboration - closed-loop iterative optimization," specifically addressing the core pain points in low-precision training and achieving efficient model training through FP8 gradient adaptation. First, by simultaneously acquiring the original high-precision gradient tensor of the current iteration step and historical gradient information, it overcomes the limitations of traditional single-step gradient dependence, providing a data foundation for handling narrow dynamic ranges. The inclusion of historical gradients dynamically captures the global characteristics of gradient distribution, avoiding representation bias caused by single-step gradient fluctuations and alleviating the problem of insufficient dynamic range under low precision. Based on this, the scaling factor and gradient values ​​are quantized according to the target FP8 format. Through a precisely designed scaling strategy, key gradient information is retained while reducing representation precision (FP8), reducing system storage and computational resource consumption (meeting low resource requirements) and avoiding information loss caused by simple low-precision quantization, thus resolving the performance degradation risks caused by "low representation precision." To address potential noise introduced during the quantization process, the solution purifies the input data through filtering and denoising, directly reducing noise interference with optimizer parameter updates and mitigating the inaccurate updates caused by noise amplification in traditional optimizers at low precision. When updating the optimizer state, a mechanism for adapting the base learning rate to system parameters is incorporated, enabling deep collaboration between the optimizer's learning mechanism and the FP8 gradient characteristics. This avoids mechanism mismatch in low-precision scenarios and reduces numerical instability phenomena such as gradient vanishing / exploding and loss oscillations. Finally, a pre-defined evaluation strategy continuously optimizes the model, feeding the training results back into the adaptive gradient optimization of the next iteration, forming a "quantization-optimization-feedback" closed loop. This accelerates model convergence and ensures the final model approaches high-precision training levels in terms of accuracy, perplexity, and other performance metrics. The overall solution, through adaptive management of FP8 gradients, significantly improves model learning efficiency while reducing system resource consumption, achieving a balance between system storage accuracy, efficiency, and resource consumption under low-precision training.

[0017] In one embodiment, during the learning iteration process of the large language model on the user input data, the processor obtains the original high-precision gradient tensor of the data and the historical information containing historical gradients stored in the memory. The processor pushes the acceleration value for calculating the original high-precision gradient tensor into the circular queue of historical information in the memory. The processor takes the maximum value of the acceleration value in the new circular queue in the memory, performs format switching according to the target FP8 format, and then quantizes the scaling factor. The processor scales the original high-precision gradient tensor according to the quantized scaling factor: ; ; in, For the original high-precision gradient tensor, is a scaling factor for quantization, is a scaled high-precision gradient value, is a dynamic range margin, is an acceleration value of the original high-precision gradient tensor, is a target FP8 format; the scaled original high-precision gradient tensor is quantized into the target FP8 format to obtain quantized input data and is stored in the memory.

[0018] In one of the embodiments, the processor filters the dequantized gradient value of the working precision of the quantized input data stored in the memory by using a time index exponential smoothing filtering algorithm: ; wherein, is a filtered gradient value, is the dequantized gradient value of the working precision, is a smoothing factor. The processor updates the state of the optimizer according to the dequantized gradient value of the working precision stored in the memory and the filtered gradient value of the last iteration step, and stores the updated state in the memory, and outputs the filtered quantized gradient corresponding to the current iteration step.

[0019] In one of the embodiments, if the optimizer is Adam, the processor updates the first-order momentum and the second-order momentum of the optimizer according to the filtered quantized gradient stored in the memory and the system parameters, and stores the updated first-order momentum and the second-order momentum in the memory, and then corrects the deviation of the updated first-order momentum and the second-order momentum: ; ; ; ; ; wherein, is the updated first-order momentum, is the updated second-order momentum, , are different hyperparameters of the large language model, is the filtered quantized gradient, is a gradient square term, is the filtered quantized gradient value of the current iteration step, is the first-order momentum after the correction of the deviation, is the second-order momentum after the correction of the deviation. The processor calculates the system parameter update amount according to the first-order momentum after the correction of the deviation, the second-order momentum after the correction of the deviation, the master weight of the large language model, and the base learning rate stored in the memory: ; ; ; wherein, is the system parameter update quantity corresponding to the current iteration step, is the applied learning rate of the Adam optimizer, is the base learning rate, is the weight decay rate, is the master weight, is the FP8-specific stabilizer.

[0020] In one of the embodiments, the processor checks the loss value of the master weight and the system parameter update quantity stored in the memory using the anomaly detection strategy, and when an anomaly is detected, it rolls back to the stable master weight of the previous iteration step stored in the memory after completing the parameter update of the large language model before the next iteration step.

[0021] In one of the embodiments, if the optimizer is SGD, the processor updates the momentum accumulation item of the optimizer according to the filtered quantized gradient stored in the memory and the system parameter, and stores it in the memory: ; wherein, is the updated momentum accumulation item of the current iteration step, is the momentum coefficient, is the momentum accumulation item of the previous iteration step without update, is the filtered quantized gradient value of the current iteration step. The processor obtains the system parameter update quantity according to the updated momentum accumulation item stored in the memory, the master weight of the large language model, and the base learning rate, and stores it in the memory: ; wherein, is the system parameter update quantity, is the base learning rate, is the updated momentum accumulation item of the current iteration step.

[0022] In one of the embodiments, the processor checks the loss value of the master weight and the system parameter update quantity stored in the memory using the anomaly detection strategy, and when an anomaly is detected, it rolls back to the stable master weight of the previous iteration step stored in the memory after completing the parameter update of the large language model before the next iteration step, and hot starts the SGD optimizer in FP8 format with the updated learning rate, wherein the learning rate and the optimizer state are stored in the memory.

[0023] In one of the embodiments, an FP8 gradient adaptive optimization step for large language model training is provided, with the following details: 1. Initialization: Model parameters (usually stored as BF16 or FP32-Master Weights).

[0024] Adam states: first momentum (BF16 / FP32), second momentum (BF16 / FP32).

[0025] Hyperparameters: (e.g., 0.9, 0.999), original base learning rate , weight decay .

[0026] FP8 related configurations: initial parameters of GP-ADR module (e.g., amax history window size), initial parameters of GNF-SE module (e.g., smoothing factor ), initial values or adjustment strategies of OCM-F8 module , initial threshold value or adaptive strategy parameters of NSC-E module.

[0027] Iteration counter .

[0028] 2. Iteration loop starts : a. Get the current batch data, calculate the model forward propagation and loss function.

[0029] b. Perform backpropagation to get the high-precision gradient under the current parameters (e.g., BF16).

[0030] c. Module 1: GP-ADR pair Apply dynamic range adaptive scaling (DRAS) and gradient characteristic-aware format selection (GAFS) to get the preliminary quantization and preprocessed FP8 gradient and its inverse scaling factor .

[0031] d. Module 2: GNF-SE pair (Firstly, quantize to working precision) apply time exponential smoothing filter (TESF) and possible gradient confidence weighting (GCW) to get the filtered gradient (working precision, e.g., BF16).

[0032] ​e. Module 4: NSC-E-ACT pair Apply Adaptive Clipping Threshold (ACT) to get clipped gradients .

[0033] f. Module 3: OCM-F8-FP8-AdamGuard core update: i. Update first order momentum: .

[0034] ii. Update second order momentum: .

[0035] iii. Calculate bias-corrected momentum: .

[0036] iv. Get current scheduled learning rate . Where, is the learning rate scheduling function.

[0037] v. Calculate parameter update: . According to FP8 feature dynamically set.

[0038] g. Module 4: NSC-E-PLCR (optional) If Quantized before finally applied to FP8 parameters, record the quantization residual and use it for subsequent compensation.

[0039] h. Parameter update: • Apply weight decay: (if using AdamW method).

[0040] • Final update: Here is the high-precision master weight.

[0041] i. Module 4: NSC-E-NDR check Check if NaN / Inf exists in the current loss value. If so, perform recovery strategies (such as rollback, reduce learning rate).

[0042] j. If the master weight needs to be quantized to FP8 for the next round of calculation (such as the model parameters themselves also use FP8 storage), then quantization is performed at this time.

[0043] 3. Iteration end: Determine whether the preset convergence condition (such as the validation set performance no longer improves) or the maximum number of iterations has been reached .

[0044] In one of the embodiments, an overall processing flow of an adaptive optimization algorithm adapted to FP8 gradient is provided, and the specific steps are as follows: Embodiment 1: An adaptive optimization algorithm (FP8-AdamWAdapt) adapted to FP8 gradient based on AdamW improvement This embodiment deeply integrates four core modules designed to adapt to the characteristics of FP8 gradient on the basis of the widely used AdamW optimization algorithm. AdamW is selected as the basis because of its excellent performance in large model training and correct handling of weight decay.

[0045] 1. Specific implementation of FP8 gradient adaptive preprocessing and dynamic representation module (GP-ADR): Input: the original high-precision gradient tensor calculated by the current training iteration step (usually in BF16 or FP32 format), and a dictionary state_gp_adr storing module state, which contains, for example, the historical record state_gp_adr[amax_history] of the maximum value (amax) of the gradient absolute value of the past steps and a counter / flag for dynamic format selection.

[0046] Step 1.1: Gradient statistics and analysis: Calculate the amax value of the current gradient tensor , denoted as current_amax. At the same time, some features of its statistical distribution can be calculated, such as mean, standard deviation, sparsity (zero value proportion), to assist subsequent dynamic format selection.

[0047] Step 1.2: Determination of dynamic scaling factor (scale_for_quantization) (DRAS implementation): a. Push current_amax into the state_gp_adr[amax_history] circular queue of fixed length.

[0048] b. Select a representative amax value amax_representative from state_gp_adr[amax_history]. For example, you can take the maximum value in the history window, or more robustly take a certain high percentile (99.5%) of the amax value in the history window, or use the Delayed Scaling recipe in NVIDIA Transformer Engine (for example, take the maximum value from the amax history).

[0049] ​c. Select the target FP8 format. Default can be set to E4M3, based on the gradient characteristic analysis in step 1.1. If there are too many outliers or the range is too large, the GAFS mechanism can temporarily switch to E5M2. Let FP8_max_representable be the maximum normal value that can be represented by the selected FP8 format.

[0050] d. Calculate the scaling factor for quantization: where margin is a coefficient less than 1 (e.g. 0.98) to provide some dynamic range margin and reduce clipping. To prevent too small (when amax_representative is very small), set a minimum allowed value (e.g. based on the minimum normal number of FP8).

[0051] Step 1.3: Gradient scaling and quantization to FP8: a. Scale the gradient values to be quantized: .

[0052] b. Quantize the scaled gradient values to the target FP8 format (e.g. E4M3). This process includes converting the floating point numbers to binary representation of FP8, and applying a rounding rule (e.g. Stochastic Rounding, or Round-to-Nearest-Even), to get the FP8 gradient . Stochastic Rounding helps to reduce quantization bias.

[0053] Step 1.4: Anti-scaling factor passing: pass (or its inverse, defined according to the subsequent usage habit) together with to the subsequent module, for restoring the FP8 gradient to the approximate original scale when needed.

[0054] Output: the pre-processed FP8 gradient tensor , its corresponding (anti-)scaling factor , and the updated state_gp_adr.

[0055] 2. Detailed implementation of the multi-scale gradient noise filtering and signal enhancement module (GNF-SE): Input: the and its scaling factor from the output of module one, and the module state state_gnf_se (containing the smoothed gradient and the smoothing coefficient of TESF from the previous time step, etc.).

[0056] ​Step 2.1: Preliminary dequantization to working precision: where, is the working precision, is the dequantization function, this step restores the FP8 gradient to a working precision (e.g., BF16) close to the original scale but still containing FP8 quantization noise.

[0057] Step 2.2: Time Series Exponential Smoothing Filter (TESF): ; smoothing factor can be dynamically adjusted: for example, in the initial stage of training, or when the loss function changes significantly, can be set to a larger value (e.g., 0.3-0.5) to quickly track gradient changes; in the later stages of training or in stable stages, can be reduced (e.g., 0.05-0.1) to enhance the noise smoothing effect. state_gnf_sec can save the logic for adjusting .

[0058] Step 2.3: (Optional advanced strategy) Gradient Confidence Weighting (GCW) or Direction Consistency Enhancement: a. Calculate the cosine similarity with (or the average direction of the past K-step smoothed gradients).

[0059] b. If is below a certain threshold (indicating that the current gradient is significantly different from the historical trend, possibly due to severe noise influence or encountering a sudden change point), then or the magnitude of can be further reduced, or more reliance can be placed on .

[0060] c. The final filtered gradient will be the module output. If there is no such advanced strategy, .

[0061] Output: Filtered gradient (working precision, e.g., BF16), and updated state_gnf_se.

[0062] 3. Specific implementation of FP8-friendly AdamW core mechanism improvement module (OCM-F8) (FP8-AdamWAdapt): Input: the output of module two (BF16), the current parameter master weight (BF16 / FP32), the optimizer state state_ocm_f8 (containing the first-order momentum (BF16 / FP32), second order momentum (BF16 / FP32), number of iterations ), and hyperparameters (original base learning rate , , FP8-specific stabilization term weight decay rate ).

[0063] Step 3.1: Update first order momentum (Momentum): . Maintained at higher precision (BF16 / FP32) to accumulate historical information.

[0064] Step 3.2: Update second order momentum (Variance): a. Compute gradient square term: . Since the square operation is sensitive to outliers, one can consider applying a slight Huber loss function transformation or value clipping before using to limit the impact of extreme values on the second order momentum.

[0065] b. , where is again maintained at higher precision.

[0066] Step 3.3: Bias Correction: , .

[0067] Step 3.4: Compute parameter update: a. Determine the learning rate for the current epoch (e.g. from the original base learning rate by a learning rate scheduler such as cosine annealing).

[0068] b. FP8-specific stabilization term : Can be a fixed value slightly larger than the minimum resolution of the used FP8 format (e.g. to ).

[0069] c. Compute update direction and magnitude: .

[0070] d. Apply learning rate: . Where is the parameter update function of the optimizer Adam.

[0071] Step 3.5: Apply weight decay (AdamW way): (Note that weight decay in AdamW is added to the final update and coupled with the learning rate).

[0072] Output: Final parameter update (BF16 / FP32), and updated state_ocm_f8 .

[0073] 4. Integrated application of Numerical Stability and Convergence Enhancement module (NSC-E): Adaptive Clipping Threshold (ACT): Before step 3.1, i.e., obtaining , clip its norm. The clipping threshold can be dynamically set based on the moving average or percentile of historical gradient norms, e.g. , denotes the clipping coefficient, typically 2-10, EMA denotes the exponential moving average of the corresponding element, is the historical gradient norm.

[0074] NaN / Inf Detection and Handling (NDR): After each parameter update (i.e., obtaining ), immediately check all elements of and the loss value of the current batch. If any NaN or Inf value is detected: a. Record the event, roll back the model parameters to the last stable state (or the latest checkpoint).

[0075] b. Temporarily significantly reduce the current learning rate (e.g., multiply by 0.1 or 0.5).

[0076] c. (Optional) Enhance the filtering strength of module two GNF-SE (e.g., temporarily reduce in the next few steps).

[0077] d. (Optional) Skip the parameter update of the current batch of data completely, or retry the current batch with a very small learning rate.

[0078] (Optional) Optimizer State Quantization (OSQ): For extreme compression of memory, high-precision Before storing to state_ocm_f8, quantize to FP8 format using similar DRAS and GAFS techniques as module one. Before the next iteration starts (before steps 3.1 and 3.2), dequantize them back from FP8 to BF16 / FP32 for computation. This requires very careful handling of precision loss and possible bias accumulation during quantization and dequantization.

[0079] Through the cooperation of the above modules, the FP8-AdamWAdapt algorithm can alleviate the adverse effects of FP8 gradient to a large extent, and achieve more stable and efficient training.

[0080] It is worth mentioning that, as Figure 2 shown in the multi-scale gradient noise filtering and signal enhancement module, the input pre-processed FP8 gradient (already dequantized to working precision) is first passed through TESF (time series exponential smoothing), and its output is then weighted with the confidence calculated by a certain confidence evaluation mechanism (GCW), and finally the filtered and enhanced gradient is output. The smoothing factor and the confidence how to affect the final output.

[0081] Example 2: Adaptive optimization algorithm based on improved SGD adapted to FP8 gradient (FP8-SGDMAdapt) This embodiment is improved based on the momentum SGD (SGDM) algorithm. SGDM is selected because of its simplicity, good generalization performance, and advantages over Adam-type algorithms in certain scenarios (especially after fine-tuning).

[0082] 1. FP8 gradient adaptive preprocessing and dynamic representation module (GP-ADR): the implementation is basically the same as described in Example 1. For SGDM, it may focus more on preserving the high precision characteristics of E4M3 through GAFS, because SGDM does not have a second-order momentum to smooth the square of the noise.

[0083] 2. Multi-scale gradient noise filtering and signal enhancement module (GNF-SE): the implementation is basically the same as described in Example 1. For SGDM, since its parameter update directly depends on the gradient (after momentum accumulation), the GNF-SE module is particularly important for smoothing and denoising the gradient. Stronger filtering settings or additional noise robustness mechanisms can be considered.

[0084] 3. FP8-friendly SGDM core mechanism improvement module (OCM-F8) specific implementation (FP8-SGDMAdapt): Input: (BF16) output of module two , current parameter master weight (BF16 / FP32), optimizer state state_ocm_f8 (contains momentum accumulation term from last time step (BF16 / FP32), number of iterations ), and hyperparameters (original base learning rate , momentum coefficient , weight decay rate ).

[0085] Step 3.1: Update momentum accumulation term ): .

[0086] Note that, unlike standard SGDM, the learning rate here is usually applied to the final parameter update step after momentum accumulation and maintained at BF16 / FP32 precision.

[0087] Step 3.2: Apply learning rate and weight decay, compute parameter update: Get the learning rate for the current epoch (computed by the learning rate scheduler from ); If weight decay is used, it is usually applied directly to the gradient: (L2-regularized gradient term). If not, then .

[0088] Compute the final parameter update: .

[0089] Enhanced integration of learning rate dynamic adjustment strategies: Since SGDM is more sensitive to learning rate, especially in the noisy environment of FP8 gradients, more complex adaptive learning rate adjustment mechanisms can be integrated. For example: Adjustment based on consistency of gradient and momentum direction: If the current filtered gradient continues to be highly consistent with the direction of the last momentum term (cosine similarity), the learning rate can be moderately increased; if the direction frequently reverses, the learning rate should be decreased.

[0090] Adjustment based on gradient norm or sparsity: If the gradient norm continues to be small or the gradient is very sparse, it may indicate that learning has entered a stable period or some parameters are no longer important, at which point targeted adjustment of the learning rate can be considered.

[0091] Output: final parameter update (BF16 / FP32), and updated state_ocm_f8 .

[0092] 4. Integration of Numerical Stability and Convergence Enhancement Module (NSC-E): Adaptive Clipping Threshold (ACT): Similar to Embodiment 1, acting on the learning rate adjusted gradient before momentum update.

[0093] NaN / Inf Detection and Handling (NDR): Similar to Embodiment 1.

[0094] Warm-up & FP8 Adaptation Period: Considering the instability of SGDM in the early stage of training, especially in the FP8 environment, a “warm-up” phase can be designed. In this phase: a. Perform gradient computation and accumulation with relatively higher precision (e.g., use BF16 gradient for the first K steps, or use a very conservative quantization strategy for FP8 gradient, such as fixed use of E5M2, and cooperate with a larger scaling factor to sacrifice part of the precision in exchange for range).

[0095] b. Cooperate with a very small initial learning rate, and gradually warm-up it to the target base learning rate.

[0096] c. After the end of this phase, smoothly transition to a more aggressive FP8 quantization strategy and normal learning rate scheduling. This helps the model establish a relatively stable foundation in the early stage of training, and then gradually adapt to the challenges brought by FP8.

[0097] Momentum Quantization: Similar to the discussion of Adam state in Embodiment 1, if further memory compression is needed, the momentum term can be quantized to FP8 storage and de-quantized in the next round of calculation. This also needs to handle the error introduced by quantization carefully.

[0098] FP8-SGDMAdapt aims to make SGDM perform well in the FP8 environment by strengthening gradient handling and introducing stability measures specific to SGDM characteristics, especially suitable for scenarios with more stringent requirements for memory and computational complexity.

[0099] It should be understood that although Figures 1-2 the steps in the flowchart of the method are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated otherwise in this document, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, Figures 1-2At least one of the steps in the method can comprise a plurality of sub-steps or a plurality of stages, which sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the order of the sub-steps or stages is not necessarily sequential, but can be performed alternately or in rotation with other steps or sub-steps or stages of other steps.

[0100] In one embodiment, as shown in Figure 3 An FP8 gradient adaptive optimization device for large language model training is provided, comprising: a quantization module 302, a gradient optimization module 304, and a gradient adaptive module 306, wherein: The quantization module 302 is configured to, in a learning iteration process of the large language model on user input data, obtain, by a processor, an original high-precision gradient tensor of a current iteration step and historical information containing historical gradients stored in a memory, and quantize and scale the gradient values according to a target FP8 format to obtain quantized input data; and the quantized input data is stored in the memory.

[0101] The gradient optimization module 304 is configured to, after the processor filters and denoises the quantized input data stored in the memory, update the state of an optimizer and store it in the memory, and obtain a system parameter update amount by the processor using a learning mechanism corresponding to the optimizer according to a base learning rate and system parameters.

[0102] The gradient adaptive module 306 is configured to optimize the large language model according to the system parameter update amount and a preset evaluation strategy by the processor to obtain a trained large language model, and complete gradient adaptive optimization of input data of the next iteration step using the trained large language model to output high-precision data, wherein intermediate data in the iteration process are stored by the memory and processed by the processor.

[0103] For specific limitations of the FP8 gradient adaptive optimization device for large language model training, refer to the limitations of the FP8 gradient adaptive optimization method for large language model training in the foregoing, which will not be repeated here. Each module in the above FP8 gradient adaptive optimization device for large language model training can be realized by software, hardware, and combinations thereof, in whole or in part. The above modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operations corresponding to each module.

[0104] Those skilled in the art can understand that Figure 3The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0105] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, database or other medium used in each embodiment provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0106] Each technical feature of the above embodiments can be combined arbitrarily. In order to make the description simple, all possible combinations of each technical feature in the above embodiments are not described, but as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.

[0107] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the present application. It should be pointed out that for a person of ordinary skill in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. An FP8 gradient self-adaptive optimization method for large language model training, characterized in that, The method comprises: In the learning iteration process of the large language model on the user input data, the processor acquires the original high-precision gradient tensor of the current iteration step and the historical information containing historical gradients stored in the memory, and scales the gradient value according to the target FP8 format quantization scaling factor by the processor to obtain quantized input data; the quantized input data is stored in the memory; After the processor filters and denoises the quantized input data stored in the memory, the state of the optimizer is updated and stored in the memory, and the processor acquires the system parameter update amount by using the learning mechanism corresponding to the optimizer according to the base learning rate and the system parameter. The processor optimizes the large language model according to the system parameter update amount and the preset evaluation strategy to obtain the trained large language model, and uses the trained large language model to complete the gradient adaptive optimization of the input data of the next iteration step, and outputs high-precision data, wherein the intermediate data in the iteration process are stored in the memory and processed by the processor.

2. The method of claim 1, wherein, In the learning iteration process of the large language model on the user input data, the processor acquires the original high-precision gradient tensor of the current iteration step and the historical information containing historical gradients stored in the memory, and scales the gradient value according to the target FP8 format quantization scaling factor by the processor to obtain quantized input data, comprising: In the learning iteration process of the large language model on the user input data, the processor acquires the original high-precision gradient tensor of the data and the historical information containing historical gradients stored in the memory, pushes the acceleration value calculated for the original high-precision gradient tensor into the circular queue of the historical information in the memory by the processor, takes the maximum value of the acceleration value in the new circular queue in the memory by the processor, and quantizes the scaling factor after format conversion according to the target FP8 format; The processor scales the original high-precision gradient tensor according to the quantized scaling factor: ; ; wherein, is the original high-precision gradient tensor, is a quantization scaling factor, is the scaled high-precision gradient value, is a dynamic range margin, is an acceleration value of the original high-precision gradient tensor, is a target FP8 format; The original high-precision gradient tensor after scaling is quantized to the target FP8 format to obtain quantized input data and store it in the memory.

3. The method of claim 2, wherein, After the processor filters and denoises the quantized input data stored in the memory, the state of the optimizer is updated and stored in the memory, comprising: The processor uses a time series exponential smoothing filtering algorithm to filter the gradient value of the dequantization to working precision of the quantized input data stored in the memory: ; wherein, is the filtered gradient value, is the gradient value dequantized to the working precision, is the smoothing factor, is the quantized input data; The processor updates the state of the optimizer according to the dequantized gradient value to working precision stored in the memory and the gradient value after filtering of the last iteration step, and stores it in the memory, and outputs the filtered quantized gradient corresponding to the current iteration step.

4. The method of claim 3, wherein, The processor acquires the system parameter update amount by using the learning mechanism corresponding to the optimizer according to the base learning rate and the system parameter, comprising: If the optimizer is Adam, the processor updates the first-order momentum and the second-order momentum of the optimizer according to the filtered quantized gradient and the system parameters stored in the memory, and stores them in the memory, and then corrects the deviation of the updated first-order momentum and the second-order momentum: ; ; ; ; ; wherein, is the updated first order momentum, is the updated second order momentum, , are different hyperparameters of the large language model, respectively, is the filtered quantized gradient, is the gradient square is the filtered quantized gradient value at the current iteration step, is the first order momentum after correcting the bias, is the second order momentum after correcting the bias; The processor calculates the system parameter update amount according to the first-order momentum after the correction of the deviation, the second-order momentum after the correction of the deviation, the main weight of the large language model, and the basic learning rate stored in the memory: ; ; ; wherein, is the system parameter update for the current iteration step, is the applied learning rate for the Adam optimizer, is the base learning rate, is the weight decay rate, is the master weight, is the FP8 specific stabilizer, is the parameter update function for the Adam optimizer.

5. The method of claim 4, wherein, After the processor calculates the system parameter update amount according to the first-order momentum after the correction of the deviation, the second-order momentum after the correction of the deviation, the main weight of the large language model, and the basic learning rate stored in the memory, the method further comprises: The processor checks the loss value of the main weight and the system parameter update amount stored in the memory using an anomaly detection strategy, and when an anomaly is detected, it rolls back to the stable main weight of the last iteration step stored in the memory after completing the parameter update of the large language model before the next iteration step.

6. The method of claim 3, wherein, The processor obtains the system parameter update amount according to the basic learning rate and the system parameters using the learning mechanism corresponding to the optimizer, comprising: If the optimizer is SGD, the processor updates the momentum accumulation item of the optimizer according to the filtered quantized gradient and the system parameters stored in the memory, and stores them in the memory: ; wherein, is the updated momentum accumulation for the current iteration step, is the momentum coefficient, is the non-updated momentum accumulation for the previous iteration step, is the filtered quantized gradient value for the current iteration step; The processor obtains the system parameter update amount according to the updated momentum accumulation item stored in the memory, the main weight of the large language model, and the basic learning rate, and stores it in the memory: ; wherein, is a system parameter update, is a base learning rate, is a momentum accumulation item updated at the current iteration step.

7. The method of claim 6, wherein, After the processor obtains the system parameter update amount according to the updated momentum accumulation item stored in the memory, the main weight of the large language model, and the basic learning rate, and stores it in the memory, the method further comprises: The processor checks the loss value of the main weight and the system parameter update amount stored in the memory using an anomaly detection strategy, and when an anomaly is detected, it rolls back to the stable main weight of the last iteration step stored in the memory after completing the parameter update of the large language model before the next iteration step.

8. An FP8 gradient self-adaptive optimization device for large language model training, characterized in that, The device comprises: A quantization module for, in the learning iteration process of a large language model on user input data, the processor obtains the original high-precision gradient tensor of the current iteration step and the historical information containing historical gradients stored in the memory, and the processor quantizes the scaling factor and the gradient value according to the target FP8 format to obtain quantized input data; the quantized input data is stored in the memory; A gradient optimization module for, after the processor filters and denoises the quantized input data stored in the memory, updating the state of the optimizer and storing it in the memory, and the processor obtains the system parameter update amount using the learning mechanism corresponding to the optimizer according to the basic learning rate and the system parameters; A gradient adaptation module is configured to update the large language model according to the system parameter update quantity and a preset evaluation strategy, obtain a trained large language model, and use the trained large language model to complete gradient adaptation optimization of input data in a next iteration step, and output high-precision data, wherein intermediate data in the iteration process are stored by a memory and processed by a processor.

Citation Information

Patent Citations

  • Large language model reasoning acceleration method and system based on dynamic video memory compression and memory isomerism

    CN120371524A

  • Model training method and device, equipment, storage medium and program product

    CN120509453A

  • Dynamic optimization system for AI model training parameters

    CN120633719A

  • Large language model optimization method and system based on variance reduction and momentum acceleration

    CN120910340A

  • Fast Adaptive Optimization

    US20210295201A1

Cited By

  • FP8 quantization noise compensation method and system for large language model training

    CN121171246A

  • Text acceleration generation method and system based on dynamic mask and parallel decoding

    CN121881994A