Customized autograd: Correct forwards do not replace reverse contracts

Customally defined automatic fractional functions are used to encapsulate special calculations or clear reverse rules.

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

Try to do it after reading

  • Verify custom lead times to the upstream gradient
  • It's a small step from the top

Suggested first

  • Python Basic Syntax:
  • Thick shape with Index

Define an algorithm outside the framework

Customally defined automatic fractional functions are used to encapsulate special calculations or clear reverse rules. Its responsibility is not only to return the correct forward value, but also to return the upstream gradient received for the output to each input according to the chain rule. The two attainments, which are fully consistent, may be trained into different models because of inverse writing errors, and therefore require independent gradient checks.

The marker function y = x 3, output 8 at x = 2, local guide 3 x 2 = 12. If the upstream target is L = 5 y, the custom reverse upstream gradient is 5 and the input gradient should be 5x12 = 60. Only 12 returns ignored the upstream factor and only x 2 missed the factor 3, and neither error was exposed in the forward output test.

Inverse input or intermediate value requirements should be managed according to the preservation mechanism provided by the framework, rather than being randomly placed as untraceable objects. Saves what values relate to memory, in situ modification check and high-level guidance. If the number of Python is used instead of the need for a small volume, the first step may appear to be correct and the second step chart has been broken.

The second degree of the same function is 6 x and 12 at x = 2. Support for the first inverse does not automatically indicate support for the second inverse, especially when the inverse inverts an indisputable external realization. The self-defined algorithm should specify which dtype, which shape and the equipment are to be supported, rather than allowing the user to extrapolate the full capability from a normal execution.

gradcheck commonly uses double accuracy and minor disturbance to compare values with differences, but needs to be remote from the point of view; Random forwards also control conditions. Multiple input times are checked item by item and broadcast input is correctly returned to the original shape. Returns the number of gradients corresponding to the input parameters, and the non-guiding parameters should be treated as agreed at the interface, and cannot block everything into one.

backward receives the lead number for output from the function upstream, not the original label. (b) Customized local guides multiplied by the upstream; When you have more output or more input, the number and order of the return gradient must be interfaced. The actual acceptance shall cover both the front, the different upstream coefficients, the first step, the upper step and the boundary shape, and none of the passages shall replace the others.

Change the upstream gradient from 5 to -2 and what is the input gradient?

For −2x12=−24, the custom reverse must use the actually transferred upstream gradient.

First order gradcheck passes, can you claim second rank?

It is not possible, but it is also necessary to confirm that inverse calculations can form the correct high-level chart and be verified with corresponding high-level checks or independent deferences.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Double Backward with Custom Functions
  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.