Gradient crop: Controls the input range for an update

Distinguishing global paradigm and element-by-element tailoring, judging the precision and cumulative order of cropping and mixing.

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

Try to do it after reading

  • Distinguishing global paradigm and element-by-element tailoring
  • Determining the order of accuracy and accumulation of crop and blending

Suggested first

  • Gradient and vector calculations

The scope of the crop resolution

Long series, occasional distress samples or unstable calculation maps may allow a single gradient to be much larger than the normal scale. The global scale is first viewed as a long vector with a gradient of parameters that needs to be updated, scaling as a whole when the threshold is exceeded. This limits the gradient range for sending the optimizer, while retaining the direction of the vector. The crop does not fix the standardization of the wrong labels, overlays or errors, and the frequent triggering itself is itself a signal worthy of diagnosis.

The whole picture here refers to all the gradients involved in this crop, not all of them. If the same threshold is used on a layer-by-layer basis, the total parameters may still increase with the layer; If a group of parameters is omitted, it will not be protected. You need to tell the gradients first, then the threshold size.

Numerical differences between the two operations

The gradient is (3,4), the second parameter is 5 and the threshold is 2. The global scale is multiplied by 2/5 and obtained (1.2,1.6), with a new paradigm of 2, with the ratio of two coordinates remaining at 3:4. Each coordinates are limited to [−2,2] by element, obtain (2,2) and the paradigm is approximately 2.828, and the direction has changed. Thus, the rules “no more than 2 per gradient” and “total no more than 2”.

If the normal gradient is used to decrease and the learning rate is 0.1, then the parameter is moved to (-0.12,-0.16) and the parameter is 0.2. However, in an optimist that drives or adapts to the scaling, the movement of parameters is not necessarily subject to the same simple boundary, as historical states are also involved in the calculation. The gradient threshold cannot be explained directly as the upper limit for moving the parameters of all optimizers.

The order is more important than a line of interfaces

When the gradient accumulates, it should be cropped after a large number of gradients have been formed. Each small batch is then added separately and does not amount to pre-aggression before the latter corresponds to a large number of sub-targets. If the gradient is enlarged in the mix accuracy, the scaling should be lifted and then cropped at the true scale; Otherwise, the threshold meaning changes with the scaling factor. Distributive training also confirms that the crop takes place after the required gradient aggregation has been completed.

It is desirable that surveillance should also record pre-cut parameters, crop scales and a limited number of times. If each step is pressed to the same level, the model may lose useful ranges, and learning rates, lost weights and extreme samples should be examined. When an infinite or non-numbered gradient occurs, scaling does not automatically make it an effective gradient; Anomalous silence should not be swallowed up by clear skipping, misreporting or repairing upstream calculations.

g′=gmin(1,c‖g‖2)

Two tailors for the same gradientOriginal gradient (3,4) parameter 5; Global tailoring (1.2,1.6) and element by element (2,2) are different directions.Original norm: 5Global clipping norm: 2Element clipping norm: 2.828Same coordinate scale · threshold c=2
Original gradient (3,4) parameter 5; Global tailoring (1.2,1.6) and element by element (2,2) are different directions.

Self-measurement and provocator

Gradient (3,4) is cropped by a total paradigm threshold of 2. What is it?

Received (1.2,1.6) a 2-square. Element-by-element tailoring will get (2,2) and not the same operation.

When driving, can a gradient parameter not exceed 2 be guaranteed to move the parameter by no more than 2 bt?

Can't. The historical momentum will also affect this step update. This simple boundary is only directly applicable to gradient decreases without additional state.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — clip_grad_norm_
  2. Boyd and Vandenberghe — Convex Optimization

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.