Gradient accumulation: different sizes microbatch cannot be easily over-average

The gradient accumulates a number of small batches that together form an update of the parameters and are often used for limited memory training.

• Step by stepCollate in 2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives . 1 first fix

Try to do it after reading

  • Explains the accumulation of gradients: different sizes microbatch cannot simply be over-average mechanisms and prerequisites
  • Positioning the mechanism ' s fault limits with fixed examples

Suggested first

  • Loss attribution and gradient linearity

Issues and mechanisms

The gradient accumulates a number of small batches that together form an update of the parameters and are often used for limited memory training. Equivalence depends on the target denominator, whether the parameters are updated in the middle and on random layers of behaviour. Separated from the fixed cumulative number of losss per batch, the original sample weight may be changed in the event of a difference in the last batch or validity of token.

If the target is an average of all valid token, the individual instalments of loss and the sum of valid token shall be accumulated, and the equivalent value shall be used as the sum of valid token. The average of each sequence is another target. The same parameters should be maintained during the accumulation process, and then cropped and updated only after completion; The status and randomity of some modules may make them not fully equivalent to a large batch, which needs to be explained separately.

A concrete example

The two sets of valid targets were synthesized as three and one, with losses and losses of six and four, respectively. The correct overall mean value is four divided by four, or 2.5; The average of two and four batches is obtained on average. The gradient also follows the corresponding denominator. If only one microbatch is in the last group, the four batches are divided by four, and the update will be additionally reduced. Small data can be saved item by item and gradient, comparing cumulative with direct overall calculations.

Borders and checks

The distribution also requires a check of whether or not rank is valid or averaged, and local valid counts cannot be used as global denominators. The number of batches with a valid goal of zero should be explicitly addressed, avoiding the elimination of zero or pretending to be perfect forecasts. Performance enhancement must be reported under the same statistical objective; A similar training curve is weak evidence and cannot substitute for a gradient equivalent check of fixed values.

A method of verification

The gradient equals test allows the first closing of the random layer, processing three samples in different groups, comparing the final gradient with the updated loss. Adding the last deficit group to confirm that its weight is not diluted by fixed cumulative numbers. If a gradient is used, it must be applied to the target after full accumulation and standardization; A small batch of clippings is usually not equal to pre-packaged cropping. This non-linear boundary is often ignored and needs to be clearly identified in the optimization contract, which does not compensate for any differences by adjusting the learning rate.

Check understanding

What is the overall average of three and one batches, two and four?

Weighted by valid item 2.5, not three. Simple average average batch averages are equal to items only if the two batches have the same number of validity values.

Can you do step for each of the four batches?

That was four updates on different parameters, not a cumulative one; Optimization of trajectories, even if learning rates are reduced elsewhere, is not an equivalent price.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Distributed Data Parallel
  2. PyTorch — Automatic Mixed Precision

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.