Inverse of broadcast: how to retrieve the gradient from the bias used for replication

We'll add one sample to the same sample. bias ♪ When it looks like a front ♪ bias Copy to each line.

Thematic shorts • IntroductionCollate in 2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives 2 first fixes

Try to do it after reading

  • Export shape by broadcast rules
  • Approximate gradient along extended dimensions

Suggested first

  • Python Basic Syntax:
  • Thick shape with Index

Sharing a bias will be used several times over

We'll add one sample to the same sample. bias ♪ When it looks like a front ♪ bias Copy to each line. Reverses the contribution of all use locations to the original bias. Radio does not create independent training parameters for each sample, and one of the gradients is used to optimize the other.

Remove X = [(1,2,3], [4,5,5]], shape to 2x3, bias to [10,20,30], shape to 3. Align the tailings with a forward output [11,22,33], [14,25,36]. If the loss was to be reconciled for all six outputs, with a value of 141, the upstream lead for each output was 1. Thus, each bias received two contributions, with a gradient of [2,2,2].

If the loss is converted to an average of six elements, the upper limit is 1/6 and the bias gradient becomes [1/3, 1/3, 1/3). Can't get a frame. mean Gradient is removed batch size Once, otherwise the repetitions would be normalized. The summation of the shared dimensions and the attribution of the loss itself are two steps, although it is possible to combine algebras and the meaning should be clear.

Broadcasting rules are usually compared from the end dimension and extended by the same length or by one of them. The comparison between the projection of [B] for the mistaken target of [B] and the projection of [B,1] may result in [B, B], and the application still returns the mark loss but no longer corresponds to the sample. A little batch, if it happens to be B = 1, the error may not be visible for the time being.

Therefore, when checking a broadcast, you must also record input, target, parameter and output of shape. For multi-source data, it is particularly important to confirm whether an axis of size 1 is intended to be shared or whether the time or sample dimensions were accidentally lost during upstream aggregation. The dimensions can be automatically extended, not semantic evidence.

Inversely, the summation along the axis of actual expansion should be done and the single dimension retained should be compatible with the original parameter shape. An additional batch axis with a length of 1 may also hide errors and should be checked using input over batches of more than 1. The fixed integer forward and gradient count may be reviewed independently; The actual code should add a different batch size test to avoid using only single samples to cover the wrong axis.

Checks also whether bias is actually shared by features or is misspelled as time-based. The shape assertion does not necessarily reveal errors when the two axes are by chance identical in size; Gives small values in different modes of time and characteristics to determine where each is added.

Review with standard Python

X=[[1,2,3],[4,5,6]]
b=[10,20,30]
out=[[v+b[j] for j,v in enumerate(row)] for row in X]
assert sum(map(sum,out))==141

Only fixed arithmeticals and indexes are validated above and no framework training is called.

Why not each of the biass is not gradient 1?

Because each is used in both rows, the two paths of the overall goal are added to the same parameter.

Would it be the same if the search for peace was changed to an average, but the learning rate remained the same?

No, the gradient is six times smaller. Compare the achievement of the need to align with updated configurations such as reduction and learning rates.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Introduction to PyTorch Tensors
  2. PyTorch — The Fundamentals of Autograd

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.