Activate recalculation: swap intermediate state memory with extra calculation

Reverses require some forward median value.

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

  • Recalculable portion of the location training memory
  • Check randomity and side effects

Suggested first

  • Target function to oversee learning
  • Basic training and validation cycle

You can also calculate the reverse without saving all actives

Reverses require some forward median value. Activate the check point selection to retain only part of the boundary, re-execut the internal forward and restore the required activation when it is reversed. It mainly reduces intermediate saving and does not automatically reduce model weights, optimizer status or input into its own memory.

The chain has four layers, each with 10 MB output. The simple way may keep multiple layers of output; If only one entry and the necessary boundary are retained, the internal activation may be regenerated in reverse. It is not possible simply to claim that the percentage savings are fixed, as what amounts are actually saved, whether there is an internal cache or a segmentation, will change the outcome.

The cost is extra forward calculation. If a period requires 3 milliseconds for the forward, 6 milliseconds for the reverse and 3 milliseconds for the recalculation, then the calculated amount in that paragraph would vary from approximately 9 to 12 milliseconds. This composite example only shows the direction, and real vomiting may also be affected by changes in RAM bandwidth, dispatch and available batches.

Recalculation must represent the same function

When containing a random layer, the recalculation needs to be in a random state corresponding to the previous direction, otherwise the inverse function may not be the one that produces the original output. The framework provides relevant status processing, but still needs to be reconciled across equipment, external random libraries or custom side effects. The additions to the counter, file writing and Python list may also be performed several times during the recalculation.

In particular, updates such as BatchNorm mobile statistics in training are worth checking. If a subparagraph is re-implemented, whether the status side effects are repeated and how the framework mechanism is handled, it should be validated by a small example. The value of loss cannot be seen as fully consistent with the original model.

PyTorch currently offers different options for checkpoint realization, which should be used to select and check its automatic fractional constraints in an official manner, without mechanically following the old example default. The custom function is more likely to test the alignment of the gradient with the complex embedded structure and whether the parameters are updated.

This section activates the re-calculation principle, not the training sustainability check point. Both are called checkpoint, but they handle memory and malfunction recovery separately. 10 MB and the time number are synthesized estimates.

Activating the recalculation automatically reduces Adam 's rectangular memory?

Can't. It is for forward activated preservation and the optimist state belongs to another category of durable training memory.

There's a counter plus one in the recalculation code. Why be careful?

The same logic may be repeated in reverse recalculation, with a change in the number of side effects, a potential contamination state or log.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — torch.utils.checkpoint
  2. Training Deep Nets with Sublinear Memory Cost

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.