Gradient accumulation optimization method and system for fp8 mixed precision training

By optimizing the gradient accumulation method for FP8 mixed-precision training, and utilizing directional rounding bias estimation and dynamic scaling factor, the gradient direction correction and accumulator state awareness are achieved, solving the bias and overflow problems in the gradient accumulation process and maintaining high-precision gradient accumulation effect.

CN123178982APending Publication Date: 2026-11-27SHANDONG XIEHE UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611665318.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-27
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies in FP8 mixed-precision training suffer from linear growth of directional rounding bias during gradient accumulation, lack of accumulator state awareness in scaling factor calculation, and lack of tracking mechanism for quantization error accumulation state, leading to gradient direction deviation, overflow risk, and accuracy loss.

Method used

By reading historical gradient sign distribution statistics to estimate directional rounding bias, dynamically calculating scaling factors and monitoring quantization errors, gradient pre-correction, accumulator state awareness, and error-driven scheduling are achieved, forming a closed-loop optimization.

Benefits of technology

It effectively eliminates gradient direction deviation, prevents overflow risk, keeps the accuracy loss of gradient accumulation close to the full accuracy level, and avoids NaN generation and loss spikes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178982A_ABST
    Figure CN123178982A_ABST
Patent Text Reader

Abstract

The application relates to a gradient accumulation optimization method and system for FP8 hybrid precision training. The application relates to the technical field of numerical calculation optimization of a deep learning model. The method comprises the following steps: based on E5M2 quantization boundary region symbol statistics, calculating a directional rounding deviation and pre-correcting a gradient element by element; combining an accumulator inverse quantization value with a pre-corrected gradient superposition amplitude and a dynamic safety margin to calculate a cumulative perception scaling factor, performing E5M2 quantization and accumulation; maintaining a quantization error residual, monitoring the timing change of the scaling factor, and switching the precision mode when the trigger condition is met. The method can prevent overflow and precision waste in the accumulation process, inhibit loss spikes and NaN interruptions, and improve the FP8 gradient accumulation precision and stability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of numerical computation optimization technology for deep learning models, and in particular to a gradient accumulation optimization method and system for FP8 mixed-precision training. Background Technology

[0002] FP8 mixed-precision training has become a key acceleration method for training large-scale deep learning models. Among them, the E5M2 format (1 sign bit, 5 exponent bits, 2 mantissa bits) is widely used for gradient representation and backpropagation due to its large dynamic range. In the gradient accumulation process, the core approach of existing technologies (such as NVIDIA Transformer Engine and FP8-LM) is to transmit and store gradients in E5M2 format, but the accumulator is still maintained with FP32 precision, failing to achieve true FP8 format accumulation to take advantage of its memory. When attempting to migrate the accumulation process to FP8, existing solutions have three unresolved technical problems: First, the E5M2 format only has 2 mantissa bits, and the quantization step size is 25% of the current exponent. When using Round-to-Nearest-Even deterministic rounding, gradient elements in the quantization boundary region are dominated by parity rules, and the rounding error exhibits a systematic statistical advantage in a certain direction, forming a "directional rounding bias". Theoretical analysis shows that this bias increases linearly with the number of cumulative steps, leading to a non-negligible systematic shift in the gradient direction in the 64 to 512 cumulative steps commonly used in large model training. However, existing solutions (including random rounding solutions, which require hardware random number support and increase the rounding noise variance) have not provided a feasible solution to eliminate this bias under deterministic rounding hardware conditions.

[0003] Secondly, existing scaling strategies (delayed scaling, block-by-block scaling) calculate scaling factors based solely on the magnitude statistics of the current or historical batch gradients, failing to consider the dynamic range occupied by the accumulated gradients in the FP8 accumulator as an input variable. This design flaw leads to two consequences: when the accumulator is close to its E5M2 maximum value and the current gradient and the accumulator's internal value are superimposed with the same sign, the scaling factor based on the current gradient magnitude cannot predict the overflow risk, and continued use will result in overflow of the accumulation result; when the accumulator's internal value and the current gradient have opposite signs, the actual superimposed magnitude is much smaller than the sum of absolute values, and existing methods, unable to perceive sign information, adopt a fixed headroom or even completely abandon FP8 accumulation, resulting in a waste of dynamic range precision. This fundamentally stems from the lack of awareness of the accumulator's true remaining capacity in the scaling factor calculation, and no technical solution has been found in existing literature and patents to feed back the accumulator's accumulated state to the scaling factor calculation stage.

[0004] Third, the existing framework lacks a mechanism for continuously tracking the accumulation of quantization errors layer by layer. During low-precision accumulation, the relative error introduced by each E5M2 quantization step can reach 100% when the gradient magnitude is small. After multiple accumulation steps, the quantization error exhibits a non-linear amplification effect, causing distortion of the gradient spectrum magnitude. Existing precision switching mechanisms (such as global rollback) are based solely on indirect macroscopic signals such as training loss, and cannot intervene in a timely manner when the quantization error accumulates to an unacceptable level. They also lack the ability to schedule differentially layer by layer, leading to loss spikes or even NaN interruptions during training. Summary of the Invention

[0005] Therefore, it is necessary to provide a gradient accumulation optimization method and system for FP8 mixed-precision training that can improve the automatic scheduling accuracy in numerical computation of deep learning models and address the above-mentioned technical problems.

[0006] A gradient accumulation optimization method for FP8 mixed-precision training, applied to deep learning models in artificial intelligence infrastructure, the method comprising: Read the sign distribution statistics of the historical gradient tensor in the E5M2 quantization boundary region, calculate the directional rounding bias estimate based on the sign distribution statistics, use the bias estimate to perform element-by-element pre-correction processing on the current batch of gradient tensors, and output the pre-corrected gradient tensors to the subsequent quantization pipeline.

[0007] Read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. Then, perform element-wise superposition of the dequantized accumulated gradient tensor with the pre-corrected gradient tensor of the current batch and calculate the maximum absolute value of the superposition result as the amplitude estimate.

[0008] The safety margin ratio is dynamically calculated based on the current cumulative progress. The scaling factor of the gradient tensor of the current batch is calculated based on the amplitude estimate and the safety margin ratio. The pre-corrected gradient tensor is quantized in E5M2 format using the scaling factor, and the quantization result is accumulated into the FP8 accumulator.

[0009] In each accumulation step, the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization is calculated. This difference is accumulated into the floating-point precision error residual tensor. The norm of the error residual tensor is calculated, and the temporal variation characteristics of the scaling factor are monitored. When the norm or temporal variation characteristics meet preset trigger conditions, a precision mode switch is performed, changing the current accumulation mode from E5M2 format to high-precision format. When a preset recovery condition is met, a reverse switch is performed, remapping the high-precision accumulation result back to E5M2 format.

[0010] A gradient accumulation optimization system for FP8 mixed-precision training, the system comprising: The pre-calibration module is used to read the sign distribution statistics of historical gradient tensors in the E5M2 quantization boundary region, calculate the directional rounding deviation estimate based on the sign distribution statistics, use the deviation estimate to perform element-by-element pre-calibration processing on the current batch of gradient tensors, and output the pre-calibrated gradient tensors to the subsequent quantization pipeline.

[0011] The amplitude estimation module is used to read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. It then performs element-wise superposition of the dequantized accumulated gradient tensor with the pre-corrected gradient tensor of the current batch and calculates the maximum absolute value of the superposition result as the amplitude estimate.

[0012] The cumulative sensing scaling module is used to dynamically calculate the safety margin ratio based on the current accumulation progress, calculate the scaling factor of the current batch gradient tensor based on the amplitude estimate and the safety margin ratio, perform E5M2 format quantization on the pre-corrected gradient tensor using the scaling factor, and accumulate the quantization result into the FP8 accumulator.

[0013] The error-driven scheduling module calculates the difference between the pre-corrected gradient tensor and the corresponding E5M2 quantized and dequantized gradient tensor in each accumulation step. This difference is accumulated into the floating-point precision error residual tensor. The module also calculates the norm of the error residual tensor and monitors the temporal variation characteristics of the scaling factor. When the norm or temporal variation characteristics meet preset trigger conditions, a precision mode switch is executed, changing the current accumulation mode from E5M2 format to a high-precision format. When preset recovery conditions are met, a reverse switch is executed, remapping the high-precision accumulation result back to E5M2 format.

[0014] The aforementioned gradient accumulation optimization method and system for FP8 mixed-precision training first reads the sign distribution statistics of historical gradients in the E5M2 quantization boundary region, calculates the estimated value of directional rounding bias, and performs element-wise pre-correction on the current gradient. The mechanism behind this approach is that the E5M2 format has only two mantissas, and the rounding direction of elements in the quantization boundary region is governed by the RTNE (Round-to-Nearest-Even) odd-even rule. The statistical offset of the sign distribution directly reflects the systematic rounding preference of the quantizer. Since this bias increases linearly with the number of steps during the accumulation of tens to hundreds of steps, without correction, the gradient direction will continuously deviate from the true gradient direction by a fixed angle per step. Pre-correction eliminates the source of this systematic bias accumulation by subtracting a correction amount proportional to the ULP (Unit in the Last Place) from the gradient before quantization.

[0015] Secondly, this method reads the E5M2 encoding of the accumulated value in the accumulator and dequantizes it. It then superimposes this encoding with the current gradient's true value and takes the maximum absolute value as the magnitude estimate. Finally, it dynamically calculates the safety margin ratio based on the accumulation progress to determine the scaling factor. Traditional methods rely solely on the current gradient magnitude to determine the scaling factor, failing to predict the actual peak value after superposition. When the accumulator is nearing saturation and the sign of the current gradient is the same as the value within the accumulator, direct quantization will lead to overflow; when the signs are opposite, the actual superimposed magnitude is far less than the sum of the absolute peak values. This method accurately estimates the accumulated magnitude by superimposing the true values ​​and dynamically reserves headroom (exponential margin) based on the remaining accumulation steps: a larger headroom in the early stages of accumulation to mitigate uncertainty, and a smaller headroom in the later stages to fully utilize the dynamic range. This ensures the scaling factor always matches the accumulator's true capacity, fundamentally eliminating the overflow risk of superlinear growth with increasing accumulation steps under a fixed scaling strategy.

[0016] Finally, the difference between the pre-corrected gradient and the gradient after quantization and dequantization is accumulated into the error residual tensor at each step, and the changing trends of its L2 norm and scaling factor are monitored to drive the precision mode switching. The core of this mechanism is that the error residual directly measures the information loss accumulated during the quantization process, rather than relying on indirect signals such as training loss. When the accumulated error reaches a threshold or the scaling factor drops sharply (indicating a gradient surge), degradation is triggered, which can prevent NaN generation and loss spikes in a timely manner; the cooling period after recovery and the residual reset mechanism avoid frequent mode oscillations. The three measures thus form a complete closed loop: pre-correction eliminates deviations at the source, accumulation-aware scaling prevents abnormal amplification along the path, and error-driven scheduling provides a safety net at the end. The three work together to control the accumulated precision loss of FP8 to near full precision. Attached Figure Description

[0017] Figure 1 This is a diagram illustrating an application scenario of a gradient accumulation optimization method for FP8 mixed-precision training in one embodiment. Figure 2 This is a flowchart illustrating a gradient accumulation optimization method for FP8 mixed-precision training in one embodiment. Figure 3 This is a sequence diagram of the interaction between core functional modules in one embodiment; Figure 4 Here is a flowchart of the E5M2 directional rounding deviation prediction and pre-correction algorithm in one embodiment; Figure 5 Here is a flowchart of the cumulative sensing scaling factor calculation in one embodiment; Figure 6 Here is a flowchart of the error-driven precision scheduling state transition in one embodiment; Figure 7 This is a comparison chart of three scaling strategies in one embodiment; Figure 8 This is a block diagram of a gradient accumulation optimization system for FP8 mixed-precision training in one embodiment. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0019] The gradient accumulation optimization method for FP8 mixed-precision training provided in this application can be applied to, for example... Figure 1 The complete system framework shown is for gradient accumulation optimization in the FP8 E5M2 format. It includes four core functional modules: orientation bias correction module, accumulation sensing scaling factor management module, FP8 quantization and accumulation E5M2 module, and error monitoring and accuracy scheduling module.

[0020] The data flow and control flow relationships between the modules are as follows: the data flow is from right to left, the original gradient passes through the orientation bias correction module, the cumulative sensing scaling factor management module, the FP8 quantizer and then enters the FP8 accumulator, and finally is dequantized and output to the parameter updater; the control flow is bidirectionally connected from the error monitor to the cumulative sensing scaling factor management module and the orientation bias correction module.

[0021] In one embodiment, such as Figure 2 As shown, a gradient accumulation optimization method for FP8 mixed-precision training is provided, which is then applied to... Figure 1 Taking the system framework in [the document] as an example, the following steps are included: Step 202: Read the sign distribution statistics of the historical gradient tensor in the E5M2 quantization boundary region, calculate the directional rounding deviation estimate based on the sign distribution statistics, use the deviation estimate to perform element-by-element pre-correction processing on the current batch of gradient tensors, and output the pre-corrected gradient tensor to the subsequent quantization pipeline.

[0022] Step 204: Read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. Then, perform element-wise superposition of the dequantized accumulated gradient tensor with the pre-corrected gradient tensor of the current batch and calculate the maximum absolute value of the superposition result as the amplitude estimate.

[0023] Step 206: Calculate the safety margin ratio dynamically based on the current cumulative progress, calculate the scaling factor of the current batch gradient tensor based on the amplitude estimate and the safety margin ratio, perform E5M2 format quantization on the pre-corrected gradient tensor using the scaling factor, and accumulate the quantization result into the FP8 accumulator.

[0024] Step 208: In each accumulation step, calculate the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization. Accumulate this difference into the floating-point precision error residual tensor. Calculate the norm of the error residual tensor and monitor the temporal variation characteristics of the scaling factor. When the norm or temporal variation characteristics meet a preset trigger condition, perform a precision mode switch, changing the current accumulation mode from E5M2 format to a high-precision format. When a preset recovery condition is met, perform a reverse switch, remapping the high-precision accumulation result back to E5M2 format.

[0025] In the gradient accumulation optimization method for FP8 mixed-precision training described above, the first step is to read the sign distribution statistics of historical gradients in the E5M2 quantization boundary region, calculate the estimated value of directional rounding bias, and pre-correct the current gradient element-by-element. The mechanism behind this approach is that the E5M2 format has only two mantissas, and the rounding direction of elements in the quantization boundary region is governed by the RTNE (Round-to-Nearest-Even) odd-even rule. The statistical offset of the sign distribution directly reflects the systematic rounding bias of the quantizer. Since this bias increases linearly with the number of steps during the accumulation of tens to hundreds of steps, without correction, the gradient direction will continuously deviate from the true gradient direction by a fixed angle per step. Pre-correction eliminates the source of this systematic bias accumulation by subtracting a correction amount proportional to the ULP (Unit in the Last Place) from the gradient before quantization.

[0026] Secondly, this method reads the E5M2 encoding of the accumulated value in the accumulator and dequantizes it. It then superimposes this encoding with the current gradient's true value and takes the maximum absolute value as the magnitude estimate. Finally, it dynamically calculates the safety margin ratio based on the accumulation progress to determine the scaling factor. Traditional methods rely solely on the current gradient magnitude to determine the scaling factor, failing to predict the actual peak value after superposition. When the accumulator is nearing saturation and the sign of the current gradient is the same as the value within the accumulator, direct quantization will lead to overflow; when the signs are opposite, the actual superimposed magnitude is far less than the sum of the absolute peak values. This method accurately estimates the accumulated magnitude by superimposing the true values ​​and dynamically reserves headroom (exponential margin) based on the remaining accumulation steps: a larger headroom in the early stages of accumulation to mitigate uncertainty, and a smaller headroom in the later stages to fully utilize the dynamic range. This ensures the scaling factor always matches the accumulator's true capacity, fundamentally eliminating the overflow risk of superlinear growth with increasing accumulation steps under a fixed scaling strategy.

[0027] Finally, the difference between the pre-corrected gradient and the gradient after quantization and dequantization is accumulated into the error residual tensor at each step, and the changing trends of its L2 norm and scaling factor are monitored to drive the precision mode switching. The core of this mechanism is that the error residual directly measures the information loss accumulated during the quantization process, rather than relying on indirect signals such as training loss. When the accumulated error reaches a threshold or the scaling factor drops sharply (indicating a gradient surge), degradation is triggered, which can prevent NaN generation and loss spikes in a timely manner; the cooling period after recovery and the residual reset mechanism avoid frequent mode oscillations. The three measures thus form a complete closed loop: pre-correction eliminates deviations at the source, accumulation-aware scaling prevents abnormal amplification along the path, and error-driven scheduling provides a safety net at the end. The three work together to control the accumulated precision loss of FP8 to near full precision.

[0028] In one embodiment, each gradient element in the current batch gradient tensor is traversed, and the quantized relative distance is calculated: ; in, To quantify relative distance, For if and only if, The first gradient tensor in the current batch One element, This is the E5M2 quantization function. To quantify unit length, This is the boundary tolerance parameter. Gradient elements whose quantized relative distances fall within the preset boundary tolerance interval are marked as boundary region elements. The sign bits of all elements marked as boundary region elements are read, and the instantaneous deviation for the current step is calculated: ; in, For instantaneous deviation, For the set of boundary regions, The total number of elements in the boundary region. The sign function is used. An exponentially weighted moving average is calculated between the historical instantaneous deviation and the current instantaneous deviation using a preset momentum factor. The weighted average result is then output as a smoothed, directional rounding deviation estimate. ; in, This is the estimated value of the directional rounding bias for the next step. The momentum factor of the EMA. This is the estimated directional rounding bias value corresponding to the current step. The correction amount is calculated based on the estimated directional rounding bias value, the quantization unit length, and the sign bit of the gradient element: ; in, This is the correction amount. Subtracting the correction amount from the gradient element magnitude yields the pre-corrected gradient element.

[0029] In one embodiment, the E5M2 encoded value of the accumulated gradient tensor is read from the FP8 accumulator, and the current scaling factor of the FP8 accumulator is obtained. The E5M2 encoded value is then dequantized to floating-point precision using the scaling factor to obtain the dequantized value of the accumulated gradient tensor. The dequantized value of the accumulated gradient tensor is then element-wise added to the current batch of pre-corrected gradient tensors. Each element in the superposition result is iterated over, and its absolute value is taken. The maximum value among all absolute values ​​is used as the estimated superposition amplitude. Based on the ratio of the current accumulation step index to the preset total number of accumulation steps, the safety margin ratio corresponding to the current step is calculated. ; in, For the first The dynamic headroom safety margin ratio of the step. To preset the initial headroom ratio, This is the index of the current cumulative step. To preset the total cumulative iteration rounds, To preset the attenuation shape parameters, the safety margin ratio is limited to a preset upper and lower boundary range. The maximum representable value preset in E5M2 format is read, and the scaling factor of the current batch gradient tensor is calculated. ; in, For the first The cumulative perceptual scaling factor of the step. The maximum representable value preset for E5M2 format. This represents the safety margin ratio for the current step. For the first Dequantize the step accumulator to floating-point precision. The gradient tensor is the pre-corrected gradient tensor for the current batch. The maximum absolute value of the superimposed results. A preset minimum constant is used to prevent division by zero.

[0030] In one embodiment, for non-zero gradient values, the quantization unit length is calculated as: ; in, To quantify unit length, The value v is in E5M2 format. This is a floor function. For zero values, the quantization unit length is the quantization step size corresponding to the minimum positive specification number of E5M2.

[0031] In one embodiment, a floating-point precision error residual tensor is independently assigned to each model parameter layer and initialized to a zero tensor. In each accumulation step, the quantization error is calculated and accumulated according to the following formula: ; in, For the first The quantization error residual tensor of the step, The gradient tensor is the pre-corrected gradient tensor for the current batch. for The gradient tensor after E5M2 quantization and dequantization. The L2 norm of the error residual tensor is calculated as the first monitoring indicator. ; in, As the primary monitoring indicator, Let L2 norm be the error residual tensor. To establish a preset emergency threshold, the rate of change of the scaling factor in consecutive cumulative steps is recorded as a second monitoring indicator. A second flag is output when the scaling factor continuously decreases more than a preset number of times. The preset emergency threshold... The scaling factor is obtained by scaling based on the size of the deep learning model: ; in, This is the scaled emergency threshold. As the baseline emergency threshold, This represents the number of parameters in the current deep learning model. The reference model parameters are used. The temporal variation characteristics of the scaling factor are monitored, and an emergency status flag is output. in, This is an emergency sign. This is a flag indicating that the first monitoring indicator has exceeded a preset emergency threshold. This is a flag indicating that the scaling factor in the second monitoring indicator has decreased more than a preset number of times.

[0032] In one embodiment, upon receiving the emergency status flag, the current cumulative accuracy mode is switched from E5M2 format to high-precision format, and the preset enhancement factor of the deviation correction magnitude is simultaneously increased to the current effective factor. The disappearance of the emergency status flag is monitored. After the emergency status flag disappears, a preset recovery observation period is entered. During the recovery observation period, after continuously confirming that the first monitoring index is below a preset recovery threshold, the high-precision cumulative result is requantized into E5M2 format and written to the accumulator. The error residual tensor is set to zero element by element, the deviation estimate is reinitialized to zero, and a preset cooling cycle counter is started. Responding to new emergency status flags is prohibited until the cooling cycle counter reaches zero.

[0033] In one embodiment, the sign bit of each gradient element in the current batch gradient tensor is traversed to calculate the sign consistency rate: ; in, For symbol consistency flags, The absolute value of the sign of all elements in the gradient tensor is 0.9, indicating that more than 90% of the gradient elements have the same sign. When the sign consistency flag and the emergency state flag are both valid, the preset enhancement factor of the deviation correction magnitude is increased to a higher second enhancement factor; when the sign consistency flag is valid only and the emergency state flag is invalid, only a log record is generated without triggering a mode switch.

[0034] In one embodiment, such as Figure 3 As shown, a sequence diagram illustrates the complete interactive timing of the six core roles in a single-step gradient accumulation process: original gradient, bias correction and scaling, FP8 quantization, FP8 accumulator, error monitoring, and scheduling. Starting from the original gradient input, the process sequentially goes through 6 sub-steps of bias prediction, 2 sub-steps of pre-correction, 4 sub-steps of scaling factor calculation, 3 sub-steps of FP8 quantization and accumulation, 2 sub-steps of error monitoring, and finally to the multi-path branch of scheduling decision, totaling 21 timing nodes, fully depicting the standardized execution flow of single-step accumulation. Figure 3 The diagram also shows the position of the boundary protection mechanism (correction amount not exceeding 50% of the gradient magnitude) in the pre-correction step, and the triggering logic of the hysteresis protection mechanism in the scheduling decision branch.

[0035] In one embodiment, such as Figure 4 As shown, an E5M2 directional rounding bias prediction and pre-correction algorithm flow is provided. After the flow starts, the original gradient tensor is received, and for each gradient element, the relative quantization distance between the original value and the value after E5M2 quantization and dequantization is calculated. ,determination Generate a boundary mask. The time boundary interval is [0.2, 0.8]. For elements outside the boundary region, the deviation statistics are skipped; for elements in the boundary region, the instantaneous deviation is obtained from the sign mean of the statistical values. Smoothed by EMA Output the estimated deviation value. Then perform pre-correction. and apply boundary protection. Output the corrected gradient.

[0036] In one embodiment, such as Figure 5 As shown, a cumulative sensing scaling factor calculation process is provided, with the specific steps being: the input is the pre-corrected gradient. accumulator dequantization value Current step index Total cumulative steps The following steps are executed sequentially: read the accumulator state and dequantize; estimate the maximum accumulated value. ;according to Calculate dynamic headroom and clamp to ;according to Calculate the scaling factor and perform upper and lower limit protection (upper limit to prevent overflow, lower limit to prevent underflow); output the scaling factor and detect a continuous downward trend (trigger an emergency flag when the scaling factor decreases by more than 20% for 5 consecutive steps).

[0037] In one embodiment, such as Figure 6 As shown, an error-driven precision scheduling state transition process is provided, demonstrating the state transition relationship between FP8 normal mode and high-precision backoff mode, including five core states and six state transitions. The initial state is FP8 normal accumulation mode, and the error residual norm is checked after each accumulation step. Scaling factor drops sharply (decreases by more than 20% in 5 consecutive steps), gradient sign consistency rate Three conditions apply. When any emergency condition is met, the system switches from FP8 normal mode via monitoring mode to FP16 high-precision rollback mode (deviation correction enhanced to 1.5 times). If still unstable, it further switches to FP32 mode (deviation correction enhanced to 2.0 times, cooling cycle doubled to 200 steps). Recovery occurs when the cooling cycle (50 steps) reaches zero and the error residual is below [a certain value]. The observation period continues for 50 steps, after which the high-precision mode returns to the FP8 normal mode.

[0038] In one embodiment, such as Figure 7 As shown, the scaling factor calculation basis of the three strategies is compared from the perspective of decision space. Fixed scaling (FP8-LM): The scaling factor is fixed at... Based solely on the current gradient magnitude, without accumulator state awareness, the decision space is a one-dimensional fixed point, and the overflow rate exhibits superlinear growth as the number of accumulation steps increases. Delayed scaling (TransformerEngine): Predicts the scaling factor based on a historical Amax sliding window. The scaling factor lags behind the current true state, and the decision space is a one-dimensional sequence in the time dimension, unable to perceive the remaining capacity of the current accumulator. This invention uses accumulation-aware scaling, with the scaling factor being: ; Simultaneously, the accumulated state of the accumulator and the current gradient true value are used as inputs. The superposition magnitude is accurately estimated by superimposing the true values. The decision space is two-dimensional (accumulator state × current gradient magnitude). The headroom is dynamically adjusted according to the accumulation progress (a larger safety margin in the early stage of accumulation to resist uncertainty, and a smaller safety margin in the later stage of accumulation to make full use of the dynamic range), covering a better scaling decision space. This fundamentally eliminates the risk of the overflow rate growing superlinearly with the number of accumulation steps under a fixed scaling strategy.

[0039] It should be understood that, although Figure 2 , Figures 4-6 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 , Figures 4-6 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0040] In one embodiment, such as Figure 8 As shown, a gradient accumulation optimization system for FP8 mixed-precision training is provided, including: a pre-calibration module 802, an amplitude estimation module 804, an accumulation-aware scaling module 806, and an error-driven scheduling module 808, wherein: The pre-calibration module 802 is used to read the sign distribution statistics of historical gradient tensors in the E5M2 quantization boundary region, calculate the directional rounding deviation estimate based on the sign distribution statistics, use the deviation estimate to perform element-by-element pre-calibration processing on the current batch of gradient tensors, and output the pre-calibrated gradient tensors to the subsequent quantization pipeline.

[0041] The amplitude estimation module 804 is used to read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. The dequantized accumulated gradient tensor is then superimposed element by element with the pre-corrected gradient tensor of the current batch, and the maximum absolute value of the superposition result is calculated as the amplitude estimate.

[0042] The cumulative sensing scaling module 806 is used to dynamically calculate the safety margin ratio based on the current accumulation progress, calculate the scaling factor of the current batch gradient tensor based on the amplitude estimate and the safety margin ratio, perform E5M2 format quantization on the pre-corrected gradient tensor using the scaling factor, and accumulate the quantization result into the FP8 accumulator.

[0043] The error-driven scheduling module 808 is used to calculate the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization in each accumulation step. This difference is accumulated into the floating-point precision error residual tensor. The norm of the error residual tensor is calculated, and the temporal variation characteristics of the scaling factor are monitored. When the norm or temporal variation characteristics meet preset trigger conditions, a precision mode switch is performed, changing the current accumulation mode from E5M2 format to a high-precision format. When a preset recovery condition is met, a reverse switch is performed, remapping the high-precision accumulation result back to E5M2 format.

[0044] Specific limitations regarding the gradient accumulation optimization system for FP8 mixed-precision training can be found in the limitations of the gradient accumulation optimization method for FP8 mixed-precision training described above, and will not be repeated here. Each module in the aforementioned gradient accumulation optimization system for FP8 mixed-precision training can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device in software form, so that the processor can call and execute the corresponding operations of each module.

[0045] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0046] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this 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. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink, DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0047] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0048] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A gradient accumulation optimization method for FP8 mixed-precision training, characterized in that, A deep learning model applied to artificial intelligence infrastructure, the method comprising: Read the sign distribution statistics of the historical gradient tensor in the E5M2 quantization boundary region, calculate the directional rounding deviation estimate based on the sign distribution statistics, use the deviation estimate to perform element-by-element pre-correction processing on the current batch of gradient tensors, and output the pre-corrected gradient tensors to the subsequent quantization pipeline. Read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. Then, add the dequantized accumulated gradient tensor to the current batch of pre-corrected gradient tensors element by element and calculate the maximum absolute value of the superposition result as the amplitude estimate. The safety margin ratio is dynamically calculated based on the current cumulative progress. The scaling factor of the current batch gradient tensor is calculated based on the amplitude estimate and the safety margin ratio. The pre-corrected gradient tensor is quantized using the scaling factor in E5M2 format. The quantization result is accumulated into the FP8 accumulator. In each accumulation step, the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization is calculated. The difference is accumulated into the floating-point precision error residual tensor. The norm of the error residual tensor is calculated and the temporal variation characteristics of the scaling factor are monitored. When the norm or the temporal variation characteristics meet the preset trigger conditions, a precision mode switch is performed, switching the current accumulation mode from E5M2 format to high-precision format. When the preset recovery conditions are met, a reverse switch is performed, remapping the high-precision accumulation result back to E5M2 format.

2. The gradient accumulation optimization method for FP8 mixed-precision training according to claim 1, characterized in that, Read the sign distribution statistics of historical gradient tensors in the E5M2 quantization boundary region, calculate the directional rounding bias estimate based on the sign distribution statistics, and use the bias estimate to perform element-by-element pre-correction processing on the current batch of gradient tensors, including: Iterate through each gradient element in the current batch gradient tensor and calculate the quantized relative distance: in, To quantify relative distance, for, The first gradient tensor in the current batch One element, This is the E5M2 quantization function. To quantify unit length, This refers to the boundary tolerance parameter; Gradient elements whose quantized relative distance falls within a preset boundary tolerance range are marked as boundary region elements; Read the sign bits of all elements marked as boundary regions and calculate the instantaneous deviation for the current step: in, For instantaneous deviation, For the set of boundary regions, The total number of elements in the boundary region. It is a symbolic function; An exponentially weighted moving average is calculated on the historical instantaneous deviation and the current instantaneous deviation using a preset momentum factor. The weighted average result is then output as a smoothed estimate of the directional rounding deviation. in, This is the estimated value of the directional rounding bias for the next step. The momentum factor of the EMA. This is the estimated value of the directional rounding deviation corresponding to the current step; The correction amount is calculated based on the estimated directional rounding bias, the quantization unit length, and the sign bit of the gradient element: in, For correction; The pre-corrected gradient element is obtained by subtracting the correction amount from the magnitude of the gradient element.

3. The gradient accumulation optimization method for FP8 mixed-precision training according to claim 2, characterized in that, The safety margin ratio is dynamically calculated based on the current cumulative progress. The scaling factor of the current batch gradient tensor is calculated based on the amplitude estimate and the safety margin ratio, including: Read the E5M2 encoded value of the accumulated gradient tensor from the FP8 accumulator, obtain the current scaling factor of the FP8 accumulator, and dequantize the E5M2 encoded value to floating-point precision using the scaling factor to obtain the dequantized value of the accumulated gradient tensor. The dequantized value of the accumulated gradient tensor is added to the pre-corrected gradient tensor of the current batch element by element. Each element in the superposition result is traversed and its absolute value is taken. The maximum value among all absolute values ​​is used as the estimated value of the superposition magnitude. Calculate the safety margin ratio for the current step based on the ratio of the current cumulative step index to the preset total cumulative steps: in, For the first The safety margin ratio of the dynamic index margin of the step. This is the proportion of the preset initial index margin. This is the index of the current cumulative step. To preset the total cumulative iteration rounds, To preset attenuation shape parameters, the safety margin ratio is limited to a preset upper and lower boundary range; Read the maximum representable value preset in E5M2 format and calculate the scaling factor of the gradient tensor for the current batch: in, For the first The cumulative perceptual scaling factor of the step. The maximum representable value preset for E5M2 format. This represents the safety margin ratio for the current step. For the first Dequantize the step accumulator to floating-point precision. The gradient tensor is the pre-corrected gradient tensor for the current batch. The maximum absolute value of the superimposed results. A preset minimum constant is used to prevent division by zero.

4. The gradient accumulation optimization method for FP8 mixed-precision training according to any one of claims 1 to 3, characterized in that, For non-zero gradient values, the quantization unit length is calculated as follows: in, To quantify unit length, The value v is in E5M2 format. This is the floor function; For zero values, the quantization unit length is the quantization step size corresponding to the minimum positive specification number of E5M2.

5. The gradient accumulation optimization method for FP8 mixed-precision training according to claim 4, characterized in that, In each accumulation step, the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization is calculated. This difference is accumulated into the floating-point precision error residual tensor. The norm of the error residual tensor is calculated, and the temporal variation characteristics of the scaling factor are monitored, including: For each model parameter layer, an independent floating-point precision error residual tensor is assigned and initialized to zero. In each accumulation step, the quantization error is calculated and accumulated according to the following formula: in, For the first The quantization error residual tensor of the step, The gradient tensor is the pre-corrected gradient tensor for the current batch. for The gradient tensor after E5M2 quantization and dequantization; Calculate the L2 norm of the error residual tensor as the first monitoring indicator: in, As the primary monitoring indicator, Let L2 norm be the error residual tensor. To set a preset emergency threshold, the rate of change of the scaling factor in consecutive cumulative steps is recorded as a second monitoring indicator. When the scaling factor decreases continuously for more than a preset number of times, a second flag is output. Among them, the preset emergency threshold The scaling factor is obtained by scaling based on the size of the deep learning model: in, This is the scaled emergency threshold. As the baseline emergency threshold, This represents the number of parameters in the current deep learning model. For reference model parameter quantities; Monitor the temporal variation characteristics of the scaling factor and output an emergency status flag: in, This is an emergency sign. This is a flag indicating that the first monitoring indicator has exceeded a preset emergency threshold. This is a flag indicating that the scaling factor in the second monitoring indicator has decreased more than a preset number of times.

6. The gradient accumulation optimization method for FP8 mixed-precision training according to claim 5, characterized in that, When the norm or the time series change feature meets the preset triggering condition, the precision mode switch is executed, and the current accumulation mode is switched from E5M2 format to high precision format. When preset recovery conditions are met, a reverse switch is performed to remap the high-precision accumulated results to the E5M2 format, including: Upon receiving the emergency status flag, the current cumulative accuracy mode is switched from E5M2 format to high accuracy format, and the preset enhancement factor of the deviation correction magnitude is simultaneously increased to the current effective factor. The system monitors the disappearance of the emergency status flag. After the emergency status flag disappears, it enters a preset recovery observation period. During the recovery observation period, it continuously confirms that the first monitoring index is lower than the preset recovery threshold. Then, it requantizes the high-precision cumulative result into E5M2 format and writes it into the accumulator. The error residual tensor is set to zero element by element. The deviation estimate is reinitialized to zero. A preset cooling cycle counter is started. Before the cooling cycle counter reaches zero, the system prohibits the response to new emergency status flags.

7. The gradient accumulation optimization method for FP8 mixed-precision training according to claim 6, characterized in that, The steps for setting the preset trigger conditions are as follows: Iterate through the sign bit of each gradient element in the current batch gradient tensor and calculate the sign agreement rate: in, For symbol consistency flags, The mean of the signs of all elements in the gradient tensor; When the symbol consistency flag and the emergency status flag are both valid, the preset enhancement factor of the deviation correction magnitude is increased to a higher second enhancement factor; when the symbol consistency flag is valid alone and the emergency status flag is invalid, only log records are generated and mode switching is not triggered.

8. A gradient accumulation optimization system for FP8 mixed-precision training, characterized in that, The system includes: The pre-calibration module is used to read the sign distribution statistics of historical gradient tensors in the E5M2 quantization boundary region, calculate the directional rounding deviation estimate based on the sign distribution statistics, use the deviation estimate to perform element-by-element pre-calibration processing on the current batch of gradient tensors, and output the pre-calibrated gradient tensors to the subsequent quantization pipeline. The amplitude estimation module is used to read the E5M2 encoded value of the accumulated gradient tensor in the FP8 accumulator and dequantize it to floating-point precision. It then performs element-wise superposition of the dequantized accumulated gradient tensor with the pre-corrected gradient tensor of the current batch and calculates the maximum absolute value of the superposition result as the amplitude estimate. The cumulative sensing scaling module is used to dynamically calculate the safety margin ratio according to the current accumulation progress, calculate the scaling factor of the current batch gradient tensor according to the amplitude estimate and the safety margin ratio, perform E5M2 format quantization on the pre-corrected gradient tensor using the scaling factor, and accumulate the quantization result to the FP8 accumulator. The error-driven scheduling module is used to calculate the difference between the pre-corrected gradient tensor and the corresponding gradient tensor after E5M2 quantization and dequantization in each accumulation step, accumulate the difference into the floating-point precision error residual tensor, calculate the norm of the error residual tensor and monitor the temporal variation characteristics of the scaling factor. When the norm or the temporal variation characteristics meet the preset trigger conditions, a precision mode switch is performed to switch the current accumulation mode from E5M2 format to high precision format; when the preset recovery conditions are met, a reverse switch is performed to remap the high precision accumulation result back to E5M2 format.